看完01-资料篇:webots和ros2笔记01-资料 - 古月居 (guyuehome.com)

是不是有点冲动,想跑一个案例看看效果如何呢?

开始吧。

成功

失败

安装包
安装有两种方式,如果是linux就非常方便,使用如下命令就可以了。

sudo apt-get install ros-$ROS_DISTRO-webots-ros2


其中,$ROS_DISTRO为ROS2版本号,如foxy,命令如下:

sudo apt-get install ros-foxy-webots-ros2


但如果是其他操作系统,那么只能编译源码了哦。

编译源码
Windows

call C:\dev\ros2\local_setup.bat
 
# Retrieve the sources
cd /path/to/ros2_ws
git clone --recurse-submodules -b $ROS_DISTRO https://github.com/cyberbotics/webots_ros2.git src/webots_ros2
 
# Building packages
colcon build
 
# Source this workspace (careful when also sourcing others)
call install\local_setup.bat


Linux

source /opt/ros/$ROS_DISTRO/local_setup.bash
 
# Retrieve the sources
cd /path/to/ros2_ws
git clone --recurse-submodules -b $ROS_DISTRO https://github.com/cyberbotics/webots_ros2.git src/webots_ros2
 
# Check dependencies
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro $ROS_DISTRO
 
# Building packages
colcon build
 
# Source this workspace (careful when also sourcing others)
source install/local_setup.bash


macOS

source ~/ros2/local_setup.zsh
 
# Retrieve the sources
cd /path/to/ros2_ws
git clone --recurse-submodules -b $ROS_DISTRO https://github.com/cyberbotics/webots_ros2.git src/webots_ros2
 
# Building packages
colcon build
 
# Source this workspace (careful when also sourcing others)
source install/local_setup.zsh


完成之后就像正常的功能包一样使用就行啦!

注意事项


1,webots以及ros2安装版本要和源码指定的版本匹配!
2,当安装多个版本的webots和ros2时需要配置环境说明!
3,如果ROS2_WEBOTS_HOME设置了环境变量,ROS2将使用该文件夹中的Webots。
4,如果WEBOTS_HOME设置了环境变量,ROS2将使用该文件夹中的Webots。
5,如果没有设置/安装上一步,ROS2将在默认安装路径(例如/usr/local/webots)中查找Webots 。(ubuntu)
6,如果找不到Webots,webots_ros2将显示一个窗口并提供自动的Webots安装。(ubuntu)

测试
使用如下命令:

ros2 launch webots_ros2_demos armed_robots.launch.py


报错如下,说明没有call(windows):

正确配置后:

更新,ROS2foxy+Webots2021a。

使用最新版本webots_ros2包,2021年1月10日左右官方最新更新。配置为webots2021a。官网下载龟速,使用如下链接下载速度快:


有新报错信息:

然后colcon build,就一切ok:

使用时出现如下错误,请安装webots2021a。

Windows效果与Ubuntu一致。


Ubuntu下效果:

 


————————————————