ROS 2 Lyrical Luth · Lesson 29 of 86
Gazebo plugins: sensors and controllers
System plugins, sensor plugins and the ros2_control Gazebo plugin.
Estimated time · 60–90 min
Learning goals
What you will understand
- Explain gazebo plugins: sensors and controllers in your own words
- Use it in a small robotics example
- Verify the result instead of assuming it worked
Understand the idea first
The mental model
Plugins add behaviour to a simulation. World-level system plugins provide physics, the scene broadcaster and the sensors system. Sensor plugins simulate lidars, cameras and IMUs and publish on Gazebo topics. Model plugins can drive joints, for example the gz_ros2_control system that connects Gazebo to ros2_control.
In a URDF the plugin goes inside <gazebo> tags. After adding one, use gz topic -l to see the new topics and bridge the ones ROS 2 needs. A missing system plugin (for example sensors) is the most common reason a sensor publishes nothing.
Guided lesson
Work through these steps
- 1.
Source the ROS 2 Lyrical environment in a fresh terminal.
- 2.
Read the gazebo plugins: sensors and controllers example and identify what each line does.
- 3.
Build only the affected package, source the workspace overlay, and run the example.
- 4.
Inspect the result from a second terminal with the ros2 CLI or RViz2 and compare it with the expected result.
Worked example
Read it before you run it
<gazebo>
<!-- Simulation-only extension in the URDF. -->
<plugin filename="gz_ros2_control-system" name="gz_ros2_control::GazeboSimROS2ControlPlugin">
<!-- Connects ros2_control to Gazebo. -->
<parameters>$(find robot_bringup)/config/controllers.yaml</parameters>
<!-- The controller configuration to load. -->
</plugin>
<!-- End of the plugin. -->
</gazebo>
<!-- End of the extension. -->What the example is doing
- 1.The ros2 commands query the running graph; they do not prove that a node's internal behavior is correct.
- 2.Build from the workspace root, then source install/setup.bash so the shell can discover the new package.
- 3.Use a second sourced terminal to inspect nodes and interfaces while the example runs.
Watch it run · Mobile robot
See what this code does
The terminal types this lesson's practice solution and runs it. The scene shows the kind of robot behaviour that code drives. It plays by itself and loops.
Demo for Gazebo plugins: sensors and controllers. Expected result: gz_ros2_control loads and controllers become available
Practice code
Now type it yourself
Copy the starter into your ROS 2 package, replace every TODO, then build with colcon build and run it from a sourced terminal.
<gazebo>
<!-- TODO: add the plugin gz_ros2_control::GazeboSimROS2ControlPlugin from file gz_ros2_control-system -->
</gazebo>Expected output
gz_ros2_control loads and controllers become availableStuck? Show the full solution (try it yourself first)
<gazebo>
<plugin filename="gz_ros2_control-system" name="gz_ros2_control::GazeboSimROS2ControlPlugin">
<parameters>config/controllers.yaml</parameters>
</plugin>
</gazebo>Expected result
How you know it worked
- ROS_DISTRO is lyrical in every terminal used for the exercise.
- The complete package from the exercise builds and the expected graph entity appears in a second terminal.
Practical exercise
Apply the lesson
Add the ros2_control Gazebo plugin to your robot, load joint_state_broadcaster, and confirm /joint_states appears. Then remove the sensors system plugin from the world and note what stops.
Before you continue
- ROS_DISTRO reports lyrical in every terminal you used
- The example builds and runs without errors
- You checked the result with a ros2 command, RViz2 or a test, not just by reading the code
If something goes wrong
Source /opt/ros/lyrical/setup.bash, build from the workspace root, then source install/setup.bash in that terminal.
Confirm both terminals use Lyrical, the same ROS_DOMAIN_ID, and compatible network/discovery settings.