예제 #1
0
def fsm():
    class StateOne(State):
        async def run(self):
            self.agent.state = STATE_ONE
            self.set_next_state(STATE_TWO)
            self.kill()
            await self.agent.sync1_behaviour.wait()

    class StateTwo(State):
        async def run(self):
            self.agent.state = STATE_TWO
            self.set_next_state(STATE_THREE)
            self.kill()
            await self.agent.sync2_behaviour.wait()

    class StateThree(State):
        async def run(self):
            self.agent.state = STATE_THREE
            self.kill()

    fsm_ = FSMBehaviour()
    state_one = StateOne()
    state_two = StateTwo()
    state_three = StateThree()
    fsm_.add_state(STATE_ONE, state_one, initial=True)
    fsm_.add_state(STATE_TWO, state_two)
    fsm_.add_state(STATE_THREE, state_three)
    fsm_.add_transition(STATE_ONE, STATE_TWO)
    fsm_.add_transition(STATE_TWO, STATE_THREE)

    fsm_.state_one = state_one
    fsm_.state_two = state_two
    fsm_.state_three = state_three

    return fsm_
예제 #2
0
def test_fsm_fail_on_end():
    class StateOne(State):
        async def run(self):
            pass

        async def on_end(self):
            raise Exception

    fsm_ = FSMBehaviour()
    state_one = StateOne()
    fsm_.add_state(STATE_ONE, state_one, initial=True)

    agent = make_connected_agent()
    future = agent.start(auto_register=False)
    future.result()

    agent.add_behaviour(fsm_)

    fsm_.join()

    assert fsm_.is_killed()

    assert type(fsm_.exit_code) == Exception

    agent.stop()
예제 #3
0
    async def setup(self):
        print("[{}] Starting".format(self.jid))
        self.count = 0

        self.behaviour = FSMBehaviour()
        self.behaviour.add_state(name="Hello", state=self.Hello(), initial=True)
        self.behaviour.add_state(name="Count", state=self.Count())
        self.behaviour.add_state(name="Die", state=self.Die())
        self.behaviour.add_transition(source="Hello", dest="Count")
        self.behaviour.add_transition(source="Count", dest="Count")
        self.behaviour.add_transition(source="Count", dest="Die")
        self.add_behaviour(self.behaviour)
예제 #4
0
파일: CTroop.py 프로젝트: gti-ia/pgomas
    def Launch_FSM_Behaviour(self):

        # FSM Declaration
        self.m_FSM = FSMBehaviour()

        # Register state STATE_STANDING (first state)
        self.m_FSM.add_state(self.STATE_STANDING,
                             self.FSM_Standing(),
                             initial=True)

        # Register state STATE_GOTO_TARGET
        self.m_FSM.add_state(self.STATE_GOTO_TARGET, self.FSM_GoToTarget())

        # Register state STATE_TARGET_REACHED
        self.m_FSM.add_state(self.STATE_TARGET_REACHED,
                             self.FSM_TargetReached())

        # Register state STATE_FIGHTING
        self.m_FSM.add_state(self.STATE_FIGHTING, self.FSM_Fighting())

        # Register state STATE_QUIT (final state)
        self.m_FSM.add_state(self.STATE_QUIT, self.FSM_Quit())

        # Register the transitions
        # m_FSM.registerDefaultTransition(STATE_STANDING, STATE_QUIT);
        # self.m_FSM.registerDefaultTransition(self.STATE_STANDING, self.STATE_STANDING) ## OJO
        self.m_FSM.add_transition(self.STATE_STANDING, self.STATE_STANDING)
        self.m_FSM.add_transition(self.STATE_STANDING, self.STATE_GOTO_TARGET)
        self.m_FSM.add_transition(self.STATE_STANDING, self.STATE_QUIT)

        # self.m_FSM.registerDefaultTransition(self.STATE_GOTO_TARGET, self.STATE_GOTO_TARGET)
        self.m_FSM.add_transition(self.STATE_GOTO_TARGET,
                                  self.STATE_GOTO_TARGET)
        self.m_FSM.add_transition(self.STATE_GOTO_TARGET, self.STATE_STANDING)
        self.m_FSM.add_transition(self.STATE_GOTO_TARGET,
                                  self.STATE_TARGET_REACHED)
        self.m_FSM.add_transition(self.STATE_GOTO_TARGET, self.STATE_FIGHTING)

        # self.m_FSM.registerDefaultTransition(self.STATE_TARGET_REACHED, self.STATE_STANDING)
        self.m_FSM.add_transition(self.STATE_TARGET_REACHED,
                                  self.STATE_STANDING)
        self.m_FSM.add_transition(self.STATE_TARGET_REACHED,
                                  self.STATE_STANDING)

        # self.m_FSM.registerDefaultTransition(self.STATE_FIGHTING, self.STATE_FIGHTING)
        self.m_FSM.add_transition(self.STATE_FIGHTING, self.STATE_FIGHTING)
        self.m_FSM.add_transition(self.STATE_FIGHTING, self.STATE_STANDING)

        # launching the FSM
        self.add_behaviour(self.m_FSM)
