ROS bridge installation

The ROS bridge enables two-way communication between ROS and CARLA. The information from the CARLA server is translated to ROS topics. In the same way, the messages sent between nodes in ROS get translated to commands to be applied in CARLA.


Requirements

ROS Kinetic/Melodic

  • ROS Kinetic/Melodic. Install ROS Melodic, for Ubuntu 18.04, or Kinetic, for Ubuntu 16.04. ROS packages may be required, depending on the user needs. rviz to visualize ROS data.
  • CARLA 0.9.7 or later. Previous versions are not compatible with the ROS bridge. Follow the quick start installation or make the build for the corresponding platform.

Important

Make sure that both CARLA and ROS work properly before continuing with the installation.


Bridge installation

a) Using apt repository

Add the apt repository.

  • Bridge for ROS Melodic.
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 81061A1A042F527D &&
sudo add-apt-repository "deb [arch=amd64 trusted=yes] http://dist.carla.org/carla-ros-bridge-melodic/ bionic main"
  • Bridge for ROS Kinetic.
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 9BE2A0CDC0161D6C &&
sudo add-apt-repository "deb [arch=amd64 trusted=yes] http://dist.carla.org/carla-ros-bridge-kinetic xenial main"

Install the ROS bridge.

sudo apt update &&
sudo apt install carla-ros-bridge-<melodic or kinetic>

b) Using source repository

A catkin workspace is needed to use the ROS bridge. It should be cloned and built in there. The following code creates a new workspace, and clones the repository in there.

#setup folder structure
mkdir -p ~/carla-ros-bridge/catkin_ws/src
cd ~/carla-ros-bridge
git clone https://github.com/carla-simulator/ros-bridge.git
cd catkin_ws/src
ln -s ../../ros-bridge
source /opt/ros/kinetic/setup.bash #Watch out, this sets ROS Kinetic. 
cd ..

#install required ros-dependencies
rosdep update
rosdep install --from-paths src --ignore-src -r

#build
catkin_make

Run the ROS bridge

1) Run CARLA. The way to do so depends on the CARLA installation.

  • Quick start/release package. ./CarlaUE4.sh in carla/.
  • apt installation. ./CarlaUE4.sh in opt/carla/bin/.
  • Build installation. make launch in carla/.

2) Add the source path. The source path for the workspace has to be added, so that the ROS bridge can be used from a terminal.

  • Source for apt ROS bridge.
source /opt/carla-ros-bridge/<melodic or kinetic>/setup.bash
  • Source for ROS bridge repository download.
source ~/carla-ros-bridge/catkin_ws/devel/setup.bash

Important

The source path can be set permanently, but it will cause conflict when working with another workspace.

3) Start the ROS bridge. Use any of the different launch files available to check the installation. Here are some suggestions.

# Option 1: start the ros bridge
roslaunch carla_ros_bridge carla_ros_bridge.launch

# Option 2: start the ros bridge together with RVIZ
roslaunch carla_ros_bridge carla_ros_bridge_with_rviz.launch

# Option 3: start the ros bridge together with an example ego vehicle
roslaunch carla_ros_bridge carla_ros_bridge_with_example_ego_vehicle.launch
ImportError: no module named CARLA
The path to CARLA Python is missing. The apt installation does this automatically, but it may be missing for other installations. Execute the following command with the complete path to the .egg file (included). Use the one supported by the Python version installed.
Note: .egg files may be either in `/PythonAPI/` or `/PythonAPI/dist/` depending on the CARLA installation.
    export PYTHONPATH=$PYTHONPATH:<path/to/carla/>/PythonAPI/<your_egg_file>
Import CARLA from Python and wait for a sucess message to check the installation.
python -c 'import carla;print("Success")'

Setting CARLA

To modify the way CARLA works along with the ROS bridge, edit share/carla_ros_bridge/config/settings.yaml.

  • Host/port. Network settings to connect to CARLA using a Python client.
  • Synchronous mode.
    • If false (default). Data is published on every world.on_tick() and every sensor.listen() callbacks.
    • If true The bridge waits for all the sensor messages expected before the next tick. This might slow down the overall simulation but ensures reproducible results.
  • Wait for vehicle command. In synchronous mode, pauses the tick until a vehicle control is completed.
  • Simulation time-step. Simulation time (delta seconds) between simulation steps. It must be lower than 0.1. Take a look at the documentation to learn more about this.
  • Role names for the Ego vehicles. Role names to identify ego vehicles. These will be controllable from ROS and thus, relevant topics will be created.

Warning

In synchronous mode only the ros-bridge is allowed to tick. Other clients must passively wait.

Synchronous mode

To control the step update when in synchronous mode, use the following topic. The message contains a constant named command that allows to Pause/Play the simulation, and execute a single step.

Topic Message type
/carla/control carla_msgs.CarlaControl


The Control rqt plugin launches a new window with a simple interface. It is used to manage the steps and publish in the corresponding topic. Simply run the following when CARLA in synchronous mode.

rqt --standalone rqt_carla_control