Webots和ROS2使用說明(部分翻譯)
- 2019 年 10 月 5 日
- 筆記
版權聲明:本文為部落客原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接和本聲明。
本文鏈接:https://blog.csdn.net/ZhangRelay/article/details/100519183
參考鏈接 Reference:
目前,已經測試過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
注意:control_msgs(在19年9月3日時,還不能使用apt install安裝),需要源碼編譯。
將包從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包的每個子包的描述和教程。
- webots_ros2_msgs包 服務,消息和操作定義。
- webots_ros2_core包 核心介麵包。
- webots_ros2_examples包 示例ROS2節點連接Webots和ROS2
- 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).