控制机械臂
1 滑块控制
打开命令行并运行:
# mycobot 320-M5 版本的默认串行端口名称为"/dev/ttyUSB0",波特率为 115200。某些型号的串行端口名称为 "dev/ttyACM0"。如果默认串行端口名称有误,可以将串行端口名称更改为"/dev/ttyACM0"。
ros2 launch mycobot_320 slider_control.launch.py
它会打开 rviz2 和一个滑块组件,你会看到类似下面的内容:
然后,您可以在 rviz2 中通过拖动滑块来控制模型的移动。真实的 mycobot 机器人也会随之移动。
请注意:由于在命令输入的同时机械臂会移动到模型目前的位置,在您使用命令之前请确保 rviz 中的模型没有出现穿模现象 不要在连接机械臂后做出快速拖动滑块的行为,防止机械臂损坏
2 模型跟随
除了上面的控制,我们也可以让模型跟随真实的机械臂运动。
打开一个命令行运行:
# mycobot 320-M5 版本的默认串行端口名称为"/dev/ttyUSB0",波特率为 115200。某些型号的串行端口名称为 "dev/ttyACM0"。如果默认串行端口名称有误,可以将串行端口名称更改为"/dev/ttyACM0"。
ros2 launch mycobot_320 mycobot_follow.launch.py
它将打开 rviz 以显示模型跟随效果 。
3 GUI 控制
在前者的基础上,本软件包还提供了一个简单的图形用户界面控制接口。这种方法意味着真正的机械臂是相互连接的,请连接到 mycobot。
打开命令行:
# mycobot 320-M5 版本的默认串行端口名称为"/dev/ttyUSB0",波特率为 115200。某些型号的串行端口名称为 "dev/ttyACM0"。如果默认串行端口名称有误,可以将串行端口名称更改为"/dev/ttyACM0"。
ros2 launch mycobot_320 simple_gui.launch.py
4 键盘控制
在 "mycobot_320pi "软件包中添加了键盘控制功能,并在 rviz 中实时同步。 该功能依赖于 pythonApi,因此请确保与真正的机械臂连接。
打开命令行并运行:
# mycobot 320-M5 版本的默认串行端口名称为"/dev/ttyUSB0",波特率为 115200。某些型号的串行端口名称为 "dev/ttyACM0"。如果默认串行端口名称有误,可以将串行端口名称更改为"/dev/ttyACM0"。
ros2 launch mycobot_320 teleop_keyboard.launch.py
操作效果如下:
命令行中将会输出 mycobot 信息,如下:
[INFO] [launch]: All log files can be found below /home/u20/.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/ttyUSB0, baud:115200
接下来,打开另一个 命令行:
ros2 run mycobot_320 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
在该终端中,您可以通过命令行中的按键控制机械臂的状态并移动机械臂。