当前位置:网站首页>rosbridge-WSL2 && carla-win11
rosbridge-WSL2 && carla-win11
2022-08-03 22:47:00 【Lemon_Yam】
安装 ROS
- 方法一:可参考我之前一篇博客《WSL+ROS》,里面讲述了如何在 WSL 中安装
ROS1并给出相应简单的 CPP、Python 程序和 launch 文件(本人使用的) - 方法二:通过在 WSL 终端运行
wget http://fishros.com/install -O fishros && . fishros来根据自己的需求选择安装相应内容,该方法来自鱼香社区。若使用该方法可以考虑安装里面 rosdepc,因为后面需要用到(方法二比较便捷)

安装 ROS bridge
️本人使用的是 ROS1,所以下面主要讲 ROS1 的 ROS bridge 怎么安装。此外,如果后面用到的 .egg 文件是直接从官网上下载的,则需要用到 python3.7 环境,否则会出现很多问题!python 环境可使用 conda 来创建,但 conda 创建 python 环境会出现 ROS:ModuleNotFoundError: No module named ‘rospkg‘ 等错误,可通过 pip 安装相应包(注意查看报错信息,包缺失信息在我这是在报错信息的中间,需要仔细排查),我这大概安装了 4 个包,具体是哪些也没仔细记录
方法一:通过 apt-get 安装,但只适用于 Ubuntu18.04,具体命令如下
# Set up the Debian repository in your system
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"
# Install the 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
# Check the ROS bridge has been installed successfully in the /opt/ folder
方法二:从源码中编译(本人使用的)
- 创建
catkin工作空间,下面命令会在用户目录下创建一个文件夹(工作空间)
mkdir -p ~/carla-ros-bridge/catkin_ws/src
- 从 github 上下载 ROS bridge 源码及其相关模块
cd ~/carla-ros-bridge
git clone --recurse-submodules https://github.com/carla-simulator/ros-bridge.git catkin_ws/src/ros-bridge

- 根据已安装的 ROS1 设置 ROS 环境,这里可选有
melodic(Ubuntu18.04) 和noetic(Ubuntu20.04)
source /opt/ros/<melodic/noetic>/setup.bash
- 安装必须的 ROS 依赖,若安装 ROS 时采用方法二,则
rosdep需改成rosdepc
cd catkin_ws
rosdep update # 若 update 中有部分没有 Hit 到则重复运行
rosdep install --from-paths src --ignore-src -r
# 若出现错误 ERROR: the following rosdeps failed to install,则安装 pip 或 pip3


- 构建 ROS bridge
catkin build # alternatively catkin_make
# 若出现错误:catkin: command not found,则根据 python 版本运行以下命令手动安装根据
sudo apt install python3-catkin-tools
sudo apt install python-catkin-tools

运行 ROS bridge
- 运行 carla,源码编译的可直接点击
CarlaUE4.uproject。若未安装 carla,可参考我之前的博客《win11 下编译 CARLA0.9.13》 - 将 carla 模块添加到 Python 路径,
CARLA_ROOT为 carla 安装的根路径,由于是在 WSL 中 export 路径,所以需要添加/mnt,而PYTHONPATH中的.egg文件路径则根据自己安装的路径来查找。后面可通过在 WSL 终端echo $PYTHONPATH命令查看 PYTHONPATH,若类似于/opt/ros/noetic/lib/python3/dist-packages:/mnt/e/carla/PythonAPI/carla/dist/carla-0.9.13-py3.7-win-amd64.egg:/mnt/e/carla/PythonAPI/carla则应该是成功了(export 只在当前终端生效!)
export CARLA_ROOT=/mnt/e/carla # /mnt/e/carla 为安装 carla 的路径(在 win 中是 e 盘下 carla 目录)
export PYTHONPATH=$PYTHONPATH:$CARLA_ROOT/PythonAPI/carla/dist/carla-0.9.13-py3.7-linux-x86_64.egg:$CARLA_ROOT/PythonAPI/carla # carla-0.9.13-py3.7-linux-x86_64.egg 是 carla 名称
由于 ROS bridge 是安装在 WSL 中,所以使用的 .egg 文件需要是 linux 版本的,若使用 win 版本则会出现 invalid ELF header 错误!该 linux 版本可通过官方的 GitHub 库下载,也可下载我上传的资源(包括0.9.12 和 0.9.13)
- 根据安装 ROS bridge 的方式为 ROS bridge 工作空间添加
source path
# 从 Github 上源码编译的(我使用的方式)
source ~/carla-ros-bridge/catkin_ws/devel/setup.bash
# 直接安装 ROS bridge 的
source /opt/carla-ros-bridge/<melodic/noetic>/setup.bash
为了避免重复上述环境配置指令,可在项目根路径下创建一个 envs.bash 文件,将指令整合在一起,然后在终端中运行 source envs.bash(一个终端运行一次即可,不然会出现错误),若没有创建该文件则每个新终端都需要运行以下 3 条命令,文件内容参考如下:
export CARLA_ROOT=/mnt/e/carla
export PYTHONPATH=$PYTHONPATH:$CARLA_ROOT/PythonAPI/carla/dist/carla-0.9.13-py3.7-linux-x86_64.egg:$CARLA_ROOT/PythonAPI/carla
source ~/carla13-ros-bridge/catkin_ws/devel/setup.bash
- 由于文章的 ROS bridge 是安装在 WSL 中,所以需要先确定 WSL 和 win 主机能否通信,可参考这篇博客。通常 win 主机是能
ping通 WSL 的,而若 WSLping不通 win 主机,则以管理员身份运行powershell并输入如下命令:
New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow
- 在启动前,需要修改连接的 CARLA 服务端地址 ,如我们要运行
carla_ros_bridge.launch文件,则修改该文件的host参数,该参数是 win 在 WSL 中的地址,具体如下:

