コード例 #1
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)
コード例 #2
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)
コード例 #3
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)
コード例 #4
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)