Beispiel #1
0
 def test_steer_with_fcs(self):
     fdm = CreateFDM(self.sandbox)
     fdm.load_model('L410')
     aircraft_path = self.sandbox.path_to_jsbsim_file('aircraft')
     fdm.load_ic(os.path.join(aircraft_path, 'L410', 'reset00'), False)
     fdm.run_ic()
     self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 0.0)
     self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], 0.0)
     fdm['fcs/steer-cmd-norm'] = 1.0
     self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 1.0)
     fdm.run()
     self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 1.0)
     self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], 5.0)
     fdm['/controls/switches/full-steering-sw'] = 1.0
     fdm.run()
     self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 1.0)
     self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], 0.0)
     fdm['/controls/switches/full-steering-sw'] = 2.0
     fdm.run()
     self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 1.0)
     self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], 45.0)
     fdm['fcs/steer-cmd-norm'] = -0.5
     fdm.run()
     self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], -0.5)
     self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], -22.5)
Beispiel #2
0
    def test_waypoint(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_model('c310')
        aircraft_path = self.sandbox.path_to_jsbsim_file('aircraft')
        fdm.load_ic(os.path.join(aircraft_path, 'c310', 'reset00'), False)

        slr = 20925646.32546  # Sea Level Radius
        TestCases = ((0.25*math.pi, 0.5*math.pi, 0.0, 0.0),
                     (0.0, 0.5*math.pi, math.pi, slr*0.25*math.pi),
                     # North pole
                     (0.5*math.pi, 0.5*math.pi, 0.0, slr*0.25*math.pi),
                     # South pole
                     (-0.5*math.pi, 0.5*math.pi, math.pi, slr*0.75*math.pi),
                     (0.0, 0.0, 1.5*math.pi, slr*0.5*math.pi),
                     (0.0, math.pi, 0.5*math.pi, slr*0.5*math.pi))

        fdm['ic/lat-gc-rad'] = TestCases[0][0]
        fdm['ic/long-gc-rad'] = TestCases[0][1]

        for case in TestCases:
            fdm['guidance/target_wp_latitude_rad'] = case[0]
            fdm['guidance/target_wp_longitude_rad'] = case[1]
            fdm.run_ic()
            self.assertAlmostEqual(fdm['guidance/wp-heading-rad'], case[2])
            self.assertAlmostEqual(fdm['guidance/wp-distance'], case[3])
Beispiel #3
0
 def test_steer_with_fcs(self):
     fdm = CreateFDM(self.sandbox)
     fdm.load_model('L410')
     aircraft_path = self.sandbox.path_to_jsbsim_file('aircraft')
     fdm.load_ic(os.path.join(aircraft_path, 'L410', 'reset00'), False)
     fdm.run_ic()
     self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 0.0)
     self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], 0.0)
     fdm['fcs/steer-cmd-norm'] = 1.0
     self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 1.0)
     fdm.run()
     self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 1.0)
     self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], 5.0)
     fdm['/controls/switches/full-steering-sw'] = 1.0
     fdm.run()
     self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 1.0)
     self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], 0.0)
     fdm['/controls/switches/full-steering-sw'] = 2.0
     fdm.run()
     self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 1.0)
     self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], 45.0)
     fdm['fcs/steer-cmd-norm'] = -0.5
     fdm.run()
     self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], -0.5)
     self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], -22.5)
Beispiel #4
0
    def test_direct_steer(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_model('c172r')
        aircraft_path = self.sandbox.path_to_jsbsim_file('aircraft')
        fdm.load_ic(os.path.join(aircraft_path, 'c172r', 'reset00'), False)
        fdm.run_ic()
        self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 0.0)
        self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], 0.0)

        # Should be part of a unit test in C++ ?
        fpectl.turnon_sigfpe()

        grndreact = fdm.get_ground_reactions()
        for i in xrange(grndreact.get_num_gear_units()):
            gear = grndreact.get_gear_unit(i)
            self.assertEqual(gear.get_steer_norm(), 0.0)

        fpectl.turnoff_sigfpe()

        fdm['fcs/steer-pos-deg'] = 5.0
        self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], 5.0)
        fdm.run()
        self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 0.0)
        fdm['fcs/steer-cmd-norm'] = 1.0
        self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 1.0)
        fdm.run()
        self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 1.0)
        self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], 10.0)
Beispiel #5
0
    def test_trim_doesnt_ignite_rockets(self):
        # Run a longitudinal trim with a rocket equipped with solid propellant
        # boosters (aka SRBs). The trim algorithm will try to reach a vertical
        # equilibrium by tweaking the throttle but since the rocket is nose up,
        # the trim cannot converge. As a result the algorithm will set full
        # throttle which will result in the SRBs ignition if the integration is
        # not suspended. This bug has been reported in FlightGear and this test
        # is checking that there is no regression.

        fdm = CreateFDM(self.sandbox)
        fdm.load_model('J246')
        fdm.load_ic(
            self.sandbox.path_to_jsbsim_file('aircraft', 'J246', 'LC39'),
            False)
        fdm.run_ic()

        # Check that the SRBs are not ignited
        self.assertEqual(fdm['propulsion/engine[0]/thrust-lbs'], 0.0)
        self.assertEqual(fdm['propulsion/engine[1]/thrust-lbs'], 0.0)

        try:
            fdm['simulation/do_simple_trim'] = 1
        except RuntimeError as e:
            # The trim cannot succeed. Just make sure that the raised exception
            # is due to the trim failure otherwise rethrow.
            if e.args[0] != 'Trim Failed':
                raise

        # Check that the trim did not ignite the SRBs
        self.assertEqual(fdm['propulsion/engine[0]/thrust-lbs'], 0.0)
        self.assertEqual(fdm['propulsion/engine[1]/thrust-lbs'], 0.0)