- 启动 ROS bridge,默认使用的地图是
Town1,可先切换至该地图
# 每个终端都应该激活相应 python 环境
# 终端 1,启动 ROS bridge
source envs.bash
roslaunch carla_ros_bridge carla_ros_bridge.launch
# 终端 2,生成相关物体,包括 ego vehicle
source envs.bash
roslaunch carla_spawn_objects carla_spawn_objects.launch
# 终端 3,控制 ego vehicle,若需要手动控制则需先按 B 键,不然控制不了,P 键是自动驾驶
source envs.bash
roslaunch carla_manual_control carla_manual_control.launch
# 终端 4,启动 RVIZ 可视化
rosrun rviz rviz

运行上述 4 条命令并配置 RVIZ 后的结果
我这里使用多个终端运行而不直接使用 roslaunch carla_ros_bridge carla_ros_bridge_with_example_ego_vehicle.launch 是因为把最后一个 launch 文件终止后 CARLA 会出现无法响应状态,不知道问题出在哪里。无响应可通过任务管理器结束该进程即可
边栏推荐
- Research status of target detection at home and abroad
- 【day6】类与对象、封装、构造方法
- Network basic learning series four (network layer, data link layer and some other important protocols or technologies)
- start with connect by 实现递归查询
- How many way of calling a function?
- 云平台建设解决方案
- Cloud platform construction solutions
- Lift, Splat, Shoot: Encoding Images from Arbitrary Camera Rigs by Implicitly Unprojecting to 3D 论文笔记
- Codeup brushing notes - simple simulation
- MiniAPI of .NET6 (14): Cross-domain CORS (Part 1)
猜你喜欢

Lift, Splat, Shoot: Encoding Images from Arbitrary Camera Rigs by Implicitly Unprojecting to 3D 论文笔记

《数字经济全景白皮书》金融数字用户篇 重磅发布!

Cisco ike2 IPSec configuration

override学习(父类和子类)

2022-08-02 mysql/stonedb slow SQL-Q18 - memory usage surge analysis

Click the icon in Canvas App to generate PDF and save it to Dataverse

pikachu Over permission 越权

FinClip最易用的智能电视小程序

PowerMockup 4.3.4::::Crack

Analysys Analysis: The transaction scale of China's online retail B2C market in Q2 2022 will reach 2,344.47 billion yuan
随机推荐
HDU 5655 CA Loves Stick
Gains double award | know micro easily won the "2021 China digital twin solution suppliers in excellence" "made in China's smart excellent recommended products" double award!
Makefile
生成器版和查看器版有什么区别?
Makefile
Quickly build a website with static files
4年工作经验,多线程间的5种通信方式都说不出来,你敢信?
113. Teach a Man how to fish - How to query the documentation and technical implementation details of any SAP UI5 control property by yourself
Summary bug 】 【 Elipse garbled solution project code in Chinese!
override learning (parent and child)
Fluorescein-PEG-CLS,胆固醇-聚乙二醇-荧光素科研试剂
How many way of calling a function?
Kotlin - 扩展函数和运算符重载
BMN: Boundary-Matching Network for Temporal Action Proposal Generation阅读笔记
ML之interpret:基于titanic泰坦尼克是否获救二分类预测数据集利用interpret实现EBC模型可解释性之全局解释/局部解释案例
UVa 1025 - A Spy in the Metro(白书)
L2-041 插松枝
Canvas App中点击图标生成PDF并保存到Dataverse中
UVa 1025 - A Spy in the Metro (White Book)
软测人每个阶段的薪资待遇,快来康康你能拿多少?