Ejemplo n.º 1
0
def test_write_column_sets_all_servos_in_desired_columns_to_position(
        mock_comm):
    wall = Wall(comm=mock_comm)
    wall.write_column('3', 0.314)

    assert wall.servos['E']['3'].position == 0.314
    assert wall.servos['C']['3'].position == 0.314
Ejemplo n.º 2
0
def test_write_wall_writes_all_servos_on_wall(mock_comm):
    wall = Wall(comm=mock_comm)
    wall.write([
        [0.5, 0.5, 0.5, 0.5, 0.5, 0.5],
        [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5],
        [0.5, 0.5, 0.5, 0.5, 0.5, 0.5],
        [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5],
    ])

    for servo in wall.list_servos():
        assert servo.position == 0.5
Ejemplo n.º 3
0
    def __init__(self, com_port):
        self.active = False
        configure_logger()
        self.connect_comm(com_port)

        try:
            from gpiozero import Button, LED
            self.routine_indicator = LED(ROUTINE_LED_PIN)
            self.routine_indicator.on()
            time.sleep(3)
            self.routine_indicator.off()
            self.routine_button = Button(ROUTINE_BUTTON_PIN)
        except Exception as e:
            logging.error('Could not connect to GPIO')
            raise (e)

        self.routines = list_routines()
        self.wall = Wall(self.comm)
        super(Controller, self).__init__()
Ejemplo n.º 4
0
        wall.write_column('7', -1)
        time.sleep(2)

        wall.write_column('10', 0.8)
        wall.write_column('8', -1)
        time.sleep(2)

        wall.write_column('11', 0.8)
        wall.write_column('9', -1)
        time.sleep(2)

        wall.write_column('12', 0.8)
        wall.write_column('10', -1)
        time.sleep(2)

        wall.write_column('13', 0.8)
        wall.write_column('11', -1)
        time.sleep(2)

        wall.write_column('14', 0.8)
        wall.write_column('12', -1)
        time.sleep(2)

    wall.write_column('13', -1)
    wall.write_column('14', -1)


if __name__ == '__main__':
    wall = Wall()
    run(wall)
Ejemplo n.º 5
0
class Controller(Thread):
    def __init__(self, com_port):
        self.active = False
        configure_logger()
        self.connect_comm(com_port)

        try:
            from gpiozero import Button, LED
            self.routine_indicator = LED(ROUTINE_LED_PIN)
            self.routine_indicator.on()
            time.sleep(3)
            self.routine_indicator.off()
            self.routine_button = Button(ROUTINE_BUTTON_PIN)
        except Exception as e:
            logging.error('Could not connect to GPIO')
            raise (e)

        self.routines = list_routines()
        self.wall = Wall(self.comm)
        super(Controller, self).__init__()

    # Run specific wall routine (pattern)
    def run_routine(self, routine_name):
        try:
            self.routine_indicator.on()
            self.routines[routine_name].run(self.wall)
            self.wall.reset()
            time.sleep(5)
            self.routine_indicator.off()
        except (WallInterrupt, Exception) as e:
            logging.error('Routine "{}" failed'.format(routine_name))
            logging.error(e)

    # Activate the wall
    def activate(self):
        if not self.active:
            super(Controller, self).__init__()
            self.active = True
            self.start()
            if not self.is_alive():
                logging.error('Failed to activate controller')

    # Deactivate the wall
    def deactivate(self):
        if self.active:
            self.active = False
            self.join()
            if self.is_alive():
                raise Exception('Failed to deactivate controller')

    def run(self):
        while self.active:
            self.routine_button.wait_for_press(timeout=None)
            self.run_routine(random.choice(self.routines.keys()))

    # Connect to COM port in order to run
    def connect_comm(self, com_port, retry=5, timeout=DEFAULT_TIMEOUT):
        for i in range(retry):
            try:
                self.comm = serial.serial_for_url(com_port,
                                                  baudrate=DEFAULT_COM_BAUD)
                return self.comm
            except Exception as e:
                logging.error(e)
                logging.warn('Retry count {}'.format(i))
                time.sleep(timeout)

        raise IOError('Failed to connect to wall on comm: {}'.format(com_port))
Ejemplo n.º 6
0
def test_write_column_raises_if_servo_location_invalid(mock_comm):
    wall = Wall(comm=mock_comm)
    with pytest.raises(KeyError):
        wall.write_row('99', 0.69)
Ejemplo n.º 7
0
def test_write_row_sets_all_servos_in_desired_row_to_position(mock_comm):
    wall = Wall(comm=mock_comm)
    wall.write_row('C', 0.314)
    for servo in wall.servos['C'].values():
        assert servo.position == 0.314
Ejemplo n.º 8
0
def test_write_servo_sets_servo_to_desired_position(mock_comm):
    wall = Wall(comm=mock_comm)
    wall.write_servo('C', '7', 0.314)
    assert wall.servos['C']['7'].position == 0.314
Ejemplo n.º 9
0
def test_init_wall_creates_correct_number_of_servos(mock_comm):
    wall = Wall(comm=mock_comm)
    assert len(wall.list_servos()) == 26
Ejemplo n.º 10
0
def test_init_wall_sets_list_servos_to_starting_position(mock_comm):
    wall = Wall(comm=mock_comm)
    for servo in wall.list_servos():
        assert servo.position == -1.0