![]() |
ros2_control - kilted
|
Base class for MuJoCo ROS 2 control plugins. More...
#include <mujoco_ros2_control_plugins_base.hpp>

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. | |
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.
|
pure virtual |
Cleanup the plugin.
Implemented in 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, mujoco_ros2_control_plugins::RangefinderLidarPlugin, and external_plugin_test::TestPlugin.
|
pure virtual |
Initialize the plugin.
| node | Shared pointer to the ROS 2 node for accessing parameters |
| model | Pointer to the MuJoCo model |
| data | Pointer to the MuJoCo data |
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.
|
inlinevirtual |
Called after a world reset (ResetWorld service or UI reset). Default does nothing.
| data | Pointer to the live MuJoCo data in its post-reset state. |
Reimplemented in external_plugin_test::TestPlugin.
|
inlinevirtual |
Called immediately before every simulation step on the physics thread. Default does nothing.
USE WITH CAUTION.
| data | Pointer to the live MuJoCo data, can be modified as needed. |
Reimplemented in mujoco_ros2_control_plugins::BaseVelocityPlugin, and mujoco_ros2_control_plugins::ExternalWrenchPlugin.
|
inlinevirtual |
Same as update_write(). Default does nothing.
update_write() instead, to keep it distinct from update_read(). | model | Pointer to the MuJoCo model |
| data | Pointer to a recent snapshot (not the live mj_data_) |
|
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.
| model | Pointer to the MuJoCo model |
| data | Scratch data holding the latest control state, modify it in place |
Reimplemented in external_plugin_test::TestPlugin, and mujoco_ros2_control_plugins::FtsGravCompPlugin.
|
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.
| model | Pointer to the MuJoCo model |
| data | Pointer 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.