ROS 2 Lyrical Luth · Lesson 83 of 86
Building a warehouse simulation
Project: a warehouse world with shelves, aisles, docks and moving obstacles.
Estimated time · 120–180 min
Learning goals
What you will understand
- Explain building a warehouse simulation 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 warehouse simulation combines the world (walls, aisles, shelves, pallets, a charging dock), one or more robots and any moving obstacles such as people or forklifts. Write it as a world SDF with parameterized model poses and a launch file that starts Gazebo, spawns the robots and bridges the topics.
Make it repeatable: fixed random seeds, the same starting poses, and scripted scenarios (deliver a pallet, cross a busy aisle) so you can compare software versions. Log every run to a bag and compute metrics: success rate, time per task, collisions, near misses and recoveries.
Guided lesson
Work through these steps
- 1.
Source the ROS 2 Lyrical environment in a fresh terminal.
- 2.
Read the building a warehouse simulation 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
worlds/warehouse.sdf
# The world: 30 × 20 m, four aisles, twelve shelves, one charging dock.
launch/sim.launch.py
# Starts Gazebo with the world and the ROS bridges.
scenarios/deliver_pallet.yaml
# Scripted task: pick point, drop point, time limit.
ros2 launch warehouse_sim sim.launch.py world:=warehouse.sdf robots:=2
# Start the world with two robots.
ros2 bag record -o run_001 /odom /scan /tf /goal_status
# Record a run for later analysis.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 a warehouse simulation. Expected result: The world starts with 12 shelves
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.
# launch/sim.launch.py
from launch import LaunchDescription
from launch.actions import ExecuteProcess
def generate_launch_description():
# TODO: start Gazebo with the world file worlds/warehouse.sdf, running immediately (-r)
return LaunchDescription([gz])Expected output
The world starts with 12 shelvesStuck? Show the full solution (try it yourself first)
# launch/sim.launch.py
from launch import LaunchDescription
from launch.actions import ExecuteProcess
def generate_launch_description():
gz = ExecuteProcess(cmd=['gz', 'sim', '-r', 'worlds/warehouse.sdf'], output='screen')
return LaunchDescription([gz])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 the warehouse world with twelve shelves and one dock, run a scripted scenario ten times, record bags, and report success rate, average time and number of recoveries.
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.