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

Plugin that publishes the mujoco camera data to ROS 2 topics. More...

#include <camera_plugin.hpp>

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

Public Types

using GlfwInitFn = std::function< int()>
 

Public Member Functions

bool init (rclcpp::Node::SharedPtr node, const mjModel *model, mjData *data) override
 Initialize the plugin.
 
bool init (rclcpp::Node::SharedPtr node, const mjModel *model, mjData *data, GlfwInitFn glfw_init_fn)
 Overload of init() that takes an injectable GLFW initializer.
 
void update_write (const mjModel *model, mjData *data) override
 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.
 
void cleanup () override
 Cleanup the plugin.
 
void trigger_update ()
 Synchronously run a single render/publish cycle in the calling thread.
 
bool is_rendering_available () const
 Whether the rendering thread has successfully initialized its GL context.
 
- 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 (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.
 

Detailed Description

Plugin that publishes the mujoco camera data to ROS 2 topics.

Camera topics can be named in the ROS 2 controls plugins YAML config file and loaded as node parameters. If any of the parameters are not specified, default topic names will be assigned. A user can provide topic names for multiple cameras as long as cameras are not named the same. Name collision is resolved by last name in the yaml file.

Plugin Parameters Structure (and default topics)

mujoco_camera_plugin: type: "mujoco_ros2_control_plugins/CameraPlugin"

All cameras will publish data at the same rate

camera_publish_rate: 6.0 <camera_name>: policy: <policy> # "disabled", "polled", or "streaming" frame_name: <camera_name>_frame info_topic: <camera_name>/camera_info image_topic: <camera_name>/color depth_topic: <camera_name>/depth trigger_service_name: <camera_name>/trigger # only used for polling camera policy

Implementation notes

If the camera name, in the parameters, does not match any of the mujoco cameras the data will not be published to ROS topics. If no camera parameters are given, but the mujoco_camera_plugin and its policy are declared, the default policy (streaming), topics, and frame are used automatically.

Member Typedef Documentation

◆ GlfwInitFn

Signature of the GLFW initializer; injectable for testing.

Member Function Documentation

◆ cleanup()

void mujoco_ros2_control_plugins::CameraPlugin::cleanup ( )
overridevirtual

◆ init() [1/2]

bool mujoco_ros2_control_plugins::CameraPlugin::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.

◆ init() [2/2]

bool mujoco_ros2_control_plugins::CameraPlugin::init ( rclcpp::Node::SharedPtr  node,
const mjModel *  model,
mjData *  data,
GlfwInitFn  glfw_init_fn 
)

Overload of init() that takes an injectable GLFW initializer.

Exists so tests can substitute a fake glfw_init_fn (e.g. one that always fails) to exercise the EGL fallback / rendering-disabled paths without requiring a real display or GL context. The public init() override simply forwards to this overload using the real glfwInit.

Parameters
glfw_init_fnFunction used to attempt GLFW initialization; same signature as glfwInit.

◆ is_rendering_available()

bool mujoco_ros2_control_plugins::CameraPlugin::is_rendering_available ( ) const
inline

Whether the rendering thread has successfully initialized its GL context.

Primarily useful for tests that need to wait for the asynchronous rendering thread to come up before forcing a render.

◆ trigger_update()

void mujoco_ros2_control_plugins::CameraPlugin::trigger_update ( )

Synchronously run a single render/publish cycle in the calling thread.

This mirrors what the rendering thread does on each pass: streaming cameras are always selected, and polled cameras are selected only if their trigger service has been called since the last cycle. It is intended for tests, where it lets the camera selection logic be exercised deterministically without relying on the asynchronous rendering thread or a live GL context.

◆ update_write()

void mujoco_ros2_control_plugins::CameraPlugin::update_write ( const mjModel *  model,
mjData *  data 
)
overridevirtual

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


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