一、准备的东西
一个机械臂的urdf
规划的路径点
二、launch文件的撰写
1.初始化
<?xml version="1.0" encoding="utf-8"?>
<launch><param name="robot_description" textfile="机械臂.urdf" /><node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" /><node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" /><node name="rviz" pkg="rviz" type="rviz" args="机械臂.rviz"required="true" /></launch>
2.加入自己路径点发布节点后的launch文件
(去除joint_state_publisher即可)
rqt_graph
<?xml version="1.0" encoding="utf-8"?>
<launch><param name="robot_description" textfile="机械臂.urdf" /><node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" /><node name="rviz" pkg="rviz" type="rviz" args="机械臂.rviz"required="true" /></launch>
3.发布路径点话题
写一个节点,它需要发布类型为sensor_msgs / JointState的关节信息
发布了节点之后再打开rqt_grah
sensor_msgs/JointState Documentation
import rospy
import numpy as np
from geometry_msgs.msg import PoseStamped
from sensor_msgs.msg import JointStatedef tra_generate(joints):joints.position[0] += 0.1joints.velocity = []joints.effort = []return jointsdef Path_Publish(): # 初始化节点rospy.init_node("joint_states")# 创建一个发布者,发布数据类型为Pathpub = rospy.Publisher("joint_states", JointState, queue_size=10)# 设置发布频率rate = rospy.Rate(10)joints = JointState()joints.position = [0.1, 0.1, 0.1, 0.1, 0.1, 0.1]joints.name = ["joint_1", "joint_2", "joint_3", "joint_4", "joint_5", "joint_6"]while not rospy.is_shutdown():# 消息while True:msg = tra_generate(joints)msg.header.stamp = rospy.Time.now()# 发布消息rospy.loginfo("Publishing Plan...")pub.publish(msg)# 按照循环频率延时rate.sleep()if __name__ == "__main__":try:Path_Publish()except rospy.ROSInterruptException:pass