This section is a guide on how to install the ROS bridge on Linux for use with ROS 2. You will find the prerequisites, installation steps, how to run a basic package to make sure everything is working well and commands to run tests.
!!! Important ROS is still experimental for Windows. It has only been tested for Linux systems.
You will need to fulfill the following software requirements before using the ROS bridge:
- Install ROS:
- ROS 2 Foxy — For Ubuntu 20.04 (Focal)
- Additional ROS packages may be required depending on your needs. rviz is highly recommended to visualize ROS data.
- CARLA 0.9.11 or later — Previous versions are not compatible with the ROS bridge. Follow the quick start installation or make the build for Linux. It is recommended to match the ROS bridge version to the CARLA version when possible.
!!! Note The Debian package installation is not yet available for ROS 2.
1. Set up the project directory and clone the ROS bridge repository and submodules:
mkdir -p ~/carla-ros-bridge && cd ~/carla-ros-bridge
git clone --recurse-submodules https://github.com/carla-simulator/ros-bridge.git src/ros-bridge
2. Set up the ROS environment:
source /opt/ros/foxy/setup.bash
3. Install the ROS dependencies:
rosdep update
rosdep install --from-paths src --ignore-src -r
4. Build the ROS bridge workspace using colcon:
colcon build
1. Start a CARLA server according to the installation method used to install CARLA:
# Package version in carla root folder
./CarlaUE4.sh
# Debian installation in `opt/carla-simulator/`
./CarlaUE4.sh
# Build from source version in carla root folder
make launch
2. Add the correct CARLA modules to your Python path:
export CARLA_ROOT=<path-to-carla>
export PYTHONPATH=$PYTHONPATH:$CARLA_ROOT/PythonAPI/carla/dist/carla-<carla_version_and_arch>.egg:$CARLA_ROOT/PythonAPI/carla
3. Add the source path for the ROS bridge workspace:
source ./install/setup.bash
4. In another terminal, start the ROS 2 bridge. You can run one of the two options below:
# Option 1, start the basic ROS bridge package
ros2 launch carla_ros_bridge carla_ros_bridge.launch.py
# Option 2, start the ROS bridge with an example ego vehicle
ros2 launch carla_ros_bridge carla_ros_bridge_with_example_ego_vehicle.launch.py
!!! Note
If you receive the error: `ImportError: no module named CARLA` then the path to the CARLA Python API is missing. The apt installation sets the path automatically, but it may be missing for other installations.
You will need to add the appropriate `.egg` file to your Python path. You will find the file in either `/PythonAPI/` or `/PythonAPI/dist/` depending on the CARLA installation. Execute the following command with the complete path to the `.egg` file, using the file that corresponds to your installed version of Python:
`export PYTHONPATH=$PYTHONPATH:path/to/carla/PythonAPI/<your_egg_file>`
It is recommended to set this variable permanently by adding the previous line to your `.bashrc` file.
To check the CARLA library can be imported correctly, run the following command and wait for a success message:
python3 -c 'import carla;print("Success")' # python3
or
python -c 'import carla;print("Success")' # python2
To execute tests using colcon:
1. Build the package:
colcon build --packages-up-to carla_ros_bridge
2. Run the tests:
launch_test carla_ros_bridge/test/ros_bridge_client_ros2_test.py