Install Carla-ROS Bridge in Ubuntu 18.04
This article will walk you through the steps to successfully install Carla-ROS bridge in your Ubuntu 18.04 machine. Note that this article is a follow-up of my previous article which explains how to successfully install the Carla simulator and its required dependencies on the same environment.
Before diving on the installation steps let’s first understand what is this frameworks and why would we want it installed in our system.
What is ROS?
ROS stands for Robotic Operating System and it may be defined as a framework for the development of robotic applications using a publish/subscribe communication paradigm. At its core it consists of a number of nodes communicating with each other through specific communication channels, known as topics, each with a supported type of data where different publishers and subscriber nodes of each topic publish and retrieve information.
Many different robotics applications makes use of this framework for developing and testing state-of-the-art robotic-specific applications due to its scalable and flexible architecture. If you would like to have a better understanding of how ROS works internally please take a look at the docs.
What is Carla-ROS Bridge?
Briefly, the Carla-ROS bridge allows the integration of ROS components into a Carla simulation. It offers the means of communicating with a running instance of the simulator externally, using ROS components. Because this communication is two-way it supports both the sending (i.e. vehicle commands, setting weather conditions, etc.) as well as the retrieval (i.e. vehicle information, vehicle status, etc.) of information from the simulation.
Such framework allows multiple use-cases such as to reproduce the simulation’s ego vehicle behavior in a real-world robot (simulation -> ROS) or the use of ROS components to influence the simulation (ROS -> simulation). As you can see this framework allows you to leverage even more the power of the Carla simulator thus extending its capabilities.
Prerequisites
- Carla Simulator (v0.9.9) —(check installation guide here)
- Ubuntu 18.04
ROS Melodic Installation
The installation of ROS melodic (version for Ubuntu 18.04) is pretty straightforward. One just needs to paste the commands presented in the installation page and we’re all set. For convenience I pasted them below.
$ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu (lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'$ sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654$ sudo apt-get update$ sudo apt install ros-melodic-desktop$ echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc$ source ~/.bashrc$ sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential$ sudo rosdep init$ rosdep update
If everything was successful then we can move to the next part of the installation process.
Carla-ROS Bridge Installation
- Clone the Carla-ROS bridge git repository.
$ git clone https://github.com/carla-simulator/ros-bridge.git$ cd ros-bridge$ git checkout tags/0.9.8
Please note that only the version 0.9.8 is only compatible with the version 0.9.9 of the simulator. If you don’t run the last command this will cause future errors when running the bridge.
2. Next up, we just need to follow the below steps for cloning the bridge and initializing the ROS workspace.
#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 ros-bridge$ git submodule update --init$ cd ../catkin_ws/src$ ln -s ../../ros-bridge$ source /opt/ros/melodic/setup.bash$ cd ..
#install required ros-dependencies
$ rosdep update$ rosdep install --from-paths src --ignore-src -r
#build
$ catkin_make
If everything worked correctly then you will be able to start running the bridge.
Running the Bridge
After successfully installing both ROS and the Carla-ROS bridge we are now able to run an instance of the simulator using the bridge.
# Export Carla's distribution to current PYTHON_PATH environment variable so that the bridge components are able to successfully import carla modules$ export PYTHONPATH=<path-to-your-carla-repo>/PythonAPI/carla/dist/carla-0.9.9-py2.7-linux-x86_64.egg:$PYTHONPATH# Source Carla-ROS bridge workspace$ source <path-to-carla-ros-bridge>/carla-ros-bridge/catkin_ws/devel/setup.bash# Launch bridge in synchronous mode so that all the sensors publish information at a fixed time-rate (20 FPS)$ roslaunch carla_ros_bridge carla_ros_bridge_with_example_ego_vehicle.launch synchronous_mode:=true synchronous_mode_wait_for_vehicle_control_command:=false fixed_delta_seconds:=0.05
This will launch a new simulator window in which you can interact exactly the same as if running a simple Carla client. However, ROS support is now enabled and you are free to communicate with the ongoing simulation using the available ROS topics.
Below you can see the available list of topics upon starting a Carla-ROS Bridge execution.
You may run the rostopic echo command to print the contents being published to that topic.
… and that is it! You now have the Carla-ROS bridge installed and you are free to do different experiments with it! You can create new ROS nodes which can retrieve or publish data from or to the topics and thus interact with the current simulation.
!! Potential Issue: NPM Removal !!
Note that by installing ROS-Melodic in Ubuntu 18.04 it will break your current version of npm (and vice-versa) due to dependency conflicts. This is very annoying as you will not be able to run your node-based projects. In case this happens to you then do not desperate, you will be able to still have ROS and NPM successfully installed! Follow the below steps for a workaround I found regarding this issue.
# Install Nodeenv
$ sudo pip install nodeenv# Create new node environment
$ nodeenv <name-of-the-environment>
This creates a virtual environment (similar to virtualenv) to hold node packages directories which are not shared with other environments and thus because the installation is isolated fromthe remaining packages, no conflict will arise and you will be able to successfully install npm packages.
Afterwards, you just need to activate this new node environment whenever you want to work in your node application and pull your dependencies with zero problems:
$ . ./<name-of-the-environment>/bin/activate$ cd /<name-of-the-environment>/src$ npm install
Now you are able to run your node application however you would like. If you want to stop working on the node project just remember to deactivate the environment by running:
$ deactivate_node
Hope you liked this installation guide on how to install the Carla-ROS bridge in Ubuntu 18.04. Please let me know if you have any doubts or if something is broken so that I can fix it asap. Thanks for reading and see you at another time!