Plugin System
MuJoCo ROS uses pluginlib to load simulation extensions at runtime. The core server owns MuJoCo’s global callback hooks and dispatches them to each loaded MujocoPlugin instance.
Plugin Configuration
Plugins are configured under the MujocoPlugins parameter.
The server first searches within its private namespace and then globally.
MujocoPlugins:
- type: package_name/PluginClass
custom_option: 1.0
- type: other_package/OtherPlugin
Each entry must provide type. Additional keys are passed to that plugin as its configuration.
Lifecycle
DiscoveryThe server finds the
MujocoPluginslist on the parameter server.RegistrationEach list entry is checked and the plugin type is resolved through pluginlib.
InstantiationThe plugin instance is created and receives its ROS node handle, configuration, and owning
MujocoEnv.LoadAfter the MuJoCo model and data exist, the plugin receives
mjModelandmjDatapointers and can bind model-specific resources.RunThe server calls plugin callbacks while stepping physics and rendering. Callback order follows the load order.
UnloadPlugins are unloaded when the server shuts down or reloads the model.
Callbacks
Plugins override only the callbacks they need:
controlCallbackruns from MuJoCo’s control callback.passiveCallbackruns from MuJoCo’s passive callback.lastStageCallbackruns at the end of a physics step, before the offscreen render turn for that step. Fromload, a plugin callsMujocoEnv::OpenOffscreenCamera(name),SetGeomGroup,SetVisualFlag, andEnableFrames. While a reload is still in progress those setter calls andEnableFramesare recorded on the handle and applied once the camera exists.GeomGroupEnabled,VisualFlagEnabled, andTakeLatestneed a live camera and throwstd::runtime_errorwith messagecamera is unavailable during reloadif reload is still in progress. While camera retirement is pending, every call on the handle is rejected with the same message. Do not open the handle fromlastStageCallbackor other step callbacks; use the load-time bind and queued settings instead.lastStageCallbackcallsTakeLatestto borrow the previous completed frame. The lease fieldsimulation_time_nsis the simulated time of the rendered state, not wall clock. The handle rebinds by name after reload; a missing name throws. CallingTakeLatestbeforeEnableFrames, or callingEnableFramestwice, throwsstd::logic_error.renderCallbackcan add visualization geoms before a GUI or offscreen scene is rendered.resetlets a plugin clear internal state after a simulation reset.
Warning
A plugin must not replace MuJoCo’s global callback functions directly. The server owns those hooks so it can resolve the active environment and dispatch to all loaded plugin instances.
Reload Behavior
On reload, the server unloads plugins, reloads the model/data, reads plugin configuration again, and loads plugins again. Configuration changes therefore only require a reload, not a full server restart.