ROS 2 Lyrical Luth · Lesson 35 of 86
Building custom worlds: warehouse, office and outdoor
Writing SDF worlds, including models, lights, physics and reusing model libraries.
Estimated time · 60–90 min
Learning goals
What you will understand
- Explain building custom worlds: warehouse, office and outdoor 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 world file lists a physics configuration, lights and models. Build a warehouse with static shelves and walls, an office with corridors and doors, or an outdoor scene with ground and obstacles. Use <include> to pull ready-made models from Gazebo Fuel instead of modelling everything.
Keep worlds small at first (rendering and physics cost grows with objects), make static things <static>true</static>, and set a realistic physics step (max_step_size 0.001–0.004 s). Save worlds in a package and set GZ_SIM_RESOURCE_PATH so models are found.
Guided lesson
Work through these steps
- 1.
Source the ROS 2 Lyrical environment in a fresh terminal.
- 2.
Read the building custom worlds: warehouse, office and outdoor 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
<sdf version="1.9"><world name="warehouse">
<!-- A new world named warehouse. -->
<physics type="ode"><max_step_size>0.004</max_step_size></physics>
<!-- Physics steps of 4 ms. -->
<include><uri>model://ground_plane</uri></include>
<!-- Reuse a standard ground plane model. -->
<include><name>shelf_1</name><uri>model://shelf</uri><pose>3 0 0 0 0 0</pose></include>
<!-- Place a shelf 3 m along X. -->
<model name="wall_north"><static>true</static><pose>0 5 1 0 0 0</pose><link name="l"><collision name="c"><geometry><box><size>10 0.2 2</size></box></geometry></collision><visual name="v"><geometry><box><size>10 0.2 2</size></box></geometry></visual></link></model>
<!-- A static 10 m wall. -->
</world></sdf>
<!-- End of the world. -->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 Building custom worlds: warehouse, office and outdoor. Expected result: The warehouse world opens with one shelf
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.
<sdf version="1.9">
<world name="warehouse">
<include><uri>model://ground_plane</uri></include>
<!-- TODO: include a shelf model named shelf_1 at position x = 3, y = 0 -->
</world>
</sdf>Expected output
The warehouse world opens with one shelfStuck? Show the full solution (try it yourself first)
<sdf version="1.9">
<world name="warehouse">
<include><uri>model://ground_plane</uri></include>
<include><name>shelf_1</name><uri>model://shelf</uri><pose>3 0 0 0 0 0</pose></include>
</world>
</sdf>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
Build a 10 m × 10 m warehouse world with four walls and three shelves, place your robot inside, drive to each shelf, and create a second, outdoor world with ground and five obstacles.
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.