36 from .
import BondSM_sm
38 from bond.msg
import Constants, Status
42 if not isinstance(d, rospy.Duration):
43 return rospy.Duration.from_sec(d)
48 if isinstance(d, rospy.Duration):
58 self.
timer.daemon =
True
65 self.
timer.daemon =
True
74 return max(rospy.Duration(0), rospy.Duration(self.
deadline - time.time()))
94 def __init__(self, topic, id, on_broken=None, on_formed=None):
126 self.
pub = rospy.Publisher(self.
topic, Status, queue_size=1)
135 connect_timeout = property(get_connect_timeout, set_connect_timeout)
144 heartbeat_timeout = property(get_heartbeat_timeout, set_heartbeat_timeout)
153 disconnect_timeout = property(get_disconnect_timeout, set_disconnect_timeout)
161 heartbeat_period = property(get_heartbeat_period, set_heartbeat_period)
176 self.
sm.ConnectTimeout()
181 disable_heartbeat_timeout = rospy.get_param(
182 Constants.DISABLE_HEARTBEAT_TIMEOUT_PARAM,
False)
183 if disable_heartbeat_timeout:
185 "Heartbeat timeout is disabled. Not breaking bond (topic: %s, id: %s)" %
190 self.
sm.HeartbeatTimeout()
195 self.
sm.DisconnectTimeout()
203 if self.
sub is not None:
204 self.
sub.unregister()
207 if self.
sm.getState().getName() !=
'SM.Dead':
209 self.
pub.unregister()
217 if msg.id == self.
id and msg.instance_id != self.
instance_id:
224 "More than two locations are trying to use a single bond (topic: %s, id: %s). " +
225 "You should only instantiate at most two bond instances for each (topic, id) pair." %
230 self.
sm.SisterAlive()
241 msg.header.stamp = rospy.Time.now()
247 self.
pub.publish(msg)
252 while not self.
is_shutdown and self.
sm.getState().getName()
in [
'SM.WaitingForSister',
'SM.Alive']:
257 while not self.
is_shutdown and self.
sm.getState().getName() ==
'SM.AwaitSisterDeath':
259 self.
condition.wait(Constants.DEAD_PUBLISH_PERIOD)
318 while self.
sm.getState().getName() ==
'SM.WaitingForSister':
319 if rospy.is_shutdown():
325 wait_duration = min(wait_duration, self.
deadline.left().to_sec())
327 return self.
sm.getState().getName() !=
'SM.WaitingForSister'
340 while self.
sm.getState().getName() !=
'SM.Dead':
341 if rospy.is_shutdown():
347 wait_duration = min(wait_duration, self.
deadline.left().to_sec())
349 return self.
sm.getState().getName() ==
'SM.Dead'
355 return self.
sm.getState().getName() ==
'SM.Dead'
365 return "[Bond %s, Instance %s (%s)]" % \