Exemplo n.º 1
0
    def test_publish_transition(self):
        ROSINIT()
        lm = LifecycleManager(NODE_NAME)
        lm.start()

        state_sub = rospy.Subscriber(NODE_NAME + '/' + LIFECYCLE_STATE_TOPIC,
                                     Lifecycle, self.subscriber_cb)
        spin_thread = SpinThread(2, "SubscriberCB_Thread", 2)
        spin_thread.setDaemon(True)
        spin_thread.start()

        lm.configure()
        self.assertEquals(State.INACTIVE, lm.get_current_state())
        rospy.sleep(1.0)
        lm.cleanup()
        self.assertEquals(State.UNCONFIGURED, lm.get_current_state())
        rospy.sleep(1.0)
        lm.configure()
        rospy.sleep(1.0)
        lm.activate()
        self.assertEquals(State.ACTIVE, lm.get_current_state())
        rospy.sleep(1.0)
        lm.shutdown()
        self.assertEquals(State.FINALIZED, lm.get_current_state())
        rospy.sleep(3.0)
        self.assertEquals(5, self.Count)

        spin_thread.join(1.0)

        lm.__del__()
Exemplo n.º 2
0
class ManagedNode(object):
    __metaclass__ = ABCMeta

    def __init__(self, component_fqn):
        super(ManagedNode, self).__init__()
        self._lm = LifecycleManager(component_fqn)
        self._lm.set_transition_callback(Transition.CONFIGURE,
                                         self._on_configure)
        self._lm.set_transition_callback(Transition.CLEANUP, self._on_cleanup)
        self._lm.set_transition_callback(Transition.ACTIVATE,
                                         self._on_activate)
        self._lm.set_transition_callback(Transition.DEACTIVATE,
                                         self._on_deactivate)
        self._lm.set_transition_callback(Transition.SHUTDOWN,
                                         self._on_shutdown)
        self._lm.set_error_cb(self._on_error)
        #start the action server
        self._lm.start()

    def __del__(self):
        self._lm.__del__()

    def _on_configure(self):
        return True

    def _on_cleanup(self):
        return False

    '''A node must not start directly after process creation when the life-cycle is in use,
    so the user needs to provide an on_activate callback and this is enforced by using abstractmethod.'''

    @abstractmethod
    def _on_activate(self):
        return True

    def _on_deactivate(self):
        return False

    def _on_shutdown(self):
        return True

    def _on_error(self, ex):
        return False
Exemplo n.º 3
0
 def test_through_action_client(self):
     ROSINIT()
     lm = LifecycleManager(NODE_NAME)
     lm.start()