Skip to content

Installing Gazebo for ROS 2 Humble

Guilherme Burkert edited this page Feb 17, 2025 · 1 revision

Installing the correct Gazebo version

To Install the Default Gazebo/ROS Pairing just use:

sudo apt-get install ros-${ROS_DISTRO}-ros-gz

Testing an Example

Launching a simulation

You can try Gazebo using a demo. In this case, simulating a simple differential drive robot in Gazebo that is defined in one of the world examples of Gazebo, called visualize_lidar.sdf. To run this example, execute:

ign gazebo -v 4 -r visualize_lidar.sdf

Configuring ROS 2

To enable communication between the simulation and ROS 2, you need to use a package called ros_gz_bridge, which can be installed by running:

sudo apt-get install ros-humble-ros-ign-bridge

Then to launch a bridge from ROS to Gazebo (in this case, the bridge is for the topic /model/vehicle_blue/cmd_vel), run:

source /opt/ros/humble/setup.bash
ros2 run ros_gz_bridge parameter_bridge /model/vehicle_blue/cmd_vel@geometry_msgs/msg/Twist]ignition.msgs.Twist

Once the bridge is running, will be able to follow your motor commands. There are two options to send a command:

• Send a command to the topic using ros2 topic pub:

ros2 topic pub /model/vehicle_blue/cmd_vel geometry_msgs/Twist "linear: { x: 0.1 }"

• Use the keyboard by installing the teleop_twist_keyboard package:

sudo apt-get install ros-humble-teleop-twist-keyboard

In this case, simply type:

source /opt/ros/humble/setup.bash
ros2 run teleop_twist_keyboard teleop_twist_keyboard --ros-args -r /cmd_vel:=/model/vehicle_blue/cmd_vel

Visualizing lidar data in Rviz2

To send the data generated by Gazebo to ROS 2, you need to launch another bridge. In the case the data from the lidar is provided in the Gazebo Transport topic /lidar2, which you are going to remap in the bridge. This topic then will be available under the topic /lidar_scan:

source /opt/ros/humble/setup.bash
ros2 run ros_gz_bridge parameter_bridge /lidar2@sensor_msgs/msg/LaserScan[ignition.msgs.LaserScan --ros-args -r /lidar2:=/laser_scan

Then, use Rviz2 to visualize the data:

source /opt/ros/humble/setup.bash
rviz2

After that, configure the fixed frame camp to vehicle_blue/lidar_link/gpu_lidar and click the “Add” button to include a display for visualizing the lidar data inside Rviz2.

image

image

By now you should see the data from the lidar in Rviz2:

image

More information

If more information is needed, you can consult the ROS documentation at:

Installing Gazebo with ROS

Configuring Gazebo with ROS 2 Humble