def test_pa1_4b(self):
        string = '00010001000110'
        fail_string = '000100010000'

        start_state = 'A'
        transitions = {
            'A': (
                ('0', 'A'),
                ('1', 'B'),
            ),
            'B': (
                ('0', 'B'),
                ('1', 'C'),
            ),
            'C': (
                ('0', 'C'),
                ('1', 'D'),
            ),
            'D': (
                ('0', 'D'),
                ('1', 'D'),
            )       
        }
        final_states = ('D')

        result = fsm(string, start_state, transitions, final_states)
        self.assertTrue(result)

        result = fsm(fail_string, start_state, transitions, final_states)
        self.assertFalse(result)
示例#2
0
 def __init__(self, emulator=None):
     self._packet_processors = []
     for i in range(PacketType.NUM_TYPES):
         self._packet_processors.append(PacketProcessor(i))
     if emulator:        
         self._fsm = fsm.fsm(emulator.process_packet)
         emulator.set_encoder(self._fsm.process_outgoing)
     else:
         self._fsm = fsm.fsm()
示例#3
0
	def __init__(self, handle_pub, T):
		self.twist = Twist()
		self.twist_real = Twist()
		self.vreal = 0.0 # longitudial velocity
		self.wreal = 0.0 # angular velocity
		self.vmax = 1.5
		self.wmax = 4.0
		self.previous_signal = 0
		self.button_pressed = False
		self.joy_activated = False

		self.bumper_activated = False
		self.bumper_left=False
		self.bumper_center=False
		self.bumper_right=False
		self.rob_stopped = False
		self.rotate_over = False

		self.pub = handle_pub
		self.T = T
		# instance of fsm with source state, destination state, condition (transition), callback (defaut: None)
		self.fs = fsm([ ("Start","JoyControl", True ),
			("JoyControl","AutonomousMode1", self.check_JoyControl_To_AutonomousMode1, self.DoAutonomousMode1),
			("JoyControl","JoyControl", self.KeepJoyControl, self.DoJoyControl),
			("AutonomousMode1","JoyControl", self.check_AutonomousMode1_To_JoyControl, self.DoJoyControl),
			("AutonomousMode1","AutonomousMode1", self.KeepAutonomousMode1, self.DoAutonomousMode1),


			("AutonomousMode1","StopBumper",self.check_AutonomousMode1_To_StopBumper,self.DoStopBumper),
			("StopBumper","Rotate",self.check_StopBumper_To_Rotate,self.DoRotate),
			("Rotate","AutonomousMode1",self.check_Rotate_To_AutonomousMode1,self.DoAutonomousMode1),
			("StopBumper","StopBumper",self.KeepStopBumper,self.DoStopBumper),
			("Rotate","Rotate",self.KeepRotate,self.DoRotate)])
示例#4
0
    def create_modules(self):
        """ Construct all the required modules """

        self.lfsr = lfsr(size=self.addr_size, name="bist_lfsr")
        self.add_mod(self.lfsr)

        self.fsm = fsm()
        self.add_mod(self.fsm)

        self.xor2 = xor2()
        self.add_mod(self.xor2)

        self.inv = pinv()
        self.add_mod(self.inv)

        if self.async_bist:
            self.osc = oscillator(self.delay)
            self.add_mod(self.osc)

        else:
            self.osc = frequency_divider()
            self.add_mod(self.osc)

        self.data_pattern = data_pattern(self.data_size)
        self.add_mod(self.data_pattern)

        self.comparator = comparator(self.data_size)
        self.add_mod(self.comparator)
 def test_simple(self):
     string = 'a'
     start_state = 'A'
     transitions = {
         'A': (('a', 'W'),),
         'W': ()
     }
     final_states = ('W')
     result = fsm(string, start_state, transitions, final_states)
     self.assertTrue(result)
 def test_multiple_final_states(self):
     string = 'b'
     start_state = 'A'
     transitions = {
         'A': ((r"[ab]", 'W'),),
         'W': ()
     }
     final_states = ('A', 'W')
     result = fsm(string, start_state, transitions, final_states)
     self.assertTrue(result)
 def test_not_accepted(self):
     string = 'a'
     start_state = 'A'
     transitions = {
         'A': (('a', 'W'),),
         'W': ()
     }
     final_states = ('A')        
     result = fsm(string, start_state, transitions, final_states)
     self.assertFalse(result)
示例#8
0
def main():
    # Initiate the FSM giving a transition table and the initial state

    light_fsm = fsm(trans_table, states["OFF"])
    while True:
        c = sys.stdin.read(1)
        if c == 'p':
            light_switch.state = True
        # FSM activation
        light_fsm.fsm_fire()
    def test_pa1_4c(self):
        string = '00101'
        string2 = ''
        fail_string = '110111'

        start_state = 'A'

        transitions = {
            'A': (
                (r"[01]", 'B'),
            ),
            'B': (
                (r"[01]", 'C'),
            ),
            'C': (
                (r"[01]", 'D'),
            ),
            'D': (
                (r"[01]", 'E'),
            ),
            'E': (
                (r"[01]", 'F'),
            ),
            'F': (
                (r"[01]", 'G'),
            ),
            'G': (
                (r"[01]", 'G'),
            ),                                                                      
        }

        final_states = ('A', 'B', 'C', 'D', 'E', 'F')

        result = fsm(string, start_state, transitions, final_states)
        self.assertTrue(result)

        result = fsm(string2, start_state, transitions, final_states)
        self.assertTrue(result)

        result = fsm(fail_string, start_state, transitions, final_states)
        self.assertFalse(result)        
示例#10
0
 def makeUnweighted(self):
     states = self.States()
     alphabet = self.Alpha()
     final = self.Final()
     start = self.Start()
     transition = []
     for trans in self.Trans():
         src, destination, alpha, wt = trans
         transUnweighted = src,  destination, alpha
         if transUnweighted not in transition:
             transition.append(transUnweighted)
     return fsm(states, alphabet, transition, start, final)
    def test_pa1_4d(self):
        string = '0101100'
        string2 = '110'
        fail_string = ''
        fail_string2 = '0010'

        start_state = 'A'

        transitions = {
            'A': (
                (r"[01]", 'B'),
            ),
            'B': (
                (r"[01]", 'C'),
            ),
            'C': (
                ('0', 'D'),
                ('1', 'E')
            ),
            'D': (
                (r"[01]", 'D'),
            ),
            'E': (
                (r"[01]", 'E'),
            ),                                                                  
        }

        final_states = ('D')

        result = fsm(string, start_state, transitions, final_states)
        self.assertTrue(result)

        result = fsm(string2, start_state, transitions, final_states)
        self.assertTrue(result)

        result = fsm(fail_string, start_state, transitions, final_states)
        self.assertFalse(result)

        result = fsm(fail_string2, start_state, transitions, final_states)
        self.assertFalse(result)
