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)
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())
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)
def test_get_object_resource_data(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdmexec = fdm_builder.create_fdm() accelerations = Accelerations(fdmexec) accelerations_schema = AccelerationsSchema() object_resource = ObjectResource(accelerations, accelerations_schema) response = object_resource.get() expected_result = { "x": accelerations.x, "y": accelerations.y, "z": accelerations.z, "p_dot": accelerations.p_dot, "q_dot": accelerations.q_dot, "r_dot": accelerations.r_dot, "u_dot": accelerations.u_dot, "v_dot": accelerations.v_dot, "w_dot": accelerations.w_dot, "gravity": accelerations.gravity } self.assertDictEqual(response, expected_result)
def test_accelerometer_bias_and_noise_modification_updates(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdmexec = fdm_builder.create_fdm() accelerometer = Accelerometer(fdmexec) accelerometer._x_measurement_noise = 0.0 fdmexec.Run() self.assertEqual(accelerometer.x_measurement_noise, 0.0) #make sure the model is not paused fdmexec.Resume() run_until = fdmexec.GetSimTime() + (1.0 / accelerometer.update_rate) + 1.0 while fdmexec.GetSimTime() < run_until: fdmexec.Run() #self.assertAlmostEqual(accelerometer.x, accelerometer.true_x + accelerometer._x_measurement_noise, 3) self.assertNotEqual(accelerometer.x_measurement_noise, 0.0)
def test_accelerometer(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdmexec = fdm_builder.create_fdm() accelerometer = Accelerometer(fdmexec) self.assertAlmostEqual( accelerometer.true_x, convert_jsbsim_acceleration( fdmexec.GetAuxiliary().GetPilotAccel(1)), 3) self.assertAlmostEqual( accelerometer.true_y, convert_jsbsim_acceleration( fdmexec.GetAuxiliary().GetPilotAccel(2)), 3) self.assertAlmostEqual( accelerometer.true_z, convert_jsbsim_acceleration( fdmexec.GetAuxiliary().GetPilotAccel(3)), 3) self.assertAlmostEqual( accelerometer.x, accelerometer.true_x + accelerometer.x_measurement_noise, 3) self.assertAlmostEqual( accelerometer.y, accelerometer.true_y + accelerometer.y_measurement_noise, 3) self.assertAlmostEqual( accelerometer.z, accelerometer.true_z + accelerometer.z_measurement_noise, 3)
def test_get_fdm_data(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdmexec = fdm_builder.create_fdm() aircraft = Aircraft(fdmexec) fdm = FDM(fdmexec) resource = FDMResource(fdm, aircraft) fdm_data = resource.get() self.assertAlmostEqual(fdm.fdmexec.GetSimTime(), fdm_data["time"], 3) self.assertAlmostEqual(fdm.fdmexec.GetDeltaT(), fdm_data["dt"], 3) self.assertAlmostEqual(fdm.position.latitude, fdm_data["latitude"], 3) self.assertAlmostEqual(fdm.position.longitude, fdm_data["longitude"], 3) self.assertAlmostEqual(fdm.position.altitude, fdm_data["altitude"], 3) self.assertAlmostEqual(fdm.velocities.true_airspeed, fdm_data["airspeed"], 3) self.assertAlmostEqual(fdm.position.heading, fdm_data["heading"], 3) self.assertAlmostEqual(fdm.accelerations.x, fdm_data["x_acceleration"], 3) self.assertAlmostEqual(fdm.accelerations.y, fdm_data["y_acceleration"], 3) self.assertAlmostEqual(fdm.accelerations.z, fdm_data["z_acceleration"], 3) self.assertAlmostEqual(fdm.velocities.p, fdm_data["roll_rate"], 3) self.assertAlmostEqual(fdm.velocities.q, fdm_data["pitch_rate"], 3) self.assertAlmostEqual(fdm.velocities.r, fdm_data["yaw_rate"], 3) self.assertAlmostEqual(fdm.atmosphere.temperature, fdm_data["temperature"], 3) self.assertAlmostEqual(fdm.atmosphere.pressure, fdm_data["static_pressure"], 3) self.assertAlmostEqual(aircraft.sensors.pitot_tube.true_pressure, fdm_data["total_pressure"], 3) self.assertAlmostEqual(fdm.orientation.phi, fdm_data["roll"], 3) self.assertAlmostEqual(fdm.orientation.theta, fdm_data["pitch"], 3) climb_rate = convert_jsbsim_velocity(-fdmexec.GetPropagate().GetVel(3)) self.assertAlmostEqual(climb_rate, fdm_data["climb_rate"], 3)
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)
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)
def test_datagram_received(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) controls_protocol = ControlsProtocol(fdmexec) aileron = 0.1 elevator = 0.2 rudder = 0.3 throttle = 0.4 controls = fdm_pb2.Controls() controls.aileron = aileron controls.elevator = elevator controls.rudder = rudder controls.throttle = throttle controls_datagram = controls.SerializeToString() host = "127.0.0.1" port = 12345 controls_protocol.datagramReceived(controls_datagram, (host, port)) self.assertAlmostEqual(aircraft.controls.aileron, aileron, 3) self.assertAlmostEqual(aircraft.controls.elevator, elevator, 3) self.assertAlmostEqual(aircraft.controls.rudder, rudder, 3) self.assertAlmostEqual(aircraft.controls.throttle, throttle, 3)
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)
def test_get_atmospheric_data(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdmexec = fdm_builder.create_fdm() atmosphere = Atmosphere(fdmexec) self.assertAlmostEqual( atmosphere.pressure, convert_jsbsim_pressure(fdmexec.GetAtmosphere().GetPressure()), 3) self.assertAlmostEqual( atmosphere.sea_level_pressure, convert_jsbsim_pressure(fdmexec.GetAtmosphere().GetPressureSL()), 3) self.assertAlmostEqual( atmosphere.temperature, convert_jsbsim_temperature( fdmexec.GetAtmosphere().GetTemperature()), 3) self.assertAlmostEqual( atmosphere.sea_level_temperature, convert_jsbsim_temperature( fdmexec.GetAtmosphere().GetTemperatureSL()), 3) self.assertAlmostEqual( atmosphere.density, convert_jsbsim_density(fdmexec.GetAtmosphere().GetDensity()), 3) self.assertAlmostEqual( atmosphere.sea_level_density, convert_jsbsim_density(fdmexec.GetAtmosphere().GetDensitySL()), 3)
def test_create_fdmexec(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdm = fdm_builder.create_fdm() self.assertIsNotNone(fdm) self.assertEqual(fdm.GetSimTime(), 0.0) self.assertEqual(fdm.GetDeltaT(), configuration.DT) self.assertAlmostEqual(fdm.GetIC().GetLatitudeDegIC(), configuration.LATITUDE, 3) self.assertAlmostEqual(fdm.GetIC().GetLongitudeDegIC(), configuration.LONGITUDE, 3) self.assertAlmostEqual(fdm.GetIC().GetPsiDegIC(), configuration.HEADING, 3) altitude = configuration.ALTITUDE * ur.meter altitude.ito(ur.foot) altitude_in_feet = altitude.magnitude self.assertAlmostEqual(fdm.GetIC().GetAltitudeASLFtIC(), altitude_in_feet, 3) airspeed = configuration.AIRSPEED * ur.meters_per_second airspeed.ito(ur.knot) airspeed_in_knots = airspeed.magnitude self.assertAlmostEqual(fdm.GetIC().GetVtrueKtsIC(), airspeed_in_knots, 3)
def test_gyroscope(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdm_builder.aircraft = "Rascal" fdmexec = fdm_builder.create_fdm() gyroscope = Gyroscope(fdmexec) self.assertAlmostEqual(gyroscope.true_roll_rate, math.degrees(fdmexec.GetPropagate().GetPQR(1)), 3) self.assertAlmostEqual(gyroscope.true_pitch_rate, math.degrees(fdmexec.GetPropagate().GetPQR(2)), 3) self.assertAlmostEqual(gyroscope.true_yaw_rate, math.degrees(fdmexec.GetPropagate().GetPQR(3)), 3) self.assertAlmostEqual( gyroscope.roll_rate, gyroscope.true_roll_rate + gyroscope._roll_rate_measurement_noise, 3) self.assertAlmostEqual( gyroscope.pitch_rate, gyroscope.true_pitch_rate + gyroscope._pitch_rate_measurement_noise, 3) self.assertAlmostEqual( gyroscope.yaw_rate, gyroscope.true_yaw_rate + gyroscope._yaw_rate_measurement_noise, 3)
def test_inertialNavigationSystem(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdm_builder.aircraft = "Rascal" fdmexec = fdm_builder.create_fdm() sensors = Sensors(fdmexec) self.assertAlmostEqual(sensors.inertial_navigation_system.true_roll, fdmexec.GetPropagate().GetEulerDeg(1), 3) self.assertAlmostEqual(sensors.inertial_navigation_system.true_pitch, fdmexec.GetPropagate().GetEulerDeg(2), 3) self.assertAlmostEqual( sensors.inertial_navigation_system.true_latitude, fdmexec.GetPropagate().GetLatitudeDeg(), 3) self.assertAlmostEqual( sensors.inertial_navigation_system.true_longitude, fdmexec.GetPropagate().GetLongitudeDeg(), 3) self.assertAlmostEqual( sensors.inertial_navigation_system.true_altitude, fdmexec.GetPropagate().GetAltitudeASLmeters(), 3) self.assertAlmostEqual( sensors.inertial_navigation_system.true_airspeed, convert_jsbsim_velocity(fdmexec.GetAuxiliary().GetVtrueFPS()), 3) self.assertAlmostEqual( sensors.inertial_navigation_system.true_heading, math.degrees(fdmexec.GetPropagate().GetEuler(3)), 3)
def test_update_initial_condition(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdmexec = fdm_builder.create_fdm() ic_resource = InitialConditionResource(fdmexec) new_ic = { "latitude": 10.0, "longitude": 20.0, "altitude": 150.0, "airspeed": 60.0, "heading": 90.0 } ic_resource.update_initial_conditions(new_ic) response = ic_resource.get() self.assertAlmostEqual(response["latitude"], 10.0, 3) self.assertAlmostEqual(response["longitude"], 20.0, 3) self.assertAlmostEqual(response["altitude"], 150.0, 3) self.assertAlmostEqual(response["airspeed"], 60.0, 3) self.assertAlmostEqual(response["heading"], 90.0, 3)
def test_ins_meaurement_noise_update(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdm_builder.aircraft = "Rascal" fdmexec = fdm_builder.create_fdm() ins = InertialNavigationSystem(fdmexec) ins._roll_measurement_noise = 0.0 ins._pitch_measurement_noise = 0.0 ins._heading_measurement_noise = 0.0 ins._latitude_measurement_noise = 0.0 ins._longitude_measurement_noise = 0.0 ins._altitude_measurement_noise = 0.0 ins._airspeed_measurement_noise = 0.0 fdmexec.Run() self.assertEqual(ins._roll_measurement_noise, 0.0) self.assertEqual(ins.roll_measurement_noise, 0.0) self.assertEqual(ins._pitch_measurement_noise, 0.0) self.assertEqual(ins.pitch_measurement_noise, 0.0) self.assertEqual(ins._heading_measurement_noise, 0.0) self.assertEqual(ins.heading_measurement_noise, 0.0) self.assertEqual(ins._latitude_measurement_noise, 0.0) self.assertEqual(ins.latitude_measurement_noise, 0.0) self.assertEqual(ins._longitude_measurement_noise, 0.0) self.assertEqual(ins.longitude_measurement_noise, 0.0) self.assertEqual(ins._airspeed_measurement_noise, 0.0) self.assertEqual(ins.airspeed_measurement_noise, 0.0) self.assertEqual(ins._altitude_measurement_noise, 0.0) self.assertEqual(ins.altitude_measurement_noise, 0.0) run_until = fdmexec.GetSimTime() + (1.0 / ins.update_rate) + 1.0 while fdmexec.GetSimTime() < run_until: fdmexec.Run() self.assertNotEqual(ins.roll_measurement_noise, 0.0) self.assertEqual(ins._roll_measurement_noise, ins.roll_measurement_noise) self.assertNotEqual(ins.pitch_measurement_noise, 0.0) self.assertEqual(ins._pitch_measurement_noise, ins.pitch_measurement_noise) self.assertNotEqual(ins.heading_measurement_noise, 0.0) self.assertEqual(ins._heading_measurement_noise, ins.heading_measurement_noise) self.assertNotEqual(ins.latitude_measurement_noise, 0.0) self.assertEqual(ins._latitude_measurement_noise, ins.latitude_measurement_noise) self.assertNotEqual(ins.longitude_measurement_noise, 0.0) self.assertEqual(ins._longitude_measurement_noise, ins.longitude_measurement_noise) self.assertNotEqual(ins.altitude_measurement_noise, 0.0) self.assertEqual(ins._altitude_measurement_noise, ins.altitude_measurement_noise) self.assertNotEqual(ins.airspeed_measurement_noise, 0.0) self.assertEqual(ins._airspeed_measurement_noise, ins.airspeed_measurement_noise)
def test_engine(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdm_builder.aircraft = "Rascal" fdmexec = fdm_builder.create_fdm() engine = Engine(fdmexec) self.assertAlmostEqual(engine.thrust, convert_jsbsim_force(fdmexec.GetPropulsion().GetEngine(0).GetThruster().GetThrust())) self.assertAlmostEqual(engine.throttle, fdmexec.GetFCS().GetThrottleCmd(0))
def test_get_heading_indicator_data(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdmexec = fdm_builder.create_fdm() heading_indicator = HeadingIndicator(fdmexec) orientation = Orientation(fdmexec) self.assertAlmostEqual(heading_indicator.heading, orientation.psi, 3)
def test_set_throttle(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) fdmexec.GetFCS().SetThrottleCmd(0, 0.198) self.assertAlmostEqual(aircraft.controls.throttle, 0.198)
def test_step(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdm_builder.aircraft = "Rascal" fdmexec = fdm_builder.create_fdm() simulator = Simulator(fdmexec) result = simulator.step() self.assertTrue(result)
def test_presure_sensor(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdm_builder.aircraft = "Rascal" fdmexec = fdm_builder.create_fdm() sensors = Sensors(fdmexec) self.assertAlmostEqual( sensors.pressure_sensor.true_pressure, convert_jsbsim_pressure(fdmexec.GetAtmosphere().GetPressure()))
def test_set_rudder(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) fdmexec.GetFCS().SetDrCmd(0.178) self.assertAlmostEqual(aircraft.controls.rudder, 0.178, 0.0)
def test_pitot_tube(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdm_builder.aircraft = "Rascal" fdmexec = fdm_builder.create_fdm() sensors = Sensors(fdmexec) self.assertAlmostEqual( sensors.pitot_tube.true_pressure, convert_jsbsim_pressure(fdmexec.GetAuxiliary().GetTotalPressure()))
def test_get_attitude_indicator_data(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdmexec = fdm_builder.create_fdm() attitude_indicator = AttitudeIndicator(fdmexec) orientation = Orientation(fdmexec) self.assertAlmostEqual(attitude_indicator.roll, orientation.phi, 3) self.assertAlmostEqual(attitude_indicator.pitch, orientation.theta, 3)
def test_get_airspeed(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdmexec = fdm_builder.create_fdm() airspeed_indicator = AirspeedIndicator(fdmexec) airspeed_indicator_resource = AirspeedIndicatorResource(airspeed_indicator) response = airspeed_indicator_resource.get() self.assertAlmostEqual(response["airspeed"], airspeed_indicator.airspeed, 3)
def test_get_engine_data(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdmexec = fdm_builder.create_fdm() aircraft = Aircraft(fdmexec) resource = EngineResource(aircraft.engine) engine_data = resource.get() self.assertAlmostEqual(aircraft.engine.thrust, engine_data["thrust"], 3)
def test_get_heading_indicator_data(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdmexec = fdm_builder.create_fdm() heading_indicator = HeadingIndicator(fdmexec) heading_indicator_resource = HeadingIndicatorResource(heading_indicator) response = heading_indicator_resource.get() self.assertAlmostEqual(response["heading"], heading_indicator.heading, 3)
def test_get_aircraft_information(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdmexec = fdm_builder.create_fdm() aircraft = Aircraft(fdmexec) resource = AircraftResource(aircraft) aircraft_data = resource.get() self.assertDictEqual(aircraft_data, {"type": "Rascal"})
def test_get_climb_rate(self): huginn_data_path = configuration.get_data_path() fdm_builder = FDMBuilder(huginn_data_path) fdmexec = fdm_builder.create_fdm() vertical_speed_indicator = VerticalSpeedIndicator(fdmexec) vertical_speed_indicator_resource = VerticalSpeedIndicatorResource(vertical_speed_indicator) response = vertical_speed_indicator_resource.get() self.assertAlmostEqual(response["climb_rate"], vertical_speed_indicator.climb_rate, 3)
def create_simulator(self): """Create the Simulator object""" fdm_builder = FDMBuilder(self.data_path) fdm_builder.dt = self.dt fdm_builder.latitude = self.latitude fdm_builder.longitude = self.longitude fdm_builder.altitude = self.altitude fdm_builder.airspeed = self.airspeed fdm_builder.heading = self.heading fdmexec = fdm_builder.create_fdm() aircraft = Aircraft(fdmexec) aircraft.start_engines() logger.debug("trimming the aircraft at mode %d", self.trim_mode) trim_result = aircraft.trim(self.trim_mode) if not trim_result: logger.warning("Failed to trim the aircraft") # reset the aircraft control because the trim operation might # have messed them up aircraft.controls.aileron = 0.0 aircraft.controls.elevator = 0.0 aircraft.controls.rudder = 0.0 aircraft.controls.throttle = 0.0 simulator = Simulator(fdmexec) simulator.trim_mode = self.trim_mode simulator.start_paused = self.start_paused result = simulator.step() if not result: logger.error("Failed to execute simulator run") return None if self.start_paused: simulator.pause() return simulator