ros中绕过控制器直接更新robot的状态

1.将话题改名:(直接rosrun joint_state_publisher /joint_states:= /state无效,不清楚为啥)

<launch>  
   <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher">
   <remap from="/joint_states" to="/state"/>
  </node>
</launch>

2.编写自己的话题,为了与ros时间戳同步,需要接收/state,我们只更改msg.position=[0,0,0,0,0,0]

#!/usr/bin/env python
# -*- coding: utf-8 -*- 

import rospy
from sensor_msgs.msg import JointState

def replaceCallback(msg):
    msg.position=[0,0,0,0,0,0]
    print(msg.position)
    robot_state_transmit_pub.publish(msg)


    
if __name__ == '__main__':
    try:
        rospy.init_node('robot_state_transmit', anonymous = True)
        robot_state_transmit_pub= rospy.Publisher('/joint_states', JointState, queue_size=10)
        rospy.Subscriber("/state", 
                        JointState, 
                        replaceCallback)
        rospy.spin()
    except rospy.ROSInterruptException:
        pass

资源链接:
https://download.csdn.net/download/qq_41673009/86220437

你可能感兴趣的:(ros接口moveit,其他)