使用 MoveIt 控制自己的真实机械臂【2】——编写 action server 端代码

本文档介绍了如何通过ROS Action在真实机械臂上实现MoveIt的控制。首先,作者指出了在尝试运行demo.launch时,由于缺少action server导致的错误。然后,通过分析问题,说明在Gazebo仿真环境中,ROS_control插件充当了action server的角色,而在真实机械臂场景中,这一角色缺失。接着,作者编写了一个简单的action server节点,用于接收和解析MoveIt规划的轨迹数据。通过验证,这个action server成功与MoveIt的action client建立了连接,并能接收到轨迹数据。最后,作者指出下一步将发送这些轨迹数据给真实机械臂执行。

上一篇文章中, 使用 MoveIt 控制自己的真实机械臂【1】——配置 action client 端,已经完成了 MoveIt 这边 action client 的基本配置,MoveIt 理论上可以将规划好的 trajectory 以 action 的形式发布出来了,浅浅尝试一下,在 terminal 中运行 roslaunch xmate7_moveit_config_new demo.launch
在这里插入图片描述报错提示他在等待 xmate_arm_controller/follow_joint_trajectory 这个 action sever 的到来,显然,他等的好辛苦,却还是没有等来所期待的人,最终遗憾地告诉大家,以 xmate_arm_controller/follow_joint_trajectory 为 action 名称的 action client 端没有被连接。

此时,rostopic list 一下:

hjs@hjs:~/new_xmate7pro_ws$ rostopic list
/attached_collision_object
/collision_object
/execute_trajectory/cancel
/execute_trajectory/feedback
/execute_trajectory/goal
/execute_trajectory/result
/execute_trajectory/status
/head_mount_kinect/depth_registered/points
/joint_states
/move_group/cancel
/move_group/display_contacts
/move_group/display_cost_sources
/move_group/display_grasp_markers
/move_group/display_planned_path
/move_group/feedback
/move_group/filtered_cloud
/move_group/goal
/move_group/monitored_planning_scene
/move_group/motion_plan_request
/move_group/ompl/parameter_descriptions
/move_group/ompl/parameter_updates
/move_group/plan_execution/parameter_descriptions
/move_group/plan_execution/parameter_updates
/move_group/planning_scene_monitor/parameter_descriptions
/move_group/planning_scene_monitor/parameter_updates
/move_group/result
/move_group/sense_for_plan/parameter_descriptions
/move_group/sense_for_plan/parameter_updates
/move_group/status
/move_group/trajectory_execution/parameter_descriptions
/move_group/trajectory_execution/parameter_updates
/pickup/cancel
/pickup/feedback
/pickup/goal
/pickup/result
/
### 使用MoveIt代码控制实际机械教程 为了使用MoveIt代码控制真实的机器人手,通常需要完成一系列配置和编程工作。这不仅涉及设置MoveIt本身,还包括确保ROS环境能够与物理硬件通信。 #### 配置MoveIt以支持特定型号的机器人手 首先,在启动任何运动规划之前,必须为具体的机器人创建或获取其对应的URDF文件以及相应的MoveIt配置包[^1]。这些资源定义了机器人的几何结构、关节限制和其他重要参数。一旦有了合适的配置包,就可以通过`moveit_setup_assistant`工具进一步定制化设置。 #### 编写用于发送目标位置的服务节点 对于实际控制命令的发出,可以参考如下Python脚本模板: ```python import sys import copy import rospy import moveit_commander import moveit_msgs.msg import geometry_msgs.msg def all_close(goal, actual, tolerance): """ Convenience method for testing if a list of values are within a tolerance of their counterparts in another list @param: goal A list of floats, a Pose or a PoseStamped @param: actual A list of floats, a Pose or a PoseStamped @param: tolerance A float @returns: bool """ all_equal = True if type(goal) is list: for index in range(len(goal)): if abs(actual[index] - goal[index]) > tolerance: return False elif type(goal) is geometry_msgs.msg.PoseStamped: return all_close(goal.pose, actual.pose, tolerance) elif type(goal) is geometry_msgs.msg.Pose: return all_close(pose_to_list(goal), pose_to_list(actual), tolerance) return True class MoveGroupPythonIntefaceTutorial(object): def __init__(self): super(MoveGroupPythonIntefaceTutorial, self).__init__() ## First initialize `moveit_commander`_ and a `rospy`_ node: moveit_commander.roscpp_initialize(sys.argv) rospy.init_node('move_group_python_interface_tutorial', anonymous=True) robot = moveit_commander.RobotCommander() scene = moveit_commander.PlanningSceneInterface() group_name = "arm" move_group = moveit_commander.MoveGroupCommander(group_name) display_trajectory_publisher = rospy.Publisher('/move_group/display_planned_path', moveit_msgs.msg.DisplayTrajectory, queue_size=20) planning_frame = move_group.get_planning_frame() eef_link = move_group.get_end_effector_link() group_names = robot.get_group_names() def go_to_pose_goal(self): move_group = self.move_group pose_goal = geometry_msgs.msg.Pose() pose_goal.orientation.w = 1.0 pose_goal.position.x = 0.4 pose_goal.position.y = 0.1 pose_goal.position.z = 0.4 move_group.set_pose_target(pose_goal) plan = move_group.go(wait=True) move_group.stop() move_group.clear_pose_targets() current_pose = self.move_group.get_current_pose().pose return all_close(pose_goal, current_pose, 0.01) def main(): try: print "" print "----------------------------------------------------------" print "Welcome to the MoveIt MoveGroup Python Interface Tutorial" print "----------------------------------------------------------" print "Press Ctrl-D to exit at any time" print "" print "============ Press `Enter` to begin the tutorial by setting up the moveit_commander ..." raw_input() tutorial = MoveGroupPythonIntefaceTutorial() print "============ Press `Enter` to execute a movement using a pose goal ..." raw_input() tutorial.go_to_pose_goal() print "Complete!" except rospy.ROSInterruptException: pass if __name__ == '__main__': main() ``` 此段代码展示了如何利用MoveIt! API中的`move_group`接口实现基本的动作规划并执行给定的目标姿态。需要注意的是,这段程序假设已经存在名为“arm”的控制器组,并且该设备已经被正确初始化以便接收来自ROS的消息[^2]。 此外,当涉及到视觉处理部分时,比如基于图像识别物体的位置并将之传递给抓取逻辑,则可能需要用到像Baxter这样的案例中提到的技术栈——即订阅摄像头话题并通过OpenCV库分析数据流,最后发布包含对象位姿信息的话题消息给其他组件处理[^3]。
评论 12
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值