适合初学者的ROS机器⼈教程(3):ROS下使⽤Python对UR5机器⼈建模与
控制
作者:知乎
1. 安装UR机器⼈ROS包
$ sudo apt-get install ros-kinetic-universal-robot
2. 查询下看看有哪些包是和UR机器相关
$ sudo rospack list | grep ur
sqlserver备份到本地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和service这两种通信机制实现发送命令和接收数据。topic是
单⽅⾯通信,就是我只管发不管收,或只管收不发东西。service这种是双向通信,我既可以发给你,你也可以反馈信息给我。他们通信的格式叫做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/set_link_state
/
gazebo/set_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。pose是位姿,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]]
def main():
rospy.init_node('send_joints')
pub = rospy.Publisher('/arm_controller/command',
JointTrajectory,
queue_size=10)
# Create the topic message随机数据生成
html表格里面嵌套表格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)strcmp和strncmp的区别
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:
python入门教程 下载print("Program interrupted before completion")
MoveIt!⼯作机制
所有的接⼝都是和名字叫做move_group的这个节点通信。机械臂关节点信息是通过Robot Sensors这个节点获取。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。