예제 #5
0
def fsm():
    fsm_ = FSMBehaviour()
    state_one = StateOne()
    state_two = StateTwo()
    state_three = StateThree()
    fsm_.add_state(STATE_ONE, state_one, initial=True)
    fsm_.add_state(STATE_TWO, state_two)
    fsm_.add_state(STATE_THREE, state_three)
    fsm_.add_transition(STATE_ONE, STATE_TWO)
    fsm_.add_transition(STATE_TWO, STATE_THREE)

    fsm_.state_one = state_one
    fsm_.state_two = state_two
    fsm_.state_three = state_three

    return fsm_
    def setup(self):
        fsm = FSMBehaviour()
        fsm.add_state(name=STATE_ZERO,
                      state=CheckCurrentStateFromUser(),
                      initial=True)
        fsm.add_state(name=STATE_ONE, state=RunFirmwareDumpingAgent())
        fsm.add_state(name=STATE_TWO, state=RunUnpackingAgent())
        fsm.add_state(name=STATE_THREE, state=RunReportingAgent())

        fsm.add_transition(source=STATE_ZERO, dest=STATE_ONE)
        fsm.add_transition(source=STATE_ZERO, dest=STATE_TWO)
        fsm.add_transition(source=STATE_ZERO, dest=STATE_THREE)

        fsm.add_transition(source=STATE_ONE, dest=STATE_TWO)
        fsm.add_transition(source=STATE_TWO, dest=STATE_THREE)
        self.add_behaviour(fsm)
예제 #7
0
    def setup(self):
        print("Agent Director starting...")
        # Implement periodic behaviour
        #start_at = datetime.datetime.now() + datetime.timedelta(seconds=5)
        self.bus_check = self.BusCheckPeriodic(period=30)
        self.message_check = self.DirectorCheckMessage(period=10)
        # Add periodic behaviour
        self.add_behaviour(self.bus_check)
        self.add_behaviour(self.message_check)
        # Create FSB behaviour model
        fsm = FSMBehaviour()
        # Add states to FSM model
        fsm.add_state(name=STATE_WAIT, state=self.BusWaitBehav(), initial=True)
        # Add transition to FSM model's state
        fsm.add_state(name=STATE_APPROVE, state=self.BusApproveBehav())
        fsm.add_transition(source=STATE_WAIT, dest=STATE_WAIT)
        fsm.add_transition(source=STATE_WAIT, dest=STATE_APPROVE)
        self.add_behaviour(fsm)

        tell_buses_desired_distance = self.TellBusesDesiredDistance()
        self.add_behaviour(tell_buses_desired_distance)
예제 #8
0
    def setup(self):
        self.better_printer("Agent Bus starting")
        # Create handles for agent's behaviour
        start_ride = self.StartRideBehav()
        answer_check = self.AnswerOnCheck(period=10)
        message_check = self.BusCheckMessage(period=10)

        template_desired_distance = Template()
        template_desired_distance.set_metadata("information",
                                               "desired_distance")

        template_my_position = Template()
        template_my_position.set_metadata("information", "my_position")
        self.add_behaviour(message_check,
                           template_desired_distance | template_my_position)

        get_coords = self.BusGetCoords(period=15)
        # Create FSM object
        fsm = FSMBehaviour()
        # Add states to your FSM object
        fsm.add_state(name=STATE_START,
                      state=self.StartRideBehav(),
                      initial=True)
        fsm.add_state(name=STATE_WAIT, state=self.WaitForApproval())
        fsm.add_state(name=STATE_DRIVING, state=self.Driving())
        fsm.add_state(name=STATE_PASS_KNOWLEDGE,
                      state=self.PassYourKnowledge())
        # Add transitions of your FSM object
        fsm.add_transition(source=STATE_START, dest=STATE_WAIT)
        fsm.add_transition(source=STATE_WAIT, dest=STATE_START)
        fsm.add_transition(source=STATE_WAIT, dest=STATE_WAIT)
        fsm.add_transition(source=STATE_WAIT, dest=STATE_DRIVING)
        fsm.add_transition(source=STATE_DRIVING, dest=STATE_DRIVING)
        fsm.add_transition(source=STATE_DRIVING, dest=STATE_PASS_KNOWLEDGE)
        fsm.add_transition(source=STATE_PASS_KNOWLEDGE, dest=STATE_DRIVING)
        # Add agent's behaviour
        self.add_behaviour(answer_check)
        self.add_behaviour(start_ride)
        self.add_behaviour(get_coords)
        self.add_behaviour(fsm)