Module: StatefulSysModel

class DynParamRegisterer
#include <StatefulSysModel.h>

A short-lived class passed to StatefulSysModel for them to 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 StatefulSysModel as long as the prefix are unique. Second, it exponses only the registerState method from the DynParamManager. This prevents StatefulSysModel 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 thorugh a message, not by sharing a state or property.

Public Functions

inline DynParamRegisterer(DynParamManager &manager, std::string stateNamePrefix)

Constructor

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)

Creates and returns a new state, which will be 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 StatefulSysModel are allowed to use the same state name, however.

This method may optionally be templated to create StateData of subclasses of StateData.

Protected Attributes

DynParamManager &manager

wrapped manager

std::string stateNamePrefix

prefix added to all registered state names

class StatefulSysModel : public SysModel
#include <StatefulSysModel.h>

A SysModel that has continuous-time states.

StatefulSysModel are added on the dynamics task of an MJScene. On its UpdateState method, a StatefulSysModel should call each state’s setDerivative method. This value will be used by the integrator to update the state for the next integrator step.

The sample code below shows how to get the current value of the state and how to set its derivative. In this case, x would follow an exponential trajectory:

void UpdateState(uint64_t CurrentSimNanos) override {
    auto x = this->xState->getState();
    this->xState->setDerivative( x );
}

Public Functions

StatefulSysModel() = default

Default constructor

virtual void registerStates(DynParamRegisterer registerer) = 0

Used to register states on the given DynParamRegisterer.

The main purpose of this method is for this class to call registerState on the registerer. Note that state names should not be repeated within the same StatefulSysModel.

void registerStates(DynParamRegisterer& registerer) override {
    this->posState = registerer.register(3, 1, "pos");
    this->massState = registerer.register(1, 1, "mass");
    // etc.
}