Beispiel #6
0
    def testKinematicTiming(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_model('c172r')
        fdm.load_ic(self.sandbox.path_to_jsbsim_file('aircraft', 'c172r',
                                                     'reset00'), False)
        fdm.run_ic()
        self.assertEqual(fdm['fcs/flap-cmd-norm'], 0.0)
        self.assertEqual(fdm['fcs/flap-pos-deg'], 0.0)

        # Test the flap down sequence. The flap command is set to a value
        # higher than 1.0 to check that JSBSim clamps it to 1.0
        fdm['fcs/flap-cmd-norm'] = 1.5
        t = fdm['simulation/sim-time-sec']

        while t < 2.0:
            self.assertAlmostEqual(fdm['fcs/flap-pos-deg'], 5.*t)
            fdm.run()
            t = fdm['simulation/sim-time-sec']

        while t < 4.0:
            self.assertAlmostEqual(fdm['fcs/flap-pos-deg'], 10.*(t-1.))
            fdm.run()
            t = fdm['simulation/sim-time-sec']

        while t < 5.0:
            self.assertAlmostEqual(fdm['fcs/flap-pos-deg'], 30.)
            fdm.run()
            t = fdm['simulation/sim-time-sec']

        # Test the flap up sequence with an interruption at 7.5 deg
        fdm['fcs/flap-cmd-norm'] = 0.25

        while t < 7.0:
            self.assertAlmostEqual(fdm['fcs/flap-pos-deg'], 30.-10.*(t-5.))
            fdm.run()
            t = fdm['simulation/sim-time-sec']

        while t < 7.5:
            self.assertAlmostEqual(fdm['fcs/flap-pos-deg'], 10.-5.*(t-7.))
            fdm.run()
            t = fdm['simulation/sim-time-sec']

        while t < 8.0:
            self.assertAlmostEqual(fdm['fcs/flap-pos-deg'], 7.5)
            fdm.run()
            t = fdm['simulation/sim-time-sec']

        # Complete the flap up sequence. The flap command is set to a value
        # lower than 0.0 to check that JSBSim clamps it to 0.0
        fdm['fcs/flap-cmd-norm'] = -1.

        while t < 9.5:
            self.assertAlmostEqual(fdm['fcs/flap-pos-deg'], 10.-5.*(t-7.5))
            fdm.run()
            t = fdm['simulation/sim-time-sec']

        while t < 10.0:
            self.assertAlmostEqual(fdm['fcs/flap-pos-deg'], 0.0)
            fdm.run()
            t = fdm['simulation/sim-time-sec']
Beispiel #7
0
    def test_trim_doesnt_ignite_rockets(self):
        # Run a longitudinal trim with a rocket equipped with solid propellant
        # boosters (aka SRBs). The trim algorithm will try to reach a vertical
        # equilibrium by tweaking the throttle but since the rocket is nose up,
        # the trim cannot converge. As a result the algorithm will set full
        # throttle which will result in the SRBs ignition if the integration is
        # not suspended. This bug has been reported in FlightGear and this test
        # is checking that there is no regression.

        fdm = CreateFDM(self.sandbox)
        fdm.load_model('J246')
        fdm.load_ic(self.sandbox.path_to_jsbsim_file('aircraft', 'J246',
                                                     'LC39'), False)
        fdm.run_ic()

        # Check that the SRBs are not ignited
        self.assertEqual(fdm['propulsion/engine[0]/thrust-lbs'], 0.0)
        self.assertEqual(fdm['propulsion/engine[1]/thrust-lbs'], 0.0)

        try:
            fdm['simulation/do_simple_trim'] = 1
        except RuntimeError as e:
            # The trim cannot succeed. Just make sure that the raised exception
            # is due to the trim failure otherwise rethrow.
            if e.args[0] != 'Trim Failed':
                raise

        # Check that the trim did not ignite the SRBs
        self.assertEqual(fdm['propulsion/engine[0]/thrust-lbs'], 0.0)
        self.assertEqual(fdm['propulsion/engine[1]/thrust-lbs'], 0.0)
Beispiel #8
0
    def test_direct_steer(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_model('c172r')
        aircraft_path = self.sandbox.path_to_jsbsim_file('aircraft')
        fdm.load_ic(os.path.join(aircraft_path, 'c172r', 'reset00'), False)
        fdm.run_ic()
        self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 0.0)
        self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], 0.0)

        # Should be part of a unit test in C++ ?
        fpectl.turnon_sigfpe()

        grndreact = fdm.get_ground_reactions()
        for i in xrange(grndreact.get_num_gear_units()):
            gear = grndreact.get_gear_unit(i)
            self.assertEqual(gear.get_steer_norm(), 0.0)

        fpectl.turnoff_sigfpe()

        fdm['fcs/steer-pos-deg'] = 5.0
        self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], 5.0)
        fdm.run()
        self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 0.0)
        fdm['fcs/steer-cmd-norm'] = 1.0
        self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 1.0)
        fdm.run()
        self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 1.0)
        self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], 10.0)
