rviz_joint_publisher.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # coding: utf-8
3 
4 import rospy
5 import math
6 from sensor_msgs.msg import JointState
7 
8 
9 class RvizMaster:
10  def __init__(self):
11  self.sub = rospy.Subscriber("/raspigibbon_on_rviz/joint_states", JointState, self.joint_callback, queue_size=10)
12  self.pub = rospy.Publisher("master_joint_state", JointState, queue_size=10)
13  self.r = rospy.Rate(40)
14 
15  def joint_callback(self, msg):
16  js = JointState();
17  if len(msg.position) > 0:
18  js.name = ["joint{}".format(i) for i in range(1, 6)]
19  js.position = [max(-150, min(150, math.degrees(msg.position[i]))) for i in range(0, 5)]
20  self.pub.publish(js)
21  self.r.sleep()
22 
23 if __name__ == "__main__":
24  try:
25  while not rospy.is_shutdown():
26  rospy.init_node("rviz_joint_state_publisher")
27  rviz = RvizMaster()
28  rospy.spin()
29  except rospy.ROSInterruptException:
30  pass
31 


raspigibbon_bringup
Author(s): Daisuke Sato , Shota Hirama
autogenerated on Mon Jun 10 2019 14:27:11