ros2_control - jazzy
Loading...
Searching...
No Matches
mujoco_ros2_control_plugins::MuJoCoROS2ControlPluginBase Class Referenceabstract

Base class for MuJoCo ROS 2 control plugins. More...

#include <mujoco_ros2_control_plugins_base.hpp>

Inheritance diagram for mujoco_ros2_control_plugins::MuJoCoROS2ControlPluginBase:

Public Member Functions

virtual bool init (rclcpp::Node::SharedPtr node, const mjModel *model, mjData *data)=0
 Initialize the plugin.
virtual void update_read (const mjModel *, mjData *)
 Called once per read() cycle, on the control thread, before the state is handed to ros2_control. Default does nothing.
virtual void update_write (const mjModel *model, mjData *data)
 Called once per write() cycle, on the control thread, after the hardware interface has staged the controller commands and right before they are sent to the simulation.
virtual void update (const mjModel *, mjData *)
 Same as update_write(). Default does nothing.
virtual void pre_step (mjData *)
 Called immediately before every simulation step on the physics thread. Default does nothing.
virtual void on_reset (mjData *)
 Called after a world reset (ResetWorld service or UI reset). Default does nothing.
virtual void cleanup ()=0
 Cleanup the plugin.

Detailed Description

Base class for MuJoCo ROS 2 control plugins.

Plugins extend mujoco_ros2_control with custom behavior, e.g. publishing extra topics or applying external forces.

Four optional hooks are available. Override whichever fits your use case:

  • update_read() runs on the ros2_control control thread, once per read() cycle, before the state is handed to ros2_control. data holds only the per-step control state (time, qpos, qvel, act, qfrc_actuator, sensordata, ctrl); everything else is stale. Plugins run in order and each sees the previous one's changes. Use this to post-process states or sensors, e.g. compensating a force/torque sensor.
  • update_write() runs on the ros2_control control thread, once per write() cycle. data is a recent snapshot, not the live mj_data_. Use this for anything that doesn't need to run on exactly one physics step, e.g. publishing sensor data or servicing a trigger.
  • pre_step() runs on the physics thread, immediately before every mj_step(), with direct access to the live mj_data_. Use this for anything that must hold for exactly one step, e.g. a hard kinematic override. There's no command buffer: an untouched entry keeps its last value, so releasing a command (e.g. an expired force) needs an explicit write. This should be used with caution!
  • on_reset() runs immediately after a world reset, with the live mj_data_ in its post-reset state. Use this to clear plugin state that refers to the pre-reset world, e.g. a latched command.
Note
All hooks must avoid blocking or the control loop or simulation itself will be held up!

Member Function Documentation

◆ cleanup()

◆ init()

virtual bool mujoco_ros2_control_plugins::MuJoCoROS2ControlPluginBase::init ( rclcpp::Node::SharedPtr node,
const mjModel * model,
mjData * data )
pure virtual

Initialize the plugin.

Parameters
nodeShared pointer to the ROS 2 node for accessing parameters
modelPointer to the MuJoCo model
dataPointer to the MuJoCo data
Returns
true if initialization was successful
Note
This method will be called once when the plugin is loaded. It can be used to read parameters, set up publishers/subscribers, etc. The node will be a child of the main mujoco_ros2_control node, so parameters should be namespaced accordingly.

Implemented in external_plugin_test::TestPlugin, mujoco_ros2_control_plugins::BaseVelocityPlugin, mujoco_ros2_control_plugins::CameraPlugin, mujoco_ros2_control_plugins::ExternalWrenchPlugin, mujoco_ros2_control_plugins::FreeJointStatePublisherPlugin, mujoco_ros2_control_plugins::FtsGravCompPlugin, mujoco_ros2_control_plugins::HeartbeatPublisherPlugin, mujoco_ros2_control_plugins::Mujoco3dLidarPlugin, and mujoco_ros2_control_plugins::RangefinderLidarPlugin.

◆ on_reset()

virtual void mujoco_ros2_control_plugins::MuJoCoROS2ControlPluginBase::on_reset ( mjData * )
inlinevirtual

Called after a world reset (ResetWorld service or UI reset). Default does nothing.

Parameters
dataPointer to the live MuJoCo data in its post-reset state.

Reimplemented in external_plugin_test::TestPlugin.

◆ pre_step()

virtual void mujoco_ros2_control_plugins::MuJoCoROS2ControlPluginBase::pre_step ( mjData * )
inlinevirtual

Called immediately before every simulation step on the physics thread. Default does nothing.

USE WITH CAUTION.

Parameters
dataPointer to the live MuJoCo data, can be modified as needed.

Reimplemented in mujoco_ros2_control_plugins::BaseVelocityPlugin, and mujoco_ros2_control_plugins::ExternalWrenchPlugin.

◆ update()

virtual void mujoco_ros2_control_plugins::MuJoCoROS2ControlPluginBase::update ( const mjModel * ,
mjData *  )
inlinevirtual

Same as update_write(). Default does nothing.

Deprecated
Override update_write() instead, to keep it distinct from update_read().
Parameters
modelPointer to the MuJoCo model
dataPointer to a recent snapshot (not the live mj_data_)

◆ update_read()

virtual void mujoco_ros2_control_plugins::MuJoCoROS2ControlPluginBase::update_read ( const mjModel * ,
mjData *  )
inlinevirtual

Called once per read() cycle, on the control thread, before the state is handed to ros2_control. Default does nothing.

Only the control state fields of data are valid (time, qpos, qvel, act, qfrc_actuator, sensordata, ctrl), all from the same physics step. Derived quantities (e.g. site_xpos) are stale: call mj_kinematics() or similar on data if needed. Changes to the control state fields are what ros2_control reads.

Parameters
modelPointer to the MuJoCo model
dataScratch data holding the latest control state, modify it in place

Reimplemented in external_plugin_test::TestPlugin, and mujoco_ros2_control_plugins::FtsGravCompPlugin.

◆ update_write()

virtual void mujoco_ros2_control_plugins::MuJoCoROS2ControlPluginBase::update_write ( const mjModel * model,
mjData * data )
inlinevirtual

Called once per write() cycle, on the control thread, after the hardware interface has staged the controller commands and right before they are sent to the simulation.

Plugins run in order and can read and rewrite ctrl/qfrc_applied. The default forwards to the deprecated update() so plugins that still override it keep working.

Parameters
modelPointer to the MuJoCo model
dataPointer to a recent snapshot (not the live mj_data_)

Reimplemented in external_plugin_test::TestPlugin, mujoco_ros2_control_plugins::CameraPlugin, mujoco_ros2_control_plugins::FreeJointStatePublisherPlugin, mujoco_ros2_control_plugins::HeartbeatPublisherPlugin, mujoco_ros2_control_plugins::Mujoco3dLidarPlugin, and mujoco_ros2_control_plugins::RangefinderLidarPlugin.


The documentation for this class was generated from the following file: