ROS 2 and Gazebo
Integration Best Practices-Michael Carroll & Dharini Dut ia

Outline★ Choosing a ROS 2 and Gazebo Version★ St ruct ure your project★ Creat ing Gazebo syst em plugins t o cont rol cust om simulat or behavior★ Map ROS 2 and Gazebo t opics/ messages using a bridge★ Creat ing or import ing asset s t o be simulat ed★ Running a simulat ion

Choosing a version● Choose a version t hat mat ches any hard project const raint s○ e.g. OS version, ROS version, Gazebo version● Levels of support○ Official binary support ed combinat ions
○ Official source support ed combinat ions
○ Unsupport ed combinat ions

2020
ROS 1

CLASSIC

2021

2022

2023

2024

Gazebo 9
Melodic
Gazebo 11
NoeticCit adelFoxy
Rolling
Edifice

ROS 2

Galactic
Fort ress
HumbleGarden

today

Iron
Gz-H

2025

Noetic

CitadelFoxy

Edifice

Galactic

Fortress

HumbleRolling

Gardenbinaries available
only from source*Binary packages indicat e recommended combinat ionsNoetic

CitadelFoxy

Edifice

Galactic

Fortress

HumbleRolling

Gardenbinaries available
only from source*Binary packages indicat e recommended combinat ionsNoetic

CitadelFoxy

Edifice

Galactic

Fortress

HumbleRollingGardenbinaries available
only from source*Binary packages indicat e recommended combinat ions

ROS 2 and Gazebo
Usage Survey
Statistics*

Diagram text

Though Gazebo Classic is widely used,half of surveyed ROS2 users have alreadyworked wit h Gazebo Fort ress

*Still accepting responses

Structure your ProjectTo get started quickly, use the ros_gz_project_template!

ROS 2 application libraries and nodes
ROS 2 launch files
SDFormat description of simulation assets
Gazebo specific system implementations
https://github.com/gazebosim/ros_gz_project_templateWriting Gazebo Systems● Gazebo syst ems encapsulat e all simulat ion-specific logic● In cont rast t o Gazebo-classic, syst ems aren't specifically at t ached t o models orworlds, but inst ead act upon ent it ies and component s● Syst ems implement various int erfaces t o dict at e behavior
TIP: Check t o see what syst ems have been implement ed before choosing t ocreat e one: ht t ps:/ / git hub.com/ gazebosim/ gz-simThe Entity Component Manager● Every piece ofsimulat ion is an ent it y
● Each ent it y has one
more more component sat t ached t o itWriting Gazebo Systems
APIs system developers can implement:● Configure○ Called when plugin loaded, provided ECM and SDF at t ribut es● PreUpdat e○ Can mut at e ent it ies and component s t o set forces, t orques, velocit ies● Updat e○ Physics updat e, generally should not be implement ed by any ot her syst ems● Post Updat e○ Cannot mut at e, but can read component s and publish/ send event s● Reset○ Can be used t o add reset -specific behavior

The Simulation Loop

Building a Gazebo system in ROS 2● Gazebo syst ems are shared libraries locat ed via environment variables● Wit h ROS 2 , use ament _hooks t o inst all and locat e Gazebo syst ems

Connecting Gazebo and ROS 2
Two primary mechanisms depending on your application:

Use ros_gz_bridge t o
dynamically connect t opics
bet ween ROS 2 and Gazebo

Embed ROS 2 direct ly in aGazebo syst em pluginros_gz

topics

topicsThe bridge isolates Gazebo transport topics and ROS 2 topics.
Each t opic can be connect ed in one direct ion or bidirect ionally.

Configuring ros_gz_bridge

YAML

Command Line Arguments

Embedding ROS 2 in Gazebo

Embedding ROS 2 in Gazebo
BridgeDirectEmbedding

Bridge vs Embedding
ros_gz_bridge

Embedded Node

- Limited to topics and services+ More access to ROS primitives+ Isolates Gazebo and ROS versions- Couples Gazebo and ROS versions+ Isolates Gazebo and ROS runtime- Couples Gazebo and ROS runtime- Access to simulator state only
through exposed transport topics+ Direct access to simulator state

Bonus: In ROS 2, no roscore makes embedding easier than ever!

Simulation Assets● Asset s = models (URDF, SDF, et c), meshes and mat erials, world SDFs
● Can be inst alled as part of ROS 2 packages and export ed as model:/ / orpackage:/ /Creating Assets● Simulat ed models and worlds are definedby SDFormat descript ion files in Gazebo● SDF files can be st at ic (loaded from disk)or dynamically generat ed on t he fly:
○ Using t emplat e languages like ERB○ Using pySDF● Gazebo syst ems are at t ached via t he sdf
plugin t ag

Importing Existing Assets● There is a library of SDF simulat ion asset son Fuel● Support for ot her file format s:○ USD○ Mujoco○ URDF● Assimp loader for ot her mesh format s○ Collada, Blender, glTF

FUEL

app.gazebosim.org/dashboard

Using Assets in ROS
Use sdformat_urdf to share common assets:

Using Assets in ROS
Use sdformat_urdf to share common assets:

Running a simulationExamples of successful integrations

DARPA SubT Challenge

MBZIRC UAV and USV Challenge

MBARI Wave Energy Converter

TurtleBot 4 Simulator

Please fill out the ROS and Gazebo UserSurvey!

Thank you!
Anyquestions?

https://github.com/gazebosim/ros_gz
https://github.com/gazebosim/ros_gz_project_templateMigration Notes for Gazebo -Classic to Gazebo Sim// OLD

class GAZEBO_VISIBLE ArduPilotPlugin:public ModelPlugin// NEW
class GZ_SIM_VISIBLE ArduPilotPlugin:public gz::sim::System,
public gz::sim::ISystemConfigure,public gz::sim::ISystemPostUpdate,public gz::sim::ISystemPreUpdate

Migration Notes for Gazebo -Classic to Gazebo Sim// OLD

virtual void Load(physics::ModelPtr _model,sdf::ElementPtr _sdf);// NEW
void Configure(const gz::sim::Entity &_entity,
const std::shared_ptr<const sdf::Element> &_sdf,
gz::sim::EntityComponentManager &_ecm,
gz::sim::EventManager &_eventMgr);

Migration Notes for Gazebo -Classic to Gazebo Sim// NEW// OLD

void OnUpdate()

void PreUpdate(const gz::sim::UpdateInfo &_info,
gz::sim::EntityComponentManager &_ecm);
void PostUpdate(const gz::sim::UpdateInfo &_info,
const gz::sim::EntityComponentManager &_ecm);