![]() |
ros2_control - kilted
|
Plugin that publishes the mujoco camera data to ROS 2 topics. More...
#include <camera_plugin.hpp>


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. | |
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.
mujoco_camera_plugin: type: "mujoco_ros2_control_plugins/CameraPlugin"
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
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.
| using mujoco_ros2_control_plugins::CameraPlugin::GlfwInitFn = std::function<int()> |
Signature of the GLFW initializer; injectable for testing.
|
overridevirtual |
Cleanup the plugin.
Implements mujoco_ros2_control_plugins::MuJoCoROS2ControlPluginBase.
|
overridevirtual |
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 |
Implements mujoco_ros2_control_plugins::MuJoCoROS2ControlPluginBase.
| 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.
| glfw_init_fn | Function used to attempt GLFW initialization; same signature as glfwInit. |
|
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.
| 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.
|
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.
| model | Pointer to the MuJoCo model |
| data | Pointer to a recent snapshot (not the live mj_data_) |
Reimplemented from mujoco_ros2_control_plugins::MuJoCoROS2ControlPluginBase.