Ejemplo n.º 1
0
def main():

    GPIO.setwarnings(False)
    print("\nResetting all pins..")

    gyroAddress = 0x68
    buzzerPin = 17
    hapticPin = 27
    buttonPin = 6
    laserPin = 5
    ledPin = 25

    gyroAddress = gyroAddress
    buzzerPin = buzzerPin
    hapticPin = hapticPin
    buttonPin = buttonPin
    laserPin = laserPin
    ledPin = ledPin

    state = State()
    gyro = MPU6050(gyroAddress)
    buzzer = OutputComponent(buzzerPin)
    haptic = OutputComponent(hapticPin)
    button = Button(buttonPin)
    laser = OutputComponent(laserPin)
    led = OutputComponent(ledPin)

    GPIO.cleanup()
    print("\t..done.\n")
Ejemplo n.º 2
0
def build_LR0_automaton(grammar):
    assert len(grammar.startSymbol.productions) == 1, 'Grammar must be augmented'

    start_production = grammar.startSymbol.productions[0]
    start_item = Item(start_production, 0)

    automaton = State(start_item, True)

    pending = [start_item]
    visited = {start_item: automaton}

    while pending:
        current_item = pending.pop()
        if current_item.IsReduceItem:
            continue

        next_symbol = current_item.NextSymbol

        next_item = current_item.NextItem()
        if not next_item in visited:
            pending.append(next_item)
            visited[next_item] = State(next_item, True)

        if next_symbol.IsNonTerminal:
            for prod in next_symbol.productions:
                next_item = Item(prod, 0)
                if not next_item in visited:
                    pending.append(next_item)
                    visited[next_item] = State(next_item, True)

        current_state = visited[current_item]

        current_state.add_transition(next_symbol.Name, visited[current_item.NextItem()])

        if next_symbol.IsNonTerminal:
            for prod in next_symbol.productions:
                current_state.add_epsilon_transition(visited[Item(prod, 0)])

    return automaton
Ejemplo n.º 3
0
def build_lr1_automaton(grammar):
    assert len(grammar.startSymbol.productions) == 1, 'Grammar must be augmented'

    firsts = compute_firsts(grammar)
    firsts[grammar.EOF] = ContainerSet(grammar.EOF)

    start_production = grammar.startSymbol.productions[0]
    start_item = Item(start_production, 0, lookaheads=(grammar.EOF,))
    start = frozenset([start_item])

    closure = closure_lr1(start, firsts)
    automaton = State(frozenset(closure), True)

    pending = [start]
    visited = {start: automaton}

    while pending:
        current = pending.pop()
        current_state = visited[current]

        for symbol in grammar.terminals + grammar.nonTerminals:

            kernels = goto_lr1(current_state.state, symbol, just_kernel=True)

            if not kernels:
                continue

            try:
                next_state = visited[kernels]
            except KeyError:
                pending.append(kernels)
                visited[pending[-1]] = next_state = State(frozenset(goto_lr1(current_state.state, symbol, firsts)),
                                                          True)

            current_state.add_transition(symbol.Name, next_state)

    automaton.set_formatter(multi_line_formatter)
    return automaton
Ejemplo n.º 4
0
    def __init__(self, gyroAddress, buzzerPin, hapticPin, buttonPin, laserPin,
                 ledPin):

        self.gyroAddress = gyroAddress
        self.buzzerPin = buzzerPin
        self.hapticPin = hapticPin

        self.hapticPin2 = None
        if (settings.enableSecondHaptic):
            self.hapticPin2 = settings.secondaryHapticPin

        self.buttonPin = buttonPin
        self.laserPin = laserPin
        self.ledPin = ledPin

        self.state = State(State.StateType.PAUSED)
        self.gyro = MPU6050(self.gyroAddress)
        self.buzzer = Buzzer(self.buzzerPin)
        self.haptic = OutputComponent(self.hapticPin)

        self.haptic2 = None
        if (settings.enableSecondHaptic):
            self.haptic2 = OutputComponent(self.hapticPin2)

        self.button = Button(self.buttonPin)
        self.laser = OutputComponent(self.laserPin)
        self.led = LED(self.ledPin)

        self.metronomeDelay = ((float(60) / settings.numberOfSteps) -
                               (settings.stepdownDelay))

        if (self.metronomeDelay <= 0):
            print("\t**ERROR** Not a valid numberOfSteps defined in" +
                  " InitSettings.py. Exiting..")
            sys.exit(0)

        self.clf = joblib.load(
            '/home/pi/gaitmate/pi/MachineLearn/dTreeExport.pkl')
        self.predictedResult = None
        self.prevPredictedResult = None