示例#12
0
def bench(name, out_dir, lengths):
    build_reticle()
    make_dir(out_dir)
    backends = ["base", "baseopt", "reticle"]
    runtime = {}
    util = {}
    for l in lengths:
        bench_name = "{}{}".format(name, l)
        reticle_file = create_path(out_dir, "{}.ret".format(bench_name))
        if name == "tadd":
            tadd(bench_name, l, reticle_file)
        elif name == "fsm":
            fsm(bench_name, l, reticle_file)
        else:
            sys.exit(1)
        for b in backends:
            print("Running {} backend with length={}".format(b, l))
            file_name = "{}_{}".format(bench_name, b)
            verilog_file = create_path(out_dir, "{}.v".format(file_name))
            if b == "reticle":
                asm_file = create_path(out_dir, "{}.rasm".format(file_name))
                placed_file = create_path(out_dir,
                                          "{}_placed.rasm".format(file_name))
                reticle_to_asm(reticle_file, asm_file)
                prim = "lut" if name == "fsm" else "dsp"
                reticle_place_asm(asm_file, placed_file, prim)
                reticle_asm_to_verilog(placed_file, verilog_file)
                vivado("reticle.tcl", [out_dir, file_name, bench_name])
            else:
                use_dsp = True if b == "baseopt" else False
                compile_baseline(reticle_file, verilog_file, use_dsp)
                vivado("baseline.tcl", [out_dir, file_name, bench_name])
            runtime = parse_runtime(runtime, name, out_dir, l, b)
            util = parse_util(util, name, out_dir, l, b)
    runtime_df = pd.DataFrame.from_dict(runtime)
    util_df = pd.DataFrame.from_dict(util)
    runtime_df.to_csv(create_path(out_dir, "{}_runtime.csv".format(name)),
                      index=False)
    util_df.to_csv(create_path(out_dir, "{}_util.csv".format(name)),
                   index=False)
示例#13
0
def bench(name, out_dir, lengths):
    build_reticle()
    make_dir(out_dir)
    backends = ["base", "baseopt", "reticle"]
    data = {}
    for l in lengths:
        bench_name = "{}{}".format(name, l)
        reticle_file = create_path(out_dir, "{}.ret".format(bench_name))
        if name == "tadd":
            tadd(bench_name, l, reticle_file)
        elif name == "fsm":
            fsm(bench_name, l, reticle_file)
        else:
            sys.exit(1)
        for b in backends:
            print("Running {} backend with length={}".format(b, l))
            file_name = "{}_{}".format(bench_name, b)
            verilog_file = create_path(out_dir, "{}.v".format(file_name))
            if b == "reticle":
                asm_file = create_path(out_dir, "{}.rasm".format(file_name))
                placed_file = create_path(out_dir,
                                          "{}_placed.rasm".format(file_name))
                start = perf_counter()
                reticle_to_asm(reticle_file, asm_file)
                prim = "lut" if name == "fsm" else "dsp"
                reticle_place_asm(asm_file, placed_file, prim)
                elapsed = perf_counter() - start
            else:
                use_dsp = True if b == "baseopt" else False
                compile_baseline(reticle_file, verilog_file, use_dsp)
                start = perf_counter()
                vivado("synth_place.tcl", [out_dir, file_name, bench_name])
                elapsed = perf_counter() - start
            data = update(data, b, l, elapsed)
    df = pd.DataFrame.from_dict(data)
    df.to_csv(create_path(out_dir, "{}.csv".format(name)), index=False)
示例#14
0
    def makeFSMfromWFSM(self):
        states = self.States()
        final = self.Final()
        start = self.Start()
        
        alphaFSM = []
        transFSM = []
        for trans in self.Trans():
            src, destination, alpha, wt = trans
            transNew = src, destination, [alpha, wt]
            alphaNew = [alpha, wt]
            transFSM.append(transNew)
            if alphaNew not in alphaFSM:
                alphaFSM.append(alphaNew)

        return fsm(states, alphaFSM, transFSM, start, final)
示例#15
0
    def generate_fsm(self):
        self.current_string = ""
        self.fsm = {}
        doc = self.definitions.document()
        block = doc.begin()
        lits = list()
        if block.text() != '':
            s = block.text().split('=')
            if len(s) == 2:
                lits.append(s)
        for i in range(1, doc.blockCount()):
            block = block.next()
            if block.text() != '':
                s = block.text().split('=')
                if len(s) == 2:
                    lits.append(s)

        if len(lits) <= 0:
            return
        for i in range(0, len(lits)):
            ls = self.rd.tree_list(('', lits[i][1]))
            self.fsms[lits[i][0]] = fsm.fsm([], [], str(i))
            self.fsms[lits[i][0]].chain2(
                str(i) + '0',
                str(i) + '1', str(i), ls, i)
            self.print_fsm_table(self.fsms[lits[i][0]])

        s = list()
        for i in range(len(lits) - 1, -1, -1):
            s.append(lits[i])

        for i in range(0, len(s)):
            for j in range(0, i):
                print "------------------------------------------", i
                self.fsms[s[i][0]].join(self.fsms[s[j][0]], s[j][0])
                #self.fsms[s[i][0]].add()

        self.main_fsm = lits[0][0]
        self.fsms[self.main_fsm].add()
        self.fsms[self.main_fsm].map_states()
        self.print_fsm_table(self.fsms[self.main_fsm])
        self.current_state = self.fsms[self.main_fsm].start_states[0]
        st = self.fsms[self.main_fsm].states[self.current_state]
        self.current_st.setText(st)
        self.draw_state()
示例#16
0
    def generate_fsm(self):
        self.current_string = ""
        self.fsm = {}
        doc = self.definitions.document()
        block = doc.begin()
        lits = list()
        if block.text() != '':
            s = block.text().split('=')
            if len(s) == 2:
                lits.append(s)
        for i in range(1, doc.blockCount()):
            block = block.next()
            if block.text() != '':
                s = block.text().split('=')
                if len(s) == 2:
                    lits.append(s)

        if len(lits) <= 0:
            return
        for i in range(0, len(lits)):
            ls = self.rd.tree_list(('', lits[i][1]))
            self.fsms[lits[i][0]] = fsm.fsm([], [], str(i))
            self.fsms[lits[i][0]].chain2(str(i) + '0', str(i) + '1',
                                        str(i), ls, i)
            self.print_fsm_table(self.fsms[lits[i][0]])

        s = list()
        for i in range(len(lits) - 1, -1, -1):
            s.append(lits[i])

        for i in range(0, len(s)):
            for j in range(0, i):
                print "------------------------------------------", i
                self.fsms[s[i][0]].join(self.fsms[s[j][0]], s[j][0])
                #self.fsms[s[i][0]].add()

        self.main_fsm = lits[0][0]
        self.fsms[self.main_fsm ].add()
        self.fsms[self.main_fsm].map_states()
        self.print_fsm_table(self.fsms[self.main_fsm])
        self.current_state = self.fsms[self.main_fsm].start_states[0]
        st = self.fsms[self.main_fsm].states[self.current_state]
        self.current_st.setText(st)
        self.draw_state()
