ros2_control - kilted
Loading...
Searching...
No Matches
Public Member Functions | List of all members
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:
Inheritance graph
[legend]

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:

Note
All hooks must avoid blocking or the control loop or simulation itself will be held up!

Member Function Documentation

◆ cleanup()

virtual void mujoco_ros2_control_plugins::MuJoCoROS2ControlPluginBase::cleanup ( )
pure virtual

◆ 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: