ROS 2 Lyrical Luth · Lesson 31 of 86
Simulated camera
Camera sensor, image and camera_info bridges and viewing in rqt_image_view.
Estimated time · 45–75 min
Learning goals
What you will understand
- Explain simulated camera 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
A simulated camera is an SDF sensor of type camera with resolution, field of view, update rate and clip distances. It publishes an image plus camera info (intrinsics). Bridge both to sensor_msgs/msg/Image and CameraInfo, or use ros_gz_image for image topics.
Match the field of view and resolution to your real camera so perception code behaves the same. Frame ids must match the optical frame used by your perception nodes. View with ros2 run rqt_image_view rqt_image_view.
Guided lesson
Work through these steps
- 1.
Source the ROS 2 Lyrical environment in a fresh terminal.
- 2.
Read the simulated camera 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
<sensor name="camera" type="camera">
<!-- A colour camera. -->
<update_rate>30</update_rate>
<!-- 30 frames per second. -->
<topic>camera/image</topic>
<!-- Gazebo topic. -->
<camera><horizontal_fov>1.047</horizontal_fov>
<!-- 60 degree field of view (in radians). -->
<image><width>640</width><height>480</height><format>R8G8B8</format></image>
<!-- 640×480 RGB images. -->
<clip><near>0.1</near><far>50</far></clip></camera>
<!-- Objects between 0.1 m and 50 m are drawn. -->
</sensor>
<!-- End of the sensor. -->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 · Sensor view
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 Simulated camera. Expected result: rqt_image_view shows the simulated scene
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.
# TODO: bridge camera/image from Gazebo (gz.msgs.Image) to ROS 2 (sensor_msgs/msg/Image)
ros2 run rqt_image_view rqt_image_viewExpected output
rqt_image_view shows the simulated sceneStuck? Show the full solution (try it yourself first)
ros2 run ros_gz_bridge parameter_bridge /camera/image@sensor_msgs/msg/Image[gz.msgs.Image
ros2 run rqt_image_view rqt_image_viewExpected 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 a 640×480 30 Hz camera to your robot, bridge the image, open it in rqt_image_view, and place a coloured box in front of the robot to confirm it is seen.
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.