示例#17
0
    def __init__(self, mode, port, avr):
        self.mode = mode
        self.app = flask.Flask(__name__)
        self.port = port
        self.avr = avr
        self.fsm = fsm(self.avr)

        @self.app.route("/connect")
        def connect():
            return self.impl_connect()

        @self.app.route("/setdevice", methods=['POST'])
        def setdevice():
            json = request.get_json()
            return self.impl_setdevice(json)

        @self.app.route("/")
        def root():
            return self.impl_root()
示例#18
0
    def prodGameWithNotProperty(self, notNashProperty):
        
        states = notNashProperty.States()
        

        labelledWfsm = self.makeLabelledWfsm()
        alphaGame = labelledWfsm.Alpha()
        """print alphaGame"""
        alphaNotNashPropAux = notNashProperty.Alpha()
        alphaNotNashProp = []
        """for alpha in alphaNotNashPropAux:
            if alpha not in alphaNotNashProp:
                alphaNotNashProp.append(alpha)
        """
        """print len(alphaNotNashPropAux), len(alphaGame)"""
        newAlpha = [alpha1 + alpha2 for alpha1 in alphaGame  for alpha2 in alphaNotNashPropAux]


        transitionOfProduct = []
        notNashPropertyTrans  = notNashProperty.Trans()
        
        """startNotNash = notNashProperty.Start()[0]
        for trans in notNashPropertyTrans:
            src = trans[0]
            if src == startNotNash:
                print trans"""

        for trans in notNashPropertyTrans:
            for alpha in alphaGame:
                """print alpha, trans"""
                src, destination, alphaNotNash = trans
                newTrans = src, destination, alpha + alphaNotNash
                """if newTrans not in transitionOfProduct:"""
                transitionOfProduct.append(newTrans)
                
        
        start = notNashProperty.Start()
        final = notNashProperty.Final()

        """print "Start State " + str(start)
        print "All States " + str(states)
        print "Final States " + str(final)"""
        return fsm(states, newAlpha, transitionOfProduct, start, final)
示例#19
0
    def reassign(self):
        states = self.States()
        
        statesMap = {}

        i = 0
        for state in states:
            statesMap[str(state)] = i
            i += 1
        
        newStates = [statesMap[str(state)] for state in self.States()]
        
        newTrans = [(statesMap[str(src)], statesMap[str(destination)], alphabet) for (src, destination, alphabet) in self.Trans()]

        newFinal = [statesMap[str(state)] for state in self.Final()]

        newStart = [statesMap[str(state)] for state in self.Start()]

        reassignedFSM = fsm(states, self.Alpha(), newTrans, newStart, newFinal)

        return reassignedFSM
示例#20
0
def convertBAToFSM(inputFileName):
    file = open(inputFileName, "r")
    start = getStartStates(file)
    transitions, alphabet, states, first = manipulateTransitions(file)
    final = getFinalStates(file)
    """print "FINAl IS : "+ str(final)"""
    
    """print transitions
    print alphabet
    print states
    print first"""

    if start == []:
        start = [first]

    if final == []:
        final = states

    file.close()
    
    return fsm(states, alphabet, transitions, start, final)
    def __init__(self, heading_list, submarine):

        self.heading_list = heading_list
        self.isobath = -18
        self.depth = -submarine.getEchosounder()
        self.cap = 0
        self.heading_order = heading_list[0]

        self.fs = fsm([("Start", "0", True),
                       ("0", "0", self.outside, self.Continue),
                       ("0", "1_in", self.inside, self.DoHeading1),
                       ("1_in", "1_in", self.inside, self.Continue),
                       ("1_in", "2_out", self.outside, self.DoHeading2),
                       ("2_out", "2_out", self.outside, self.Continue),
                       ("2_out", "2_in", self.inside, self.Continue),
                       ("2_in", "2_in", self.inside, self.Continue),
                       ("2_in", "3_out", self.outside, self.DoHeading3),
                       ("3_out", "3_out", self.outside, self.Continue),
                       ("3_out", "3_in", self.inside, self.Continue),
                       ("3_in", "3_in", self.inside, self.Continue),
                       ("3_in", "1_out", self.outside, self.DoHeading1),
                       ("1_out", "1_out", self.outside, self.Continue),
                       ("1_out", "1_in", self.inside, self.Continue)])
