예제 #1
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
예제 #2
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
예제 #3
0
    def test_reset_output_files(self):
      #
      # Regular run that checks the correct CSV file is created
      # We are just checking its existence, not its content. To accelerate the
      # test execution, the simulation is interrupted after 1.0sec of simulated
      # time.
      #
      fdm = CreateFDM(self.sandbox)
      fdm.load_script(self.sandbox.path_to_jsbsim_file('scripts', 'c1722.xml'))

      fdm.run_ic()
      ExecuteUntil(fdm, 1.0)

      self.assertTrue(self.sandbox.exists('JSBout172B.csv'),
                      msg="Standard run: the file 'JSBout172B.csv' should exist.")

      #
      # Reset the simulation and check that iteration number is correctly
      # appended to the filename.
      #
      fdm.reset_to_initial_conditions(1)
      ExecuteUntil(fdm, 1.0)

      self.assertTrue(self.sandbox.exists('JSBout172B_0.csv'),
                      msg="Reset: the file 'JSBout172B_0.csv' should exist.")

      #
      # Change the output filename and check that the naming logic is reset
      # (e.g. that no iteration number is appended to the filename)
      #
      fdm.set_output_filename(0, 'dummy.csv')
      fdm.reset_to_initial_conditions(1)
      ExecuteUntil(fdm, 1.0)

      self.assertTrue(self.sandbox.exists('dummy.csv'),
                      msg="Output name renaming: the file 'dummy.csv' should exist.")

      #
      # Call FGFDMExec::SetOutputFileName() after the simulation is reset. And
      # verify that the new output file name is ignored until the next call to
      # FGOutput::SetStartNewOutput(). This should be so according to the
      # documentation of FGOutput::SetOutputName().
      #
      fdm.reset_to_initial_conditions(1)
      fdm.set_output_filename(0, 'dummyx.csv')
      ExecuteUntil(fdm, 1.0)

      self.assertTrue(not self.sandbox.exists('dummyx.csv'),
                      msg="Late renaming: 'dummyx.csv' should not exist.")
      self.assertTrue(self.sandbox.exists('dummy_0.csv'),
                      msg="Late renaming: 'dummy_0.csv' should exist.")

      #
      # Check that the new filename is taken into account when the simulation is
      # reset.
      #
      fdm.reset_to_initial_conditions(1)
      ExecuteUntil(fdm, 1.0)

      self.assertTrue(self.sandbox.exists('dummyx.csv'),
                      msg="Reset after late renaming: 'dummyx.csv' should exist.")

      #
      # Check against multiple calls to FGFDMExec::SetOutputFileName()
      #
      fdm.set_output_filename(0, 'this_one.csv')
      fdm.set_output_filename(0, 'that_one.csv')
      fdm.reset_to_initial_conditions(1)
      ExecuteUntil(fdm, 1.0)

      self.assertTrue(not self.sandbox.exists('this_one.csv'),
                      msg="Output name overwritten: 'this_one.csv' should not exist.")
      self.assertTrue(self.sandbox.exists('that_one.csv'),
                      msg="Output name overwritten: 'that_one.csv' should exist.")

      #
      # Check again on a brand new FDM
      #
      self.sandbox.delete_csv_files()

      # Because JSBSim internals use static pointers, we cannot rely on Python
      # garbage collector to decide when the FDM is destroyed otherwise we can
      # get dangling pointers.
      del fdm

      fdm = CreateFDM(self.sandbox)
      fdm.load_script(self.sandbox.path_to_jsbsim_file('scripts', 'c1722.xml'))

      fdm.run_ic()
      fdm.set_output_filename(0,'oops.csv') # Oops!! Changed my mind
      ExecuteUntil(fdm, 1.0)

      self.assertTrue(not self.sandbox.exists('oops.csv'),
                      msg="New FDM: 'oops.csv' should not exist.")
      self.assertTrue(self.sandbox.exists('JSBout172B.csv'),
                      msg="New FDM: 'JSBout172B.csv' should exist.")

      #
      # The new file name 'oops.csv' has been ignored.
      # Check if it is now taken into account.
      #
      fdm.reset_to_initial_conditions(1)
      ExecuteUntil(fdm, 1.0)

      self.assertTrue(self.sandbox.exists('oops.csv'),
                      msg="Reset new FDM: 'oops.csv' should exist.")
예제 #4
0
#
# Reset the simulation and check that iteration number is correctly appended to
# the filename.
#
fdm.reset_to_initial_conditions(1)
ExecuteUntil(fdm, 1.0)

if not sandbox.exists('JSBout172B_0.csv'):
  print "Reset: the file 'JSBout172B_0.csv' should exist."
  sys.exit(-1) # 'make test' will report the test failed.

#
# Change the output filename and check that the naming logic is reset (e.g. that
# no iteration number is appended to the filename
#
fdm.set_output_filename(0, 'dummy.csv')
fdm.reset_to_initial_conditions(1)
ExecuteUntil(fdm, 1.0)

