demo使用moveit完成关节角度的控制,api完成笛卡尔空间的位置控制
- moveit控制运动,需保证周围空间空旷无障碍物
- api控制方式,无除机械臂外的障碍物控制,注意防碰撞
- 如出现碰撞,及时关闭机械臂电源,并用手托住机械臂,放置在适当位置,查找并解决问题后再重启程序
启动机械臂驱动
roslaunch dual_jaco_bringup bringup.launch
roslaunch dual_jaco_bringup left_arm_bringup.launch
启动moveit
roslaunch dual_jaco_moveit_config execute.launch
启动机械臂控制
roslaunch moveit_control moveit_control.cpp
(1)参数文件
demo中使用moveit关节角度控制,保存预设关节角度在moveit_control/config/config.yaml文件中,每一个位置包含双臂共12个关节角度,依次为左臂1-6关节角度,右臂1-6关节角度
例 config.yaml:
arm_pose:
home: [0.052110824862029406, 1.6504915997012053, 0.6110209011934232, -2.204320174983982, 1.82235297205681, 2.0653875609382055, 9.586364021524787e-05, 4.693209010688541, 5.734204083144525, 2.204337580660823, -1.9960762870139437, 1.2322970561111344]
pick: [0.6992535816455534, 1.3448285667648554, 1.6788709587652206, -2.5964881094158003, 1.543228216663173, 0.8628290661054863, -0.8974066003181504, 4.955051676266042, 4.879916791844716, 5.040274028342491, -4.383829689950012, 4.19193876472422]
out: [0.33887052077529106, 1.3038820372740596, 0.7731120616649589, -2.499210332616153, 1.994593293584222, 1.4486496079405466, -0.32864740900463507, 4.8492291969602, 5.736553459593088, 2.6884229171874385, -2.4154413760013522, 1.6711912329417504]
(2)获得当前关节角度方法
控制机械臂移动至目标状态,读取关节角度信息
rostopic echo /joint_states
输出信息
查看name与position.将双臂各1-6关节的position值(共12个)保存至config.yaml参数文件中,此处示例为单臂状态,注意区分
header:
seq: 101
stamp:
secs: 1608721703
nsecs: 175502360
frame_id: ''
name: [j2n6s200_joint_1, j2n6s200_joint_2, j2n6s200_joint_3, j2n6s200_joint_4, j2n6s200_joint_5,
j2n6s200_joint_6, j2n6s200_joint_finger_1, j2n6s200_joint_finger_2, j2n6s200_joint_finger_tip_1,
j2n6s200_joint_finger_tip_2]
position: [3.8101733862997875, 3.6757537923874555, 0.7652536134379255, 3.448440742808178, 1.759262111869297, 2.4818187282885815, 0.0, 0.0012319971190548208, 0.0, 0.0]
velocity: [-0.009166644164539372, 0.0, 0.0, 0.0, -0.0004958321561296851, 0.0, 0.0, 0.0, 0.0, 0.0]
effort: [0.0, -5.120358943939209, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
---
根据以上信息,可添加新的位置:
arm_pose:
home: []
pick: []
out: []
new_pose: [3.8101733862997875, 3.6757537923874555, 0.7652536134379255, 3.448440742808178, 1.759262111869297, 2.4818187282885815, 另一机械臂的关节角度信息]
(3)代码中移动至新设位置,添加以下新内容
...
// 读取新的关节角度信息
std::vector<double> arm_standby_pose_right(12);
nh_.getParam("arm_pose/home", arm_standby_pose_right);
...
// 移动至新的关节角度
robot_group.setJointValueTarget(arm_standby_pose_right);
robot_group.move();
ros::WallDuration(1.0).sleep();
(4)编译重新运行