ros2_control - kilted
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
mujoco_ros2_control_plugins::BaseVelocityPlugin Class Reference

Drives a mobile/floating-base robot from a commanded planar body velocity (vx, vy, yaw-rate) by writing a hard kinematic override of the base's free-joint velocity directly into data->qvel every cycle. More...

#include <base_velocity_plugin.hpp>

Inheritance diagram for mujoco_ros2_control_plugins::BaseVelocityPlugin:
Inheritance graph
[legend]
Collaboration diagram for mujoco_ros2_control_plugins::BaseVelocityPlugin:
Collaboration graph
[legend]

Public Member Functions

bool init (rclcpp::Node::SharedPtr node, const mjModel *model, mjData *data) override
 Initialize the plugin.
 
void pre_step (mjData *data) override
 Called immediately before every simulation step on the physics thread. Default does nothing.
 
void cleanup () override
 Cleanup the plugin.
 
- Public Member Functions inherited from mujoco_ros2_control_plugins::MuJoCoROS2ControlPluginBase
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 on_reset (mjData *)
 Called after a world reset (ResetWorld service or UI reset). Default does nothing.
 

Detailed Description

Drives a mobile/floating-base robot from a commanded planar body velocity (vx, vy, yaw-rate) by writing a hard kinematic override of the base's free-joint velocity directly into data->qvel every cycle.

Wheel-terrain friction/slip modelling is often unreliable enough to make it a poor foundation for testing navigation stacks. This plugin instead subscribes to a cmd_vel-style topic and, every cycle, writes the (optionally clamped) commanded planar velocity directly into the base body's free-joint qvel entries in data. There is no gain to tune and no convergence delay: the measured body velocity on the driven DOFs is exactly the commanded velocity on the very next simulation step.

The trade-off is that the driven DOFs cannot be influenced by anything else – not contacts, not forces from other bodies rigidly mounted on the base (e.g. a swinging arm). They are simply reasserted every cycle regardless of what the physics engine computed in between.

Only the planar DOFs are driven: world-frame linear x/y (converted from the commanded body-frame vx/vy via the body's current orientation) and body-local yaw-rate about z. Vertical linear velocity and local roll/pitch are left untouched every cycle, so gravity and contacts continue to settle the base onto the ground normally.

Configuration parameters (declared under "mujoco_plugins.<instance_name>.")

body (string, required) - MJCF body name of the base. Must have a <freejoint>; init() fails otherwise, since there is no qvel to override without one. cmd_vel_topic (string, default "cmd_vel") - command topic name. use_stamped_twist (bool, default false) - subscribe to geometry_msgs/TwistStamped instead of geometry_msgs/Twist. max_linear_velocity (double, default +inf) - clamps the commanded planar speed sqrt(vx^2+vy^2) [m/s]; direction is preserved when scaled down. max_yaw_rate (double, default +inf) - clamps the commanded yaw-rate [rad/s]. cmd_timeout (double, default 0.5) - seconds since the last command after which it is treated as zero (safety stop).

Member Function Documentation

◆ cleanup()

void mujoco_ros2_control_plugins::BaseVelocityPlugin::cleanup ( )
overridevirtual

◆ init()

bool mujoco_ros2_control_plugins::BaseVelocityPlugin::init ( rclcpp::Node::SharedPtr  node,
const mjModel *  model,
mjData *  data 
)
overridevirtual

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.

Implements mujoco_ros2_control_plugins::MuJoCoROS2ControlPluginBase.

◆ pre_step()

void mujoco_ros2_control_plugins::BaseVelocityPlugin::pre_step ( mjData *  )
overridevirtual

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 from mujoco_ros2_control_plugins::MuJoCoROS2ControlPluginBase.


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