控制机械臂
1 滑块控制
点击桌面上的 "ROS2 Shell "图标或桌面下栏的相应图标,打开 ROS2 环境终端:
然后运行命令:
# mycobot 320-PI 版本的默认串行端口名称为"/dev/ttyAMA0",波特率为 115200。
ros2 launch mycobot_320pi slider_control.launch.py
它会打开 rviz 和一个滑块组件,你会看到类似这样的内容:
然后,您可以在 rviz2 中通过拖动滑块来控制模型的移动。真实的 mycobot 机器人也会随之移动。
请注意:由于在命令输入的同时机械臂会移动到模型目前的位置,在您使用命令之前请确保 rviz 中的模型没有出现穿模现象 不要在连接机械臂后做出快速拖动滑块的行为,防止机械臂损坏
2 模型跟随
除了上面的控制,我们也可以让模型跟随真实的机械臂运动。打开一个命令行运行:
点击桌面上的ROS2 Shell
图标或桌面下栏的相应图标,打开 ROS2 环境终端:
然后运行命令:
# mycobot 320-PI 版本的默认串行端口名称为"/dev/ttyAMA0",波特率为 115200。
ros2 launch mycobot_320pi mycobot_follow.launch.py
它将打开 rviz 以显示模型跟随效果 。
3 GUI 控制
在前者的基础上,本软件包还提供了一个简单的图形用户界面控制接口。这种方法意味着真正的机械臂是相互连接的,请连接到 mycobot。
点击桌面上的 "ROS2 Shell "图标或桌面下栏的相应图标,打开 ROS2 环境终端:
然后运行命令:
# mycobot 320-PI 版本的默认串行端口名称为"/dev/ttyAMA0",波特率为 115200。
ros2 launch mycobot_320pi simple_gui.launch.py
4 键盘控制
在 "mycobot_320pi "软件包中添加了键盘控制功能,并在 rviz 中实时同步。 该功能依赖于 pythonApi,因此请确保与真正的机械臂连接。
点击桌面上的 ROS2 Shell
图标或桌面下栏的相应图标,打开 ROS2 环境终端:
然后运行命令:
# mycobot 320-PI 版本的默认串行端口名称为"/dev/ttyAMA0",波特率为 115200。
ros2 launch mycobot_320pi teleop_keyboard.launch.py
操作效果如下:
命令行将输出 mycobot 的信息,如下所示:
[INFO] [launch]: All log files can be found below /home/er/.ros/log/2022-08-05-10-43-12-301971-u20-VirtualBox-6290
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [robot_state_publisher-1]: process started with pid [6293]
[INFO] [rviz2-2]: process started with pid [6295]
[INFO] [follow_display-3]: process started with pid [6297]
[robot_state_publisher-1] Parsing robot urdf xml string.
[robot_state_publisher-1] Link link1 had 1 children
[robot_state_publisher-1] Link link2 had 1 children
[robot_state_publisher-1] Link link3 had 1 children
[robot_state_publisher-1] Link link4 had 1 children
[robot_state_publisher-1] Link link5 had 1 children
[robot_state_publisher-1] Link link6 had 0 children
[robot_state_publisher-1] [INFO] [1659667392.703132973] [robot_state_publisher]: got segment base
[robot_state_publisher-1] [INFO] [1659667392.703485410] [robot_state_publisher]: got segment link1
[robot_state_publisher-1] [INFO] [1659667392.703545198] [robot_state_publisher]: got segment link2
[robot_state_publisher-1] [INFO] [1659667392.703571119] [robot_state_publisher]: got segment link3
[robot_state_publisher-1] [INFO] [1659667392.703587512] [robot_state_publisher]: got segment link4
[robot_state_publisher-1] [INFO] [1659667392.703603744] [robot_state_publisher]: got segment link5
[robot_state_publisher-1] [INFO] [1659667392.703619685] [robot_state_publisher]: got segment link6
[rviz2-2] [INFO] [1659667393.588026632] [rviz2]: Stereo is NOT SUPPORTED
[rviz2-2] [INFO] [1659667393.588472253] [rviz2]: OpenGl version: 3.1 (GLSL 1.4)
[rviz2-2] [INFO] [1659667393.766777360] [rviz2]: Stereo is NOT SUPPORTED
[rviz2-2] Parsing robot urdf xml string.
[follow_display-3] [INFO] [1659667394.310152595] [follow_display]: port:/dev/ttyAMA0, baud:115200
接下来,打开另一个 ROS2 环境终端:
然后运行命令:
ros2 run mycobot_320pi teleop_keyboard
您将在命令行中看到以下输出:
Mycobot Teleop Keyboard Controller
---------------------------
Movimg options(control coordinations [x,y,z,rx,ry,rz]):
w(x+)
a(y-) s(x-) d(y+)
z(z-) x(z+)
u(rx+) i(ry+) o(rz+)
j(rx-) k(ry-) l(rz-)
Gripper control:
g - open
h - close
Other:
1 - Go to init pose
2 - Go to home pose
3 - Resave home pose
q - Quit
currently: speed: 30 change percent: 2
在该终端中,您可以通过命令行中的按键控制机械臂的状态并移动机械臂。