参考链接 Reference:

1,文档:http://wiki.ros.org/webots_ros2
2,源码:https://github.com/cyberbotics/webots_ros2


2021更新webots+ros2 笔记系列:

  • https://blog.csdn.net/ZhangRelay/article/details/112670542


目前,已经测试过Crystal和Dashing这两个版本的ROS2,均可非常愉快的玩耍。

At present, the two versions of ROS2, Crystal and Dashing, have been tested and can be played very happily.

下载编译包:

Crystal:sudo apt install ros-crystal-webots-ros2 

Dashing:只能源码编译。过程如下:

导入Dashing环境:
source /opt/ros/dashing/setup.bash
 
获取webots:
wget https://github.com/omichel/webots/releases/download/R2019b/webots-R2019b-x86-64.tar.bz2
 
解压:
tar xjf webots-R2019b-x86-64.tar.bz2
 
设置路径:
export WEBOTS_HOME=$PWD/webots
 
下载webots_ros2源码:
cd /path/to/catkin_ws/src
git clone -b $ROS_DISTRO https://github.com/cyberbotics/webots_ros2.git
cd /path/to/catkin_ws
 
更新rosdep,并安装需要的依赖:
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro $ROS_DISTRO
 
编译:
colcon build
 
更新工作环境:
source /path/to/catkin_ws install/setup.bash
source /path/to/catkin_ws install/local_setup.bash

将包从github下载,放置在src文件夹下:


src
使用colcon编译。

如果使用Windows环境,请参考wiki。

移动机器人示例:

启动:

ros2 launch webots_ros2_examples example.launch.py

webots

rqt:


rqt

用命令方式移动机器人或者显示传感器参数:

ros2 service call /motor webots_ros2_msgs/SetDifferentialWheelSpeed "{ left_speed: 1.0, right_speed: 0.5 }"

ros2 topic echo /sensor

给定左右轮相同速度,缓慢向前移动:


move

快接近边缘时候停止运动:


stop


传感器值感觉还是有问题的!


sensor
​​

工业机械臂示例:

单机械臂:

ros2 launch webots_ros2_universal_robot universal_robot.launch.py

universal_robot
 


universal_robot

双机械臂

ros2 launch webots_ros2_universal_robot universal_robot_multiple.launch.py

multi

移动机械臂:

ros2 action send_goal /follow_joint_trajectory control_msgs/action/FollowJointTrajectory "{
  trajectory: {
    joint_names: [shoulder_pan_joint, shoulder_lift_joint, elbow_joint, wrist_1_joint, wrist_2_joint, wrist_3_joint],
    points: [
      { positions: [3.02, -1.63, -1.88, 1.01, 1.51, 1.13], velocities: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], accelerations: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], time_from_start: { sec: 5, nanosec: 500 } },
      { positions: [-1.01, 0.38, -0.63, -0.88, 0.25, -1.63], velocities: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], accelerations: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], time_from_start: { sec: 6, nanosec: 500 } },
      { positions: [-1.01, 0.38, -0.63, -0.88, 0.25, 6.2], velocities: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], accelerations: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], time_from_start: { sec: 50, nanosec: 500 } }
    ]
  }
}"


显示关节的状态:

ros2 topic echo /joint_states

目前教程只有4个,还比较简单,但是涵盖了入门ros2和webots的基础要点:
webots_ros2包的每个子包的描述和教程。

  1. webots_ros2_msgs包
    服务,消息和操作定义。
  2. webots_ros2_core包
    核心接口包。
  3. webots_ros2_examples包
    示例ROS2节点连接Webots和ROS2
  4. webots_ros2_universal_robot包
    用于连接Universal Robots和Webots的软件包。

webots_ros2是一个ROS功能包,提供必要的接口来仿真机器人的Webots开源3D刚体模拟器中的机器人。 它使用ROS2消息,服务和操作与ROS2集成。

webots_ros2 is a package that provides the necessary interfaces to simulate a robot in the Webots open-source 3D rigid body simulator for robots. It integrates with ROS2 using ROS2 messages, services and actions.

Webots是使用webots_ros2包的先决条件。 它可以从Github存储库下载。 安装很简单,但如果需要,可以在此处找到安装说明。

或者,您也可以从webots_ros2_desktop ROS2包中获取Webot,或者从源代码构建Webots。

在运行时,ROS2将在以下位置查找Webots(按此顺序):

如果设置了ROS2_WEBOTS_HOME环境变量,ROS2将使用此文件夹中的Webots。

如果安装了webots_ros2_desktop ROS2软件包,ROS2将使用此软件包中包含的Webots版本。

如果设置了WEBOTS_HOME环境变量,ROS2将使用此文件夹中的Webots。

如果没有设置/安装前一点,ROS2将在默认安装路径中查找Webots(例如/ usr / local / webots)。

Webots is a prerequisite to use the webots_ros2 package. It can be downloaded from the Github repository. The installation is straightforward, but if need the installation instructions can be found here.

Alternatively, you can also get Webots from the webots_ros2_desktop ROS2 package or build Webots from the sources.

At runtime, ROS2 will look for Webots at the following locations (in this order):

If the ROS2_WEBOTS_HOME environment variable is set, ROS2 will use the Webots in this folder.

If the webots_ros2_desktop ROS2 package is installed, ROS2 will use the Webots version included in this package.

If the WEBOTS_HOME environment variable is set, ROS2 will use the Webots in this folder.

If none of the previous point is set/installed ROS2 will look for Webots in the default installation paths (e.g. /usr/local/webots).
————————————————