def test_model_loading(self): self.longMessage = True self.BuildReference('c1724.xml') output_ref = Table() output_ref.ReadCSV(self.sandbox('JSBout172B.csv')) self.ProcessAndCompare('aerodynamics') self.ProcessAndCompare('autopilot') self.ProcessAndCompare('flight_control') self.ProcessAndCompare('ground_reactions') self.ProcessAndCompare('mass_balance') self.ProcessAndCompare('metrics') self.ProcessAndCompare('propulsion') self.ProcessAndCompare('system') # The <output> section needs special handling. In addition to the check # conducted by ProcessAndCompare with a directive file, we need to # verify that the <output> tag has been correctly executed by JSBSim. # In the case of the script c1724.xml, this means that the data output # in JSBout172B.csv is the same between the reference 'output_ref' and # the result 'mod' below where the <output> tag was moved in a separate # file. self.ProcessAndCompare('output') mod = Table() mod.ReadCSV(self.sandbox('JSBout172B.csv')) diff = output_ref.compare(mod, 0.0) self.assertTrue(diff.empty(), msg='\nTesting section "output"\n'+repr(diff)) self.BuildReference('weather-balloon.xml') self.ProcessAndCompare('buoyant_forces') self.BuildReference('Concorde_runway_test.xml') self.ProcessAndCompare('external_reactions')
def testDebugLvl(self): fdm = CreateFDM(self.sandbox) fdm.load_script( self.sandbox.path_to_jsbsim_file('scripts', 'ball_orbit.xml')) fdm.run_ic() ExecuteUntil(fdm, 1000.) ref, current = Table(), Table() ref.ReadCSV(self.sandbox('BallOut.csv')) del fdm os.environ["JSBSIM_DEBUG"] = str(0) fdm = CreateFDM(self.sandbox) fdm.load_script( self.sandbox.path_to_jsbsim_file('scripts', 'ball_orbit.xml')) fdm.run_ic() ExecuteUntil(fdm, 1000.) current.ReadCSV(self.sandbox('BallOut.csv')) diff = ref.compare(current) self.longMessage = True self.assertTrue(diff.empty(), msg='\n' + repr(diff))
def test_model_loading(self): self.longMessage = True self.BuildReference('c1724.xml') output_ref = Table() output_ref.ReadCSV(self.sandbox('JSBout172B.csv')) self.ProcessAndCompare('aerodynamics') self.ProcessAndCompare('autopilot') self.ProcessAndCompare('flight_control') self.ProcessAndCompare('ground_reactions') self.ProcessAndCompare('mass_balance') self.ProcessAndCompare('metrics') self.ProcessAndCompare('propulsion') self.ProcessAndCompare('system') # The <output> section needs special handling. In addition to the check # conducted by ProcessAndCompare with a directive file, we need to # verify that the <output> tag has been correctly executed by JSBSim. # In the case of the script c1724.xml, this means that the data output # in JSBout172B.csv is the same between the reference 'output_ref' and # the result 'mod' below where the <output> tag was moved in a separate # file. self.ProcessAndCompare('output') mod = Table() mod.ReadCSV(self.sandbox('JSBout172B.csv')) diff = output_ref.compare(mod, 0.0) self.assertTrue(diff.empty(), msg='\nTesting section "output"\n' + repr(diff)) self.BuildReference('weather-balloon.xml') self.ProcessAndCompare('buoyant_forces') self.BuildReference('Concorde_runway_test.xml') self.ProcessAndCompare('external_reactions')
def testOrbitCheckCase(self): os.environ['JSBSIM_DEBUG'] = str(0) fdm = CreateFDM(self.sandbox) fdm.load_script(self.sandbox.path_to_jsbsim_file('scripts', 'ball_orbit.xml')) fdm.run_ic() while fdm.run(): pass ref, current = Table(), Table() ref.ReadCSV(self.sandbox.elude(self.sandbox.path_to_jsbsim_file('logged_data', 'BallOut.csv'))) current.ReadCSV(self.sandbox('BallOut.csv')) diff = ref.compare(current) self.longMessage = True self.assertTrue(diff.empty(), msg='\n'+repr(diff))
def testOrbitCheckCase(self): os.environ['JSBSIM_DEBUG'] = str(0) fdm = CreateFDM(self.sandbox) fdm.load_script( self.sandbox.path_to_jsbsim_file('scripts', 'ball_orbit.xml')) fdm.run_ic() while fdm.run(): pass ref, current = Table(), Table() ref.ReadCSV( self.sandbox.elude( self.sandbox.path_to_jsbsim_file('logged_data', 'BallOut.csv'))) current.ReadCSV(self.sandbox('BallOut.csv')) diff = ref.compare(current) self.longMessage = True self.assertTrue(diff.empty(), msg='\n' + repr(diff))
def test_gust_reset(self): fdm = CreateFDM(self.sandbox) fdm.load_script(self.sandbox.path_to_jsbsim_file('scripts', 'c172_cruise_8K.xml')) fdm.set_property_value('simulation/randomseed', 0.0) fdm.set_output_directive(self.sandbox.path_to_jsbsim_file('tests', 'output.xml')) fdm.run_ic() ExecuteUntil(fdm, 15.5) ref, current = Table(), Table() ref.ReadCSV(self.sandbox('output.csv')) fdm.set_property_value('simulation/randomseed', 0.0) fdm.reset_to_initial_conditions(1) ExecuteUntil(fdm, 15.5) current.ReadCSV(self.sandbox('output_0.csv')) diff = ref.compare(current) self.longMessage = True self.assertTrue(diff.empty(), msg='\n'+repr(diff))
def testDebugLvl(self): fdm = CreateFDM(self.sandbox) fdm.load_script(self.sandbox.path_to_jsbsim_file('scripts', 'ball_orbit.xml')) fdm.run_ic() ExecuteUntil(fdm, 1000.) ref, current = Table(), Table() ref.ReadCSV(self.sandbox('BallOut.csv')) del fdm os.environ["JSBSIM_DEBUG"]=str(0) fdm = CreateFDM(self.sandbox) fdm.load_script(self.sandbox.path_to_jsbsim_file('scripts', 'ball_orbit.xml')) fdm.run_ic() ExecuteUntil(fdm, 1000.) current.ReadCSV(self.sandbox('BallOut.csv')) diff = ref.compare(current) self.longMessage = True self.assertTrue(diff.empty(), msg='\n'+repr(diff))
def test_gust_reset(self): fdm = CreateFDM(self.sandbox) fdm.load_script( self.sandbox.path_to_jsbsim_file('scripts', 'c172_cruise_8K.xml')) fdm.set_property_value('simulation/randomseed', 0.0) fdm.set_output_directive( self.sandbox.path_to_jsbsim_file('tests', 'output.xml')) fdm.run_ic() ExecuteUntil(fdm, 15.5) ref, current = Table(), Table() ref.ReadCSV(self.sandbox('output.csv')) fdm.set_property_value('simulation/randomseed', 0.0) fdm.reset_to_initial_conditions(1) ExecuteUntil(fdm, 15.5) current.ReadCSV(self.sandbox('output_0.csv')) diff = ref.compare(current) self.longMessage = True self.assertTrue(diff.empty(), msg='\n' + repr(diff))
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program; if not, see <http://www.gnu.org/licenses/> # import sys from JSBSim_utils import CreateFDM, Table, SandBox sandbox = SandBox('check_cases', 'orbit') fdm = CreateFDM(sandbox) fdm.load_script(sandbox.path_to_jsbsim_file('scripts', 'ball_orbit.xml')) fdm.run_ic() while fdm.run(): pass ref, current = Table(), Table() ref.ReadCSV(sandbox.elude(sandbox.path_to_jsbsim_file('logged_data', 'BallOut.csv'))) current.ReadCSV(sandbox('BallOut.csv')) diff = ref.compare(current) if not diff.empty(): print diff sys.exit(-1) # Needed for 'make test' to report the test passed. sandbox.erase()
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program; if not, see <http://www.gnu.org/licenses/> # import sys from JSBSim_utils import CreateFDM, Table, SandBox sandbox = SandBox("check_cases", "orbit") fdm = CreateFDM(sandbox) fdm.load_script(sandbox.path_to_jsbsim_file("scripts", "ball_orbit.xml")) fdm.run_ic() while fdm.run(): pass ref, current = Table(), Table() ref.ReadCSV(sandbox.elude(sandbox.path_to_jsbsim_file("logged_data", "BallOut.csv"))) current.ReadCSV(sandbox("BallOut.csv")) diff = ref.compare(current) if not diff.empty(): print diff sys.exit(-1) # Needed for 'make test' to report the test passed. sandbox.erase()
class TestModelLoading(unittest.TestCase): def setUp(self): self.sandbox = SandBox() def tearDown(self): self.sandbox.erase() def BuildReference(self, script_name): # Run the script self.script = self.sandbox.path_to_jsbsim_file(os.path.join('scripts', script_name)) self.sandbox.delete_csv_files() fdm = CreateFDM(self.sandbox) fdm.set_output_directive(self.sandbox.path_to_jsbsim_file('tests', 'output.xml')) fdm.load_script(self.script) fdm.set_property_value('simulation/randomseed', 0.0) fdm.run_ic() ExecuteUntil(fdm, 50.0) self.ref = Table() self.ref.ReadCSV(self.sandbox("output.csv")) # Since the script will work with modified versions of the aircraft XML # definition file, we need to make a copy of the directory that contains # all the input data of that aircraft tree, self.aircraft_name, self.path_to_jsbsim_aircrafts = CopyAircraftDef(self.script, self.sandbox) self.aircraft_path = self.sandbox('aircraft', self.aircraft_name) def ProcessAndCompare(self, section): # Here we determine if the original aircraft definition <section> is # inline or read from an external file. tree = et.parse(os.path.join(self.path_to_jsbsim_aircrafts, self.aircraft_name + '.xml')) root = tree.getroot() # Iterate over all the tags named <section> for section_element in root.findall(section): if 'file' in section_element.keys(): self.InsertAndCompare(section_element, tree) else: self.DetachAndCompare(section_element, tree) def DetachAndCompare(self, section_element, tree): # Extract <section> from the original aircraft definition file and copy # it in a separate XML file 'section.xml' section_tree = et.ElementTree(element=section_element) if 'name' in section_element.keys(): section = section_element.attrib['name'] else: section = section_element.tag section_tree.write(os.path.join(self.aircraft_path, section+'.xml'), xml_declaration=True) # Now, we need to clean up the aircraft definition file from all # references to <section>. We just need a single <section> tag that # points to the file 'section.xml' for element in list(section_element): section_element.remove(element) section_element.attrib = {'file': section+'.xml'} tree.write(os.path.join(self.aircraft_path, self.aircraft_name+'.xml'), xml_declaration=True) self.Compare(section) def InsertAndCompare(self, section_element, tree): file_name = append_xml(section_element.attrib['file']) section_file = os.path.join(self.path_to_jsbsim_aircrafts, file_name) # If <section> is actually <system>, we need to iterate over all the # directories in which the file is allowed to be stored until the file # is located. if not os.path.exists(section_file) and section_element.tag == 'system': section_file = os.path.join(self.path_to_jsbsim_aircrafts, "systems", file_name) if not os.path.exists(section_file): section_file = self.sandbox.elude(self.sandbox.path_to_jsbsim_file("systems", file_name)) # The original <section> tag is dropped and replaced by the content of # the file. section_root = et.parse(section_file).getroot() del section_element.attrib['file'] section_element.attrib.update(section_root.attrib) section_element.extend(section_root) tree.write(os.path.join(self.aircraft_path, self.aircraft_name+'.xml')) self.Compare(section_element.tag+" file:"+section_file) def Compare(self, section): # Rerun the script with the modified aircraft definition self.sandbox.delete_csv_files() fdm = CreateFDM(self.sandbox) # We need to tell JSBSim that the aircraft definition is located in the # directory build/.../aircraft fdm.set_aircraft_path('aircraft') fdm.set_output_directive(self.sandbox.path_to_jsbsim_file('tests', 'output.xml')) fdm.load_script(self.script) fdm.set_property_value('simulation/randomseed', 0.0) fdm.run_ic() ExecuteUntil(fdm, 50.0) mod = Table() mod.ReadCSV(self.sandbox('output.csv')) # Whether the data is read from the aircraft definition file or from an # external file, the results shall be exactly identical. Hence the # precision set to 0.0. diff = self.ref.compare(mod, 0.0) self.assertTrue(diff.empty(), msg='\nTesting section "'+section+'"\n'+repr(diff)) def test_model_loading(self): self.longMessage = True self.BuildReference('c1724.xml') output_ref = Table() output_ref.ReadCSV(self.sandbox('JSBout172B.csv')) self.ProcessAndCompare('aerodynamics') self.ProcessAndCompare('autopilot') self.ProcessAndCompare('flight_control') self.ProcessAndCompare('ground_reactions') self.ProcessAndCompare('mass_balance') self.ProcessAndCompare('metrics') self.ProcessAndCompare('propulsion') self.ProcessAndCompare('system') # The <output> section needs special handling. In addition to the check # conducted by ProcessAndCompare with a directive file, we need to # verify that the <output> tag has been correctly executed by JSBSim. # In the case of the script c1724.xml, this means that the data output # in JSBout172B.csv is the same between the reference 'output_ref' and # the result 'mod' below where the <output> tag was moved in a separate # file. self.ProcessAndCompare('output') mod = Table() mod.ReadCSV(self.sandbox('JSBout172B.csv')) diff = output_ref.compare(mod, 0.0) self.assertTrue(diff.empty(), msg='\nTesting section "output"\n'+repr(diff)) self.BuildReference('weather-balloon.xml') self.ProcessAndCompare('buoyant_forces') self.BuildReference('Concorde_runway_test.xml') self.ProcessAndCompare('external_reactions')
def test_point_mass_inertia(self): script_path = self.sandbox.path_to_jsbsim_file('scripts', 'J2460.xml') fdm = CreateFDM(self.sandbox) fdm.set_output_directive(self.sandbox.path_to_jsbsim_file('tests', 'output.xml')) fdm.load_script(script_path) fdm.run_ic() ExecuteUntil(fdm, 50.0) ref = Table() ref.ReadCSV(self.sandbox("output.csv")) tree, aircraft_name, path_to_jsbsim_aircrafts = CopyAircraftDef(script_path, self.sandbox) pointmass_element = tree.getroot().find('mass_balance/pointmass//form/..') weight_element = pointmass_element.find('weight') weight = float(weight_element.text) form_element = pointmass_element.find('form') radius_element = form_element.find('radius') radius, length = (0.0, 0.0) if radius_element is not None: radius = float(radius_element.text) length_element = form_element.find('length') if length_element is not None: length = float(length_element.text) shape = form_element.attrib['shape'] pointmass_element.remove(form_element) inertia = numpy.zeros((3,3)) if string.strip(shape) == 'tube': inertia[0,0] = radius * radius inertia[1,1] = (6.0 * inertia[0,0] + length * length) / 12.0 inertia[2,2] = inertia[1,1] inertia = inertia * weight / 32.174049 # conversion between slug and lb ixx_element = et.SubElement(pointmass_element, 'ixx') ixx_element.text = str(inertia[0,0]) iyy_element = et.SubElement(pointmass_element, 'iyy') iyy_element.text = str(inertia[1,1]) izz_element = et.SubElement(pointmass_element, 'izz') izz_element.text = str(inertia[2,2]) tree.write(self.sandbox('aircraft', aircraft_name, aircraft_name+'.xml')) fdm = CreateFDM(self.sandbox) fdm.set_aircraft_path('aircraft') fdm.set_output_directive(self.sandbox.path_to_jsbsim_file('tests', 'output.xml')) fdm.load_script(script_path) fdm.run_ic() ExecuteUntil(fdm, 50.0) mod = Table() mod.ReadCSV(self.sandbox("output.csv")) diff = ref.compare(mod) self.assertTrue(diff.empty(), msg='\n'+repr(diff))
class TestModelLoading(unittest.TestCase): def setUp(self): self.sandbox = SandBox() def tearDown(self): self.sandbox.erase() def BuildReference(self, script_name): # Run the script self.script = self.sandbox.path_to_jsbsim_file( os.path.join('scripts', script_name)) self.sandbox.delete_csv_files() fdm = CreateFDM(self.sandbox) fdm.set_output_directive( self.sandbox.path_to_jsbsim_file('tests', 'output.xml')) fdm.load_script(self.script) fdm.set_property_value('simulation/randomseed', 0.0) fdm.run_ic() ExecuteUntil(fdm, 50.0) self.ref = Table() self.ref.ReadCSV(self.sandbox("output.csv")) # Since the script will work with modified versions of the aircraft XML # definition file, we need to make a copy of the directory that contains # all the input data of that aircraft tree, self.aircraft_name, self.path_to_jsbsim_aircrafts = CopyAircraftDef( self.script, self.sandbox) self.aircraft_path = self.sandbox('aircraft', self.aircraft_name) def ProcessAndCompare(self, section): # Here we determine if the original aircraft definition <section> is # inline or read from an external file. tree = et.parse( os.path.join(self.path_to_jsbsim_aircrafts, self.aircraft_name + '.xml')) root = tree.getroot() # Iterate over all the tags named <section> for section_element in root.findall(section): if 'file' in section_element.keys(): self.InsertAndCompare(section_element, tree) else: self.DetachAndCompare(section_element, tree) def DetachAndCompare(self, section_element, tree): # Extract <section> from the original aircraft definition file and copy # it in a separate XML file 'section.xml' section_tree = et.ElementTree(element=section_element) if 'name' in section_element.keys(): section = section_element.attrib['name'] else: section = section_element.tag section_tree.write(os.path.join(self.aircraft_path, section + '.xml'), xml_declaration=True) # Now, we need to clean up the aircraft definition file from all # references to <section>. We just need a single <section> tag that # points to the file 'section.xml' for element in list(section_element): section_element.remove(element) section_element.attrib = {'file': section + '.xml'} tree.write(os.path.join(self.aircraft_path, self.aircraft_name + '.xml'), xml_declaration=True) self.Compare(section) def InsertAndCompare(self, section_element, tree): file_name = append_xml(section_element.attrib['file']) section_file = os.path.join(self.path_to_jsbsim_aircrafts, file_name) # If <section> is actually <system>, we need to iterate over all the # directories in which the file is allowed to be stored until the file # is located. if not os.path.exists( section_file) and section_element.tag == 'system': section_file = os.path.join(self.path_to_jsbsim_aircrafts, "systems", file_name) if not os.path.exists(section_file): section_file = self.sandbox.elude( self.sandbox.path_to_jsbsim_file("systems", file_name)) # The original <section> tag is dropped and replaced by the content of # the file. section_root = et.parse(section_file).getroot() del section_element.attrib['file'] section_element.attrib.update(section_root.attrib) section_element.extend(section_root) tree.write( os.path.join(self.aircraft_path, self.aircraft_name + '.xml')) self.Compare(section_element.tag + " file:" + section_file) def Compare(self, section): # Rerun the script with the modified aircraft definition self.sandbox.delete_csv_files() fdm = CreateFDM(self.sandbox) # We need to tell JSBSim that the aircraft definition is located in the # directory build/.../aircraft fdm.set_aircraft_path('aircraft') fdm.set_output_directive( self.sandbox.path_to_jsbsim_file('tests', 'output.xml')) fdm.load_script(self.script) fdm.set_property_value('simulation/randomseed', 0.0) fdm.run_ic() ExecuteUntil(fdm, 50.0) mod = Table() mod.ReadCSV(self.sandbox('output.csv')) # Whether the data is read from the aircraft definition file or from an # external file, the results shall be exactly identical. Hence the # precision set to 0.0. diff = self.ref.compare(mod, 0.0) self.assertTrue(diff.empty(), msg='\nTesting section "' + section + '"\n' + repr(diff)) def test_model_loading(self): self.longMessage = True self.BuildReference('c1724.xml') output_ref = Table() output_ref.ReadCSV(self.sandbox('JSBout172B.csv')) self.ProcessAndCompare('aerodynamics') self.ProcessAndCompare('autopilot') self.ProcessAndCompare('flight_control') self.ProcessAndCompare('ground_reactions') self.ProcessAndCompare('mass_balance') self.ProcessAndCompare('metrics') self.ProcessAndCompare('propulsion') self.ProcessAndCompare('system') # The <output> section needs special handling. In addition to the check # conducted by ProcessAndCompare with a directive file, we need to # verify that the <output> tag has been correctly executed by JSBSim. # In the case of the script c1724.xml, this means that the data output # in JSBout172B.csv is the same between the reference 'output_ref' and # the result 'mod' below where the <output> tag was moved in a separate # file. self.ProcessAndCompare('output') mod = Table() mod.ReadCSV(self.sandbox('JSBout172B.csv')) diff = output_ref.compare(mod, 0.0) self.assertTrue(diff.empty(), msg='\nTesting section "output"\n' + repr(diff)) self.BuildReference('weather-balloon.xml') self.ProcessAndCompare('buoyant_forces') self.BuildReference('Concorde_runway_test.xml') self.ProcessAndCompare('external_reactions')