carla/Docs/ros_installation.md

160 lines
6.6 KiB
Markdown
Raw Normal View History

# ROS bridge installation
2020-02-24 23:40:57 +08:00
* [__Requirements__](#requirements)
* [__Bridge installation__](#bridge-installation)
2020-03-05 16:57:13 +08:00
* a) using apt repository
* b) using source repository
2020-02-24 23:40:57 +08:00
* [__Run the ROS bridge__](#run-the-ros-bridge)
2020-03-06 19:41:54 +08:00
* Solving ImportError: No module named CARLA
2020-02-26 21:54:29 +08:00
* [__Setting CARLA__](#setting-carla)
2020-02-24 23:40:57 +08:00
2020-02-26 21:54:29 +08:00
The ROS bridge enables two-way communication between ROS and CARLA.
2020-03-06 19:41:54 +08:00
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 messages.
In the same way, 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.
2020-02-24 23:40:57 +08:00
---
## Requirements
#### ROS melodic
2020-02-24 23:40:57 +08:00
2020-03-06 19:41:54 +08:00
* __ROS Kinetic/Melodic:__ follow the official documentation to [install ROS](http://wiki.ros.org/melodic/Installation/Ubuntu). Some ROS packages may be required, depending on the user needs, such as [rviz](https://wiki.ros.org/ainstein_radar_rviz_plugins) to visualize ROS data.
* __CARLA 0.9.7:__ previous versions are not compatible with the ROS bridge. Follow the [quick start installation](../getting_started/quickstart) or make the build for the corresponding platform.
2020-02-24 23:40:57 +08:00
!!! Important
Make sure that both CARLA and ROS work properly before continuing with the installation.
---
## Bridge installation
2020-02-24 23:40:57 +08:00
2020-03-05 16:57:13 +08:00
#### a) Using apt repository
2020-02-24 23:40:57 +08:00
2020-02-26 00:16:27 +08:00
First add the apt repository:
2020-02-26 21:54:29 +08:00
* __Bridge for ROS Melodic:__
2020-02-24 23:40:57 +08:00
```sh
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 81061A1A042F527D &&
2020-03-04 21:03:31 +08:00
sudo add-apt-repository "deb [trusted=yes] http://dist.carla.org/carla-ros-bridge-melodic/ bionic main"
2020-02-24 23:40:57 +08:00
```
2020-02-26 21:54:29 +08:00
* __Bridge for ROS Kinetic:__
2020-02-26 00:16:27 +08:00
```sh
2020-03-05 16:57:13 +08:00
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 9BE2A0CDC0161D6C &&
2020-02-26 00:16:27 +08:00
sudo add-apt-repository "deb [trusted=yes] http://dist.carla.org/carla-ros-bridge-kinetic xenial main"
```
2020-02-24 23:40:57 +08:00
Then simply install the ROS bridge:
```sh
2020-03-05 16:57:13 +08:00
sudo apt update &&
sudo apt install carla-ros-bridge-<melodic or kinetic>
2020-02-24 23:40:57 +08:00
```
2020-03-05 16:57:13 +08:00
#### b) Using source repository
2020-02-24 23:40:57 +08:00
2020-03-06 19:41:54 +08:00
In order to use the ROS bridge, a catkin workspace is needed. It should be cloned and built in there.
2020-02-26 21:54:29 +08:00
The following fragment creates a new workspace and clones the repository in there.
2020-02-24 23:40:57 +08:00
```sh
#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
2020-02-26 21:54:29 +08:00
source /opt/ros/kinetic/setup.bash #Watch out, this sets ROS Kinetic.
2020-02-24 23:40:57 +08:00
cd ..
#install required ros-dependencies
rosdep update
rosdep install --from-paths src --ignore-src -r
#build
catkin_make
```
---
## Run the ROS bridge
2020-02-24 23:40:57 +08:00
__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/`.
2020-03-05 16:57:13 +08:00
* __apt installation:__ run `./CarlaUE4.sh` in `/opt/carla/bin/`.
2020-02-24 23:40:57 +08:00
* __Build installation:__ run `make launch` in `/carla/`.
2020-02-26 21:54:29 +08:00
__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:
2020-03-05 16:57:13 +08:00
* __Source for apt ROS bridge:__
2020-02-26 21:54:29 +08:00
```sh
source /opt/carla-ros-bridge/<melodic or kinetic>/setup.bash
```
* __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
2020-03-06 19:41:54 +08:00
The source path can be added to the environment to 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 that will serve to check if the bridge is running properly. 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
```
2020-03-06 19:41:54 +08:00
#### Solving ImportError: no module named CARLA
2020-02-26 21:54:29 +08:00
2020-03-06 19:41:54 +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 _.egg_ file (included). Use the one that, is supported by the Python version installed:
2020-02-26 21:54:29 +08:00
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:
```sh
python -c 'import carla;print("Success")'
```
---
## Setting CARLA
2020-02-24 23:40:57 +08:00
2020-03-06 19:41:54 +08:00
Settings can be changed, in order to modify the way CARLA works along with the ROS bridge, by editing the file: [`share/carla_ros_bridge/config/settings.yaml`](https://github.com/carla-simulator/ros-bridge/blob/master/carla_ros_bridge/config/settings.yaml).
2020-02-24 23:40:57 +08:00
The parameters available refer to:
2020-02-26 21:54:29 +08:00
* __Host/port:__ the network settings to connect to CARLA using a Python client.
2020-02-24 23:40:57 +08:00
* __Synchronous mode:__
* __If false (default):__ data is published on every `world.on_tick()` and every `sensor.listen()` callbacks.
2020-03-06 19:41:54 +08:00
* __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-02-26 21:54:29 +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](../simulation_time_and_synchrony) to learn more about this.
2020-03-06 19:41:54 +08:00
* __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-26 21:54:29 +08:00
2020-02-24 23:40:57 +08:00
!!! Warning
2020-03-06 19:41:54 +08:00
In synchronous mode only the ros-bridge is allowed to tick. Other CARLA clients must passively wait.
2020-02-24 23:40:57 +08:00
#### Synchronous mode
2020-02-24 23:40:57 +08:00
2020-03-06 19:41:54 +08:00
The following topic allows to control the step update when in synchronous mode:
2020-02-24 23:40:57 +08:00
2020-02-26 21:54:29 +08:00
| Topic | Message type |
2020-02-24 23:40:57 +08:00
| ---------------- | ----------------------- |
2020-02-26 21:54:29 +08:00
| `/carla/control` | [carla_msgs.CarlaControl](../ros_msgs#carlacontrolmsg) |
The message contains a constant named `command` that allows to:
* Pause/Play the simulation.
* Execute a single step.
2020-02-24 23:40:57 +08:00
2020-02-26 21:54:29 +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 to manage these steps and publish in the corresponding topic.
Simply run the following when CARLA is in synchronous mode:
```sh
rqt --standalone rqt_carla_control
```