====== Safety Properties ====== The classes //SafetyProperties// and //SafetyLevel// offer the the basic functionality for the safety levels. A user has to define their own levels and properties of a given robot in a derived class //MySafetyProperties//. class MySafetyProperties : public eeros::safety::SafetyProperties { Now you can specify the following properties: ===== Critical Inputs and Outputs ===== Define critical output signals, get references to them from the HAL and assign them. eeros::hal::Output* watchdog; eeros::hal::Output* enable0; HAL& hal = HAL::instance(); watchdog = hal.getLogicOutput("watchdog"); enable0 = hal.getLogicOutput("enable0"); ... criticalOutputs = {watchdog, enable0, ...}; Define critical input signals, get references to them from the HAL and assign them. eeros::hal::Input* q0; eeros::hal::Input* runButton; q0 = hal.getScalableInput("q0"); limitSwitchQ0p = hal.getLogicInput("runButton"); ... criticalInputs = {q0, runButton, ...}; ===== Safety Levels ===== Define safety levels. Each level has a unique number and a description. After this the levels have to be added. The order of adding the levels is highly important and determines their logical ordering. Add the lowest safety level first. If you forget to add some levels the safety system will not check its critical inputs and will therefore not run correctly! SafetyLevel slOff("off"); SafetyLevel slIinitializing("initialize"); SafetyLevel slRunning("running"); addLevel(slOff); addLevel(slIinitializing); addLevel(slRunning); ===== Safety Events ===== * Define and add events to the safety levels. A level can have any number of associated events, including zero (no associated events). SafetyEvent seStartInitializing("start initialization"); SafetyEvent seShutDown("shuting down"); SafetyEvent seStartRunning("start running"); slOff.addEvent(seStartInitializing, slIinitializing, kPublicEvent); slIinitializing.addEvent(seStartRunning, slRunning, kPrivateEvent); slRunning.addEvent(seShutDown, slOff, kPublicEvent); ... Each event must be defined **kPublicEvent** or **kPrivateEvent**. Private events can only be fired by the safety system itself whereas public events could also be caused by the //Control System// or the //Sequencer//.\\ It is also possible to add an event to many levels. In the following example we add to all levels from //slPowerOn// onwards the event //seDoEmergency//, which causes a transition to the level //emergency// and which is a public event. // Add events to multiple levels addEventToLevelAndAbove(slPowerOn, seDoEmergency, slEmergency, kPublicEvent); Two more functions serve a similar purpose. // Add events to all levels equal or smaller than srcLevel addEventToLevelAndBelow(srcLevel, event, destLevel, kPublicEvent); // Add events to all levels in between lowerLevel and upperLevel (including lowerLevel and upperLevel) addEventToAllLevelsBetween(lowerLevel, upperLevel, event, destLevel, kPublicEvent); ===== Input and Output Actions ===== Add input and output actions to the safety levels. Each safety level has to specify what is done with all the safety critical inputs and how all the safety critical outputs have to be driven. How this is achieved is described in [[.:io_actions|Input / Output Actions]] ===== Level Actions ===== Define actions for the safety levels. Each level can cause no or one action. slOff.setLevelAction([this](SafetyContext* privateContext) { privateContext->triggerEvent(seDoSwInit); }); The method //setLevelAction// accepts a function, which is used solely here and can be defined without giving it a name. In this example the function is a so called lambda function meaning that it can be passed as a parameter without prior declaration. It must take a parameter itself of type ''SafetyContext''. This ensures that the level function can trigger a private event. === Counter === Each time that the safety system runs in a certain level a counter named ''nofActivations'' is incremented. Whenever the safety level changes due to an event this counter will be reset to 0. This allows for measuring the time the system will run in a given safety level. The following example demonstrates this. slRunning.setLevelAction([this,period](SafetyContext* privateContext) { if (slRunning.getNofActivations() * period >= 60.0) privateContext->triggerEvent(seStop); }); The system will stay for 60 seconds in safety level ''slRunning''. After this time has elapsed it will trigger a ''seStop'' event. ===== Entry Level ===== As a last point, you have to specify with which level the system has to start. setEntryLevel(slOff);