官网:https://carla.readthedocs.io/projects/ros-bridge/en/latest/ros_installation_ros1/
ROS bridge
使得 ROS
和 CARLA
之间能够进行双向通信。来自 CARLA
服务器的信息被转换成 ROS topics
。同样在 ROS
节点之间发送的信息也被转换为可在 CARLA
中应用的命令。
ROS bridge
与 ROS 1
和 ROS 2
都兼容。ROS bridge
拥有以下特点:
Ubuntu 18.04
ROS
已安装CARLA 0.9.8+
已安装可以使用 apt
安装(仅支持 Ubuntu 18.04
),或者使用源码编译安装,建议源码编译安装。
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"
sudo apt-get update # Update the Debian package index
sudo apt-get install carla-ros-bridge # Install the latest ROS bridge version, or update the current installation
apt-cache madison carla-ros-bridge # List the available versions of the ROS bridge
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
安装成功后,可以在 /opt
目录看到安装的文件。
mkdir -p ~/carla-ros-bridge/catkin_ws/src
cd ~/carla-ros-bridge
git clone --recurse-submodules https://github.com/carla-simulator/ros-bridge.git catkin_ws/src/ros-bridge
source /opt/ros/melodic/setup.bash
注意:默认此处安装的 ROS
版本为 melodic
cd catkin_ws
rosdep update
rosdep install --from-paths src --ignore-src -r
catkin build
# 或者
catkin_make
根据 CARLA
安装方式不同,选择对应的命令启动 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
安装 miniconda
,访问地址:https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
conda
的环境安装好后,创建 Python
虚拟环境
conda create -n py27 python=2.7
conda create -n py37 python=3.7
此处可以选择安装不同的版本,注意:
ros-bridge
需要安装到python2.7
的环境中。
通过如下命令查看当前环境已经拥有的虚拟环境
conda info -e
可选命令:
conda config --set auto_activate_base false
conda config --set report_errors false
激活、去激活某个版本的环境
conda activate py27
conda deactivate
基于 Python2.7
环境,配置 ROS Bridge
需要的 Python
依赖库
conda create -n py27 python=2.7
conda activate py27
在虚拟环境中永久设置 pip
源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
安装依赖库
pip install opencv-python==4.2.0.32
pip install networkx
pip install rospkg
pip install rospy
pip install simple_pid
pip install transforms3d
pip install networkx
pip install enum
pip install pygame
export CARLA_ROOT=<path-to-carla>
export PYTHONPATH=$PYTHONPATH:$CARLA_ROOT/PythonAPI/carla/dist/carla-<carla_version_and_arch>.egg:$CARLA_ROOT/PythonAPI/carla
其中:
为 CARLA
的安装路径;
为 CARLA
对应的 Python
版本包;在上一步创建的 Python2.7
虚拟环境中执行如下命令:
(py27) wohu@wohu-pc:~/tool$ export PYTHONPATH=$PYTHONPATH:/home/wohu/tool/CARLA_0.9.13/PythonAPI/carla/dist/carla-0.9.13-py2.7-linux-x86_64.egg:/home/wohu/tool/CARLA_0.9.13/PythonAPI/carla
(py27) wohu@wohu-pc:~/tool$ python -c 'import carla;print("Success")'
Success
(py27) wohu@wohu-pc:~/tool$
说明 Python
相关的依赖库安装正常。
根据安装方式的不同,选择对应的命令导入 ros bridge
环境变量
# For debian installation of ROS bridge. Change the command according to your installed version of ROS.
source /opt/carla-ros-bridge/<melodic/noetic>/setup.bash
# For GitHub repository installation of ROS bridge
source ./carla-ros-bridge/catkin_ws/devel/setup.bash
每次运行 ROS bridge
时都需要执行以上命令,也可以将上面的命令加入到 ~/.bashrc
中。
以下两个命令任意选择一个,不能同时执行。
# Option 1: start the ros bridge
roslaunch carla_ros_bridge carla_ros_bridge.launch
# Option 2: start the ros bridge together with an example ego vehicle
roslaunch carla_ros_bridge carla_ros_bridge_with_example_ego_vehicle.launch