raspigibbon_joint_subscriber.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # coding: utf-8
3 
4 import rospy
5 from sensor_msgs.msg import JointState
6 from futaba_serial_servo import RS30X
7 
8 
9 class Slave:
10  def __init__(self):
11  self.rs = RS30X.RS304MD()
12  self.sub = rospy.Subscriber("{0}master_joint_state".format(rospy.get_namespace()), JointState, self.joint_callback, queue_size=10)
13  self.r = rospy.Rate(30)
14  for i in range(1,6):
15  self.rs.setTorque(i, True)
16  rospy.sleep(0.01)
17  rospy.loginfo("servo initialized")
18 
19  def joint_callback(self, msg):
20  if len(msg.position) > 0:
21  for i in range(1, 6):
22  self.rs.setAngle(i, msg.position[i-1])
23  self.r.sleep()
24 
25 if __name__ == "__main__":
26  try:
27  while not rospy.is_shutdown():
28  rospy.init_node("slave_joint_state")
29  slave = Slave()
30  rospy.spin()
31  except rospy.ROSInterruptException:
32  pass
33 


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