示例#22
0
    def run_finite_state_machine(self):

        fs = fsm([
            (LogFileParser.START, LogFileParser.PLAYER_ATTACKING,
             lambda x: self.player_is_rolling_attack_dice(x),
             self.begin_attack_set),
            (LogFileParser.START, LogFileParser.PLAYER_DEFENDING,
             lambda x: self.player_is_defending(x)),
            (LogFileParser.PLAYER_ATTACKING, LogFileParser.START,
             lambda x: not self.player_is_rolling_dice(x),
             self.end_attack_set),
            (LogFileParser.PLAYER_ATTACKING, LogFileParser.PLAYER_ATTACKING,
             lambda x: self.player_is_rolling_attack_dice(x),
             self.end_attack_set_and_begin_new_attack_set),
            (LogFileParser.PLAYER_ATTACKING, LogFileParser.PLAYER_DEFENDING,
             lambda x: self.player_is_defending(x), self.add_defense_roll),
            (LogFileParser.PLAYER_ATTACKING,
             LogFileParser.PLAYER_MODIFYING_ATTACK_DICE,
             lambda x: self.player_is_modifying_attack_dice(x),
             self.add_attack_modification),
            (LogFileParser.PLAYER_ATTACKING,
             LogFileParser.PLAYER_ADDING_ATTACK_DICE,
             lambda x: self.player_added_attack_dice(x), self.add_attack_dice),
            (LogFileParser.PLAYER_ADDING_ATTACK_DICE, LogFileParser.START,
             lambda x: not self.player_is_rolling_dice(x),
             self.end_attack_set),
            (LogFileParser.PLAYER_ADDING_ATTACK_DICE,
             LogFileParser.PLAYER_MODIFYING_ATTACK_DICE,
             lambda x: self.player_is_modifying_attack_dice(x),
             self.add_attack_modification),
            (LogFileParser.PLAYER_ADDING_ATTACK_DICE,
             LogFileParser.PLAYER_ADDING_ATTACK_DICE,
             lambda x: self.player_added_attack_dice(x), self.add_attack_dice),
            (LogFileParser.PLAYER_ADDING_ATTACK_DICE,
             LogFileParser.PLAYER_DEFENDING,
             lambda x: self.player_is_defending(x), self.add_defense_roll),
            (LogFileParser.PLAYER_MODIFYING_ATTACK_DICE, LogFileParser.START,
             lambda x: not self.player_is_rolling_dice(x),
             self.end_attack_set),
            (LogFileParser.PLAYER_MODIFYING_ATTACK_DICE,
             LogFileParser.PLAYER_MODIFYING_ATTACK_DICE,
             lambda x: self.player_is_modifying_attack_dice(x),
             self.add_attack_modification),
            (LogFileParser.PLAYER_MODIFYING_ATTACK_DICE,
             LogFileParser.PLAYER_ADDING_ATTACK_DICE,
             lambda x: self.player_added_attack_dice(x), self.add_attack_dice),
            (LogFileParser.PLAYER_MODIFYING_ATTACK_DICE,
             LogFileParser.PLAYER_ATTACKING,
             lambda x: self.player_is_rolling_attack_dice(x),
             self.end_attack_set_and_begin_new_attack_set),
            (LogFileParser.PLAYER_MODIFYING_ATTACK_DICE,
             LogFileParser.PLAYER_DEFENDING,
             lambda x: self.player_is_defending(x), self.add_defense_roll),
            (LogFileParser.PLAYER_DEFENDING, LogFileParser.START,
             lambda x: not self.player_is_rolling_dice(x),
             self.end_attack_set),
            (LogFileParser.PLAYER_DEFENDING, LogFileParser.PLAYER_ATTACKING,
             lambda x: self.player_is_rolling_attack_dice(x),
             self.end_attack_set_and_begin_new_attack_set),
            (LogFileParser.PLAYER_DEFENDING, LogFileParser.PLAYER_DEFENDING,
             lambda x: self.player_is_defending(x), self.add_defense_roll),
            (LogFileParser.PLAYER_DEFENDING,
             LogFileParser.PLAYER_MODIFYING_DEFENSE_DICE,
             lambda x: self.player_is_modifying_defense_dice(x),
             self.add_defense_modification),
            (LogFileParser.PLAYER_DEFENDING,
             LogFileParser.PLAYER_ADDING_DEFENSE_DICE,
             lambda x: self.player_added_defense_dice(x),
             self.add_defense_dice),
            (LogFileParser.PLAYER_MODIFYING_DEFENSE_DICE, LogFileParser.START,
             lambda x: not self.player_is_rolling_dice(x),
             self.end_attack_set),
            (LogFileParser.PLAYER_MODIFYING_DEFENSE_DICE,
             LogFileParser.PLAYER_ADDING_DEFENSE_DICE,
             lambda x: self.player_added_defense_dice(x),
             self.add_defense_dice),
            (LogFileParser.PLAYER_MODIFYING_DEFENSE_DICE,
             LogFileParser.PLAYER_MODIFYING_DEFENSE_DICE,
             lambda x: self.player_is_modifying_defense_dice(x),
             self.add_defense_modification),
            (LogFileParser.PLAYER_MODIFYING_DEFENSE_DICE,
             LogFileParser.PLAYER_ATTACKING,
             lambda x: self.player_is_rolling_attack_dice(x),
             self.end_attack_set_and_begin_new_attack_set),
            (LogFileParser.PLAYER_ADDING_DEFENSE_DICE,
             LogFileParser.PLAYER_ADDING_DEFENSE_DICE,
             lambda x: self.player_added_defense_dice(x),
             self.add_defense_dice),
            (LogFileParser.PLAYER_ADDING_DEFENSE_DICE,
             LogFileParser.PLAYER_MODIFYING_DEFENSE_DICE,
             lambda x: self.player_is_modifying_defense_dice(x),
             self.add_defense_modification),
            (LogFileParser.PLAYER_ADDING_DEFENSE_DICE,
             LogFileParser.PLAYER_ATTACKING,
             lambda x: self.player_is_rolling_attack_dice(x),
             self.end_attack_set_and_begin_new_attack_set),
            (LogFileParser.PLAYER_ADDING_DEFENSE_DICE, LogFileParser.START,
             lambda x: not self.player_is_rolling_dice(x),
             self.end_attack_set),
        ])

        fs.start(LogFileParser.START)

        i = 0
        lines = self.get_lines()
        for line in lines:
            try:
                fs.event(line)
            except ValueError:
                print(
                    "Unable to transition from state {0} ({1}) using input {2}, ignoring and continuing on ..."
                    .format(fs.currentState, lines[i - 1], lines[i]))

            i = i + 1  #just for debugging purposes

        fs.event("")
示例#23
0
def convertGffToFSM(inputFileName):
    file = open(inputFileName, "r")
    line = file.readline()
    while(line.split()[0] != '<Alphabet'):
        line = file.readline()
    
    """print "start to read alphabet\n"""
    
    alphabet = []
    line = file.readline()
    while(line.strip().split()[0][:8] == '<Symbol>'):
        linecontent = line.strip().split()[0]
        """print linecontent"""
        alphaString = linecontent[8:(len(linecontent)-9)]
        """print alphaString"""
        alphabet.append(convertAlphaString(alphaString))
        """manipulate alphaString and append to alphabet for wfsm"""
        line  = file.readline()

    """print alphabet"""
    """print "Done with alphabet\n"""
    """print line"""

    """print "start to read states. Sufficient to keep count of the number of states\n"""
    line = file.readline()
    states = []
    line = file.readline()
    """print line"""
    while(line.strip() != "</StateSet>"):
        stateID = line.strip().split()
        """print stateID,  stateID[1]"""
        stateID = stateID[1].split("=")
        """print stateID[1][0], stateID[1][1], stateID[1][2]"""
        stateID =  int(stateID[1][1:len(stateID[1])-2])
        states.append([stateID])
        """print states"""
        while(line.strip()!= "</State>"):
            line = file.readline()
            """print line"""
        line = file.readline()
        """print line"""

    """print states"""
    """print "Number of states are "  + str(numStates)"""


    """print line"""

    """print "Start readling initial states\n"""

    line = file.readline()
    
    startStates = []
    line = file.readline()
    while (line.strip().split()[0][:9] == "<StateID>"):
        linecontent = line.strip().split()[0]
        """print linecontent"""
        startStateID = [int(linecontent[9:len(linecontent)-10])]
        """print startStateID"""
        """startStateName = [int(i) for i in startStateID[1:len(startStateID)-1].split(",")]"""
        startStates.append(startStateID)
        line = file.readline()
        
    """print startStates"""

    """print line"""
    """print "Done with Start States\n"""
    
    
    line = file.readline()
    """print line"""
    transitionSet = []

    transitionIDLine = file.readline()
    """print transitionIDLine"""
    while(line.strip().split()[0] != "</TransitionSet>"):
        
        
        while(line.strip().split()[0]!= "</Transition>"):
                        
            fromLine = file.readline().strip().split()[0]
            
            srcString = fromLine[6:len(fromLine)-7]
            
            src = [int(srcString)]
            """print srcString"""
            """src = [int(fromLine[6:(len(fromLine)-7)])]"""
            """print fromLine"""

            toLine = file.readline().strip().split()[0]
            destinationString = toLine[4:len(toLine)-5]
            destination = [int(destinationString)]
            """print destinationString"""
            """destination = [int(toLine[4:(len(toLine)-5)])]"""
            """print toLine"""
            

            labelLine =  file.readline().strip().split()[0]
            label = labelLine[7:(len(labelLine)-8)]
            label = convertAlphaString(label)
            """print labelLine"""

            propertyline = file.readline()
                

            line = file.readline()
            """print line"""

            transition = src, destination, label
            
            """print transition"""
            
            transitionSet.append(transition)

        line = file.readline()
        
    """print line"""
    
    line = file.readline()
    finalState = []
    
    line = file.readline()

    while (line.strip().split()[0]!="</Acc>"):
        linecontent = line.strip().split()[0]
        """print linecontent"""
        stateString = linecontent[9:(len(linecontent)-10)]
        stateAcc = [int(stateString)]
        """print stateString"""
        finalState.append(stateAcc)
        line = file.readline()
    """print finalState"""

    return fsm(states, alphabet, transitionSet, startStates, finalState)