Beispiel #9
0
    def test_waypoint(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_model('c310')
        aircraft_path = self.sandbox.path_to_jsbsim_file('aircraft')
        fdm.load_ic(os.path.join(aircraft_path, 'c310', 'reset00'), False)

        slr = 20925646.32546  # Sea Level Radius
        TestCases = (
            (0.25 * math.pi, 0.5 * math.pi, 0.0, 0.0),
            (0.0, 0.5 * math.pi, math.pi, slr * 0.25 * math.pi),
            # North pole
            (0.5 * math.pi, 0.5 * math.pi, 0.0, slr * 0.25 * math.pi),
            # South pole
            (-0.5 * math.pi, 0.5 * math.pi, math.pi, slr * 0.75 * math.pi),
            (0.0, 0.0, 1.5 * math.pi, slr * 0.5 * math.pi),
            (0.0, math.pi, 0.5 * math.pi, slr * 0.5 * math.pi))

        fdm['ic/lat-gc-rad'] = TestCases[0][0]
        fdm['ic/long-gc-rad'] = TestCases[0][1]

        for case in TestCases:
            fdm['guidance/target_wp_latitude_rad'] = case[0]
            fdm['guidance/target_wp_longitude_rad'] = case[1]
            fdm.run_ic()
            self.assertAlmostEqual(fdm['guidance/wp-heading-rad'], case[2])
            self.assertAlmostEqual(fdm['guidance/wp-distance'], case[3])
Beispiel #10
0
    def test_asl_override_vs_geod_lat(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_model('c310')
        fdm.load_ic(self.sandbox.path_to_jsbsim_file('aircraft', 'c310',
                                                     'ellington.xml'), False)

        geod_lat = fdm['ic/lat-geod-deg']
        fdm['ic/h-sl-ft'] = 35000.
        self.assertAlmostEqual(fdm['ic/lat-geod-deg'], geod_lat)
Beispiel #11
0
    def test_asl_override_vs_geod_lat(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_model('c310')
        fdm.load_ic(
            self.sandbox.path_to_jsbsim_file('aircraft', 'c310',
                                             'ellington.xml'), False)

        geod_lat = fdm['ic/lat-geod-deg']
        fdm['ic/h-sl-ft'] = 35000.
        self.assertAlmostEqual(fdm['ic/lat-geod-deg'], geod_lat)
Beispiel #12
0
    def testSpinningBodyOnOrbit(self):
        script_name = 'ball_orbit.xml'
        script_path = self.sandbox.path_to_jsbsim_file('scripts', script_name)
        self.AddAccelerometersToAircraft(script_path)

        fdm = CreateFDM(self.sandbox)
        fdm.set_aircraft_path('aircraft')
        fdm.load_model('ball')
        # Offset the CG along Y (by 30")
        fdm.set_property_value('inertia/pointmass-weight-lbs[1]', 50.0)

        aircraft_path = self.sandbox.elude(
            self.sandbox.path_to_jsbsim_file('aircraft', 'ball'))
        fdm.load_ic(os.path.join(aircraft_path, 'reset00.xml'), False)
        # Switch the accel on
        fdm.set_property_value('fcs/accelerometer/on', 1.0)
        # Set the orientation such that the spinning axis is Z.
        fdm.set_property_value('ic/phi-rad', 0.5 * math.pi)

        # Set the angular velocities to 0.0 in the ECEF frame. The angular
        # velocity R_{inertial} will therefore be equal to the Earth rotation
        # rate 7.292115E-5 rad/sec
        fdm.set_property_value('ic/p-rad_sec', 0.0)
        fdm.set_property_value('ic/q-rad_sec', 0.0)
        fdm.set_property_value('ic/r-rad_sec', 0.0)
        fdm.run_ic()

        fax = fdm.get_property_value('fcs/accelerometer/X')
        fay = fdm.get_property_value('fcs/accelerometer/Y')
        faz = fdm.get_property_value('fcs/accelerometer/Z')
        cgy_ft = fdm.get_property_value('inertia/cg-y-in') / 12.
        omega = 0.00007292115  # Earth rotation rate in rad/sec

        self.assertAlmostEqual(
            fdm.get_property_value('accelerations/a-pilot-x-ft_sec2'),
            fax,
            delta=1E-8)
        self.assertAlmostEqual(
            fdm.get_property_value('accelerations/a-pilot-y-ft_sec2'),
            fay,
            delta=1E-8)
        self.assertAlmostEqual(
            fdm.get_property_value('accelerations/a-pilot-z-ft_sec2'),
            faz,
            delta=1E-8)

        # Acceleration along X should be zero
        self.assertAlmostEqual(fax, 0.0, delta=1E-8)
        # Acceleration along Y should be equal to r*omega^2
        self.assertAlmostEqual(fay / (cgy_ft * omega * omega), 1.0, delta=1E-7)
        # Acceleration along Z should be zero
        self.assertAlmostEqual(faz, 0.0, delta=1E-8)
Beispiel #13
0
    def testKinematicSetInitialValue(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_model('p51d')
        fdm.load_ic('reset01', True)
        fdm.run_ic()

        fdm['gear/gear-cmd-norm'] = 0.5
        fdm['gear/gear-pos-norm'] = 0.5

        while fdm['simulation/sim-time-sec'] < 1.0:
            fdm.run()
            self.assertAlmostEqual(fdm['gear/gear-cmd-norm'], 0.5)
            self.assertAlmostEqual(fdm['gear/gear-pos-norm'], 0.5)
Beispiel #14
0
    def test_initial_latitude(self):
        Output_file = self.sandbox.path_to_jsbsim_file('tests', 'output.xml')
        GEODETIC, ELEVATION, ALTITUDE = (1, 2, 4)

        for v in ('', '_v2'):
            IC_file = self.sandbox.path_to_jsbsim_file('aircraft', 'ball',
                                                       'reset00' + v + '.xml')

            for i in xrange(8):
                for latitude_pos in xrange(4):
                    IC_tree = et.parse(IC_file)
                    IC_root = IC_tree.getroot()
                    if v:
                        position_tag = IC_root.find('position')
                        latitude_tag = et.SubElement(position_tag, 'latitude')
                        latitude_tag.attrib['unit'] = 'DEG'
                    else:
                        position_tag = IC_root
                        latitude_tag = IC_root.find('latitude')

                    latitude_tag.text = str(latitude_pos * 30.)

                    if i & GEODETIC:
                        latitude_tag.attrib['type'] = 'geod'

                    if i & ELEVATION:
                        elevation_tag = et.SubElement(IC_root, 'elevation')
                        elevation_tag.text = '1000.'

                    if i & ALTITUDE:
                        if v:
                            altitude_tag = position_tag.find('altitudeMSL')
                            altitude_tag.tag = 'altitudeAGL'
                        else:
                            altitude_tag = position_tag.find('altitude')
                            altitude_tag.tag = 'altitudeMSL'

                    IC_tree.write('IC.xml')

                    fdm = CreateFDM(self.sandbox)
                    fdm.load_model('ball')
                    fdm.set_output_directive(Output_file)
                    fdm.set_output_filename(1, 'check_csv_values.csv')
                    fdm.load_ic('IC.xml', False)
                    fdm.run_ic()

                    self.CheckICValues(self.GetVariables(latitude_tag),
                                       'IC%d' % (i, ), fdm, position_tag)

                    del fdm
Beispiel #15
0
    def test_static_hold_down(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_model('J246')
        aircraft_path = self.sandbox.path_to_jsbsim_file('aircraft')
        fdm.load_ic(os.path.join(aircraft_path, 'J246', 'LC39'), False)
        fdm['forces/hold-down'] = 1.0
        fdm.run_ic()
        h0 = fdm['position/h-sl-ft']
        t = 0.0

        while t < 420.0:
            fdm.run()
            t = fdm['simulation/sim-time-sec']
            self.assertAlmostEqual(fdm['position/h-sl-ft'], h0, delta=1E-5)
Beispiel #16
0
    def test_static_hold_down(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_model('J246')
        aircraft_path = self.sandbox.path_to_jsbsim_file('aircraft')
        fdm.load_ic(os.path.join(aircraft_path, 'J246', 'LC39'), False)
        fdm['forces/hold-down'] = 1.0
        fdm.run_ic()
        h0 = fdm['position/h-sl-ft']
        t = 0.0

        while t < 420.0:
            fdm.run()
            t = fdm['simulation/sim-time-sec']
            self.assertAlmostEqual(fdm['position/h-sl-ft'], h0, delta=1E-5)
Beispiel #17
0
    def testKinematicSetInitialValue(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_model('p51d')
        fdm.load_ic(self.sandbox.path_to_jsbsim_file('aircraft', 'p51d',
                                                     'reset01'), False)
        fdm.run_ic()

        fdm['gear/gear-cmd-norm'] = 0.5
        fdm['gear/gear-pos-norm'] = 0.5

        while fdm['simulation/sim-time-sec'] < 1.0:
            fdm.run()
            self.assertAlmostEqual(fdm['gear/gear-cmd-norm'], 0.5)
            self.assertAlmostEqual(fdm['gear/gear-pos-norm'], 0.5)
    def test_initial_latitude(self):
        Output_file = self.sandbox.path_to_jsbsim_file('tests', 'output.xml')
        GEODETIC, ELEVATION, ALTITUDE = (1, 2, 4)

        for v in ('', '_v2'):
            IC_file = self.sandbox.path_to_jsbsim_file('aircraft', 'ball',
                                                       'reset00'+v+'.xml')

            for i in xrange(8):
                for latitude_pos in xrange(4):
                    IC_tree = et.parse(IC_file)
                    IC_root = IC_tree.getroot()
                    if v:
                        position_tag = IC_root.find('position')
                        latitude_tag = et.SubElement(position_tag, 'latitude')
                        latitude_tag.attrib['unit'] = 'DEG'
                    else:
                        position_tag = IC_root
                        latitude_tag = IC_root.find('latitude')

                    latitude_tag.text = str(latitude_pos*30.)

                    if i & GEODETIC:
                        latitude_tag.attrib['type'] = 'geod'

                    if i & ELEVATION:
                        elevation_tag = et.SubElement(IC_root, 'elevation')
                        elevation_tag.text = '1000.'

                    if i & ALTITUDE:
                        if v:
                            altitude_tag = position_tag.find('altitudeMSL')
                            altitude_tag.tag = 'altitudeAGL'
                        else:
                            altitude_tag = position_tag.find('altitude')
                            altitude_tag.tag = 'altitudeMSL'

                    IC_tree.write('IC.xml')

                    fdm = CreateFDM(self.sandbox)
                    fdm.load_model('ball')
                    fdm.set_output_directive(Output_file)
                    fdm.set_output_filename(1, 'check_csv_values.csv')
                    fdm.load_ic('IC.xml', False)
                    fdm.run_ic()

                    self.CheckICValues(self.GetVariables(latitude_tag),
                                       'IC%d' % (i,), fdm, position_tag)

                    del fdm
Beispiel #19
0
    def test_static_hold_down(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_model('J246')
        fdm.load_ic('LC39', True)
        fdm['forces/hold-down'] = 1.0
        fdm.run_ic()
        h0 = fdm['position/vrp-radius-ft']
        t = 0.0

        while t < 420.0:
            fdm.run()
            t = fdm['simulation/sim-time-sec']
            self.assertAlmostEqual(fdm['position/vrp-radius-ft'] / h0,
                                   1.0,
                                   delta=1E-9)
Beispiel #20
0
    def testKinematicSetInitialValue(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_model('p51d')
        fdm.load_ic(
            self.sandbox.path_to_jsbsim_file('aircraft', 'p51d', 'reset01'),
            False)
        fdm.run_ic()

        fdm['gear/gear-cmd-norm'] = 0.5
        fdm['gear/gear-pos-norm'] = 0.5

        while fdm['simulation/sim-time-sec'] < 1.0:
            fdm.run()
            self.assertAlmostEqual(fdm['gear/gear-cmd-norm'], 0.5)
            self.assertAlmostEqual(fdm['gear/gear-pos-norm'], 0.5)
Beispiel #21
0
    def testAircrafts(self):
        aircraft_path = self.sandbox.path_to_jsbsim_file('aircraft')
        for d in os.listdir(aircraft_path):
            fullpath = os.path.join(aircraft_path, d)

            # Is d a directory ?
            if not os.path.isdir(fullpath):
                continue

            f = os.path.join(aircraft_path, d, d+'.xml')

            # Is f an aircraft definition file ?
            if not CheckXMLFile(f, 'fdm_config'):
                continue

            if d in ('blank'):
                continue

            fdm = CreateFDM(self.sandbox)
            self.assertTrue(fdm.load_model(d),
                            msg='Failed to load aircraft %s' % (d,))

            for f in os.listdir(fullpath):
                f = os.path.join(aircraft_path, d, f)
                if CheckXMLFile(f, 'initialize'):
                    self.assertTrue(fdm.load_ic(f, False),
                                    msg='Failed to load IC %s for aircraft %s' % (f, d))
                    try:
                        fdm.run_ic()
                    except RuntimeError:
                        self.fail('Failed to run IC %s for aircraft %s' % (f, d))

            del fdm
Beispiel #22
0
    def testAircrafts(self):
        aircraft_path = self.sandbox.path_to_jsbsim_file('aircraft')
        for d in os.listdir(aircraft_path):
            fullpath = os.path.join(aircraft_path, d)

            # Is d a directory ?
            if not os.path.isdir(fullpath):
                continue

            f = os.path.join(aircraft_path, d, d + '.xml')

            # Is f an aircraft definition file ?
            if not CheckXMLFile(f, 'fdm_config'):
                continue

            if d in ('blank'):
                continue

            fdm = CreateFDM(self.sandbox)
            self.assertTrue(fdm.load_model(d),
                            msg='Failed to load aircraft %s' % (d, ))

            for f in os.listdir(fullpath):
                f = os.path.join(aircraft_path, d, f)
                if CheckXMLFile(f, 'initialize'):
                    self.assertTrue(
                        fdm.load_ic(f, False),
                        msg='Failed to load IC %s for aircraft %s' % (f, d))
                    try:
                        fdm.run_ic()
                    except RuntimeError:
                        self.fail('Failed to run IC %s for aircraft %s' %
                                  (f, d))

            del fdm
Beispiel #23
0
    def testSpinningBodyOnOrbit(self):
        script_name = 'ball_orbit.xml'
        script_path = self.sandbox.path_to_jsbsim_file('scripts', script_name)
        self.AddAccelerometersToAircraft(script_path)

        fdm = CreateFDM(self.sandbox)
        fdm.set_aircraft_path('aircraft')
        fdm.load_model('ball')
        # Offset the CG along Y (by 30")
        fdm['inertia/pointmass-weight-lbs[1]'] = 50.0

        aircraft_path = self.sandbox.path_to_jsbsim_file('aircraft', 'ball')
        fdm.load_ic(os.path.join(aircraft_path, 'reset00.xml'), False)
        # Switch the accel on
        fdm['fcs/accelerometer/on'] = 1.0
        # Set the orientation such that the spinning axis is Z.
        fdm['ic/phi-rad'] = 0.5 * math.pi

        # Set the angular velocities so that angular velocity R_{inertial} will
        # be equal to 1.0 rad/sec.
        omega = 0.00007292115  # Earth rotation rate in rad/sec
        fdm['ic/p-rad_sec'] = 0.0
        fdm['ic/q-rad_sec'] = 0.0
        fdm['ic/r-rad_sec'] = 1.0 - omega
        fdm.run_ic()

        fax = fdm['fcs/accelerometer/X']
        fay = fdm['fcs/accelerometer/Y']
        faz = fdm['fcs/accelerometer/Z']
        cgy_ft = fdm['inertia/cg-y-in'] / 12.

        self.assertAlmostEqual(fdm['accelerations/a-pilot-x-ft_sec2'],
                               fax,
                               delta=1E-8)
        self.assertAlmostEqual(fdm['accelerations/a-pilot-y-ft_sec2'],
                               fay,
                               delta=1E-8)
        self.assertAlmostEqual(fdm['accelerations/a-pilot-z-ft_sec2'],
                               faz,
                               delta=1E-8)

        # Acceleration along X should be zero
        self.assertAlmostEqual(fax, 0.0, delta=1E-8)
        # Acceleration along Y should be equal to d*r_dot^2
        self.assertAlmostEqual(fay / cgy_ft, 1.0, delta=1E-7)
        # Acceleration along Z should be zero
        self.assertAlmostEqual(faz, 0.0, delta=1E-8)
Beispiel #24
0
 def test_direct_steer(self):
     fdm = CreateFDM(self.sandbox)
     fdm.load_model('c172r')
     aircraft_path = self.sandbox.path_to_jsbsim_file('aircraft')
     fdm.load_ic(os.path.join(aircraft_path, 'c172r', 'reset00'), False)
     fdm.run_ic()
     self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 0.0)
     self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], 0.0)
     fdm['fcs/steer-pos-deg'] = 5.0
     self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], 5.0)
     fdm.run()
     self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 0.0)
     fdm['fcs/steer-cmd-norm'] = 1.0
     self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 1.0)
     fdm.run()
     self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 1.0)
     self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], 10.0)
    def testSpinningBodyOnOrbit(self):
        script_name = 'ball_orbit.xml'
        script_path = self.sandbox.path_to_jsbsim_file('scripts', script_name)
        self.AddAccelerometersToAircraft(script_path)

        fdm = CreateFDM(self.sandbox)
        fdm.set_aircraft_path('aircraft')
        fdm.load_model('ball')
        # Offset the CG along Y (by 30")
        fdm.set_property_value('inertia/pointmass-weight-lbs[1]', 50.0)

        aircraft_path = self.sandbox.elude(self.sandbox.path_to_jsbsim_file('aircraft', 'ball'))
        fdm.load_ic(os.path.join(aircraft_path, 'reset00.xml'), False)
        # Switch the accel on
        fdm.set_property_value('fcs/accelerometer/on', 1.0)
        # Set the orientation such that the spinning axis is Z.
        fdm.set_property_value('ic/phi-rad', 0.5*math.pi)

        # Set the angular velocities to 0.0 in the ECEF frame. The angular
        # velocity R_{inertial} will therefore be equal to the Earth rotation
        # rate 7.292115E-5 rad/sec
        fdm.set_property_value('ic/p-rad_sec', 0.0)
        fdm.set_property_value('ic/q-rad_sec', 0.0)
        fdm.set_property_value('ic/r-rad_sec', 0.0)
        fdm.run_ic()

        fax = fdm.get_property_value('fcs/accelerometer/X')
        fay = fdm.get_property_value('fcs/accelerometer/Y')
        faz = fdm.get_property_value('fcs/accelerometer/Z')
        cgy_ft = fdm.get_property_value('inertia/cg-y-in') / 12.
        omega = 0.00007292115 # Earth rotation rate in rad/sec

        self.assertAlmostEqual(fdm.get_property_value('accelerations/a-pilot-x-ft_sec2'),
                               fax, delta=1E-8)
        self.assertAlmostEqual(fdm.get_property_value('accelerations/a-pilot-y-ft_sec2'),
                               fay, delta=1E-8)
        self.assertAlmostEqual(fdm.get_property_value('accelerations/a-pilot-z-ft_sec2'),
                               faz, delta=1E-8)

        # Acceleration along X should be zero
        self.assertAlmostEqual(fax, 0.0, delta=1E-8)
        # Acceleration along Y should be equal to r*omega^2
        self.assertAlmostEqual(fay / (cgy_ft * omega * omega), 1.0, delta=1E-7)
        # Acceleration along Z should be zero
        self.assertAlmostEqual(faz, 0.0, delta=1E-8)
