Class ExternalWrenchPlugin

Nested Relationships

Nested Types

Inheritance Relationships

Base Type

Class Documentation

class ExternalWrenchPlugin : public mujoco_ros2_control_plugins::MuJoCoROS2ControlPluginBase

Plugin that applies one or more external wrenches (force + torque) to named MuJoCo bodies for configurable durations.

Exposes the ROS 2 service ~/apply_wrench of type mujoco_ros2_control_msgs/srv/ApplyExternalWrench.

The service accepts an array of ExternalWrench messages so that multiple wrenches can be submitted atomically in a single call. All wrenches are validated before any are applied: if any body name is unknown the entire request is rejected.

Public Functions

ExternalWrenchPlugin() = default
~ExternalWrenchPlugin() override = default
virtual bool init(rclcpp::Node::SharedPtr node, const mjModel *model, mjData *data) override

Initialize the plugin.

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.

Parameters:
  • node – Shared pointer to the ROS 2 node for accessing parameters

  • model – Pointer to the MuJoCo model

  • data – Pointer to the MuJoCo data

Returns:

true if initialization was successful

virtual void update(const mjModel *model, mjData *data) override

Update the plugin (called every simulation step)

Note

This method will be called at the end of the mujoco_ros2_control read loop, before the update loop of controllers and the write loop. This means that changes to the data here will be visible to controllers and will affect the next simulation step.

Note

This method will be called in a real-time thread, so it should avoid blocking operations and should be efficient.

Parameters:
  • model – Pointer to the MuJoCo model

  • data – Pointer to the MuJoCo data

virtual void cleanup() override

Cleanup the plugin.

void publish_markers(visualization_msgs::msg::MarkerArray &markers) const

Append RViz arrow markers for all currently active wrenches to markers.

This method is additive: existing entries in markers are preserved. It emits nothing when there are no active wrenches, so callers can call it unconditionally and aggregate contributions from multiple plugins before publishing a single MarkerArray.

Marker namespaces: “external_wrench/force” – red arrows, one per active wrench with non-zero force “external_wrench/torque” – cyan arrows, one per active wrench with non-zero torque

Parameters:

markers – MarkerArray to append to.