32 from __future__
import print_function
38 import roslib; roslib.load_manifest(
'test_bond')
40 from bond.msg
import Constants, Status
41 from test_bond.srv
import TestBond, TestBondResponse
44 atexit.register(rospy.signal_shutdown,
'exit')
58 self.
timer = threading.Timer(self.duration.to_sec(), self.
_on_timer)
67 return max(rospy.Duration(0), self.
deadline - rospy.Time.now())
88 self.
lock = threading.RLock()
98 self.connect_timeout.reset()
104 self.thread.daemon =
True 107 if req.delay_death >= rospy.Duration(0.0):
114 self.sm.ConnectTimeout()
117 if self.req.inhibit_death:
120 self.sm.HeartbeatTimeout()
124 self.sm.DisconnectTimeout()
133 if self.sm.getState().getName() !=
'SM.Dead':
134 print(
"I'm not dead yet:%s in %s" % (self.
id, self.sm.getState().getName()))
136 self.sub.unregister()
137 self.pub.unregister()
138 self.condition.notify_all()
139 print(
"Unregistered")
143 if msg.id == self.
id and msg.instance_id != self.
instance_id:
147 self.sm.SisterAlive()
149 if self.req.inhibit_death:
160 msg.header.stamp = rospy.Time.now()
165 if not msg.active
and self.req.inhibit_death_message:
168 self.pub.publish(msg)
172 time.sleep(self.req.delay_connect.to_sec())
176 while not self.
is_shutdown and self.sm.getState().getName()
in [
177 'SM.WaitingForSister',
'SM.Alive']:
179 self.condition.wait(Constants.DEFAULT_HEARTBEAT_PERIOD)
182 while not self.
is_shutdown and self.sm.getState().getName() ==
'SM.AwaitSisterDeath':
184 self.condition.wait(Constants.DEAD_PUBLISH_PERIOD)
187 self.connect_timeout.cancel()
188 self.condition.notify_all()
193 self.heartbeat_timeout.reset()
199 self.condition.notify_all()
200 self.heartbeat_timeout.cancel()
201 self.disconnect_timeout.cancel()
206 self.heartbeat_timeout.cancel()
207 self.disconnect_timeout.reset()
213 self.deadline.cancel()
218 while self.sm.getState().getName() ==
'SM.WaitingForSister':
219 if self.
deadline and self.deadline.left() == rospy.Duration(0):
221 self.condition.wait(self.
deadline and self.deadline.left().to_sec())
222 return self.sm.getState().getName() !=
'SM.WaitingForSister' 226 self.deadline.cancel()
231 while self.sm.getState().getName() !=
'SM.Dead':
232 if self.
deadline and self.deadline.left() == rospy.Duration(0):
234 self.condition.wait(self.
deadline and self.deadline.left().to_sec())
235 return self.sm.getState().getName() ==
'SM.Dead' 239 return self.sm.getState().getName() ==
'SM.Dead' 247 return "[Bond %s, Instance %s (%s)]" % (
259 self.bond_tester.shutdown()
261 print(
"Test bond instance id: %s" % self.bond_tester.instance_id)
262 return TestBondResponse()
266 rospy.init_node(
'bond_tester', anonymous=
True, disable_signals=
True)
271 if __name__ ==
'__main__':
def _on_bond_status(self, msg)
def _publish(self, active)
def wait_for_life(self, timeout=None)
def __init__(self, duration, on_timeout=None)
def _on_connect_timeout(self)
def _test_bond(self, req)
def wait_for_death(self, timeout=None)
def _on_heartbeat_timeout(self)
def _on_disconnect_timeout(self)
def _publishing_thread(self)