Beispiel #26
0
    def test_dynamic_hold_down(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_model('J246')
        fdm.load_ic('LC39', True)
        fdm['forces/hold-down'] = 1.0
        fdm.run_ic()
        h0 = fdm['position/vrp-radius-ft']
        # Start solid rocket boosters
        fdm['fcs/throttle-cmd-norm[0]'] = 1.0
        fdm['fcs/throttle-cmd-norm[1]'] = 1.0
        t = 0.0

        while t < 420.0:
            fdm.run()
            t = fdm['simulation/sim-time-sec']
            self.assertAlmostEqual(fdm['position/vrp-radius-ft'] / h0,
                                   1.0,
                                   delta=1E-9)
Beispiel #27
0
    def testKinematicNoScale(self):
        # Test the <nocale/> feature
        script_path = self.sandbox.path_to_jsbsim_file('scripts', 'c1721.xml')
        tree, aircraft_name, b = CopyAircraftDef(script_path, self.sandbox)
        kinematic_tag = tree.getroot().find('flight_control/channel/kinematic')
        et.SubElement(kinematic_tag, 'noscale')
        tree.write(
            self.sandbox('aircraft', aircraft_name, aircraft_name + '.xml'))

        fdm = CreateFDM(self.sandbox)
        fdm.set_aircraft_path('aircraft')
        fdm.load_model(aircraft_name)

        fdm.load_ic('reset00', True)
        fdm.run_ic()
        fdm['fcs/flap-cmd-norm'] = 12.
        ExecuteUntil(fdm, 2.2)
        self.assertAlmostEqual(fdm['fcs/flap-pos-deg'], 12.)
Beispiel #28
0
    def testSpinningBodyOnOrbit(self):
        script_name = 'ball_orbit.xml'
        script_path = self.sandbox.path_to_jsbsim_file('scripts', script_name)
        self.AddAccelerometersToAircraft(script_path)

        fdm = CreateFDM(self.sandbox)
        fdm.set_aircraft_path('aircraft')
        fdm.load_model('ball')
        # Offset the CG along Y (by 30")
        fdm['inertia/pointmass-weight-lbs[1]'] = 50.0

        aircraft_path = self.sandbox.path_to_jsbsim_file('aircraft', 'ball')
        fdm.load_ic(os.path.join(aircraft_path, 'reset00.xml'), False)
        # Switch the accel on
        fdm['fcs/accelerometer/on'] = 1.0
        # Set the orientation such that the spinning axis is Z.
        fdm['ic/phi-rad'] = 0.5*math.pi

        # Set the angular velocities so that angular velocity R_{inertial} will
        # be equal to 1.0 rad/sec.
        omega = 0.00007292115  # Earth rotation rate in rad/sec
        fdm['ic/p-rad_sec'] = 0.0
        fdm['ic/q-rad_sec'] = 0.0
        fdm['ic/r-rad_sec'] = 1.0 - omega
        fdm.run_ic()

        fax = fdm['fcs/accelerometer/X']
        fay = fdm['fcs/accelerometer/Y']
        faz = fdm['fcs/accelerometer/Z']
        cgy_ft = fdm['inertia/cg-y-in'] / 12.

        self.assertAlmostEqual(fdm['accelerations/a-pilot-x-ft_sec2'], fax,
                               delta=1E-8)
        self.assertAlmostEqual(fdm['accelerations/a-pilot-y-ft_sec2'], fay,
                               delta=1E-8)
        self.assertAlmostEqual(fdm['accelerations/a-pilot-z-ft_sec2'], faz,
                               delta=1E-8)

        # Acceleration along X should be zero
        self.assertAlmostEqual(fax, 0.0, delta=1E-8)
        # Acceleration along Y should be equal to d*r_dot^2
        self.assertAlmostEqual(fay / cgy_ft, 1.0, delta=1E-7)
        # Acceleration along Z should be zero
        self.assertAlmostEqual(faz, 0.0, delta=1E-8)
Beispiel #29
0
    def testKinematicNoScale(self):
        # Test the <nocale/> feature
        script_path = self.sandbox.path_to_jsbsim_file('scripts', 'c1721.xml')
        tree, aircraft_name, b = CopyAircraftDef(script_path, self.sandbox)
        kinematic_tag = tree.getroot().find('flight_control/channel/kinematic')
        et.SubElement(kinematic_tag, 'noscale')
        tree.write(self.sandbox('aircraft', aircraft_name,
                                aircraft_name+'.xml'))

        fdm = CreateFDM(self.sandbox)
        fdm.set_aircraft_path('aircraft')
        fdm.load_model(aircraft_name)

        fdm.load_ic(self.sandbox.path_to_jsbsim_file('aircraft', aircraft_name,
                                                     'reset00'), False)
        fdm.run_ic()
        fdm['fcs/flap-cmd-norm'] = 12.
        ExecuteUntil(fdm, 2.2)
        self.assertAlmostEqual(fdm['fcs/flap-pos-deg'], 12.)
Beispiel #30
0
    def test_dynamic_hold_down(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_model('J246')
        aircraft_path = self.sandbox.path_to_jsbsim_file('aircraft')
        fdm.load_ic(os.path.join(aircraft_path, 'J246', 'LC39'), False)
        fdm['forces/hold-down'] = 1.0
        fdm.run_ic()
        h0 = fdm['position/vrp-radius-ft']
        # Start solid rocket boosters
        fdm['fcs/throttle-cmd-norm[0]'] = 1.0
        fdm['fcs/throttle-cmd-norm[1]'] = 1.0
        t = 0.0

        while t < 420.0:
            fdm.run()
            t = fdm['simulation/sim-time-sec']
            self.assertAlmostEqual(fdm['position/vrp-radius-ft'] / h0,
                                   1.0,
                                   delta=1E-9)
Beispiel #31
0
    def test_no_script(self):
        fdm = CreateFDM(self.sandbox)
        aircraft_path = self.sandbox.path_to_jsbsim_file('aircraft')
        fdm.load_model('c172x')

        aircraft_path = os.path.join(aircraft_path, 'c172x')
        fdm.load_ic(os.path.join(aircraft_path, 'reset01.xml'), False)
        fdm.run_ic()

        self.assertEqual(fdm['simulation/sim-time-sec'], 0.0)
        ExecuteUntil(fdm, 5.0)

        t = fdm['simulation/sim-time-sec']
        fdm['simulation/do_simple_trim'] = 1
        self.assertEqual(fdm['simulation/sim-time-sec'], t)

        fdm.reset_to_initial_conditions(1)
        self.assertEqual(fdm['simulation/sim-time-sec'], 0.0)

        del fdm
    def test_no_script(self):
        fdm = CreateFDM(self.sandbox)
        aircraft_path = self.sandbox.path_to_jsbsim_file('aircraft')
        fdm.load_model('c172x')

        aircraft_path = os.path.join(aircraft_path, 'c172x')
        fdm.load_ic(os.path.join(aircraft_path, 'reset01.xml'), False)
        fdm.run_ic()

        self.assertEqual(fdm['simulation/sim-time-sec'], 0.0)
        ExecuteUntil(fdm, 5.0)

        t = fdm['simulation/sim-time-sec']
        fdm['simulation/do_simple_trim'] = 1
        self.assertEqual(fdm['simulation/sim-time-sec'], t)

        fdm.reset_to_initial_conditions(1)
        self.assertEqual(fdm['simulation/sim-time-sec'], 0.0)

        del fdm
Beispiel #33
0
    def testKinematicAndTrim(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_model('p51d')
        fdm.load_ic('reset01', True)
        self.assertEqual(fdm['gear/gear-cmd-norm'], 1.0)
        # Set the landing gears up. Since the command is equal to 1.0, the
        # <kinematic> system will trigger the gear down sequence.
        fdm['gear/gear-pos-norm'] = 0.0
        fdm.run_ic()

        # The test succeeds if the trim does not raise an exception i.e. if the
        # <kinematic> system does not interfer with the trim on ground
        # algorithm.
        fdm['simulation/do_simple_trim'] = 2  # Ground trim

        # Check that the gear is down after the trim as requested by
        # gear/gear-cmd-norm
        self.assertAlmostEqual(fdm['gear/gear-pos-norm'], 1.0)

        # Check that the gear is not moving to another position after trim.
        fdm.run()
        self.assertAlmostEqual(fdm['gear/gear-pos-norm'], 1.0)
Beispiel #34
0
    def testKinematicAndTrim(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_model('p51d')
        fdm.load_ic(self.sandbox.path_to_jsbsim_file('aircraft', 'p51d',
                                                     'reset01'), False)
        self.assertEqual(fdm['gear/gear-cmd-norm'], 1.0)
        # Set the landing gears up. Since the command is equal to 1.0, the
        # <kinematic> system will trigger the gear down sequence.
        fdm['gear/gear-pos-norm'] = 0.0
        fdm.run_ic()

        # The test succeeds if the trim does not raise an exception i.e. if the
        # <kinematic> system does not interfer with the trim on ground
        # algorithm.
        fdm['simulation/do_simple_trim'] = 2  # Ground trim

        # Check that the gear is down after the trim as requested by
        # gear/gear-cmd-norm
        self.assertAlmostEqual(fdm['gear/gear-pos-norm'], 1.0)

        # Check that the gear is not moving to another position after trim.
        fdm.run()
        self.assertAlmostEqual(fdm['gear/gear-pos-norm'], 1.0)
    def test_body_frame(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_model('f16')
        fdm.load_ic('reset00.xml', True)
        fdm.run_ic()

        self.assertAlmostEqual(
            fdm['external_reactions/pushback/location-x-in'], -2.98081)
        self.assertAlmostEqual(
            fdm['external_reactions/pushback/location-y-in'], 0.0)
        self.assertAlmostEqual(
            fdm['external_reactions/pushback/location-z-in'], -1.9683)
        self.assertAlmostEqual(fdm['external_reactions/pushback/x'], 1.0)
        self.assertAlmostEqual(fdm['external_reactions/pushback/y'], 0.0)
        self.assertAlmostEqual(fdm['external_reactions/pushback/z'], 0.0)
        self.assertAlmostEqual(fdm['external_reactions/pushback/magnitude'],
                               0.0)

        self.assertAlmostEqual(fdm['external_reactions/hook/location-x-in'],
                               100.669)
        self.assertAlmostEqual(fdm['external_reactions/hook/location-y-in'],
                               0.0)
        self.assertAlmostEqual(fdm['external_reactions/hook/location-z-in'],
                               -28.818)
        dx = -0.9995
        dz = 0.01
        fhook = np.array([dx, 0.0, dz])
        fhook /= np.linalg.norm(fhook)

        self.assertAlmostEqual(fdm['external_reactions/hook/x'], fhook[0])
        self.assertAlmostEqual(fdm['external_reactions/hook/y'], fhook[1])
        self.assertAlmostEqual(fdm['external_reactions/hook/z'], fhook[2])
        self.assertAlmostEqual(fdm['external_reactions/hook/magnitude'], 0.0)

        self.assertAlmostEqual(fdm['forces/fbx-external-lbs'], 0.0)
        self.assertAlmostEqual(fdm['forces/fby-external-lbs'], 0.0)
        self.assertAlmostEqual(fdm['forces/fbz-external-lbs'], 0.0)
        self.assertAlmostEqual(fdm['moments/l-external-lbsft'], 0.0)
        self.assertAlmostEqual(fdm['moments/m-external-lbsft'], 0.0)
        self.assertAlmostEqual(fdm['moments/n-external-lbsft'], 0.0)

        # Check the 'pushback' external force alone
        fdm['/sim/model/pushback/position-norm'] = 1.0
        fdm['/sim/model/pushback/target-speed-fps'] = 1.0
        fdm['/sim/model/pushback/kp'] = 0.05
        fdm.run()

        fpb = np.array([1.0, 0.0, 0.0]) * 0.05
        self.assertAlmostEqual(fdm['external_reactions/pushback/magnitude'],
                               0.05)
        self.assertAlmostEqual(fdm['forces/fbx-external-lbs'], fpb[0])
        self.assertAlmostEqual(fdm['forces/fby-external-lbs'], fpb[1])
        self.assertAlmostEqual(fdm['forces/fbz-external-lbs'], fpb[2])

        m = np.cross(self.getLeverArm(fdm, 'pushback'), fpb)
        self.assertAlmostEqual(fdm['moments/l-external-lbsft'], m[0])
        self.assertAlmostEqual(fdm['moments/m-external-lbsft'], m[1])
        self.assertAlmostEqual(fdm['moments/n-external-lbsft'], m[2])

        # Reset the 'pushback' external force to zero
        fdm['/sim/model/pushback/position-norm'] = 0.0
        fdm.run()
        self.assertAlmostEqual(fdm['external_reactions/pushback/magnitude'],
                               0.0)
        self.assertAlmostEqual(fdm['forces/fbx-external-lbs'], 0.0)
        self.assertAlmostEqual(fdm['forces/fby-external-lbs'], 0.0)
        self.assertAlmostEqual(fdm['forces/fbz-external-lbs'], 0.0)
        self.assertAlmostEqual(fdm['moments/l-external-lbsft'], 0.0)
        self.assertAlmostEqual(fdm['moments/m-external-lbsft'], 0.0)
        self.assertAlmostEqual(fdm['moments/n-external-lbsft'], 0.0)

        # Check the 'hook' external force alone
        fdm['external_reactions/hook/magnitude'] = 10.0
        fhook *= 10.0
        fdm.run()
        self.assertAlmostEqual(fdm['forces/fbx-external-lbs'], fhook[0])
        self.assertAlmostEqual(fdm['forces/fby-external-lbs'], fhook[1])
        self.assertAlmostEqual(fdm['forces/fbz-external-lbs'], fhook[2])

        m = np.cross(self.getLeverArm(fdm, 'hook'), fhook)
        self.assertAlmostEqual(fdm['moments/l-external-lbsft'], m[0])
        self.assertAlmostEqual(fdm['moments/m-external-lbsft'], m[1])
        self.assertAlmostEqual(fdm['moments/n-external-lbsft'], m[2])

        # Add the 'pushback' force to the hook force and check that the global
        # external forces is the sum of the push back force and the hook force.
        fdm['/sim/model/pushback/position-norm'] = 1.0
        fdm.run()
        fp = fdm['systems/pushback/force']
        fpb = np.array([1.0, 0.0, 0.0]) * fp
        f = fhook + fpb
        self.assertAlmostEqual(fdm['external_reactions/pushback/magnitude'],
                               fp)
        self.assertAlmostEqual(fdm['forces/fbx-external-lbs'], f[0])
        self.assertAlmostEqual(fdm['forces/fby-external-lbs'], f[1])
        self.assertAlmostEqual(fdm['forces/fbz-external-lbs'], f[2])

        # Modify the push back force direction and check that the global external
        # force is modified accordingly.
        fdm['external_reactions/pushback/x'] = 1.5
        fdm['external_reactions/pushback/y'] = 0.1
        fdm.run()
        fp = fdm['systems/pushback/force']
        fpb = np.array([1.5, 0.1, 0.0]) * fp
        f = fhook + fpb
        self.assertAlmostEqual(fdm['external_reactions/pushback/magnitude'],
                               fp)
        self.assertAlmostEqual(fdm['forces/fbx-external-lbs'], f[0])
        self.assertAlmostEqual(fdm['forces/fby-external-lbs'], f[1])
        self.assertAlmostEqual(fdm['forces/fbz-external-lbs'], f[2])

        m = (np.cross(self.getLeverArm(fdm, 'pushback'), fpb) +
             np.cross(self.getLeverArm(fdm, 'hook'), fhook))
        self.assertAlmostEqual(fdm['moments/l-external-lbsft'], m[0])
        self.assertAlmostEqual(fdm['moments/m-external-lbsft'], m[1])
        self.assertAlmostEqual(fdm['moments/n-external-lbsft'], m[2])

        fdm['external_reactions/hook/location-y-in'] = 50.0
        fdm.run()
        fp = fdm['systems/pushback/force']
        fpb = np.array([1.5, 0.1, 0.0]) * fp
        f = fhook + fpb
        self.assertAlmostEqual(fdm['external_reactions/pushback/magnitude'],
                               fp)
        self.assertAlmostEqual(fdm['forces/fbx-external-lbs'], f[0])
        self.assertAlmostEqual(fdm['forces/fby-external-lbs'], f[1])
        self.assertAlmostEqual(fdm['forces/fbz-external-lbs'], f[2])

        m = (np.cross(self.getLeverArm(fdm, 'pushback'), fpb) +
             np.cross(self.getLeverArm(fdm, 'hook'), fhook))
        self.assertAlmostEqual(fdm['moments/l-external-lbsft'], m[0])
        self.assertAlmostEqual(fdm['moments/m-external-lbsft'], m[1])
        self.assertAlmostEqual(fdm['moments/n-external-lbsft'], m[2])
    def test_body_frame(self):
        fdm = CreateFDM(self.sandbox)
        aircraft_path = self.sandbox.path_to_jsbsim_file('aircraft')
        fdm.load_model('f16')

        aircraft_path = os.path.join(aircraft_path, 'f16')
        fdm.load_ic(os.path.join(aircraft_path, 'reset00.xml'), False)
        fdm.run_ic()

        self.assertAlmostEqual(fdm['external_reactions/pushback/location-x-in'],
                               -2.98081)
        self.assertAlmostEqual(fdm['external_reactions/pushback/location-y-in'],
                               0.0)
        self.assertAlmostEqual(fdm['external_reactions/pushback/location-z-in'],
                               -1.9683)
        self.assertAlmostEqual(fdm['external_reactions/pushback/x'], 1.0)
        self.assertAlmostEqual(fdm['external_reactions/pushback/y'], 0.0)
        self.assertAlmostEqual(fdm['external_reactions/pushback/z'], 0.0)
        self.assertAlmostEqual(fdm['external_reactions/pushback/magnitude'],
                               0.0)

        self.assertAlmostEqual(fdm['external_reactions/hook/location-x-in'],
                               100.669)
        self.assertAlmostEqual(fdm['external_reactions/hook/location-y-in'],
                               0.0)
        self.assertAlmostEqual(fdm['external_reactions/hook/location-z-in'],
                               -28.818)
        dx = -0.9995
        dz = 0.01
        fhook = np.array([dx, 0.0, dz])
        fhook /= np.linalg.norm(fhook)
        
        self.assertAlmostEqual(fdm['external_reactions/hook/x'], fhook[0])
        self.assertAlmostEqual(fdm['external_reactions/hook/y'], fhook[1])
        self.assertAlmostEqual(fdm['external_reactions/hook/z'], fhook[2])
        self.assertAlmostEqual(fdm['external_reactions/hook/magnitude'], 0.0)

        self.assertAlmostEqual(fdm['forces/fbx-external-lbs'], 0.0)
        self.assertAlmostEqual(fdm['forces/fby-external-lbs'], 0.0)
        self.assertAlmostEqual(fdm['forces/fbz-external-lbs'], 0.0)
        self.assertAlmostEqual(fdm['moments/l-external-lbsft'], 0.0)
        self.assertAlmostEqual(fdm['moments/m-external-lbsft'], 0.0)
        self.assertAlmostEqual(fdm['moments/n-external-lbsft'], 0.0)

        # Check the 'pushback' external force alone
        fdm['/sim/model/pushback/position-norm'] = 1.0
        fdm['/sim/model/pushback/target-speed-fps'] = 1.0
        fdm['/sim/model/pushback/kp'] = 0.05
        fdm.run()

        fpb = np.array([1.0, 0.0, 0.0]) * 0.05
        self.assertAlmostEqual(fdm['external_reactions/pushback/magnitude'],
                               0.05)
        self.assertAlmostEqual(fdm['forces/fbx-external-lbs'], fpb[0])
        self.assertAlmostEqual(fdm['forces/fby-external-lbs'], fpb[1])
        self.assertAlmostEqual(fdm['forces/fbz-external-lbs'], fpb[2])

        m = np.cross(self.getLeverArm(fdm, 'pushback'), fpb)
        self.assertAlmostEqual(fdm['moments/l-external-lbsft'], m[0])
        self.assertAlmostEqual(fdm['moments/m-external-lbsft'], m[1])
        self.assertAlmostEqual(fdm['moments/n-external-lbsft'], m[2])

        # Reset the 'pushback' external force to zero
        fdm['/sim/model/pushback/position-norm'] = 0.0
        fdm.run()
        self.assertAlmostEqual(fdm['external_reactions/pushback/magnitude'], 0.0)
        self.assertAlmostEqual(fdm['forces/fbx-external-lbs'], 0.0)
        self.assertAlmostEqual(fdm['forces/fby-external-lbs'], 0.0)
        self.assertAlmostEqual(fdm['forces/fbz-external-lbs'], 0.0)
        self.assertAlmostEqual(fdm['moments/l-external-lbsft'], 0.0)
        self.assertAlmostEqual(fdm['moments/m-external-lbsft'], 0.0)
        self.assertAlmostEqual(fdm['moments/n-external-lbsft'], 0.0)

        # Check the 'hook' external force alone
        fdm['external_reactions/hook/magnitude'] = 10.0
        fhook *= 10.0
        fdm.run()
        self.assertAlmostEqual(fdm['forces/fbx-external-lbs'], fhook[0])
        self.assertAlmostEqual(fdm['forces/fby-external-lbs'], fhook[1])
        self.assertAlmostEqual(fdm['forces/fbz-external-lbs'], fhook[2])

        m = np.cross(self.getLeverArm(fdm, 'hook'), fhook)
        self.assertAlmostEqual(fdm['moments/l-external-lbsft'], m[0])
        self.assertAlmostEqual(fdm['moments/m-external-lbsft'], m[1])
        self.assertAlmostEqual(fdm['moments/n-external-lbsft'], m[2])

        # Add the 'pushback' force to the hook force and check that the global
        # external forces is the sum of the push back force and the hook force.
        fdm['/sim/model/pushback/position-norm'] = 1.0
        fdm.run()
        fp = fdm['systems/pushback/force']
        fpb = np.array([1.0, 0.0, 0.0]) * fp
        f = fhook + fpb
        self.assertAlmostEqual(fdm['external_reactions/pushback/magnitude'], fp)
        self.assertAlmostEqual(fdm['forces/fbx-external-lbs'], f[0])
        self.assertAlmostEqual(fdm['forces/fby-external-lbs'], f[1])
        self.assertAlmostEqual(fdm['forces/fbz-external-lbs'], f[2])

        # Modify the push back force direction and check that the global external
        # force is modified accordingly.
        fdm['external_reactions/pushback/x'] = 1.5
        fdm['external_reactions/pushback/y'] = 0.1
        fdm.run()
        fp = fdm['systems/pushback/force']
        fpb = np.array([1.5, 0.1, 0.0]) * fp
        f = fhook + fpb
        self.assertAlmostEqual(fdm['external_reactions/pushback/magnitude'], fp)
        self.assertAlmostEqual(fdm['forces/fbx-external-lbs'], f[0])
        self.assertAlmostEqual(fdm['forces/fby-external-lbs'], f[1])
        self.assertAlmostEqual(fdm['forces/fbz-external-lbs'], f[2])

        m = (np.cross(self.getLeverArm(fdm, 'pushback'), fpb)
             + np.cross(self.getLeverArm(fdm, 'hook'), fhook))
        self.assertAlmostEqual(fdm['moments/l-external-lbsft'], m[0])
        self.assertAlmostEqual(fdm['moments/m-external-lbsft'], m[1])
        self.assertAlmostEqual(fdm['moments/n-external-lbsft'], m[2])

        fdm['external_reactions/hook/location-y-in'] = 50.0
        fdm.run()
        fp = fdm['systems/pushback/force']
        fpb = np.array([1.5, 0.1, 0.0]) * fp
        f = fhook + fpb
        self.assertAlmostEqual(fdm['external_reactions/pushback/magnitude'], fp)
        self.assertAlmostEqual(fdm['forces/fbx-external-lbs'], f[0])
        self.assertAlmostEqual(fdm['forces/fby-external-lbs'], f[1])
        self.assertAlmostEqual(fdm['forces/fbz-external-lbs'], f[2])

        m = (np.cross(self.getLeverArm(fdm, 'pushback'), fpb)
             + np.cross(self.getLeverArm(fdm, 'hook'), fhook))
        self.assertAlmostEqual(fdm['moments/l-external-lbsft'], m[0])
        self.assertAlmostEqual(fdm['moments/m-external-lbsft'], m[1])
        self.assertAlmostEqual(fdm['moments/n-external-lbsft'], m[2])
Beispiel #37
0
    def test_waypoint(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_model('c310')
        aircraft_path = self.sandbox.path_to_jsbsim_file('aircraft')
        fdm.load_ic(os.path.join(aircraft_path, 'c310', 'reset00'), False)

        a = 20925646.32546  # WGS84 semimajor axis length in feet
        b = 20855486.5951  # WGS84 semiminor axis length in feet
        h = (a - b) / (a + b)
        sq_h = h * h
        p = math.pi * (a + b) * (1. + 3. * sq_h /
                                 (10. + math.sqrt(4. - 3. * sq_h)))

        fdm['ic/lat-geod-rad'] = 0.0
        fdm['ic/long-gc-rad'] = 0.0
        fdm['guidance/target_wp_latitude_rad'] = 0.0

        # Check the distance and heading to other points on the equator.
        for ilon in range(-5, 6):
            lon = ilon * math.pi / 6.0
            fdm['guidance/target_wp_longitude_rad'] = lon
            fdm.run_ic()
            distance = abs(lon * a)
            self.assertAlmostEqual(fdm['guidance/wp-distance'],
                                   distance,
                                   delta=1.)
            if abs(distance > 1E-9):
                self.assertAlmostEqual(fdm['guidance/wp-heading-rad'],
                                       lon * 0.5 * math.pi / abs(lon))

        # Check the distance and heading to the North pole
        fdm['guidance/target_wp_latitude_rad'] = 0.5 * math.pi
        fdm['guidance/target_wp_longitude_rad'] = 0.0
        for ilon in range(-5, 7):
            lon = ilon * math.pi / 6.0
            fdm['ic/long-gc-rad'] = lon
            fdm.run_ic()
            self.assertAlmostEqual(fdm['guidance/wp-distance'],
                                   0.25 * p,
                                   delta=1.)
            self.assertAlmostEqual(fdm['guidance/wp-heading-rad'], 0.0)

        # Check the distance and heading to the South pole
        fdm['guidance/target_wp_latitude_rad'] = -0.5 * math.pi
        fdm['guidance/target_wp_longitude_rad'] = 0.0
        for ilon in range(-5, 7):
            lon = ilon * math.pi / 6.0
            fdm['ic/long-gc-rad'] = lon
            fdm.run_ic()
            self.assertAlmostEqual(fdm['guidance/wp-distance'],
                                   0.25 * p,
                                   delta=1.)
            self.assertAlmostEqual(fdm['guidance/wp-heading-rad'], math.pi)

        # Check the distance to the antipode
        for ilat in range(-5, 6):
            glat = ilat * math.pi / 12.
            fdm['ic/lat-geod-rad'] = glat
            fdm['guidance/target_wp_latitude_rad'] = -glat
            for ilon in range(-5, 6):
                lon = ilon * math.pi / 6.
                fdm['ic/long-gc-rad'] = lon
                fdm['guidance/target_wp_longitude_rad'] = lon + math.pi
                fdm.run_ic()
                self.assertAlmostEqual(fdm['guidance/wp-distance'],
                                       0.5 * p,
                                       delta=1.)
Beispiel #38
0
    def testKinematicTiming(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_model('c172r')
        fdm.load_ic(
            self.sandbox.path_to_jsbsim_file('aircraft', 'c172r', 'reset00'),
            False)
        fdm.run_ic()
        self.assertEqual(fdm['fcs/flap-cmd-norm'], 0.0)
        self.assertEqual(fdm['fcs/flap-pos-deg'], 0.0)

        # Test the flap down sequence. The flap command is set to a value
        # higher than 1.0 to check that JSBSim clamps it to 1.0
        fdm['fcs/flap-cmd-norm'] = 1.5
        t = fdm['simulation/sim-time-sec']

        while t < 2.0:
            self.assertAlmostEqual(fdm['fcs/flap-pos-deg'], 5. * t)
            fdm.run()
            t = fdm['simulation/sim-time-sec']

        while t < 4.0:
            self.assertAlmostEqual(fdm['fcs/flap-pos-deg'], 10. * (t - 1.))
            fdm.run()
            t = fdm['simulation/sim-time-sec']

        while t < 5.0:
            self.assertAlmostEqual(fdm['fcs/flap-pos-deg'], 30.)
            fdm.run()
            t = fdm['simulation/sim-time-sec']

        # Test the flap up sequence with an interruption at 7.5 deg
        fdm['fcs/flap-cmd-norm'] = 0.25

        while t < 7.0:
            self.assertAlmostEqual(fdm['fcs/flap-pos-deg'],
                                   30. - 10. * (t - 5.))
            fdm.run()
            t = fdm['simulation/sim-time-sec']

        while t < 7.5:
            self.assertAlmostEqual(fdm['fcs/flap-pos-deg'],
                                   10. - 5. * (t - 7.))
            fdm.run()
            t = fdm['simulation/sim-time-sec']

        while t < 8.0:
            self.assertAlmostEqual(fdm['fcs/flap-pos-deg'], 7.5)
            fdm.run()
            t = fdm['simulation/sim-time-sec']

        # Complete the flap up sequence. The flap command is set to a value
        # lower than 0.0 to check that JSBSim clamps it to 0.0
        fdm['fcs/flap-cmd-norm'] = -1.

        while t < 9.5:
            self.assertAlmostEqual(fdm['fcs/flap-pos-deg'],
                                   10. - 5. * (t - 7.5))
            fdm.run()
            t = fdm['simulation/sim-time-sec']

        while t < 10.0:
            self.assertAlmostEqual(fdm['fcs/flap-pos-deg'], 0.0)
            fdm.run()
            t = fdm['simulation/sim-time-sec']