示例#24
0
if len(sys.argv) != 3:
    print("Not all parameters passed in command line")
    sys.exit(1)

hexdata = hex("blinky8.hex")
#hexdata = hex("/home/varun/coding/c/avr/goAvrC/bin/goAvrC.hex")

if sys.argv[1] == "arduino":
    serialdataqueue = dataqueue(50)
    stopping = threading.Event()
    goavrserial.getserialportlist()
    serialadapter = goavrserial('/dev/ttyUSB0', 9600, serialdataqueue,
                                stopping)
    chip = arduinoavr(0, 0, 32, 0, 8192, 0, 0, 20, 0, 10, serialadapter,
                      serialdataqueue, hexdata)
    mode = fsm(0, chip)
    serialadapter.run()
    sleep(4)
    mode.run()
    sleep(2)
    stopping.set()

elif sys.argv[1] == "rpi":
    chip = rpiavr("atmega8", [0x1E, 0x93, 0x07], 32, 4, 8192, 512, 5, 20, 10,
                  10, hexdata)
    mode = fsm(0, chip)
    mode.run()

else:
    print("Unsupported programming mode")
示例#25
0
    joy = int(sys.argv[4])
    if joy:
        getMouv = getJoystick
        pg.init()  # Initialise la video
        pg.joystick.init()  # Initialise le joystick
        joysticks = [
            pg.joystick.Joystick(x) for x in range(pg.joystick.get_count())
        ]
        Notrejoystick = pg.joystick.Joystick(0)
        Notrejoystick.init()  # Initialise le joystick donne
        AX0 = Notrejoystick.get_axis(0)
        AX1 = Notrejoystick.get_axis(1)
        AX2 = Notrejoystick.get_axis(2)
except:
    ()
f = fsm.fsm()
move_flag = False

#Touches:

fichier = open('doc_texte_touches', 'r')
touches = fichier.readlines()[0].split(',')
fichier.close()
t_avance = touches[0]
t_pivot_r = touches[5]
t_pivot_l = touches[4]
t_wait = touches[6]
t_r = touches[3]
t_l = touches[2]
t_b = touches[1]
t_end = touches[7][0]
示例#26
0
#  Enter : event "Start"
#  Echap : event "Stop"

#  c : event "Wait"

#  z : event "Go" 
#  q : event "Turn_left"
#  s : event "Go_Back"
#  d : event "Turn_right"
#  a : event "SideStep_Left"
#  e : event "SideStep_Right"
#  1 : event "Shoot_Left" (pave numerique : 1)
#  2 : event "Shoot_Right" (pave numerique : 2)

# global variables
f = fsm.fsm();  # finite state machine

def getKey():
    c='c'
    c*k=False
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_z:
                c*k, c = True, "z"
            elif event.key == pygame.K_q:
                c*k, c = True, "q"
            elif event.key == pygame.K_s:
                c*k, c = True, "s"
            elif event.key == pygame.K_d:
