controller

class AbstractController

Generic interface for any controller.

Any controller must inherit from this base class and implement its virtual methods. Polymorphism is used to call the actual implementations.

Subclassed by jiminy::FunctionalController< F1, F2 >

Public Functions

inline virtual GenericConfig getDefaultControllerOptions()

Dictionary gathering the configuration options shared between controllers.

explicit AbstractController() noexcept
virtual ~AbstractController()
virtual void initialize(std::weak_ptr<const Robot> robot)

Initialize the internal state of the controller for a given robot.

This method can be called multiple times with different robots. The internal state of the controller will be systematically overwritten.

Parameters:

robot[in] Robot

void registerConstant(const std::string_view &name, const std::string &value)

Register a constant (so-called invariant) to the telemetry.

The user is responsible to convert it as a byte array (eg std::string), either using toString for arithmetic types or saveToBinary complex types.

Parameters:
  • name[in] Name of the constant.

  • value[in] Constant to add to the telemetry.

template<typename T>
void registerVariable(const std::string_view &name, const T &value)

Dynamically registered a scalar variable to the telemetry. It is the main entry point for a user to log custom variables.

Internally, all it does is to store a reference to the variable, then it logs its value periodically. There is no update mechanism what so ever nor safety check. The user has to take care of the life span of the variable, and to update it manually whenever it is necessary to do so.

Parameters:
  • name[in] Name of the variable. It will appear in the header of the log.

  • values[in] Variable to add to the telemetry.

void registerVariable(const std::vector<std::string> &fieldnames, const Eigen::Ref<VectorX<double>, 0, Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>> &values)

Dynamically registered a Eigen Vector to the telemetry.

Parameters:
  • fieldnames[in] Name of each element of the variable. It will appear in the header of the log.

  • values[in] Eigen vector to add to the telemetry. It accepts non-contiguous temporary.

void registerVariable(const std::vector<std::string> &fieldnames, const Eigen::Ref<VectorX<int64_t>, 0, Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>> &values)
void removeEntries()

Remove all variables dynamically registered to the telemetry.

Note that one must reset Jiminy Engine for this to take effect.

virtual void computeCommand(double t, const Eigen::VectorXd &q, const Eigen::VectorXd &v, Eigen::VectorXd &command) = 0

Compute the command.

It assumes that the robot internal state (including sensors) is consistent with other input arguments. It fetches the sensor data automatically.

Parameters:
  • t[in] Current time.

  • q[in] Current configuration vector.

  • v[in] Current velocity vector.

  • command[out] Output effort vector.

virtual void internalDynamics(double t, const Eigen::VectorXd &q, const Eigen::VectorXd &v, Eigen::VectorXd &uCustom) = 0

Emulate custom phenomenon that are part of the internal dynamics of the system but not included in the physics engine.

Parameters:
  • t[in] Current time.

  • q[in] Current configuration vector.

  • v[in] Current velocity vector.

  • uCustom[in] Output effort vector.

void setOptions(const GenericConfig &controllerOptions)

Set the configuration options of the controller.

Note that one must reset Jiminy Engine for this to take effect.

Parameters:

controllerOptions[in] Dictionary with the parameters of the controller.

const GenericConfig &getOptions() const noexcept

Dictionary with the parameters of the controller.

virtual void configureTelemetry(std::shared_ptr<TelemetryData> telemetryData, const std::string &prefix = {})

Configure the telemetry of the controller.

This method connects the controller-specific telemetry sender to a given telemetry data (which is unique for a given robot), so that it is later possible to register the variables that one want to monitor. Finally, the telemetry recorder logs every registered variables at each timestep in a memory buffer.

Remark

This method is not intended to be called manually. The Engine is taking care of it before flushing the telemetry data at the end of each simulation steps.

Parameters:

telemetryData[in] Shared pointer to the robot-wide telemetry data object

virtual void updateTelemetry()

Update the internal buffers of the telemetry associated with variables monitored by the controller.

As the main entry point for a user to log extra variables, the engine also passes the current state of the robot to enable logging of custom state- related variables.

Remark

This method is not intended to be called manually. The Engine is taking care of it before flushing the telemetry data at the end of each simulation steps.

Parameters:
  • t[in] Current time.

  • q[in] Current position.

  • v[in] Current velocity.

virtual void reset(bool resetDynamicTelemetry = false)

Reset the internal state of the controller.

Note that it resets the configuration of the telemetry.

Remark

This method is not intended to be called manually. The Engine is taking care of it when its own reset method is called.

Parameters:

resetDynamicTelemetry[in] Whether variables dynamically registered to the telemetry must be removed. Optional: False by default.

bool getIsInitialized() const

Whether the controller has been initialized.

Remark

Note that a controller can be considered initialized even if its telemetry is not properly configured. If not, it must be done before being ready to use.

bool getIsTelemetryConfigured() const

Whether the telemetry of the controller has been initialized.

Public Members

std::unique_ptr<const ControllerOptions> baseControllerOptions_ = {nullptr}

Structure with the parameters of the controller.

std::weak_ptr<const Robot> robot_ = {}

Robot for which to compute the command and internal dynamics must be computed.

SensorMeasurementTree sensorMeasurements_ = {}
struct ControllerOptions

Structure with the configuration options shared between controllers.

Public Functions

inline ControllerOptions(const GenericConfig &options)

Public Members

const bool telemetryEnable

Flag used to enable the telemetry of the controller.

template<typename F1 = std::add_pointer_t<FunctionalControllerSignature>, typename F2 = std::add_pointer_t<FunctionalControllerSignature>>
class FunctionalController : public jiminy::AbstractController

Public Functions

explicit FunctionalController(F1 &commandFun, F2 &internalDynamicsFun) noexcept

Remark

A valid ‘callable’ is a function pointer, functor or lambda with signature: void(double t, const Eigen::VectorXd & q, const Eigen::VectorXd & v, const SensorMeasurementTree & sensorMeasurements, Eigen::VectorXd & command) where I is range(n), with n the number of different type of sensor.

Parameters:
  • commandFun[in] ‘Callable’ computing the command.

  • internalDynamicsFun[in] ‘Callable’ computing the internal dynamics.

explicit FunctionalController(F1 &&commandFun, F2 &&internalDynamicsFun) noexcept
virtual ~FunctionalController() = default
virtual void computeCommand(double t, const Eigen::VectorXd &q, const Eigen::VectorXd &v, Eigen::VectorXd &command) override

Compute the command.

It assumes that the robot internal state (including sensors) is consistent with other input arguments. It fetches the sensor data automatically.

Parameters:
  • t[in] Current time

  • q[in] Current configuration vector

  • v[in] Current velocity vector

  • command[out] Output effort vector

virtual void internalDynamics(double t, const Eigen::VectorXd &q, const Eigen::VectorXd &v, Eigen::VectorXd &uCustom) override

Emulate custom phenomenon that are part of the internal dynamics of the system but not included in the physics engine.

Parameters:
  • t[in] Current time.

  • q[in] Current configuration vector.

  • v[in] Current velocity vector.

  • command[in] Output effort vector.