Ubuntu Linux for Robotics · Lesson 60 of 96
Spawning robots in Gazebo
ros_gz_sim create, spawning from robot_description and checking the model.
Estimated time · 45–75 min
Learning goals
What you will understand
- Explain spawning robots in gazebo in your own words
- Use it in a small workstation example
- Verify the result instead of assuming it worked
Understand the idea first
The mental model
Use ros_gz_sim's create tool to put a robot into a running world from the robot_description topic (or a file), giving it a name and a pose. Start Gazebo, robot_state_publisher and the spawner from one launch file so the order is right.
Check the result with gz model --list and in the Gazebo GUI. If the robot falls through the floor or explodes, check its inertia, collision geometry and spawn height. Bridge the /clock topic and set use_sim_time so ROS follows simulated time.
Guided lesson
Work through these steps
- 1.
Open a terminal and record the current state before changing anything.
- 2.
Read the spawning robots in gazebo commands and predict what each one does.
- 3.
Run the commands one at a time and compare each output with your prediction.
- 4.
Write the commands that worked in a setup note you can repeat later.
Worked example
Read it before you run it
ros2 launch ros_gz_sim gz_sim.launch.py gz_args:='-r empty.sdf'
# Start an empty world, running.
ros2 run ros_gz_sim create -name mini_bot -topic robot_description -z 0.1
# Spawn the robot 10 cm above the ground.
gz model --list
# Confirm the model exists in the simulator.
ros2 run ros_gz_bridge parameter_bridge /clock@rosgraph_msgs/msg/Clock[gz.msgs.Clock
# Bridge Gazebo's clock to ROS 2.What the example is doing
- 1.Lines without sudo only inspect or change files you own; sudo authorizes a system-wide change.
- 2.Read command output before moving to the next line. Stop if names, versions, disks, or paths differ from the lesson.
- 3.Comments beginning with # explain safety checks and are not executed by the shell.
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 Spawning robots in Gazebo. Expected result: The model mini_bot appears
Practice code
Now type it yourself
Open a terminal, run the starter line by line (or save it as practice.sh and run bash practice.sh), and replace every TODO with your own command.
# TODO: spawn a model named mini_bot from the robot_description topic at z = 0.1Expected output
The model mini_bot appearsStuck? Show the full solution (try it yourself first)
ros2 run ros_gz_sim create -name mini_bot -topic robot_description -z 0.1Expected result
How you know it worked
- Each command completes without an unexplained error.
- Your notes contain the command, the important output, and what it proves.
Practical exercise
Apply the lesson
Write a launch file that starts Gazebo, robot_state_publisher, the spawner and the clock bridge. Spawn the robot at three different heights and describe what happens.
Before you continue
- You recorded the starting state
- Every command and output is understood
- The change can be repeated from your notes
If something goes wrong
Check ownership and permissions first. Do not add sudo unless the command changes a documented system location.
Check spelling, Ubuntu version, enabled repositories, and whether the previous installation command succeeded.