def _make_alarms(cls): cls.kill_listener = yield TxAlarmListener.init(cls.nh, 'kill', cls.kill_alarm_cb) cls.odom_loss_listener = yield TxAlarmListener.init( cls.nh, 'odom-kill', lambda _, alarm: setattr(cls, 'odom_loss', alarm.raised)) fprint("Alarm listener created, listening to alarms: ", title="NAVIGATOR") cls.kill_alarm = yield cls.kill_listener.get_alarm() cls.killed = cls.kill_alarm.raised cls.odom_loss = yield cls.odom_loss_listener.is_raised() fprint("\tkill :", newline=False) fprint(cls.killed) fprint("\todom-kill :", newline=False) fprint(cls.odom_loss)
def run(sub): al = yield TxAlarmListener.init(sub.nh, "network-loss") _auto_param_watchdog(sub.nh) call_with_sub = lambda *args: _check_for_run(sub, *args) al.add_callback(call_with_sub, call_when_cleared=False) fprint("Waiting for network-loss...", msg_color="blue") yield defer.Deferred()
def main(): global publish nh = yield txros.NodeHandle.from_argv('tx_hearbeat_test') alarm_name = "test_alarm123" hbm = yield TxHeartbeatMonitor.init(nh, alarm_name, "/heartbeat", String, nowarn=True) monitor_df = hbm.start_monitor() do_publishing(nh) al = yield TxAlarmListener.init(nh, alarm_name) print "Inital Clear test" assert (yield al.is_cleared()) yield nh.sleep(0.5) print "Heartbeat raise test" publish = False yield nh.sleep(1) assert (yield al.is_raised()) yield nh.sleep(0.5) print "Hearbeat clear test" publish = True yield nh.sleep(1) assert (yield al.is_cleared()) print "Stop monitoring test" monitor_df.addErrback(lambda e: e.trap(defer.CancelledError)).cancel() publish = False yield nh.sleep(1) assert (yield al.is_cleared()) yield nh.sleep(0.5) print "Predicated test" publish = True @txros.util.cancellableInlineCallbacks def cb(nh, alarm): yield nh.sleep(1) defer.returnValue(False) # Should never raise hbm.set_predicate(cb) monitor_df = hbm.start_monitor() yield nh.sleep(0.5) publish = False yield nh.sleep(0.5) assert (yield al.is_cleared()) print "\nPassed!"
def main(): nh = yield txros.NodeHandle.from_argv('tx_alarm_test') alarm_name = "tx" ab = yield TxAlarmBroadcaster.init(nh, alarm_name) al = yield TxAlarmListener.init(nh, alarm_name, nowarn=True) assert (yield al.is_cleared()) yield ab.raise_alarm() assert (yield al.is_raised()) yield ab.raise_alarm() assert (yield al.is_raised()) yield ab.clear_alarm() assert (yield al.is_cleared()) var = False @txros.util.cancellableInlineCallbacks def cb(nh, alarm): global var var = True yield nh.sleep(1) print "DONE SLEEPING" yield al.add_callback(cb, call_when_raised=False) yield nh.sleep(.1) assert not var yield ab.raise_alarm() assert not var yield ab.clear_alarm() assert not var print "\nPassed" yield nh.sleep(2)