Exemplo n.º 1
0
    def test_manual_mode_no_input(self):
        """
        Tests an iteration of the manual mode in the main loop
        without data input from the server.
        Makes sure that if does not spontaneously turn on
        the auto mode, that is requests and sucessfully receives
        a sensor data packet, puts it in the queue, and that the 
        avr_communication reads the values correctly.
        """
        send_queue = queue.Queue()
        receive_queue = queue.Queue()
        spi = fake_spi.SpiDev()

        _set_sensor_data_sequence(spi)

        try:
            auto, _, _, _, _ = main.do_manual_mode_iteration(
                spi, spi, send_queue, receive_queue, -1, -1, -1, -1)
        except fake_spi.UnexpectedDataException as e:
            self.fail("Expected {}, got {}".format(e.expected, e.actual))

        self.assertFalse(auto)
        self.assertFalse(send_queue.empty())
        packet = send_queue.get()
        self.assertTrue(send_queue.empty())

        sensor_data = packet.sensor

        self.assertEqual(0.01, sensor_data.ir_down)
        self.assertEqual(0.01, sensor_data.ir_front_left)
        self.assertEqual(0.01, sensor_data.ir_back_left)
        self.assertEqual(0.01, sensor_data.ir_front_right)
        self.assertEqual(0.01, sensor_data.ir_back_right)
        self.assertEqual(2.58, sensor_data.lidar)
Exemplo n.º 2
0
    def test_manual_return_to_neutral(self):
        """
        Tests whether the the manual mode responds to a command
        from the server to return to neutral by sending the 
        correct commands to the motor unit.
        """
        send_queue = queue.Queue()
        receive_queue = queue.Queue()
        spi = fake_spi.SpiDev()
        _set_sensor_data_sequence(spi)
        _add_return_to_neutral(spi)

        packet = web.ServerReceivedPacket("{\"reset\": true}")

        receive_queue.put(packet)

        try:
            auto, _, _, _, _ = main.do_manual_mode_iteration(
                spi, spi, send_queue, receive_queue, -1, -1, -1, -1)
        except fake_spi.UnexpectedDataException as e:
            self.fail(
                "Something went wrong in the SPI-communication: Expected {}, got {}"
                .format(e.expected, e.actual))

        self.assertFalse(auto)
Exemplo n.º 3
0
    def test_is_busy_rotating_true(self):
        """
        Tests whether is_busy_rotating is compliant to
        the communication protocol, and that it returns
        True when the motor unit sends 0x01.
        """
        spi = fake_spi.SpiDev()
        spi.set_expected_write_sequence([
            avr_communication.GARBAGE,
            avr_communication._add_parity(avr_communication.DATA_REQ,
                                          avr_communication.BUSY_ROTATING),
            avr_communication.BUSY_ROTATING
        ])

        value = 0x01

        spi.set_fake_read_sequence([
            avr_communication.ACK,
            avr_communication._add_parity(avr_communication.BUSY_ROTATING,
                                          value), value
        ])
        try:
            result = avr_communication.is_busy_rotating(spi)
        except fake_spi.UnexpectedDataException as e:
            self.fail("Expected {}, got {}, when writing.".format(
                e.expected, e.actual))
        self.assertTrue(result)
Exemplo n.º 4
0
 def test_send_bytes(self):
     """
     Tests the _send_bytes function.
     """
     spi = fake_spi.SpiDev()
     seq = [0x00, 0x0F, 0xFF]
     spi.set_expected_write_sequence([avr_communication.GARBAGE] + seq)
     try:
         avr_communication._send_bytes(spi, *seq)
     except fake_spi.UnexpectedDataException as e:
         self.fail("Expected {}, got {}".format(e.expected, e.actual))
Exemplo n.º 5
0
 def test_read_multiple_bytes(self):
     """
     Tests the _recieve_bytes function for a multi-byte message.
     """
     spi = fake_spi.SpiDev()
     msg = [0x01, 0x02, 0x03, 0x01]
     # type that indicates that it's a multibyte message with an
     # uneven number of ones in the message and length byte
     type_ = 0b10001111
     spi.set_fake_read_sequence([type_, 4] + msg)
     result = avr_communication._recieve_bytes(spi)
     self.assertListEqual(result, msg)
Exemplo n.º 6
0
 def test_read_single_byte(self):
     """
     Tests the _recieve_bytes function for a single byte message.
     """
     spi = fake_spi.SpiDev()
     msg = 0xFE
     # type that indicates that it's a one byte message with an
     # uneven number of ones
     type_ = 0b00001110
     spi.set_fake_read_sequence([type_, msg])
     result = avr_communication._recieve_bytes(spi)
     self.assertListEqual(result, [msg])
Exemplo n.º 7
0
    def test_auto_sent_but_not_changed_manual(self):
        """
        Makes sure the auto mode does not change if a value for auto mode
        is sent but set to false when in manual mode.
        """
        send_queue = queue.Queue()
        receive_queue = queue.Queue()
        spi = fake_spi.SpiDev()
        _set_sensor_data_sequence(spi)

        packet = web.ServerReceivedPacket("{\"auto\": false}")

        receive_queue.put(packet)

        try:
            auto, _, _, _, _ = main.do_manual_mode_iteration(
                spi, spi, send_queue, receive_queue, -1, -1, -1, -1)
        except fake_spi.UnexpectedDataException as e:
            self.fail(
                "Something went wrong when reading sensor data: Expected {}, got {}"
                .format(e.expected, e.actual))

        self.assertFalse(auto)
Exemplo n.º 8
0
    def test_manual_to_auto(self):
        """
        Tests whether auto mode is changed to true if such
        a command is sent from the server, when in manual mode.
        """
        send_queue = queue.Queue()
        receive_queue = queue.Queue()
        spi = fake_spi.SpiDev()
        _set_sensor_data_sequence(spi)

        packet = web.ServerReceivedPacket("{\"auto\": true}")

        receive_queue.put(packet)

        try:
            auto, _, _, _, _ = main.do_manual_mode_iteration(
                spi, spi, send_queue, receive_queue, -1, -1, -1, -1)
        except fake_spi.UnexpectedDataException as e:
            self.fail(
                "Something went wrong when reading sensor data: Expected {}, got {}"
                .format(e.expected, e.actual))

        self.assertTrue(auto)