Running a basic Robotics Simulation with ROS 2#

SVL Simulator release 2021.2.2 or later allow robotics simulations. This document describes the process of setting up a simple robotics simulation that communicates through the ROS 2 bridge.

Table of Contents

Prerequisites top#

  • SVL Simulator release 2021.2.2 or later.
  • Linux operating system (preferably Ubuntu 18.04 or later)

For a guide to setting up and using the simulator see the Getting Started guide.

Installing ROS 2 top#

ROS2 can be installed by following the steps in the official installation guide.

Installing lgsvl_bridge top#

To communicate with the simulator the lgsvl_bridge ROS 2 package is needed. To install it, run:

sudo apt update
sudo apt install ros-$ROS_DISTRO-lgsvl-bridge

The bridge can be launched by running lgsvl_bridge in a terminal where ROS2 is sourced.

Setting up a Simulation top#

To run a simulation, we must have an ego vehicle (CLOi robot) and an environment available on the web user interface as well as a valid sensor configuration. We will go through the steps of setting these up here. To access the web user interface, run the Simulator executable and click OPEN BROWSER. Note that you may need to link to cloud and build an account/login if you have not already done so.

Robot (ego vehicle) top#

To run a robotics simulation a robot ego vehicle is needed. With 2021.2.2 release the CLoi robot has been provided in the Asset Store under Vehicles.


If it is not already added to your library click the red button with a + sign on it to add it. Click on the model to expand it. Under Sensor Configurations there will be several default sensor configurations listed. For example, the Navigation2 configuration, has the basic set of sensors needed for Nav2.

Here we will create a new sensor configuration for basic functionality.

Creating a sensor configuration#

To create a new sensor configuration, click on the configuration icon to the right of the Sensor Configuration title (see below) and in the following page click Add New Configuration.


You will be prompted to give the new configuration a name and choose a Bridge type. Choose ROS 2 from the drop-down (currently only ROS 2 bridge supports robotics).

Adding sensors#

The new configuration will only have a BaseLink connected to it which is the root object used as parent for all subsequent sensors. The position of each sensor will be with respect to BaseLink, whose position is pre-defined by the model designer (usually the center of the wheel accel).

Subsequent sensors can be added by clicking the + button next to the parent object (here BaseLink).


The most basic sensor configuration for robotics only needs a control to subscribe to control commands. The default control plugin for the LG CLoi robot is the Differential Drive Control plugin. It is highly recommended to add the Clock sensor as well.

Clock Sensor top#

Add the Clock sensor by clicking on the + button and searching for it. The location of the sensor is not important and the Frame parameter is unused. The topic name however must be configured to /clock which is the topic ROS 2 expects to see.

Note To effectively use the Clock sensor the use_sim_time param must be set to true for all ROS 2 nodes that deal with time.


Differential Drive Control Sensor top#

The Differential Drive Control Sensor is mainly responsible for subscribing to control commands in the form of a geometry_msgs/Twist ROS 2 message and driving the robot.

In addition, the sensor uses wheel rotations to calculate a dead reckoning type position estimate which is published through a nav_msgs/Odometry type message.

To configure the sensor, populate the fields as seen below.


This sensor requires the path to the links for the left and right wheels of the robot model. For the CLoi robot model these paths are LeftWheelLinkPath: link_MainBody/SuspensionLeft/link/wheel_left/link and RightWheelLinkPath: link_MainBody/SuspensionRight/link/wheel_right/link.

These paths can be found by opening the robot model in Unity and looking at the hierarchy, see below.


This sensor also has an internal PID controller used for controlling the individual wheels. The gain values can be set here, and are by default set to P_Gain: 1, I_Gain: 0.05, D_Gain: 0.

The OdometryTopic is /odom and the OdometryChildFrame is set to odom. The Frame name is set to base_footprint.

The Topic name which refers to the Control Command topic is set to /cmd_vel.

(Optional) Keyboard Control Sensor#

Add the Keyboard Control sensor to enable driving the robot with the keyboard. No configuration is required for this sensor.

Other Sensors top#

The robot model can take any other sensor that supports ROS 2. This includes RGB and Depth Cameras, Lidar, GPS/GNSS, IMU, etc. To see a full list of sensors refer to the Sensor List

Setting up a Simulation top#

Click on the Simulations tab and click Add New to create a new simulation.

  • Enter a Simulation Name and select the Cluster. Click Next.
  • Optional - Enable Interactive Mode to be able to start the simulation at the desired time by pressing a play button in the simulator screen.
  • Select the Random Traffic Runtime Template. Select LGSeocho (or any other map) under Map (if it is not present you will need to go back to the store and add the map to your library). Select the LGCloi ego vehicle and the newly created Sensor Configuration. Click Next.
  • Select Other ROS2 Autopilot under Autopilot and enter the Bridge Connection address (by default localhost:9090).
  • Click Publish

Running a simulation top#

After completing the setup outlined above follow these steps to run a simulation.

  • Start the simulation in the SVL Simulator

  • Run the Simulator binary and click OPEN BROWSER

  • In the web user interface, open the Simulations page, select the recently built simulation and click Run Simulation

  • In a new terminal start the lgsvl_bridge:

source /opt/ros/foxy/setup.bash
  • Once launched you can switch to the simulator window and click the Play button at the bottom of the screen to start the interactive simulation.

  • In a new terminal echo the /odom topic:

source /opt/ros/foxy/setup.bash
ros2 topic echo /odom

You should now see the odometry data published on the screen. You can confirm that it is changing by driving the robot around using the keyboard. Hit Ctrl + C when done to stop echo.

  • Give the robot a control command by running the command below.
source /opt/ros/foxy/setup.bash
ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.2}, angular: {z: 0.2}}" -r 10

You should see the robot driving forward and turning to the left. Play around with the numbers to change its behavior.

For a tutorial on how to autonomously drive the robot using Navigation2 see this document.