Esempio n. 1
0
    def test_handle_sensor_data_request(self):
        huginn_data_path = configuration.get_data_path()

        fdm_builder = FDMBuilder(huginn_data_path)
        fdm_builder.aircraft = "Rascal"
        fdmexec = fdm_builder.create_fdm()

        aircraft = Aircraft(fdmexec)

        factory = SensorDataFactory(aircraft)

        protocol = factory.buildProtocol(("127.0.0.1", 12345))
        protocol.send_response_string = MagicMock()

        sensor_data_request = fdm_pb2.SensorDataRequest()
        sensor_data_request.type = fdm_pb2.GPS_REQUEST

        protocol.handle_sensor_data_request(sensor_data_request)

        expected_sensor_data_response = fdm_pb2.SensorDataResponse()
        expected_sensor_data_response.type = fdm_pb2.GPS_REQUEST
        expected_sensor_data_response.gps.latitude = aircraft.instruments.gps.latitude
        expected_sensor_data_response.gps.longitude = aircraft.instruments.gps.longitude
        expected_sensor_data_response.gps.altitude = aircraft.instruments.gps.altitude
        expected_sensor_data_response.gps.airspeed = aircraft.instruments.gps.airspeed
        expected_sensor_data_response.gps.heading = aircraft.instruments.gps.heading

        protocol.send_response_string.assert_called_once_with(
            expected_sensor_data_response.SerializeToString())
Esempio n. 2
0
    def test_fill_controls_data(self):
        huginn_data_path = configuration.get_data_path()

        fdm_builder = FDMBuilder(huginn_data_path)
        fdm_builder.aircraft = "Rascal"
        fdmexec = fdm_builder.create_fdm()

        aircraft = Aircraft(fdmexec)

        factory = SensorDataFactory(aircraft)

        protocol = factory.buildProtocol(("127.0.0.1", 12345))

        sensor_data_response = fdm_pb2.SensorDataResponse()

        protocol.fill_controls_data(sensor_data_response)

        self.assertAlmostEqual(sensor_data_response.controls.aileron,
                               aircraft.controls.aileron)
        self.assertAlmostEqual(sensor_data_response.controls.elevator,
                               aircraft.controls.elevator)
        self.assertAlmostEqual(sensor_data_response.controls.rudder,
                               aircraft.controls.rudder)
        self.assertAlmostEqual(sensor_data_response.controls.throttle,
                               aircraft.controls.throttle)

        self.assertEqual(sensor_data_response.type, fdm_pb2.CONTROLS_REQUEST)
Esempio n. 3
0
    def test_fill_ins_data(self):
        huginn_data_path = configuration.get_data_path()

        fdm_builder = FDMBuilder(huginn_data_path)
        fdm_builder.aircraft = "Rascal"
        fdmexec = fdm_builder.create_fdm()

        aircraft = Aircraft(fdmexec)

        factory = SensorDataFactory(aircraft)

        protocol = factory.buildProtocol(("127.0.0.1", 12345))

        sensor_data_response = fdm_pb2.SensorDataResponse()

        protocol.fill_ins_data(sensor_data_response)

        self.assertAlmostEqual(
            sensor_data_response.ins.roll,
            aircraft.sensors.inertial_navigation_system.roll)
        self.assertAlmostEqual(
            sensor_data_response.ins.pitch,
            aircraft.sensors.inertial_navigation_system.pitch)

        self.assertEqual(sensor_data_response.type, fdm_pb2.INS_REQUEST)
Esempio n. 4
0
    def test_fill_gyroscope_data(self):
        huginn_data_path = configuration.get_data_path()

        fdm_builder = FDMBuilder(huginn_data_path)
        fdm_builder.aircraft = "Rascal"
        fdmexec = fdm_builder.create_fdm()

        aircraft = Aircraft(fdmexec)

        factory = SensorDataFactory(aircraft)

        protocol = factory.buildProtocol(("127.0.0.1", 12345))

        sensor_data_response = fdm_pb2.SensorDataResponse()

        protocol.fill_gyroscope_data(sensor_data_response)

        self.assertAlmostEqual(sensor_data_response.gyroscope.roll_rate,
                               aircraft.sensors.gyroscope.roll_rate)
        self.assertAlmostEqual(sensor_data_response.gyroscope.pitch_rate,
                               aircraft.sensors.gyroscope.pitch_rate)
        self.assertAlmostEqual(sensor_data_response.gyroscope.yaw_rate,
                               aircraft.sensors.gyroscope.yaw_rate)

        self.assertEqual(sensor_data_response.type, fdm_pb2.GYROSCOPE_REQUEST)
Esempio n. 5
0
    def test_fill_accelerometer_data(self):
        huginn_data_path = configuration.get_data_path()

        fdm_builder = FDMBuilder(huginn_data_path)
        fdm_builder.aircraft = "Rascal"
        fdmexec = fdm_builder.create_fdm()

        aircraft = Aircraft(fdmexec)

        factory = SensorDataFactory(aircraft)

        protocol = factory.buildProtocol(("127.0.0.1", 12345))

        sensor_data_response = fdm_pb2.SensorDataResponse()

        protocol.fill_accelerometer_data(sensor_data_response)

        self.assertAlmostEqual(sensor_data_response.accelerometer.x,
                               aircraft.sensors.accelerometer.x)
        self.assertAlmostEqual(sensor_data_response.accelerometer.y,
                               aircraft.sensors.accelerometer.y)
        self.assertAlmostEqual(sensor_data_response.accelerometer.z,
                               aircraft.sensors.accelerometer.z)

        self.assertEqual(sensor_data_response.type,
                         fdm_pb2.ACCELEROMETER_REQUEST)
