StatefulSysModel
-
class DynParamRegisterer
- #include <StatefulSysModel.h>
Helper passed to
StatefulSysModelinstances while they register their states.This class serves two purposes. First, it adds a prefix to every state name before registering it on the actual DynParamManager. This prevents state-name collisions between
StatefulSysModelinstances as long as the prefixes are unique. Second, it exposes only theregisterStatemethod from theDynParamManager. This preventsStatefulSysModelinstances from registering properties or accessing the states of other models, which would allow for information to flow between models without going through the message system. If a model needs to access information from another model, it should do so through a message, not by sharing a state or property.Public Functions
-
inline DynParamRegisterer(DynParamManager &manager, std::string stateNamePrefix)
Construct a state-registering helper.
- Parameters:
manager – Underlying dynamics-parameter manager.
stateNamePrefix – Prefix appended to every registered state name.
-
template<typename StateDataType = StateData, std::enable_if_t<std::is_base_of_v<StateData, StateDataType>, bool> = true>
inline StateDataType *registerState(uint32_t nRow, uint32_t nCol, std::string stateName) Create and return a new state managed by the underlying
DynParamManager.The state name should be unique: registering two states with the same name on this class will cause an error. Different
StatefulSysModelinstances are allowed to use the same state name, however.This method may optionally be templated to create StateData of subclasses of
StateData.- Template Parameters:
StateDataType – Concrete state-data type to instantiate.
- Parameters:
nRow – Number of rows in the state storage.
nCol – Number of columns in the state storage.
stateName – State name local to the registering model.
- Returns:
Pointer to the newly registered state object.
Register a shared stochastic noise source across multiple states.
Used when more than one state has dynamics perturbed by the same noise process.
For example, consider the following SDE:
\[ dx_0 = f_0(t,x)\,dt + g_{00}(t,x)\,dW_0 + g_{01}(t,x)\,dW_1 \]\[ dx_1 = f_1(t,x)\,dt + g_{11}(t,x)\,dW_1 \]In this case, state ‘x_0’ is affected by 2 sources of noise and ‘x_1’ by 1 source of noise. However, the source ‘W_1’ is shared between ‘x_0’ and ‘x_1’.
This function is called like:
dynParamManager.registerSharedNoiseSource({ {myStateX0, 1}, {myStateX1, 0} });
which means that the 2nd noise source of the
StateData‘myStateX0’ and the first noise source of theStateData‘myStateX1’ actually correspond to the same noise process.Note
Some stochastic integrators do not support shared noise sources. In this case, this method should raise
std::logic_error.- Parameters:
in – List of state/noise-source-index pairs that share one process.
Protected Attributes
-
DynParamManager &manager
Wrapped manager that owns the registered states.
-
std::string stateNamePrefix
Prefix added to all registered state names.
-
inline DynParamRegisterer(DynParamManager &manager, std::string stateNamePrefix)
-
class StatefulSysModel : public virtual SysModel
- #include <StatefulSysModel.h>
SysModelbase class for modules with continuous-time states.StatefulSysModelinstances are added to the dynamics task of anMJScene. OnUpdateState(), aStatefulSysModelshould call each state’ssetDerivativemethod. That derivative is then used by the integrator to update the state for the next integration step.The sample code below shows how to get the current value of the state and how to set its derivative. In this case,
xwould follow an exponential trajectory:void UpdateState(uint64_t CurrentSimNanos) override { auto x = this->xState->getState(); this->xState->setDerivative( x ); }
Subclassed by MeanRevertingNoise, PIDController< MeasuredPositionMsgPayload, MeasuredVelocityMsgPayload, OutputMsgPayload, DesiredPositionMsgPayload, DesiredVelocityMsgPayload >, StatefulNumbaModel
Public Functions
-
StatefulSysModel() = default
Construct a stateful system model.
-
virtual void registerStates(DynParamRegisterer registerer) = 0
Register this model’s continuous states.
The main purpose of this method is to call
registerStateon the supplied registerer. State names must not be repeated within the sameStatefulSysModelinstance.void registerStates(DynParamRegisterer registerer) override { this->posState = registerer.registerState(3, 1, "pos"); this->massState = registerer.registerState(1, 1, "mass"); // etc. }
- Parameters:
registerer – Helper used to create namespaced state registrations.
-
StatefulSysModel() = default