示例#27
0
    def __init__(self, handle_pub, T):
        self.diameter = 0.4  #0.3515 #metres
        self.twist = Twist()
        self.twist_real = Twist()
        self.vreal = 0.0  # longitudial velocity
        self.wreal = 0.0  # angular velocity
        self.vmax = 0.3  #1.5
        self.wmax = 2.0  #4.0
        self.previous_signal = 0
        self.button_pressed = False
        self.joy_activated = False

        self.bumper_activated = False  #un bumper est actionner
        self.bumper_center = False  #quel bumper est activer
        self.bumper_right = False
        self.bumper_left = False

        self.orientation = False
        self.rotate_over = False
        self.rotate_is_stopped = False
        self.compteur = 0

        self.wheel_on_ground = True  #roue sur le sol

        self.pub = handle_pub
        self.T = T

        self.init_CameraCallback = True
        self.init_IMUCallback = True
        self.dist_detection = 1.0  #distance a partir de laquel on dit qu un obstacle est trop pres
        self.obstacle = 0
        self.lambda_rotate = 0.0

        self.message = True
        self.message_info = False
        self.message_JoyControl = False
        self.message_AutonomousMode = False
        self.message_Retreat = False
        self.message_Rotate = False
        self.message_Stop = False
        self.message_ChangeDirection = False
        self.message_OnGround = False

        self.present_state = "Start"
        self.next_state = []

        # instance of fsm with source state, destination state, condition (transition), callback (defaut: None)
        self.fs = fsm([
            ("Start", "JoyControl", True),
            #transitions de base
            ("JoyControl", "AutonomousMode",
             self.check_JoyControl_To_AutonomousMode, self.DoAutonomousMode),
            ("AutonomousMode", "JoyControl", self.check_To_JoyControl,
             self.DoJoyControl),

            #transitions pour l arret bumper
            ("AutonomousMode", "Retreat", self.check_AutonomousMode_To_Retreat,
             self.DoRetreat),
            ("Retreat", "Rotate", self.check_Retreat_To_Rotate, self.DoRotate),
            ("Rotate", "Stop", self.check_Rotate_To_Stop, self.DoStop),
            ("Stop", "AutonomousMode", self.check_Stop_To_AutonomousMode,
             self.DoAutonomousMode),

            #transitions securite retour mode manuel
            ("Retreat", "JoyControl", self.check_To_JoyControl,
             self.DoJoyControl),
            ("Rotate", "JoyControl", self.check_To_JoyControl,
             self.DoJoyControl),
            ("Stop", "JoyControl", self.check_To_JoyControl,
             self.DoJoyControl),

            #transitions securite si absence contact roue sol
            ("JoyControl", "OnGround", self.check_To_OnGround, self.DoOnGround
             ),
            ("AutonomousMode", "OnGround", self.check_To_OnGround,
             self.DoOnGround),
            ("Retreat", "OnGround", self.check_To_OnGround, self.DoOnGround),
            ("Rotate", "OnGround", self.check_To_OnGround, self.DoOnGround),
            ("Stop", "OnGround", self.check_To_OnGround, self.DoOnGround),
            ("OnGround", "JoyControl", self.check_OnGround_To_JoyControl,
             self.DoJoyControl),

            #transitions kinect
            ("AutonomousMode", "ChangeDirection",
             self.check_AutonomousMode_To_ChangeDirection,
             self.DoChangeDirection),
            ("ChangeDirection", "AutonomousMode",
             self.check_ChangeDirection_To_AutonomousMode,
             self.DoAutonomousMode),
            ("ChangeDirection", "Retreat",
             self.check_ChangeDirection_To_Retreat, self.DoRetreat),
            ("ChangeDirection", "JoyControl", self.check_To_JoyControl,
             self.DoJoyControl),
            ("ChangeDirection", "OnGround", self.check_To_OnGround,
             self.DoOnGround),

            #transitions pour rester dans le meme etat
            ("JoyControl", "JoyControl", self.KeepJoyControl, self.DoJoyControl
             ),
            ("AutonomousMode", "AutonomousMode", self.KeepAutonomousMode,
             self.DoAutonomousMode),
            ("Retreat", "Retreat", self.KeepRetreat, self.DoRetreat),
            ("Rotate", "Rotate", self.KeepRotate, self.DoRotate),
            ("Stop", "Stop", self.KeepStop, self.DoStop),
            ("ChangeDirection", "ChangeDirection", self.KeepChangeDirection,
             self.DoChangeDirection),
            ("OnGround", "OnGround", self.KeepOnGround, self.DoOnGround)
        ])
示例#28
0
def laser_fsm_new():
    return fsm(laser_trans_tt, laser_states["LASER_OFF"])
示例#29
0
    def __init__(self, handle_pub, T):
        self.twist = Twist()
        self.twist_real = Twist()
        self.vreal = 0.0  # longitudial velocity
        self.wreal = 0.0  # angular velocity
        self.vmax = 0.188
        self.wmax = 1.297
        self.previous_signal = 0
        self.button_pressed = False
        self.joy_activated = False

        self.pub = handle_pub
        self.T = T

        self.PvL = 0.7
        self.entraxe = 0.29
        self.r_rotation = 1

        self.ModeCarre = False
        self.ModeRond = False
        self.ModeTriangle = False
        self.ModeCroix = False

        self.message = True
        self.message_info = False
        self.message_JoyControl = False
        self.message_AutonomousMode = False
        self.message_Carre = False
        self.message_Rond = False
        self.message_Triangle = False
        self.message_Croix = False

        self.present_state = "Start"
        self.next_state = []

        # instance of fsm with source state, destination state, condition (transition), callback (defaut: None)
        self.fs = fsm([
            ("Start", "JoyControl", True),
            #transitions de base
            ("JoyControl", "AutonomousMode",
             self.check_JoyControl_To_AutonomousMode, self.DoAutonomousMode),
            ("AutonomousMode", "JoyControl", self.check_To_JoyControl,
             self.DoJoyControl),

            #transitions trajectoire predefinies
            ("JoyControl", "Carre", self.check_JoyControl_To_Carre,
             self.DoCarre),
            ("JoyControl", "Rond", self.check_JoyControl_To_Rond, self.DoRond),
            ("JoyControl", "Triangle", self.check_JoyControl_To_Triangle,
             self.DoTriangle),
            ("JoyControl", "Croix", self.check_JoyControl_To_Croix,
             self.DoCroix),
            ("Carre", "JoyControl", self.check_To_JoyControl,
             self.DoJoyControl),
            ("Rond", "JoyControl", self.check_To_JoyControl,
             self.DoJoyControl),
            ("Triangle", "JoyControl", self.check_To_JoyControl,
             self.DoJoyControl),
            ("Croix", "JoyControl", self.check_To_JoyControl,
             self.DoJoyControl),

            #transitions pour rester dans le meme etat
            ("JoyControl", "JoyControl", self.KeepJoyControl, self.DoJoyControl
             ),
            ("AutonomousMode", "AutonomousMode", self.KeepAutonomousMode,
             self.DoAutonomousMode),
            ("Carre", "Carre", self.KeepCarre, self.DoCarre),
            ("Rond", "Rond", self.KeepRond, self.DoRond),
            ("Triangle", "Triangle", self.KeepTriangle, self.DoTriangle),
            ("Croix", "Croix", self.KeepCroix, self.DoCroix)
        ])
import sys
import fsm
import side
from MissionPlanner import *



sys.path.append(r"c:\Python27\Lib\site-packages")
sys.path.append(r"c:\Python27\Lib")
# Manque des imports ?

# global variables
f = fsm.fsm()   # defines finite state machine

global coordo
coordo = side.LoadWP("C:/Users/Thomas/Desktop/EnstaB/Python/YLAHTS-master/waysPoints.txt")

# FSM functions


def init():
    print "init"
    nextEvent = "init faite"
    return nextEvent


def decollage():
    print "decollage"
    Script.ChangeMode("TAKEOFF", coordo[0].pop(), coordo[1].pop(), coordo[2].pop() )
    nextEvent = "decollage fait"
    return nextEvent
示例#31
0
    def __init__(self):
        self.fsm = fsm()

        self.config_pin = Button(21, pull_up=True, bounce_time=1)
示例#32
0
def welder_fsm_new():
    return fsm(welder_trans_tt, welder_states["IDLE"])