Esempio n. 6
0
    def test_fill_gps_data(self):
        huginn_data_path = configuration.get_data_path()

        fdm_builder = FDMBuilder(huginn_data_path)
        fdm_builder.aircraft = "Rascal"
        fdmexec = fdm_builder.create_fdm()

        aircraft = Aircraft(fdmexec)

        factory = SensorDataFactory(aircraft)

        protocol = factory.buildProtocol(("127.0.0.1", 12345))

        sensor_data_response = fdm_pb2.SensorDataResponse()

        protocol.fill_gps_data(sensor_data_response)

        self.assertAlmostEqual(sensor_data_response.gps.latitude,
                               aircraft.instruments.gps.latitude)
        self.assertAlmostEqual(sensor_data_response.gps.longitude,
                               aircraft.instruments.gps.longitude)
        self.assertAlmostEqual(sensor_data_response.gps.altitude,
                               aircraft.instruments.gps.altitude)
        self.assertAlmostEqual(sensor_data_response.gps.airspeed,
                               aircraft.instruments.gps.airspeed)
        self.assertAlmostEqual(sensor_data_response.gps.heading,
                               aircraft.instruments.gps.heading)

        self.assertEqual(sensor_data_response.type, fdm_pb2.GPS_REQUEST)
Esempio n. 7
0
    def handle_sensor_data_request(self, sensor_data_request):
        """Fills the required data on the response object and sends the
        response back to the requesting client"""
        sensor_data_response = fdm_pb2.SensorDataResponse()

        if sensor_data_request.type == fdm_pb2.GPS_REQUEST:
            self.fill_gps_data(sensor_data_response)
        elif sensor_data_request.type == fdm_pb2.ACCELEROMETER_REQUEST:
            self.fill_accelerometer_data(sensor_data_response)
        elif sensor_data_request.type == fdm_pb2.GYROSCOPE_REQUEST:
            self.fill_accelerometer_data(sensor_data_response)
        elif sensor_data_request.type == fdm_pb2.THERMOMETER_REQUEST:
            self.fill_thermometer_data(sensor_data_response)
        elif sensor_data_request.type == fdm_pb2.PRESSURE_SENSOR_REQUEST:
            self.fill_pressure_sensor_data(sensor_data_response)
        elif sensor_data_request.type == fdm_pb2.PITOT_TUBE_REQUEST:
            self.fill_pitot_tube_data(sensor_data_response)
        elif sensor_data_request.type == fdm_pb2.ENGINE_REQUEST:
            self.fill_engine_data(sensor_data_response)
        elif sensor_data_request.type == fdm_pb2.CONTROLS_REQUEST:
            self.fill_controls_data(sensor_data_response)
        elif sensor_data_request.type == fdm_pb2.INS_REQUEST:
            self.fill_ins_data(sensor_data_response)
        else:
            self.fill_error_response(sensor_data_response)

        self.send_response_string(sensor_data_response.SerializeToString())
Esempio n. 8
0
    def test_fill_pitot_tube_data(self):
        huginn_data_path = configuration.get_data_path()

        fdm_builder = FDMBuilder(huginn_data_path)
        fdm_builder.aircraft = "Rascal"
        fdmexec = fdm_builder.create_fdm()

        aircraft = Aircraft(fdmexec)

        factory = SensorDataFactory(aircraft)

        protocol = factory.buildProtocol(("127.0.0.1", 12345))

        sensor_data_response = fdm_pb2.SensorDataResponse()

        protocol.fill_pitot_tube_data(sensor_data_response)

        self.assertAlmostEqual(sensor_data_response.pitot_tube.pressure,
                               aircraft.sensors.pitot_tube.pressure)

        self.assertEqual(sensor_data_response.type, fdm_pb2.PITOT_TUBE_REQUEST)
Esempio n. 9
0
    def test_fill_engine_data(self):
        huginn_data_path = configuration.get_data_path()

        fdm_builder = FDMBuilder(huginn_data_path)
        fdm_builder.aircraft
        fdmexec = fdm_builder.create_fdm()

        aircraft = Aircraft(fdmexec)

        factory = SensorDataFactory(aircraft)

        protocol = factory.buildProtocol(("127.0.0.1", 12345))

        sensor_data_response = fdm_pb2.SensorDataResponse()

        protocol.fill_engine_data(sensor_data_response)

        self.assertAlmostEqual(sensor_data_response.engine.thrust,
                               aircraft.engine.thrust)
        self.assertAlmostEqual(sensor_data_response.engine.throttle,
                               aircraft.engine.throttle)

        self.assertEqual(sensor_data_response.type, fdm_pb2.ENGINE_REQUEST)
Esempio n. 10
0
    def stringReceived(self, string):
        """Handle the data that have been received from the simulator"""
        sensor_data_response = fdm_pb2.SensorDataResponse()
        sensor_data_response.ParseFromString(string)

        self.factory.received_responce(sensor_data_response)