servo_test.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # license removed for brevity
3 import rospy
4 #from std_msgs.msg import Int8
5 from marty_msgs.msg import ServoMsg, ServoMsgArray
6 
7 def talker():
8  pub = rospy.Publisher('/marty/servo_array', ServoMsgArray, queue_size=10)
9  rospy.init_node('servo_test', anonymous=True)
10  rate = rospy.Rate(50)
11  servo_cmd_array = ServoMsgArray()
12  servo_cmd_1 = ServoMsg()
13  servo_cmd_2 = ServoMsg()
14  servo_cmd_1.servo_id = 7
15  servo_cmd_1.servo_cmd = 0
16  servo_cmd_2.servo_id = 8
17  servo_cmd_2.servo_cmd = 0
18  servo_cmd_array.servo_msg.append(servo_cmd_1)
19  servo_cmd_array.servo_msg.append(servo_cmd_2)
20  servo_cmd = 0
21 
22  up = True
23  inc = 5
24  lim = 120
25  while not rospy.is_shutdown():
26  if (up == True):
27  if (servo_cmd < lim):
28  servo_cmd = servo_cmd + inc
29  else:
30  up = False
31  else:
32  if (servo_cmd > -lim):
33  servo_cmd = servo_cmd - inc
34  else:
35  up = True
36 
37  servo_cmd_array.servo_msg[0].servo_cmd = servo_cmd
38  servo_cmd_array.servo_msg[1].servo_cmd = servo_cmd
39  pub.publish(servo_cmd_array)
40  rate.sleep()
41 
42 if __name__ == '__main__':
43  try:
44  talker()
45  except rospy.ROSInterruptException:
46  pass
def talker()
Definition: servo_test.py:7


ros_marty
Author(s): Alejandro Bordallo
autogenerated on Fri Jul 21 2017 14:51:45