if not sandbox.exists('dummy.csv'):
  print "Output name renaming: the file 'dummy.csv' should exist."
  sys.exit(-1) # 'make test' will report the test failed.

#
# Call FGFDMExec::SetOutputFileName() after the simulation is reset. And verify
# that the new output file name is ignored until the next call to
# FGOutput::SetStartNewOutput(). This should be so according to the
# documentation of FGOutput::SetOutputName().
#
fdm.reset_to_initial_conditions(1)
fdm.set_output_filename(0, 'dummyx.csv')
예제 #5
0
    def test_reset_output_files(self):
        #
        # Regular run that checks the correct CSV file is created
        # We are just checking its existence, not its content. To accelerate the
        # test execution, the simulation is interrupted after 1.0sec of simulated
        # time.
        #
        fdm = CreateFDM(self.sandbox)
        fdm.load_script(
            self.sandbox.path_to_jsbsim_file('scripts', 'c1722.xml'))

        fdm.run_ic()
        ExecuteUntil(fdm, 1.0)

        self.assertTrue(
            self.sandbox.exists('JSBout172B.csv'),
            msg="Standard run: the file 'JSBout172B.csv' should exist.")

        #
        # Reset the simulation and check that iteration number is correctly
        # appended to the filename.
        #
        fdm.reset_to_initial_conditions(1)
        ExecuteUntil(fdm, 1.0)

        self.assertTrue(self.sandbox.exists('JSBout172B_0.csv'),
                        msg="Reset: the file 'JSBout172B_0.csv' should exist.")

        #
        # Change the output filename and check that the naming logic is reset
        # (e.g. that no iteration number is appended to the filename)
        #
        fdm.set_output_filename(0, 'dummy.csv')
        fdm.reset_to_initial_conditions(1)
        ExecuteUntil(fdm, 1.0)

        self.assertTrue(
            self.sandbox.exists('dummy.csv'),
            msg="Output name renaming: the file 'dummy.csv' should exist.")

        #
        # Call FGFDMExec::SetOutputFileName() after the simulation is reset. And
        # verify that the new output file name is ignored until the next call to
        # FGOutput::SetStartNewOutput(). This should be so according to the
        # documentation of FGOutput::SetOutputName().
        #
        fdm.reset_to_initial_conditions(1)
        fdm.set_output_filename(0, 'dummyx.csv')
        ExecuteUntil(fdm, 1.0)

        self.assertTrue(not self.sandbox.exists('dummyx.csv'),
                        msg="Late renaming: 'dummyx.csv' should not exist.")
        self.assertTrue(self.sandbox.exists('dummy_0.csv'),
                        msg="Late renaming: 'dummy_0.csv' should exist.")

        #
        # Check that the new filename is taken into account when the simulation is
        # reset.
        #
        fdm.reset_to_initial_conditions(1)
        ExecuteUntil(fdm, 1.0)

        self.assertTrue(
            self.sandbox.exists('dummyx.csv'),
            msg="Reset after late renaming: 'dummyx.csv' should exist.")

        #
        # Check against multiple calls to FGFDMExec::SetOutputFileName()
        #
        fdm.set_output_filename(0, 'this_one.csv')
        fdm.set_output_filename(0, 'that_one.csv')
        fdm.reset_to_initial_conditions(1)
        ExecuteUntil(fdm, 1.0)

        self.assertTrue(
            not self.sandbox.exists('this_one.csv'),
            msg="Output name overwritten: 'this_one.csv' should not exist.")
        self.assertTrue(
            self.sandbox.exists('that_one.csv'),
            msg="Output name overwritten: 'that_one.csv' should exist.")

        #
        # Check again on a brand new FDM
        #
        self.sandbox.delete_csv_files()

        # Because JSBSim internals use static pointers, we cannot rely on Python
        # garbage collector to decide when the FDM is destroyed otherwise we can
        # get dangling pointers.
        del fdm

        fdm = CreateFDM(self.sandbox)
        fdm.load_script(
            self.sandbox.path_to_jsbsim_file('scripts', 'c1722.xml'))

        fdm.run_ic()
        fdm.set_output_filename(0, 'oops.csv')  # Oops!! Changed my mind
        ExecuteUntil(fdm, 1.0)

        self.assertTrue(not self.sandbox.exists('oops.csv'),
                        msg="New FDM: 'oops.csv' should not exist.")
        self.assertTrue(self.sandbox.exists('JSBout172B.csv'),
                        msg="New FDM: 'JSBout172B.csv' should exist.")

        #
        # The new file name 'oops.csv' has been ignored.
        # Check if it is now taken into account.
        #
        fdm.reset_to_initial_conditions(1)
        ExecuteUntil(fdm, 1.0)

        self.assertTrue(self.sandbox.exists('oops.csv'),
                        msg="Reset new FDM: 'oops.csv' should exist.")