|
32 | 32 | from manipulator import Manipulator
|
33 | 33 | from std_msgs.msg import Float64
|
34 | 34 | import rospy
|
| 35 | +from ..util import Watchdog |
| 36 | +from functools import partial |
35 | 37 |
|
36 | 38 | class Mico(Manipulator):
|
37 | 39 | def __init__(self, sim,
|
@@ -69,11 +71,13 @@ def __init__(self, sim,
|
69 | 71 | self.GetName(), '', self.GetArmIndices(), 0, True)
|
70 | 72 | self.servo_simulator = ServoSimulator(self, rate=20,
|
71 | 73 | watchdog_timeout=0.1)
|
72 |
| - |
73 | 74 | else:
|
74 |
| - #if not simulation, create publishers for each joint |
| 75 | + #if not simulation, create publishers for each joint |
75 | 76 | self.velocity_topic_names = ['vel_j'+str(i)+'_controller/command' for i in range(1,7)]
|
76 |
| - self.velocity_publishers = [rospy.Publisher(topic_name, Float64) for topic_name in self.velocity_topic_names] |
| 77 | + self.velocity_publishers = [rospy.Publisher(topic_name, Float64, queue_size=1) for topic_name in self.velocity_topic_names] |
| 78 | + |
| 79 | + #create watchdog to send zero velocity |
| 80 | + self.servo_watchdog = Watchdog(timeout_duration=0.3, handler=lambda: self.SendVelocitiesToMico([0.,0.,0.,0.,0.,0.,])) |
77 | 81 |
|
78 | 82 | def CloneBindings(self, parent):
|
79 | 83 | super(Mico, self).CloneBindings(parent)
|
@@ -106,9 +110,11 @@ def Servo(self, velocities):
|
106 | 110 | self.GetRobot().GetController().Reset(0)
|
107 | 111 | self.servo_simulator.SetVelocity(velocities)
|
108 | 112 | else:
|
109 |
| - for velocity_publisher,velocity in zip(self.velocity_publishers, velocities): |
110 |
| - velocity_publisher.publish(velocity) |
111 |
| - #raise NotImplementedError('Servo is not implemented.') |
112 |
| - |
| 113 | + self.SendVelocitiesToMico(velocities) |
| 114 | + #reset watchdog timer |
| 115 | + self.servo_watchdog.reset() |
113 | 116 |
|
114 | 117 |
|
| 118 | + def SendVelocitiesToMico(self, velocities): |
| 119 | + for velocity_publisher,velocity in zip(self.velocity_publishers, velocities): |
| 120 | + velocity_publisher.publish(velocity) |
0 commit comments