Architecture
How the gazebo/ colcon workspace is laid out, how sim gazebo builds it, and how the launch files orchestrate simulation startup.
gazebo/ at the repo root is a standard ROS 2 colcon workspace. Package boundaries follow reuse boundaries: the arm is shared across rovers, Viator owns its chassis and complete assembly, and simulation-only behavior stays separate from both descriptions.
gazebo/
├── arm_description/ # shared arm URDF and meshes
├── arm_bringup/ # standalone arm simulation
├── viator_description/ # Viator chassis, complete rover, and sensor xacros
├── viator_sim/ # Viator launch, config, and sensor emulation
├── sim_common/ # shared Python nodes & launch helpers
├── sim_worlds/ # world SDFs, models, and Gazebo GUI config
└── .artifacts/ # generated by colcon, Gazebo, and ArduPilot; gitignored
├── build/
├── install/
├── log/
└── drone/ # SITL EEPROM, terrain cache, logs, and crash dumpsDescription and simulation stay separate
Description packages define geometry, frames, joints, and the simulator annotations attached to that model. Simulation packages contain launch files, controller configuration, bridges, and emulated drivers. Physical subassemblies only get separate description packages when another robot reuses them.
Package types
| Package | Build type | Contains |
|---|---|---|
arm_description | ament_cmake | Shared arm URDF and meshes |
arm_bringup | ament_cmake | Standalone arm launch and config |
viator_description | ament_cmake | Viator chassis, complete assembly, ZED, and GNSS xacros |
viator_sim | ament_python | Viator launch/config plus ZED and GNSS driver emulation |
sim_worlds | ament_cmake | World SDFs, models, and Gazebo GUI config |
sim_common | ament_python | Launch helpers and ROS nodes shared by multiple simulations |
The difference between ament_cmake and ament_python packages is in its project managers.
ament_cmake uses
CMake
with the CMakeLists.txt file while ament_python uses Setup
Tools with the
setup.cfg file.
sim_common
This is a shared package containing cross-package repetitive code & also independent ROS nodes like the joint GUI. Its setup.py registers five console scripts:
| Command | Source | Purpose |
|---|---|---|
move_joints | sim_common/move_joints.py | Publishes a single JointTrajectory and exits. See Moving Joints. |
joint_gui | sim_common/joint_gui.py | Tkinter joint slider GUI. See Moving Joints for usage, or Joint GUI internals below for how it's implemented. |
controller_gui | sim_common/controller_gui.py | Tkinter keyboard-to-virtual-gamepad GUI, for driving a sim without a physical controller. See Running Gazebo. |
drivebase | sim_common/drivebase.py | Sim equivalent of the real rover's drivebase node - converts joystick deflection messages into wheel velocity commands, mirroring urc-2023/src/drivebase. |
arm | sim_common/arm.py | Sim equivalent of the real rover's arm node - jogs the arm's joints from mission-control's arm-mode bindings (sticks, triggers and A/B) via the joint trajectory controller. |
It also exports sim_common/launch_utils.py, a library (not a node) of helpers every <robot>.launch.py imports - get_asset() for resolving files in a package's share directory, plus node/launch-action builders for the Gazebo server, spawning, controllers, and the ROS-Gazebo bridge. See launch_utils.py below for what each helper does.
viator_sim
Alongside Viator's launch/config, this package emulates two of the rover's sensor drivers as ROS nodes, so the sim produces the same topics the real hardware does.
GPS
The chassis carries a simulated u-blox ZED-F9P (viator_description/urdf/viator_gps.urdf.xacro): a gps link mounted level at the centre of the chassis with a gz navsat sensor. The world's <spherical_coordinates> (in mars.world.sdf) place the origin at MDRS (38.4064, -110.7919, 1370 m).
The gz sensor is noise-free and bridged to /viator/gps/navsat as ground truth. The ublox_gps node (viator_sim/ublox_gps.py) republishes it on the same topics the real ublox_gps driver uses:
| Topic | Type |
|---|---|
/ublox_gps_node/fix | sensor_msgs/msg/NavSatFix |
/ublox_gps_node/fix_velocity | geometry_msgs/msg/TwistWithCovarianceStamped (ENU) |
Both use frame_id: gps at 1 Hz. The gps_fix_mode launch argument picks the fix quality: rtk_fixed (default, ~1 cm, STATUS_GBAS_FIX) or standalone (~1.5 m horizontal / 2.5 m vertical with slowly wandering error, STATUS_FIX).
ZED 2i camera
The chassis also carries a simulated StereoLabs ZED 2i (viator_description/urdf/viator_zed.urdf.xacro), mounted on the CAD model's own camera body (the camera link in viator_chassis.urdf.xacro). Its frame tree is ported from StereoLabs' zed_macro.urdf.xacro (zed_camera_link -> zed_camera_center -> zed_left/right_camera_frame -> ..._optical, plus zed_imu_link).
As with the GPS, Gazebo produces noise-free ground truth on /viator/zed/* and /viator/ground_truth/odometry, and the zed_camera node (viator_sim/zed_camera.py) republishes it the way zed-ros2-wrapper v5.x does with its defaults (namespace zed, node zed_node, HD720):
Topic (under /zed/zed_node/) | Type | Notes |
|---|---|---|
rgb/color/rect/image, .../camera_info | sensor_msgs/msg/Image, CameraInfo | bgra8, 1280x720, zed_left_camera_frame_optical, rectified (plumb_bob, D = 0) |
depth/depth_registered, .../camera_info | sensor_msgs/msg/Image, CameraInfo | 32FC1 metres, registered to the left camera. -inf = closer than 0.3 m, +inf = beyond 15 m or no return |
point_cloud/cloud_registered | sensor_msgs/msg/PointCloud2 | 5 Hz, organised 640x360, x y z rgb float32, zed_left_camera_frame (x forward), NaN for invalid |
imu/data, imu/data_raw | sensor_msgs/msg/Imu | 100 Hz, zed_imu_link; data_raw has no orientation |
odom, pose, pose_with_covariance, path_odom, path_map | nav_msgs/msg/Odometry, PoseStamped, ... | visual odometry from ground truth plus about 1% drift; odom -> zed_camera_link |
Images and depth publish at the zed_frame_rate launch argument (default 15 Hz; the real camera grabs at 60). Above 15 Hz the launch file thins the depth rays so their data rate stays constant, which keeps the sim real-time. Like the wrapper, each output is only computed while something subscribes to it.
The point cloud follows the wrapper's depth.point_cloud_freq and depth.point_cloud_res through the zed_point_cloud_freq (default 5 Hz) and zed_point_cloud_res launch arguments. REDUCED (the default) keeps every second pixel for a 640x360 cloud of about 3.7 MB; COMPACT publishes the full 1280x720 (about 14.7 MB). The smaller cloud is what Nav2's costmaps need, and keeps the sim's ROS traffic light enough to bridge to trickfire-urc, which carries point clouds over a more constrained TCP link.
How the real camera is approximated:
- Depth noise follows the stereo model σ = z² · σ_d / (f · B) with σ_d = 0.15 px and B = 0.12 m (about 0.7% at 3 m and 3.5% at 15 m). It is drawn on a coarse grid and upsampled, so it comes in smooth patches like neural depth.
- Depth source: depth comes from a
gpu_lidarco-located with the left camera, resampled into a pinhole image, rather than from a gz depth camera. gz-rendering's depth camera pass crashes on macOS Metal. - Intrinsics: the default
zed_horizontal_fovis typical for a rectified 2i at HD720. To match a specific unit, set it to2 * atan(640 / fx)usingfxfrom[LEFT_CAM_HD]in that camera's/usr/local/zed/settings/SN<serial>.conf. - Not modelled: stereo occlusion holes, depth failures on low-texture surfaces, auto-exposure, loop closure (so
map=odom), the 2i's magnetometer, barometer and temperature topics, and the wrapper'sodom -> zed_camera_linkTF. The sim's robot TF stays authoritative, which matches running the wrapper withpublish_tf:=false.
Rendering sensors on macOS
On macOS, gz sim can't run the server and GUI in one process, so the Viator launch uses split mode there. The server renders its sensors offscreen through Metal. On Linux it uses combined mode, which gives the server a render context.
sim_worlds
Holds the environments and task models robots spawn into:
worlds/mars.world.sdf- Viator's default Mars yard worldgui/gui.configandgz_gui.xml- the Gazebo GUI layout (camera view, panels)models/- task props and reusable world models, includinghammerandperson_walking(static models from Gazebo Fuel, not yet placed in any world) andTTT, optionally spawned ahead of the rover via thetttlaunch argument
Its share/ install path is added to GZ_SIM_RESOURCE_PATH at launch time so Gazebo can find world assets - see the SIM_WORLDS_SHARE handling in cli/gazebo/launch.py.
robots.json
The repo-root robots.json is the CLI's registry of available robots. For each one the object includes these fields:
| Field | Description |
|---|---|
name | User-facing target passed to sim gazebo |
launch_package | Package containing the target's launch file |
launch_file | Launch filename inside that package |
description_package | Description package for a simple target |
description_packages | Description packages for a composed target such as Viator |
url | Optional OnShape assembly URL for an updateable source component |
world_base_link | Whether the exported component is fixed to the world |
collision_boxes | Generate primitive collision proxies from the component's CAD |
model_collisions | Let proxies contact other components in the assembled model |
Simple entries are added automatically by sim gazebo create. Composed targets can override the package and launch fields explicitly. See Adding a New Robot.
collision_boxes and model_collisions are opt-in update settings. When enabled, sim gazebo update fits one box collision proxy around each articulated rigid body and enables contacts with other components in an assembled model. Each proxy gets a non-overlapping collision mask, so generated proxies do not contact each other. The primitive proxies work with Viator's DART physics engine and Bullet collision detector for arm-to-world and arm-to-rover contacts while retaining support for the Mars heightmap.
Entries without a type are OnShape-CAD robots (the default, implied by the presence of url/world_base_link). A "type" field distinguishes robots that don't go through the OnShape pipeline at all - for example the drone, which is entirely hand-authored and flown via ArduPilot SITL (see Drone):
{
"name": "drone",
"type": "ardupilot"
}cli/gazebo/launch.py checks this field to decide whether a robot needs special launch-time environment setup before handing off to ros2 launch.
Building
sim gazebo <robot_name> (see Running Gazebo) drives colcon for you, under the hood it uses a command like this:
$ colcon --log-base .artifacts/log build \
--build-base .artifacts/build --install-base .artifacts/install \
--packages-up-to <launch_package> <description_packages...> sim_worlds sim_common \
--cmake-args -DBUILD_TESTING=OFF--packages-up-to builds only the requested robot's packages plus their dependencies (not every robot in the workspace), so switching robots doesn't force a full rebuild. Generated ROS files live in .artifacts/build/, .artifacts/install/, and .artifacts/log/; ArduPilot keeps its runtime state in .artifacts/drone/. By default sim gazebo <robot_name> deletes the ROS build, install, and log directories first - equivalent to running sim gazebo clean - for a clean rebuild every launch. It preserves .artifacts/drone/; pass --no-build to skip building entirely and reuse the existing install.
Building a single package by hand
$ cd gazebo
$ colcon --log-base .artifacts/log build \
--build-base .artifacts/build --install-base .artifacts/install \
--packages-select arm_description
$ source .artifacts/install/setup.bashUseful when iterating on one package without going through the CLI. Remember to source .artifacts/install/setup.bash afterwards - ROS 2 won't find the package otherwise. See Dev Notes for more.
.artifacts/ is generated
Everything under .artifacts/ is gitignored. Don't edit the ROS build, install, or log
directories - they are wiped on every build. If colcon behaves strangely after unrelated
changes, delete them and rebuild with sim gazebo clean.
Launch system
Each registry target points to a launch package and file. Viator uses gazebo/viator_sim/launch/viator.launch.py; its mechanical test target uses viator_chassis.launch.py. The reusable arm keeps its standalone arm_bringup/launch/arm.launch.py entry point.
Flags
| Argument | Default | Description |
|---|---|---|
rviz | true | Open RViz with the robot's config file |
gui | true | Open the Gazebo GUI |
These are set via command line:
$ ros2 launch arm_bringup arm.launch.py gui:=false rviz:=falseStartup sequence
The launch file orchestrates several components with specific ordering dependencies:
gz_sim with the world file and GUI configSpawn Robot + Robot State Publisher (parallel) - spawns the URDF model into Gazebo and
starts robot_state_publisher with the URDF
Joint State Broadcaster - starts reading joint states from Gazebo once the spawn finishes.
Joint Trajectory Controller - accepts trajectory commands and drives joints, once the broadcaster is ready.
ROS-Gazebo Bridge, RViz, Joint GUI (all in parallel) - bridges /clock between Gazebo
and ROS, opens RViz with the saved config, and opens the Joint GUI with the URDF file.
The robot spawn uses a TimerAction with a 5-second delay to give Gazebo time to fully initialize before the model is spawned. Steps 3 and 4 use RegisterEventHandler with OnProcessExit to enforce ordering -- the trajectory controller can't start until the state broadcaster is ready, and the broadcaster can't start until the robot is spawned.
Components
Gazebo simulation
gz_sim = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(get_package_share_directory("ros_gz_sim"), "launch", "gz_sim.launch.py")
),
launch_arguments={
"gz_args": " ".join(["-r", world_file, "--gui-config", gz_gui_config])
}.items(),
)Launches Gazebo Harmonic with:
-r-- start running immediately (not paused)- The world SDF file from
sim_worlds(default:empty.world.sdf) - A custom GUI config from
sim_worlds/gui/gui.config
URDF processing
robot_desc = xacro.process_file(
urdf_file,
mappings={"controller_config": controller_config},
).toxml()The URDF is processed through xacro at launch time. The controller_config mapping passes the path to the controller YAML so the control xacro can reference it. The result is a fully resolved URDF string used for both spawning and state publishing.
Robot spawn
spawn_robot = Node(
package="ros_gz_sim",
executable="create",
arguments=["-name", "arm", "-string", robot_desc, "-x", "0", "-y", "0", "-z", "0.1"],
)Spawns the robot into the Gazebo world from the processed URDF string. The -z 0.1 offset prevents the robot from spawning inside the ground plane.
Robot state publisher
robot_state_publisher = Node(
package="robot_state_publisher",
executable="robot_state_publisher",
parameters=[{"robot_description": robot_desc}],
)Publishes the robot's TF tree and makes the URDF available on the /robot_description topic. RViz uses this to render the robot model.
Controllers
Two controllers are spawned in sequence:
joint_state_broadcaster-- reads joint states from Gazebo hardware interfaces and publishes them to/joint_statesjoint_trajectory_controller-- listens forJointTrajectorymessages on/joint_trajectory_controller/joint_trajectoryand commands Gazebo to move the joints
The controller configuration lives in config/<robot>.controller.yaml:
controller_manager:
ros__parameters:
use_sim_time: true
update_rate: 60 # Hz
joint_trajectory_controller:
ros__parameters:
joints:
- shoulder_1
- elbow_1
- wrist_1
- wrist_2
command_interfaces:
- position
state_interfaces:
- position
- velocityROS-Gazebo bridge
bridge = Node(
package="ros_gz_bridge",
executable="parameter_bridge",
arguments=["/clock@rosgraph_msgs/msg/Clock[gz.msgs.Clock"],
)Bridges the /clock topic from Gazebo to ROS 2. This is essential for use_sim_time: true -- without it, ROS nodes won't have synchronized time with the simulation.
RViz
Launches RViz2 with a saved config file. Conditional on the rviz launch argument.
Joint GUI
Launches the Tkinter joint control GUI with the URDF file path as an argument. Conditional on the
joint_gui launch argument. See Moving Joints for how to use it,
or Joint GUI internals below for how it's implemented.
launch_utils.py
The sim_common package provides a get_asset() helper used throughout launch files:
from sim_common.launch_utils import get_asset
controller_config = get_asset("arm_bringup", "config", "arm.controller.yaml")It resolves a file path inside a ROS 2 package's share directory and exits with an error if the file doesn't exist. This catches missing files early rather than failing mid-launch.
Writing a custom launch file
If you need to customize a target's launch beyond what sim gazebo create generates, edit the launch file referenced by its robots.json entry. The file is standard ROS 2 launch Python - you can add nodes, change parameters, or modify the startup sequence.
Common customizations:
- Adding sensor bridges (cameras, lidar)
- Changing spawn position
- Adding additional ROS 2 nodes
- Modifying controller parameters