scenario_AddRWFault
Overview
This script demonstrates how to use event handlers to add reaction wheel faults. The script is found in the folder basilisk/examples/BskSim/scenarios
and executed by using:
python3 scenario_AddRWFault.py
Using event handlers
The event handler class, defined in SimulationBaseClass
, allows the user to define events. These events can be used for a variety of reasons, ranging from changing flight modes to creating faults. The events used in this example are defined in BSK_Dynamics
.
When creating an event handler, the following syntax is used:
SimBase.createNewEvent("eventName", eventRate, eventActive,
conditionList=[], actionList = [])
Within the condition list should be the conditions for executing the event, specified as strings. Likewise, the action list enumerates strings that are executed when the event happens. Because the code parses these strings, rather than having complex conditions or actions in the string literals, it can be convenient to create methods (see the examples below).
By default, after the event has happened once, the eventActive flag is turned to false. For repeated events, this behavior can be overriden by calling the function setEventActivity
. Likewise, the eventActive flags of other events can be set using setAllButCurrentEventActivity
. See the associated documentation for more details.
Setting up the faults
This script uses two event handlers. The first one defines an event that injects a large, one-time static friction fault:
SimBase.createNewEvent("addOneTimeRWFault", self.processTasksTimeStep, True,
["self.TotalSim.CurrentNanos>=self.oneTimeFaultTime and self.oneTimeRWFaultFlag==1"],
["self.DynModels.AddRWFault('friction',0.05,1, self.TotalSim.CurrentNanos)", "self.oneTimeRWFaultFlag=0"])
For this event, the conditions are that the time for the fault has passed, and that the corresponding fault flag is active. The fault time is specified in the scenario script. The oneTimeRWFaultFlag
and the repeatRWFaultFlag
, also set in the scenario script, ensures that the faults are added only for the fault scenario.
The second event handler defines an event that is always active, and adds a smaller static friction fault with small probability:
SimBase.createNewEvent("addRepeatedRWFault", self.processTasksTimeStep, True,
["self.repeatRWFaultFlag==1"],
["self.DynModels.PeriodicRWFault(1./3000,'friction',0.005,1, self.TotalSim.CurrentNanos)", "self.setEventActivity('addRepeatedRWFault',True)"])
Note the command "self.setEventActivity('addRepeatedRWFault',True)"
, keeping the eventActive flag turned on for this event handler. For both event handlers, the particular methods that change the reaction wheel friction parameters are defined in BSK_Dynamics
.
Illustration of Simulation Results
showPlots = True
- scenario_AddRWFault.run(showPlots)[source]
The scenarios can be run with the following parameters:
- Parameters:
showPlots (bool) – Determines if the script should display plots