示例#33
0
    def run_finite_state_machine(self ):

        fs = fsm( [
            (
                LogFileParser.START,
                LogFileParser.PLAYER_ATTACKING,
                lambda x: self.player_is_rolling_attack_dice(x),
                self.begin_attack_set
            ),
            (
                LogFileParser.START,
                LogFileParser.PLAYER_DEFENDING,
                lambda x: self.player_is_defending(x)
            ),
            (
                LogFileParser.PLAYER_ATTACKING,
                LogFileParser.START,
                lambda x: not self.player_is_rolling_dice(x),
                self.end_attack_set
            ),
            (
                LogFileParser.PLAYER_ATTACKING,
                LogFileParser.PLAYER_ATTACKING,
                lambda x: self.player_is_rolling_attack_dice(x),
                self.end_attack_set_and_begin_new_attack_set
            ),
            (
                LogFileParser.PLAYER_ATTACKING,
                LogFileParser.PLAYER_DEFENDING,
                lambda x: self.player_is_defending(x),
                self.add_defense_roll
            ),

            (
                LogFileParser.PLAYER_ATTACKING,
                LogFileParser.PLAYER_MODIFYING_ATTACK_DICE,
                lambda x: self.player_is_modifying_attack_dice(x),
                self.add_attack_modification
            ),
            (
                LogFileParser.PLAYER_ATTACKING,
                LogFileParser.PLAYER_ADDING_ATTACK_DICE,
                lambda x: self.player_added_attack_dice(x),
                self.add_attack_dice
            ),
            (
                LogFileParser.PLAYER_ADDING_ATTACK_DICE,
                LogFileParser.START,
                lambda x: not self.player_is_rolling_dice(x),
                self.end_attack_set
            ),
            (
                LogFileParser.PLAYER_ADDING_ATTACK_DICE,
                LogFileParser.PLAYER_MODIFYING_ATTACK_DICE,
                lambda x: self.player_is_modifying_attack_dice(x),
                self.add_attack_modification
            ),
            (
                LogFileParser.PLAYER_ADDING_ATTACK_DICE,
                LogFileParser.PLAYER_ADDING_ATTACK_DICE,
                lambda x: self.player_added_attack_dice(x),
                self.add_attack_dice
            ),
            (
                LogFileParser.PLAYER_ADDING_ATTACK_DICE,
                LogFileParser.PLAYER_DEFENDING,
                lambda x: self.player_is_defending(x),
                self.add_defense_roll
            ),
            (
                LogFileParser.PLAYER_MODIFYING_ATTACK_DICE,
                LogFileParser.START,
                lambda x: not self.player_is_rolling_dice(x),
                self.end_attack_set
            ),
            (
                LogFileParser.PLAYER_MODIFYING_ATTACK_DICE,
                LogFileParser.PLAYER_MODIFYING_ATTACK_DICE,
                lambda x: self.player_is_modifying_attack_dice(x),
                self.add_attack_modification
            ),
            (
                LogFileParser.PLAYER_MODIFYING_ATTACK_DICE,
                LogFileParser.PLAYER_ADDING_ATTACK_DICE,
                lambda x: self.player_added_attack_dice(x),
                self.add_attack_dice
            ),
            (
                LogFileParser.PLAYER_MODIFYING_ATTACK_DICE,
                LogFileParser.PLAYER_ATTACKING,
                lambda x: self.player_is_rolling_attack_dice(x),
                self.end_attack_set_and_begin_new_attack_set
            ),
            (
                LogFileParser.PLAYER_MODIFYING_ATTACK_DICE,
                LogFileParser.PLAYER_DEFENDING,
                lambda x: self.player_is_defending(x),
                self.add_defense_roll
            ),
            (
                LogFileParser.PLAYER_DEFENDING,
                LogFileParser.START,
                lambda x: not self.player_is_rolling_dice(x),
                self.end_attack_set
            ),
            (
                LogFileParser.PLAYER_DEFENDING,
                LogFileParser.PLAYER_ATTACKING,
                lambda x: self.player_is_rolling_attack_dice(x),
                self.end_attack_set_and_begin_new_attack_set
            ),
            (
                LogFileParser.PLAYER_DEFENDING,
                LogFileParser.PLAYER_DEFENDING,
                lambda x: self.player_is_defending(x),
                self.add_defense_roll
            ),
             (
                LogFileParser.PLAYER_DEFENDING,
                LogFileParser.PLAYER_MODIFYING_DEFENSE_DICE,
                lambda x: self.player_is_modifying_defense_dice(x),
                self.add_defense_modification
            ),
             (
                LogFileParser.PLAYER_DEFENDING,
                LogFileParser.PLAYER_ADDING_DEFENSE_DICE,
                lambda x: self.player_added_defense_dice(x),
                self.add_defense_dice
            ),
            (
                LogFileParser.PLAYER_MODIFYING_DEFENSE_DICE,
                LogFileParser.START,
                lambda x: not self.player_is_rolling_dice(x),
                self.end_attack_set
            ),
            ( LogFileParser.PLAYER_MODIFYING_DEFENSE_DICE,
              LogFileParser.PLAYER_ADDING_DEFENSE_DICE,
              lambda x: self.player_added_defense_dice(x),
              self.add_defense_dice
            ),
            (
                LogFileParser.PLAYER_MODIFYING_DEFENSE_DICE,
                LogFileParser.PLAYER_MODIFYING_DEFENSE_DICE,
                lambda x: self.player_is_modifying_defense_dice(x),
                self.add_defense_modification
            ),

            (
                LogFileParser.PLAYER_MODIFYING_DEFENSE_DICE,
                LogFileParser.PLAYER_ATTACKING,
                lambda x: self.player_is_rolling_attack_dice(x),
                self.end_attack_set_and_begin_new_attack_set
            ),

            (
                LogFileParser.PLAYER_ADDING_DEFENSE_DICE,
                LogFileParser.PLAYER_ADDING_DEFENSE_DICE,
                lambda x: self.player_added_defense_dice(x),
                self.add_defense_dice
            ),
            (
                LogFileParser.PLAYER_ADDING_DEFENSE_DICE,
                LogFileParser.PLAYER_MODIFYING_DEFENSE_DICE,
                lambda x: self.player_is_modifying_defense_dice(x),
                self.add_defense_modification
            ),
            (
                LogFileParser.PLAYER_ADDING_DEFENSE_DICE,
                LogFileParser.PLAYER_ATTACKING,
                lambda x: self.player_is_rolling_attack_dice(x),
                self.end_attack_set_and_begin_new_attack_set
            ),
            (
                LogFileParser.PLAYER_ADDING_DEFENSE_DICE,
                LogFileParser.START,
                lambda x: not self.player_is_rolling_dice(x),
                self.end_attack_set
            ),
        ] )

        fs.start(LogFileParser.START)

        i = 0
        lines = self.get_lines()
        for line in lines:
            try:
                fs.event(line)
            except ValueError:
                print("Unable to transition from state {0} ({1}) using input {2}, ignoring and continuing on ...".format(fs.currentState, lines[i-1], lines[i]))

            i = i + 1 #just for debugging purposes

        fs.event("")
