watermelon的音标适合初学者的ROS机器⼈教程(3):ROS下使⽤Python对UR5机器⼈建模与
控制
作者:知乎
1. 安装UR机器⼈ROS包
$ sudo apt-get install ros-kinetic-universal-robot
acorn
entertaining2. 查询下看看有哪些包是和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机器⼈运动学求解
3. 在Gazebo中启动UR5机器⼈
$ roslaunch ur_gazebo ur5.launch
4. 了解⼀个机器⼈⾸先得了解怎么发送命令控制它。在ROS中是⽤过topic和rvice这两种通信机制实现发送命令和接收数据。topic是
单⽅⾯通信,就是我只管发不管收,或只管收不发东西。rvice这种是双向通信,我既可以发给你,你也可以反馈信息给我。他们通信的格式叫做message(不是我们理解的消息),这是指消息的格式。
5. 查看下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/t_link_state
/
kra
gazebo/t_model_state
/gazebo_gui/parameter_descriptions
/gazebo_gui/parameter_updates
/joint_states
/rosout
/rosout_agg
/tf
/tf_static
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可以可视化的显⽰消息⽽且还可以监听消息。不知道现在运⾏的节点有哪些,它也可以可视化显⽰。
UR5有⽤的⼀些消息接⼝
获取机械臂速度和位置信息监听topic:/arm_controller/state
获取机械臂位置和姿态、⾓速度和速度监听topic:/gazebo/link_states。po是位姿,twist是线速度⾓速度。
能获取意味着能发送命令控制它。
还有可以获取位置和线速度⽅法:joint_states
怎么编程控制UR5机器⼈
⾸先把安装的包都加⼊到catkin⼯作空间
catkin config --extend /opt/ros/kinetic。
绯闻女孩演员
#!/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]]
toro什么意思
def main():
rospy.init_node('nd_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 = w()
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这个节点获取。