ROS Bridge 笔记(01)— 简介、apt 安装、源码编译安装、安装依赖、运行显示

官网:https://carla.readthedocs.io/projects/ros-bridge/en/latest/ros_installation_ros1/

ROS bridge 使得 ROSCARLA 之间能够进行双向通信。来自 CARLA 服务器的信息被转换成 ROS topics 。同样在 ROS 节点之间发送的信息也被转换为可在 CARLA 中应用的命令。

ROS bridgeROS 1ROS 2 都兼容。ROS bridge 拥有以下特点:

  • 提供激光雷达、语义激光雷达、相机(深度、分割、RGB、DVS)、GNSS、雷达和IMU的传感器数据;
  • 提供对象数据,如变换、交通灯状态、可视化标记、碰撞和车道入侵;
  • 通过转向、油门和刹车控制AD代理;
  • 控制CARLA模拟的各个方面,如同步模式、运行和暂停仿真以及设置仿真参数;

1. 安装前提

  • Ubuntu 18.04
  • ROS 已安装
  • CARLA 0.9.8+ 已安装

可以使用 apt 安装(仅支持 Ubuntu 18.04),或者使用源码编译安装,建议源码编译安装。

2. apt 安装

2.1 添加镜像源

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"

2.2 安装 ROS bridge

  • 安装最新版本
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 目录看到安装的文件。

3. 源码编译安装

3.1 创建工作空间

mkdir -p ~/carla-ros-bridge/catkin_ws/src

3.2 克隆ROS Bridge库和子模块

cd ~/carla-ros-bridge
git clone --recurse-submodules https://github.com/carla-simulator/ros-bridge.git catkin_ws/src/ros-bridge

3.3 导入 ROS 环境变量

source /opt/ros/melodic/setup.bash

注意:默认此处安装的 ROS 版本为 melodic

3.4 安装依赖

cd catkin_ws
rosdep update
rosdep install --from-paths src --ignore-src -r

3.5 编译安装

 catkin build   
 # 或者 
 catkin_make

4. 运行

4.1 启动 CARLA

根据 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

4.2 创建虚拟环境

安装 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

4.3 将 CARLA 路径加入到 Python 环境变量中

export CARLA_ROOT=<path-to-carla> 
export PYTHONPATH=$PYTHONPATH:$CARLA_ROOT/PythonAPI/carla/dist/carla-<carla_version_and_arch>.egg:$CARLA_ROOT/PythonAPI/carla

其中:

  • <path-to-carla>CARLA 的安装路径;
  • <carla_version_and_arch>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 相关的依赖库安装正常。

4.4 导入 ROS bridge 环境变量

根据安装方式的不同,选择对应的命令导入 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 中。

4.5 运行 ROS Bridge

以下两个命令任意选择一个,不能同时执行。

# Option 1: start the ros bridge
roslaunch carla_ros_bridge carla_ros_bridge.launch

ros

# Option 2: start the ros bridge together with an example ego vehicle
roslaunch carla_ros_bridge carla_ros_bridge_with_example_ego_vehicle.launch

example

  • 3
    点赞
  • 37
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值