示例#1
0
 def __init__(self, **kwargs):
     assert all(['_' + key in self.__slots__ for key in kwargs.keys()]), \
         "Invalid arguments passed to constructor: %r" % kwargs.keys()
     from lifecycle_msgs.msg import Transition
     self.transition = kwargs.get('transition', Transition())
     from lifecycle_msgs.msg import State
     self.start_state = kwargs.get('start_state', State())
     from lifecycle_msgs.msg import State
     self.goal_state = kwargs.get('goal_state', State())
 def __init__(self, **kwargs):
     assert all('_' + key in self.__slots__ for key in kwargs.keys()), \
         'Invalid arguments passed to constructor: %s' % \
         ', '.join(sorted(k for k in kwargs.keys() if '_' + k not in self.__slots__))
     from lifecycle_msgs.msg import Transition
     self.transition = kwargs.get('transition', Transition())
     from lifecycle_msgs.msg import State
     self.start_state = kwargs.get('start_state', State())
     from lifecycle_msgs.msg import State
     self.goal_state = kwargs.get('goal_state', State())
示例#3
0
    def activate(self):
        if (self.state == State.PRIMARY_STATE_INACTIVE):

            self.state = State.TRANSITION_STATE_ACTIVATING

            self.pub_transition_event.publish(
                TransitionEvent(
                    timestamp=self.get_clock().now().nanoseconds,
                    transition=Transition(id=Transition.TRANSITION_ACTIVATE,
                                          label=self.get_label(
                                              Transition,
                                              Transition.TRANSITION_ACTIVATE)),
                    start_state=State(id=State.PRIMARY_STATE_INACTIVE,
                                      label=self.get_label(
                                          State,
                                          State.PRIMARY_STATE_INACTIVE)),
                    goal_state=State(id=self.state,
                                     label=self.get_label(State, self.state))))

            task_activate = self.executor.create_task(self.on_activate)

            self.executor.spin_until_future_complete(task_activate)

            result_transition = None
            if (task_activate.result() ==
                    Transition.TRANSITION_CALLBACK_SUCCESS):
                self.state = State.PRIMARY_STATE_ACTIVE
                result_transition = Transition.TRANSITION_ON_ACTIVATE_SUCCESS

            elif (task_activate.result() ==
                  Transition.TRANSITION_CALLBACK_FAILURE):
                self.state = State.PRIMARY_STATE_INACTIVE
                result_transition = Transition.TRANSITION_ON_ACTIVATE_FAILURE

            else:
                self.state = State.TRANSITION_STATE_ERRORPROCESSING
                result_transition = Transition.TRANSITION_ON_CONFIGURE_ERROR

            self.pub_transition_event.publish(
                TransitionEvent(
                    timestamp=self.get_clock().now().nanoseconds,
                    transition=Transition(id=result_transition,
                                          label=self.get_label(
                                              Transition, result_transition)),
                    start_state=State(id=State.TRANSITION_STATE_ACTIVATING,
                                      label=self.get_label(
                                          State,
                                          State.TRANSITION_STATE_ACTIVATING)),
                    goal_state=State(id=self.state,
                                     label=self.get_label(State, self.state))))

            return task_activate.result()

        else:
            return Transition.TRANSITION_CALLBACK_FAILURE
示例#4
0
    def create(self):
        if (self.state == State.PRIMARY_STATE_UNKNOWN):
            self.pub_transition_event.publish(
                TransitionEvent(
                    timestamp=self.get_clock().now().nanoseconds,
                    transition=Transition(id=Transition.TRANSITION_CREATE,
                                          label=self.get_label(
                                              Transition,
                                              Transition.TRANSITION_CREATE)),
                    start_state=State(id=State.PRIMARY_STATE_UNKNOWN,
                                      label=self.get_label(
                                          State, State.PRIMARY_STATE_UNKNOWN)),
                    goal_state=State(id=State.PRIMARY_STATE_UNCONFIGURED,
                                     label=self.get_label(
                                         State,
                                         State.PRIMARY_STATE_UNCONFIGURED))))

            self.state = State.PRIMARY_STATE_UNCONFIGURED
            return Transition.TRANSITION_CALLBACK_SUCCESS
        else:
            return Transition.TRANSITION_CALLBACK_FAILURE
示例#5
0
 def get_state(self, request, response):
     response.current_state = State(id=self.state,
                                    label=self.get_label(State, self.state))
     return response
