6.6 KiB
ROS bridge installation
- Requirements
- Bridge installation
- a) apt-get ROS bridge
- b) Repository download
- Run the ROS bridge
- Import error: No module named CARLA
- Setting CARLA
The ROS bridge enables two-way communication between ROS and CARLA.
In order to do so, the information from the CARLA server is translated to ROS topics. For example, the information retrieved by sensors is structured to fit ROS structure.
And also vice versa, the messages sent between nodes in ROS get translated to commands to be applied in CARLA. This is commonly used to update the state of a vehicle and apply controllers.
Requirements
ROS melodic
- ROS Kinetic/Melodic: follow the official documentation to install ROS. Some ROS packages could be necessary, depending on the user needs, such as rviz to visualize ROS data.
- CARLA 0.9.7: only this and later versions are supported. 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) apt-get ROS bridge
First add the apt repository:
- Bridge for ROS Melodic:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 81061A1A042F527D &&
sudo add-apt-repository "deb [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 [trusted=yes] http://dist.carla.org/carla-ros-bridge-kinetic xenial main"
Then simply install the ROS bridge:
sudo apt-get update &&
sudo apt-get install carla-ros-bridge
b) Repository download
In order to use the ROS bridge a catkin workspace is needed. The ROS bridge should be cloned and built in there to be available.
The following fragment 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 will depend on the the CARLA installation chosen, so here is a brief summary:
- Quick start/release package: run
./CarlaUE4.sh
in/carla/
. - apt-get installation: run
./CarlaUE4.sh
in/opt/carla/bin/
. - Build installation: run
make launch
in/carla/
.
2) Add the source path: the source path for the workspace should be added so that the ROS bridge can be used from a terminal:
- Source for apt-get 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 added to environment to 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 that will serve to check if the bridge is running properly. 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-get 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, that is supported by the Python version installed:
export PYTHONPATH=$PYTHONPATH:<path/to/carla/>/PythonAPI/<your_egg_file>
!!! Note
.egg files may be either in /PythonAPI/
or /PythonAPI/dist/
depending on the CARLA installation.
To check the installation, import CARLA from Python and wait for a sucess message:
python -c 'import carla;print("Success")'
Setting CARLA
There is some configuration for CARLA available from the ROS bridge. This can be setup by editing the file: share/carla_ros_bridge/config/settings.yaml
.
The parameters available refer to:
- Host/port: the network settings to connect to CARLA using a Python client.
- Synchronous mode:
- If false (default): data is published on every
world.on_tick()
and everysensor.listen()
callbacks. - If true: the bridge waits for all sensor data that is expected before the next tick. This might slow down the overall simulation but ensures reproducible results.
- If false (default): data is published on every
- Wait for vehicle command: in synchronous mode, pauses the tick until a vehicle control is completted.
- 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: a 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 CARLA clients must passively wait.
Synchronous mode
The following topic allows to control the stepping when in synchronous mode:
Topic | Message type |
---|---|
/carla/control |
carla_msgs.CarlaControl |
The message contains a constant named command
that allows to:
- Pause/Play the simulation.
- Execute a single step.
The Control rqt plugin launches a new window with a simple interface to manage these steps and publish in the corresponding topic.
Simply run the following when CARLA is in synchronous mode:
rqt --standalone rqt_carla_control