示例#34
0
import fsm

f = fsm.fsm(['0', '1'], 2, [0])
f.add_transitions(0, {'0' : 1, '1' : 1})
f.add_transitions(1, {'0' : 0, '1' : 0})

def checkword(w):
    return len(w) % 2 == 0

fsm.fuzzer(checkword, f, 1000, 1, 100)
示例#35
0
    def __init__(self, handle_pub, T):

        self.vector_odom = rospy.Publisher('/vector_odom',
                                           Float32MultiArray,
                                           queue_size=1)
        self.vector_visp = rospy.Publisher('/vector_visp',
                                           Float32MultiArray,
                                           queue_size=1)
        self.calib = rospy.Publisher('/calibration', Bool, queue_size=1)
        self.pub1 = rospy.Publisher('/pos_odom_init',
                                    Float32MultiArray,
                                    queue_size=1)
        self.pub2 = rospy.Publisher('/pos_odom_final',
                                    Float32MultiArray,
                                    queue_size=1)
        self.pub3 = rospy.Publisher('/pos_visp_init',
                                    Float32MultiArray,
                                    queue_size=1)
        self.pub4 = rospy.Publisher('/pos_visp_final',
                                    Float32MultiArray,
                                    queue_size=1)

        self.bin_calibration_visp = False
        self.bin_calibration_odom = False
        self.valeur_odom_prise = True
        self.valeur_visp_prise = True

        self.twist = Twist()
        self.twist_real = Twist()
        self.vreal = 0.0  # longitudial velocity
        self.wreal = 0.0  # angular velocity
        #self.vmax = 0.188
        self.vmax = 0.17
        #self.wmax = 1.297
        self.wmax = self.vmax / 0.135
        self.previous_signal = 0
        self.button_pressed = False
        self.joy_activated = False

        self.pub = handle_pub
        self.T = T

        self.PvL = 0.7
        self.entraxe = 0.27
        self.dist_detection = 0.5
        self.r_rotation = 1

        self.ModeCarre = False
        self.ModeRond = False
        self.ModeTriangle = False
        self.ModeCroix = False

        self.obstacle_detecte = False

        self.message = True
        self.message_info = False
        self.message_JoyControl = False
        self.message_AutonomousMode = False
        self.message_Carre = False
        self.message_Rond = False
        self.message_Triangle = False
        self.message_Croix = False
        self.message_ChangementDirection = False

        self.init_LidarCallback = True

        self.init_odom = True
        self.init_visp = True
        self.Mr0 = np.zeros(6)
        self.rkMr0 = np.zeros(6)

        self.cMm0 = np.zeros((4, 4))
        self.cMr0 = np.zeros((4, 4))
        self.rkMr0v = np.zeros(6)

        #matrice changement de repere entre le QRcode et le centre de rotation du robot
        self.m0Mr0 = np.zeros((4, 4))
        self.m0Mr0[0, 0] = 1
        self.m0Mr0[1, 1] = 1
        self.m0Mr0[2, 2] = 1
        self.m0Mr0[0, 3] = 0.064
        self.m0Mr0[1, 3] = 0
        self.m0Mr0[2, 3] = -(0.4335 - 0.025)
        #self.m0Mr0[2,3]=-0.12
        self.m0Mr0[3, 3] = 1
        #self.m0Mr0=np.eye(4,3)
        #print "m0Mr0"
        #print self.m0Mr0

        self.present_state = "Start"
        self.next_state = []

        # instance of fsm with source state, destination state, condition (transition), callback (defaut: None)
        self.fs = fsm([
            ("Start", "JoyControl", True),
            #transitions de base
            ("JoyControl", "AutonomousMode",
             self.check_JoyControl_To_AutonomousMode, self.DoAutonomousMode),
            ("AutonomousMode", "JoyControl", self.check_To_JoyControl,
             self.DoJoyControl),

            #transitions trajectoire predefinies
            ("JoyControl", "Carre", self.check_JoyControl_To_Carre,
             self.DoCarre),
            ("JoyControl", "Rond", self.check_JoyControl_To_Rond, self.DoRond),
            ("JoyControl", "Triangle", self.check_JoyControl_To_Triangle,
             self.DoTriangle),
            ("JoyControl", "Croix", self.check_JoyControl_To_Croix,
             self.DoCroix),
            ("Carre", "JoyControl", self.check_To_JoyControl,
             self.DoJoyControl),
            ("Rond", "JoyControl", self.check_To_JoyControl,
             self.DoJoyControl),
            ("Triangle", "JoyControl", self.check_To_JoyControl,
             self.DoJoyControl),
            ("Croix", "JoyControl", self.check_To_JoyControl,
             self.DoJoyControl),

            #transitions obstacle
            ("AutonomousMode", "ChangementDirection",
             self.check_AutonomousMode_To_ChangementDirection,
             self.DoChangementDirection),
            ("ChangementDirection", "AutonomousMode",
             self.check_ChangementDirection_To_AutonomousMode,
             self.DoAutonomousMode),
            ("ChangementDirection", "JoyControl", self.check_To_JoyControl,
             self.DoJoyControl),

            #transitions pour rester dans le meme etat
            ("JoyControl", "JoyControl", self.KeepJoyControl, self.DoJoyControl
             ),
            ("AutonomousMode", "AutonomousMode", self.KeepAutonomousMode,
             self.DoAutonomousMode),
            ("ChangementDirection", "ChangementDirection",
             self.KeepChangementDirection, self.DoChangementDirection),
            ("Carre", "Carre", self.KeepCarre, self.DoCarre),
            ("Rond", "Rond", self.KeepRond, self.DoRond),
            ("Triangle", "Triangle", self.KeepTriangle, self.DoTriangle),
            ("Croix", "Croix", self.KeepCroix, self.DoCroix)
        ])
示例#36
0
# mise en place des sockets

global msgout
mysock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server = "127.0.0.1"
port = 55042
msgout = "CLIENT DISPONIBLE"
mysock.sendto(msgout, (server, port))
msgin, rserver = mysock.recvfrom(255)
print "Received:", msgin, " from ", rserver

# AUTOMATE FINI - SIMULATION DE CARTOGRAPHIE ET LOCALISATION SIMULTANEES POUR VALIDATION DE LA DEMARCHE


f = fsm.fsm()
n = nao.Nao(15,12,0,5)
e = environnement.Environnement(20,20)
e.addObjet(3,3,2)
e.addObjet(16,8,2)
e.addObjet(12,15,2)
e.addObjet(0,14,2)


# limites de l'environnement
xMax = e.xMax
yMax = e.yMax


# rayon de "vision" du NAO
n.rVision = 5