做者:知乎@Ai酱node
- 安装UR机器人ROS包
$ sudo apt-get install ros-kinetic-universal-robot
- 查询下看看有哪些包是和UR机器相关
$ sudo rospack list | grep ur
ur5_moveit_config /opt/ros/kinetic/share/ur5_moveit_config moveit!配置功能包 ur_description /opt/ros/kinetic/share/ur_description UR机器模型包 ur_gazebo /opt/ros/kinetic/share/ur_gazebo UR机器人仿真包 ur_kinematics /opt/ros/kinetic/share/ur_kinematics UR机器人运动学求解
- 在Gazebo中启动UR5机器人
$ roslaunch ur_gazebo ur5.launch
- 了解一个机器人首先得了解怎么发送命令控制它。在ROS中是用过topic和service这两种通讯机制实现发送命令和接收数据。topic是单方面通讯,就是我只管发无论收,或只管收不发东西。service这种是双向通讯,我既能够发给你,你也能够反馈信息给我。他们通讯的格式叫作message(不是咱们理解的消息),这是指消息的格式。
- 查看下UR机器人给咱们提供了那些topic通讯接口。
~$ rostopic list /arm_controller/command /arm_controller/follow_joint_trajectory/cancel /arm_controller/follow_joint_trajectory/feedback /arm_controller/follow_joint_trajectory/goal /arm_controller/follow_joint_trajectory/result /arm_controller/follow_joint_trajectory/status /arm_controller/state /calibrated /clock /gazebo/link_states /gazebo/model_states /gazebo/parameter_descriptions /gazebo/parameter_updates /gazebo/set_link_state /gazebo/set_model_state /gazebo_gui/parameter_descriptions /gazebo_gui/parameter_updates /joint_states /rosout /rosout_agg /tf /tf_static
使用MoveIt控制UR5机器人参见:https://blog.csdn.net/varyshare/article/details/89212971
运行UR5机器人三行命令,每行命令都是得在一个新的独立terminal命令行终端里面执行。python
roslaunch ur_gazebo ur5.launch limited:=true roslaunch ur5_moveit_config ur5_moveit_planning_execution.launch sim:=true limited:=true roslaunch ur5_moveit_config moveit_rviz.launch config:=true
rqt可视化很是有用:启动rqt命令 rosrun rqt_gui rqt_gui
,rqt简直是ROS中的J20啊,太有用了。不知道下载的包各消息接口的时候能够用rqt能够可视化的显示消息并且还能够监听消息。不知道如今运行的节点有哪些,它也能够可视化显示。git
UR5有用的一些消息接口
获取机械臂速度和位置信息监听topic:/arm_controller/state
获取机械臂位置和姿态、角速度和速度监听topic:/gazebo/link_states
。pose是位姿,twist是线速度角速度。
能获取意味着能发送命令控制它。
还有能够获取位置和线速度方法:joint_states
github
怎么编程控制UR5机器人
首先把安装的包都加入到catkin工做空间
catkin config --extend /opt/ros/kinetic
。编程
catkin 命令不存在?请尝试这个安装catkin
sudo apt-get install ros-kinetic-catkin python-catkin-tools
python控制UR5机器人随机转动参考:https://github.com/vfdev-5/move_group_tutorial_ur5app
#!/usr/bin/python # Gazebo UR5 # Send joint values to UR5 using messages # from std_msgs.msg import Header from trajectory_msgs.msg import JointTrajectory from math import * from random import uniform from trajectory_msgs.msg import JointTrajectoryPoint import rospy # [0.0, -pi/2, pi/2, pi/3, 0, -pi/10] # waypoints = [[uniform(-pi, pi) for _ in range(0,6)], [0,0,0,0,0,0]] def main(): rospy.init_node('send_joints') pub = rospy.Publisher('/arm_controller/command', JointTrajectory, queue_size=10) # Create the topic message traj = JointTrajectory() traj.header = Header() # Joint names for UR5 traj.joint_names = ['shoulder_pan_joint', 'shoulder_lift_joint', 'elbow_joint', 'wrist_1_joint', 'wrist_2_joint', 'wrist_3_joint'] rate = rospy.Rate(1) cnt = 0 pts = JointTrajectoryPoint() traj.header.stamp = rospy.Time.now() while not rospy.is_shutdown(): pts.positions = [uniform(0,pi),uniform(0,-pi/2),uniform(0,pi),uniform(0,pi),uniform(0,pi),uniform(0,pi)] pts.time_from_start = rospy.Duration(1.0) cnt+=1 cnt%=2 # Set the points to the trajectory traj.points = [] traj.points.append(pts) # Publish the message pub.publish(traj) rate.sleep() if __name__ == '__main__': try: main() except rospy.ROSInterruptException: print ("Program interrupted before completion")
MoveIt!工做机制
全部的接口都是和名字叫作move_group的这个节点通讯。
机械臂关节点信息是经过Robot Sensors这个节点获取。
dom