Skip to content

Instantly share code, notes, and snippets.

@534o
Created August 31, 2017 07:40
Show Gist options
  • Save 534o/e60419a5f87bdce8edb3910050fc1d46 to your computer and use it in GitHub Desktop.
Save 534o/e60419a5f87bdce8edb3910050fc1d46 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import rospy
from sensor_msgs.msg import JointState
def joint_state_publisher():
rospy.init_node('hand_joint_state_publisher', anonymous=True)
pub = rospy.Publisher('joint_states', JointState, queue_size=1)
joint_list = ['RHAND_JOINT1']
rospy.loginfo("{} publishes fake joint states of {}".format(rospy.get_name(), joint_list))
rate = rospy.Rate(3) # 3hz
while not rospy.is_shutdown():
joint_states = JointState()
joint_states.header.stamp = rospy.Time.now()
joint_states.name = []
joint_states.position = []
for joint in joint_list:
joint_states.name.append(joint)
joint_states.position.append(0)
rospy.logdebug(joint_states)
pub.publish(joint_states)
rate.sleep()
if __name__ == '__main__':
try:
joint_state_publisher()
except rospy.ROSInterruptException:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment