此处对于机械臂的操作是实例类MoveGroupCommander(是一个接口类),其父类是move_group,基本的关系大概就是这样的
类的继承关系如下:
moveit的操作,ros的底层是用c++实现的,但是也有python的接口方便调用,以下分别是c++与python的接口文件
move_group.cpp的链接
http://docs.ros.org/groovy/api/moveit_ros_planning_interface/html/move__group_8cpp_source.html
python类接口的链接
http://docs.ros.org/kinetic/api/moveit_commander/html/move__group_8py_source.html
首先初始化move_group的API
moveit_commander.roscpp_initialize(sys.argv)
arm = moveit_commander.MoveGroupCommander('arm')
1.获取终端link的名称
end_effector_link = arm.get_end_effector_link()
2.设置目标位置所使用的参考坐标系,也是后期计算所用的坐标系
reference_frame = 'base_link'
arm.set_pose_reference_frame(reference_frame)
3.允许重新规划
arm.allow_replanning(True)
4.根据名称设置机械臂位置
arm.set_named_target('initial') #initial是moveit set中设置的初始化位置
arm.go()
5.获取机械臂各joint的值
gets_value = arm.get_joint_value_target()
print(gets_value)
6.根据posestamped设置机械臂终端位置
target_pose = PoseStamped()
target_pose.header.frame_id = reference_frame
target_pose.header.stamp = rospy.Time.now()
target_pose.pose.position.x = 0.6
target_pose.pose.position.y = 0.6
target_pose.pose.position.z = 0.6
target_pose.pose.orientation.x = 0.5
target_pose.pose.orientation.y = 0.5
target_pose.pose.orientation.z = 0.5
target_pose.pose.orientation.w = 0.2
arm.set_pose_target(target_pose, end_effector_link)
arm.go()
7.设置机械臂末端xyz位置
xyz = [0.6,0.6,1]
arm.set_position_target(xyz, end_effector_link)
traj = arm.plan()
arm.execute(traj)
8.获取当前机械臂终端位置
arm_pose = PoseStamped()
arm_pose = arm.get_current_pose()
print(arm_pose)
或者
print(arm.get_current_pose().pose)