示例#6
0
    def shutdown(self):
        if (self.state == State.PRIMARY_STATE_UNCONFIGURED):
            self.pub_transition_event.publish(
                TransitionEvent(
                    timestamp=self.get_clock().now().nanoseconds,
                    transition=Transition(
                        id=Transition.TRANSITION_UNCONFIGURED_SHUTDOWN,
                        label=self.get_label(
                            Transition,
                            Transition.TRANSITION_UNCONFIGURED_SHUTDOWN)),
                    start_state=State(id=State.PRIMARY_STATE_UNCONFIGURED,
                                      label=self.get_label(
                                          State,
                                          State.PRIMARY_STATE_UNCONFIGURED)),
                    goal_state=State(
                        id=State.TRANSITION_STATE_SHUTTINGDOWN,
                        label=self.get_label(
                            State, State.TRANSITION_STATE_SHUTTINGDOWN))))

        elif (self.state == State.PRIMARY_STATE_INACTIVE):
            self.pub_transition_event.publish(
                TransitionEvent(
                    timestamp=self.get_clock().now().nanoseconds,
                    transition=Transition(
                        id=Transition.TRANSITION_INACTIVE_SHUTDOWN,
                        label=self.get_label(
                            Transition,
                            Transition.TRANSITION_INACTIVE_SHUTDOWN)),
                    start_state=State(id=State.PRIMARY_STATE_INACTIVE,
                                      label=self.get_label(
                                          State,
                                          State.PRIMARY_STATE_INACTIVE)),
                    goal_state=State(
                        id=State.TRANSITION_STATE_SHUTTINGDOWN,
                        label=self.get_label(
                            State, State.TRANSITION_STATE_SHUTTINGDOWN))))

        elif (self.state == State.PRIMARY_STATE_ACTIVE):
            self.pub_transition_event.publish(
                TransitionEvent(
                    timestamp=self.get_clock().now().nanoseconds,
                    transition=Transition(
                        id=Transition.TRANSITION_ACTIVE_SHUTDOWN,
                        label=self.get_label(
                            Transition,
                            Transition.TRANSITION_ACTIVE_SHUTDOWN)),
                    start_state=State(id=State.PRIMARY_STATE_ACTIVE,
                                      label=self.get_label(
                                          State, State.PRIMARY_STATE_ACTIVE)),
                    goal_state=State(
                        id=State.TRANSITION_STATE_SHUTTINGDOWN,
                        label=self.get_label(
                            State, State.TRANSITION_STATE_SHUTTINGDOWN))))

        else:
            return Transition.TRANSITION_CALLBACK_FAILURE

        self.state = State.TRANSITION_STATE_SHUTTINGDOWN

        task_shutdown = self.executor.create_task(self.on_shutdown)

        self.executor.spin_until_future_complete(task_shutdown)

        result_transition = None
        if (task_shutdown.result() == Transition.TRANSITION_CALLBACK_SUCCESS):
            self.state = State.PRIMARY_STATE_FINALIZED
            result_transition = Transition.TRANSITION_ON_SHUTDOWN_SUCCESS

        else:
            self.state = State.TRANSITION_STATE_ERRORPROCESSING
            result_transition = Transition.TRANSITION_ON_SHUTDOWN_ERROR

        self.pub_transition_event.publish(
            TransitionEvent(
                timestamp=self.get_clock().now().nanoseconds,
                transition=Transition(id=result_transition,
                                      label=self.get_label(
                                          Transition, result_transition)),
                start_state=State(id=State.TRANSITION_STATE_SHUTTINGDOWN,
                                  label=self.get_label(
                                      State,
                                      State.TRANSITION_STATE_SHUTTINGDOWN)),
                goal_state=State(id=self.state,
                                 label=self.get_label(State, self.state))))

        return task_shutdown.result()
示例#7
0
    def __init__(self, node_name: str):
        super().__init__(node_name)
        self.state = State.PRIMARY_STATE_UNKNOWN

        self.available_transitions = None
        self.available_states = [
            State(id=State.PRIMARY_STATE_UNKNOWN,
                  label=self.get_label(State, State.PRIMARY_STATE_UNKNOWN)),
            State(id=State.PRIMARY_STATE_UNCONFIGURED,
                  label=self.get_label(State,
                                       State.PRIMARY_STATE_UNCONFIGURED)),
            State(id=State.PRIMARY_STATE_INACTIVE,
                  label=self.get_label(State, State.PRIMARY_STATE_INACTIVE)),
            State(id=State.PRIMARY_STATE_ACTIVE,
                  label=self.get_label(State, State.PRIMARY_STATE_ACTIVE)),
            State(id=State.PRIMARY_STATE_FINALIZED,
                  label=self.get_label(State, State.PRIMARY_STATE_FINALIZED)),
            State(id=State.TRANSITION_STATE_CONFIGURING,
                  label=self.get_label(State,
                                       State.TRANSITION_STATE_CONFIGURING)),
            State(id=State.TRANSITION_STATE_CLEANINGUP,
                  label=self.get_label(State,
                                       State.TRANSITION_STATE_CLEANINGUP)),
            State(id=State.TRANSITION_STATE_SHUTTINGDOWN,
                  label=self.get_label(State,
                                       State.TRANSITION_STATE_SHUTTINGDOWN)),
            State(id=State.TRANSITION_STATE_ACTIVATING,
                  label=self.get_label(State,
                                       State.TRANSITION_STATE_ACTIVATING)),
            State(id=State.TRANSITION_STATE_DEACTIVATING,
                  label=self.get_label(State,
                                       State.TRANSITION_STATE_DEACTIVATING)),
            State(id=State.TRANSITION_STATE_ERRORPROCESSING,
                  label=self.get_label(State,
                                       State.TRANSITION_STATE_ERRORPROCESSING))
        ]

        self.srv_get_state = self.create_service(GetState,
                                                 node_name + '/get_state',
                                                 self.get_state)

        self.srv_change_state = self.create_service(
            ChangeState, node_name + '/change_state', self.change_state)

        self.srv_get_available_states = self.create_service(
            GetAvailableStates, node_name + '/get_available_states',
            self.get_available_states)

        self.srv_get_available_transitions = self.create_service(
            GetAvailableTransitions, node_name + '/get_available_transitions',
            self.get_available_transitions)

        self.pub_transition_event = self.create_publisher(
            TransitionEvent, node_name + '/transition_event', 1)

        self.create()
示例#8
0
 def __init__(self, **kwargs):
     assert all(['_' + key in self.__slots__ for key in kwargs.keys()]), \
         "Invalid arguments passed to constructor: %r" % kwargs.keys()
     from lifecycle_msgs.msg import State
     self.current_state = kwargs.get('current_state', State())