ROS 2的ROS桥安装
本节是关于如何在 Linux 上安装 ROS 桥以与 ROS 2 一起使用的指南。您将找到先决条件、安装步骤、如何运行基本包以确保一切正常工作以及运行测试的命令。
重要
适用于Windows 的 ROS仍在实验 。它只在Linux系统上进行过测试。
开始之前
在使用ROS桥之前,您需要满足以下软件要求:
- 安装 ROS:
- ROS 2 Foxy — 针对 Ubuntu 20.04 (Focal) -根据您的需要,可能需要额外的 ROS 包。强烈建议是用 rviz 将ROS数据可视化。
- CARLA 0.9.11或更高版本——以前的版本与ROS桥不兼容。遵循快速启动安装 或者为 Linux构建 。建议尽可能将ROS桥接版本与CARLA版本相匹配。
ROS桥安装
注意
Debian软件包安装还不能用于ROS 2。
1. 设置项目目录并克隆ROS网桥存储库和子模块:
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. 设置 ROS 环境:
source /opt/ros/foxy/setup.bash
3. 安装 ROS 依赖:
rosdep update
rosdep install --from-paths src --ignore-src -r
4. 使用colcon构建ROS桥的工作空间:
colcon build
运行ROS桥
1. 请根据安装 CARLA 时使用的安装方法启动 CARLA 服务器:
# 在 Carla的根目录中运行打包好的版本
./CarlaUE4.sh
# 在`opt/carla-simulator/`的 Debian 安装
./CarlaUE4.sh
# 在 Carla 的根目录中从源代码构建
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
Windows下安装
根据链接 安装ROS2。
1.安装Chocolatey
以管理员权限打开命令提示符,运行:
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
如果报出警告:WARNING: An existing Chocolatey installation was detected. Installation will not continue. This script will not overwrite existing installations. If there is no Chocolatey installation at 'C:\ProgramData\chocolatey', delete the folder and attempt the installation again.
则删除文件夹C:\ProgramData\chocolatey
后继续执行以上命令。
验证是否安装成功,运行(必须以管理员权限运行)
choco
2.利用choco安装ROS2
choco source add -n=ros-win -s="https://aka.ms/ros/public" --priority=1
choco upgrade ros-foxy-desktop -y --execution-timeout=0
报错:Unable to connect to source 'https://aka.ms/ros/public':
这一步需要设置代理:
set http_proxy=http://127.0.0.1:7890
set https_proxy=http://127.0.0.1:7890
参考
- CARLA ROS2 Bridge 容器镜像 - 提供 Carla 和 ROS2 之间桥梁的容器