carla/Docs/ros_installation.md

179 lines
8.1 KiB
Markdown
Raw Normal View History

# ROS bridge installation
2020-02-24 23:40:57 +08:00
2020-09-24 00:40:37 +08:00
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__](#requirements)
* [Python version](#python-version)
* [__Bridge installation__](#bridge-installation)
* [A. Using Debian repository](#a-using-debian-repository)
* [B. Using source repository](#b-using-source-repository)
* [__Run the ROS bridge__](#run-the-ros-bridge)
* [__Setting CARLA__](#setting-carla)
2020-09-24 00:40:37 +08:00
!!! Important
ROS is still [experimental](http://wiki.ros.org/noetic/Installation) for Windows, so the ROS bridge has only been tested for Linux systems.
2020-02-24 23:40:57 +08:00
---
## Requirements
2020-02-24 23:40:57 +08:00
2020-09-20 16:53:48 +08:00
Make sure that both requirements work properly before continuing with the installation.
2020-02-24 23:40:57 +08:00
* __ROS Kinetic/Melodic__ — Install the ROS version corresponding to your system. Additional ROS packages may be required, depending on the user needs. [rviz](http://wiki.ros.org/rviz) is highly recommended to visualize ROS data.
2020-09-28 20:45:17 +08:00
* [__ROS Kinetic__](http://wiki.ros.org/kinetic/Installation) — For Ubuntu 16.04 (Xenial).
* [__ROS Melodic__](http://wiki.ros.org/melodic/Installation/Ubuntu) — For Ubuntu 18.04 (Bionic).
* [__ROS Noetic__](http://wiki.ros.org/noetic#Installation) — For Ubuntu 20.04 (Focal).
2020-09-24 00:40:37 +08:00
* __CARLA 0.9.7 or later__ — Previous versions are not compatible with the ROS bridge. Follow the [quick start installation](start_quickstart.md) or make the build for [Linux](build_linux.md).
2020-09-20 16:53:48 +08:00
### Python version
2020-02-24 23:40:57 +08:00
The Python version needed to run the ROS bridge depends on the ROS version being used.
2020-09-17 05:06:42 +08:00
2020-09-28 20:45:17 +08:00
* __ROS Kinetic__ and __ROS Melodic__ — Python2.
* __ROS Noetic__ — Python3.
2020-09-20 16:53:48 +08:00
CARLA provides different Python support depending on the installation method. Here is a summary.
2020-09-17 05:06:42 +08:00
* __CARLA release packages__ — Provide support for Python2 and Python3, so these can be used with any ROS version.
* __Windows build__ — Provides Support for the default Python installation in the system, so the ROS installation should match this.
* __Linux build__ — Provides support for Python3 by default (ROS Noetic). If Python2 is needed, the PythonAPI can be built for Python2 running the following command in the CARLA root directory.
2020-09-17 05:06:42 +08:00
```sh
make PythonAPI ARGS="--python-version=2" # The numeric argument can be changed to build for any specific Python version
2020-09-17 05:06:42 +08:00
```
---
## Bridge installation
2020-02-24 23:40:57 +08:00
2020-09-17 05:06:42 +08:00
!!! Important
To install ROS bridge versions prior to 0.9.10, change to a previous version of the documentation using the pannel in the bottom right corner of the window, and follow the old instructions. ![docs_version_panel](img/docs_version_panel.jpg)
2020-09-17 05:06:42 +08:00
2020-09-02 17:14:55 +08:00
### A. Using Debian repository
2020-02-24 23:40:57 +08:00
2020-09-02 17:14:55 +08:00
Set up the Debian repository in the system.
2020-02-24 23:40:57 +08:00
```sh
2020-09-01 16:27:17 +08:00
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1AF1527DE64CB8D9
sudo add-apt-repository "deb [arch=amd64] http://dist.carla.org/carla $(lsb_release -sc) main"
2020-02-24 23:40:57 +08:00
```
2020-09-02 17:14:55 +08:00
Install the ROS bridge, and check for the installation in the `/opt/` folder.
2020-02-26 00:16:27 +08:00
```sh
2020-09-02 17:14:55 +08:00
sudo apt-get update # Update the Debian package index
2020-09-01 16:27:17 +08:00
sudo apt-get install carla-ros-bridge # Install the latest ROS bridge version, or update the current installation
2020-02-26 00:16:27 +08:00
```
2020-09-01 16:27:17 +08:00
This repository contains features from CARLA 0.9.10 and later versions. To install a specific version add the version tag to the installation command.
2020-02-24 23:40:57 +08:00
```sh
2020-09-20 16:53:48 +08:00
sudo apt-get install carla-ros-bridge=0.9.10-1 # In this case, "0.9.10" refers to the ROS bridge version, and "1" to the Debian revision
2020-02-24 23:40:57 +08:00
```
2020-09-01 16:27:17 +08:00
### 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.
2020-02-24 23:40:57 +08:00
```sh
2020-09-20 16:53:48 +08:00
# Setup folder structure
2020-02-24 23:40:57 +08:00
mkdir -p ~/carla-ros-bridge/catkin_ws/src
cd ~/carla-ros-bridge
git clone https://github.com/carla-simulator/ros-bridge.git
2020-07-17 23:28:59 +08:00
cd ros-bridge
git submodule update --init
cd ../catkin_ws/src
2020-02-24 23:40:57 +08:00
ln -s ../../ros-bridge
2020-09-20 16:53:48 +08:00
source /opt/ros/kinetic/setup.bash # Watch out, this sets ROS Kinetic
2020-02-24 23:40:57 +08:00
cd ..
2020-09-20 16:53:48 +08:00
# Install required ros-dependencies
2020-02-24 23:40:57 +08:00
rosdep update
rosdep install --from-paths src --ignore-src -r
2020-09-20 16:53:48 +08:00
# Build
2020-02-24 23:40:57 +08:00
catkin_make
```
---
## Run the ROS bridge
2020-02-24 23:40:57 +08:00
__1) Run CARLA.__ The way to do so depends on the CARLA installation.
2020-02-24 23:40:57 +08:00
* __Quick start/release package.__ `./CarlaUE4.sh` in `carla/`.
2020-09-07 18:58:34 +08:00
* __Debian installation.__ `./CarlaUE4.sh` in `opt/carla-simulator/`.
* __Build installation.__ `make launch` in `carla/`.
2020-02-24 23:40:57 +08:00
__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.
2020-02-26 21:54:29 +08:00
* __Source for apt ROS bridge.__
2020-02-26 21:54:29 +08:00
```sh
2020-09-28 20:45:17 +08:00
source /opt/carla-ros-bridge/<kinetic or melodic>/setup.bash
2020-02-26 21:54:29 +08:00
```
* __Source for ROS bridge repository download.__
2020-02-24 23:40:57 +08:00
```sh
source ~/carla-ros-bridge/catkin_ws/devel/setup.bash
```
2020-02-26 21:54:29 +08:00
!!! Important
The source path can be set permanently, but it will cause conflict when working with another workspace.
2020-02-26 21:54:29 +08:00
__3) Start the ROS bridge.__ Use any of the different launch files available to check the installation. Here are some suggestions.
2020-02-24 23:40:57 +08:00
```sh
# 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
```
<details>
<summary>
<h6>ImportError: no module named CARLA</h6>
</summary>
2020-02-26 21:54:29 +08:00
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 <i>.egg</i> file (included). Use the one supported by the Python version installed.
2020-09-09 22:48:04 +08:00
<br><br>
<i><small><b>Note: </b>.egg files may be either in `/PythonAPI/` or `/PythonAPI/dist/` depending on the CARLA installation.</small></i>
2020-02-26 21:54:29 +08:00
```sh
2020-02-26 21:54:29 +08:00
export PYTHONPATH=$PYTHONPATH:<path/to/carla/>/PythonAPI/<your_egg_file>
```
2020-02-26 21:54:29 +08:00
Import CARLA from Python and wait for a sucess message to check the installation.
2020-02-26 21:54:29 +08:00
```sh
2020-09-09 22:48:04 +08:00
python3 -c 'import carla;print("Success")'
2020-02-26 21:54:29 +08:00
```
</details>
2020-02-26 21:54:29 +08:00
---
## Setting CARLA
2020-02-24 23:40:57 +08:00
To modify the way CARLA works along with the ROS bridge, edit [`share/carla_ros_bridge/config/settings.yaml`](https://github.com/carla-simulator/ros-bridge/blob/master/carla_ros_bridge/config/settings.yaml).
2020-02-26 21:54:29 +08:00
* __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.
2020-03-29 18:51:16 +08:00
* __Simulation time-step.__ Simulation time (delta seconds) between simulation steps. __It must be lower than 0.1__. Take a look at the [documentation](adv_synchrony_timestep.md) 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.
2020-02-24 23:40:57 +08:00
!!! Warning
In synchronous mode only the ros-bridge is allowed to tick. Other clients must passively wait.
2020-02-24 23:40:57 +08:00
### Synchronous mode
2020-02-26 21:54:29 +08:00
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__.
2020-02-26 21:54:29 +08:00
| Topic | Message type |
| ------------------------------------------------ | ------------------------------------------------ |
| `/carla/control` | [carla\_msgs.CarlaControl](<../ros_msgs#carlacontrolmsg>) |
2020-02-24 23:40:57 +08:00
The [Control rqt plugin](https://github.com/carla-simulator/ros-bridge/blob/master/rqt_carla_control/README.md) 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.
2020-02-26 21:54:29 +08:00
```sh
rqt --standalone rqt_carla_control
```