本文整理汇总了Python中JSBSim_utils.CreateFDM类的典型用法代码示例。如果您正苦于以下问题:Python CreateFDM类的具体用法?Python CreateFDM怎么用?Python CreateFDM使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CreateFDM类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_trim_on_ground
def test_trim_on_ground(self):
fdm = CreateFDM(self.sandbox)
fdm.load_model('c172x')
fdm['ic/theta-deg'] = 10.0
fdm.run_ic()
fdm['ic/theta-deg'] = 0.0
fdm['simulation/do_simple_trim'] = 2
示例2: LoadScript
def LoadScript(self, tree, script_path, prop_output_to_CSV=[]):
# Make a local copy of files referenced by the script.
for element in list(tree.getroot()):
if 'file' in element.keys():
name = append_xml(element.attrib['file'])
name_with_path = os.path.join(os.path.dirname(script_path),
name)
if os.path.exists(name_with_path):
shutil.copy(name_with_path, name)
# Generate a CSV file to check that it is correctly initialized
# with the initial values
output_tag = et.SubElement(tree.getroot(), 'output')
output_tag.attrib['name'] = 'check_csv_values.csv'
output_tag.attrib['type'] = 'CSV'
output_tag.attrib['rate'] = '10'
position_tag = et.SubElement(output_tag, 'position')
position_tag.text = 'ON'
velocities_tag = et.SubElement(output_tag, 'velocities')
velocities_tag.text = 'ON'
for props in prop_output_to_CSV:
property_tag = et.SubElement(output_tag, 'property')
property_tag.text = props
f = os.path.split(script_path)[-1] # Script name
tree.write(f)
# Initialize the script
fdm = CreateFDM(self.sandbox)
self.assertTrue(fdm.load_script(f),
msg="Failed to load script %s" % (f,))
fdm.run_ic()
return (f, fdm)
示例3: test_fuel_tanks_content
def test_fuel_tanks_content(self):
script_path = self.sandbox.path_to_jsbsim_file('scripts', 'J2460.xml')
fdm = CreateFDM(self.sandbox)
fdm.load_script(script_path)
fdm.run_ic()
tree = et.parse(script_path)
use_tag = tree.getroot().find('use')
aircraft_name = use_tag.attrib['aircraft']
aircraft_path = self.sandbox.path_to_jsbsim_file('aircraft',
aircraft_name)
aircraft_tree = et.parse(os.path.join(aircraft_path,
aircraft_name+'.xml'))
total_fuel_quantity = 0.0
total_oxidizer_quantity = 0.0
for tank in aircraft_tree.findall('propulsion/tank'):
contents = float(tank.find('contents').text)
if tank.attrib['type'] == "FUEL":
total_fuel_quantity += contents
elif tank.attrib['type'] == 'OXIDIZER':
total_oxidizer_quantity += contents
self.assertAlmostEqual(fdm['propulsion/total-fuel-lbs'],
total_fuel_quantity)
self.assertAlmostEqual(fdm['propulsion/total-oxidizer-lbs'],
total_oxidizer_quantity)
示例4: test_actuator_rate_from_property
def test_actuator_rate_from_property(self):
# Second part of the test.
# #######################
#
# The test is run again but this time, <rate_limit> will be read from a
# property instead of being read from a value hard coded in the
# aircraft definition file. It has been reported in the bug 1503 of
# FlightGear that for such a configuration the <actuator> output is
# constantly increasing even if the input is null. For this script the
# <actuator> output is stored in the property
# fcs/left-aileron-pos-rad. The function ScriptExecution will monitor
# that property and if it changes then the test is failed.
tree = et.parse(os.path.join(self.path_to_jsbsim_aircrafts, self.aircraft_name+'.xml'))
actuator_element = tree.getroot().find('flight_control/channel/actuator//rate_limit/..')
rate_element = actuator_element.find('rate_limit')
flight_control_element = tree.getroot().find('flight_control')
property = et.SubElement(flight_control_element, 'property')
property.text = 'fcs/rate-limit-value'
property.attrib['value'] = rate_element.text
actuator_element = flight_control_element.find('channel/actuator//rate_limit/..')
rate_element = actuator_element.find('rate_limit')
rate_element.attrib['sense'] = 'decr'
rate_element.text = property.text
new_rate_element = et.SubElement(actuator_element, 'rate_limit')
new_rate_element.attrib['sense'] = 'incr'
new_rate_element.text = rate_element.text
tree.write(self.sandbox('aircraft', self.aircraft_name, self.aircraft_name+'.xml'))
fdm = CreateFDM(self.sandbox)
fdm.set_aircraft_path('aircraft')
self.ScriptExecution(fdm)
del fdm
示例5: testDebugLvl
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 = pd.read_csv('BallOut.csv', index_col=0)
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 = pd.read_csv('BallOut.csv', index_col=0)
# Check the data are matching i.e. the time steps are the same between
# the two data sets and that the output data are also the same.
self.assertTrue(isDataMatching(ref, current))
# Find all the data that are differing by more than 1E-8 between the
# two data sets.
diff = FindDifferences(ref, current, 1E-8)
self.longMessage = True
self.assertEqual(len(diff), 0, msg='\n'+diff.to_string())
示例6: test_output
def test_output(self):
tree = et.parse(self.script_path)
output_tag = et.SubElement(tree.getroot(), 'output')
output_tag.attrib['name'] = 'test.csv'
output_tag.attrib['type'] = 'CSV'
output_tag.attrib['rate'] = '10'
property_tag = et.SubElement(output_tag, 'property')
property_tag.text = 'position/vrp-radius-ft'
tree.write('c1722_0.xml')
fdm = CreateFDM(self.sandbox)
fdm.load_script('c1722_0.xml')
fdm.run_ic()
ExecuteUntil(fdm, 10.)
self.assertTrue(self.sandbox.exists(output_tag.attrib['name']),
msg="The file 'output.csv' has not been created")
orig = pd.read_csv('JSBout172B.csv', index_col=0)
test = pd.read_csv('test.csv', index_col=0)
pname = '/fdm/jsbsim/' + property_tag.text
ref = orig[pname]
mod = test[pname]
# Check the data are matching i.e. the time steps are the same between
# the two data sets.
self.assertTrue(isDataMatching(ref, mod))
# Find all the data that are differing by more than 1E-8 between the
# two data sets.
delta = pd.concat([np.abs(ref - mod), ref, mod], axis=1)
delta.columns = ['delta', 'ref value', 'value']
diff = delta[delta['delta'] > 1E-8]
self.longMessage = True
self.assertEqual(len(diff), 0, msg='\n'+diff.to_string())
示例7: testAircrafts
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
示例8: test_actuator_rate_from_property
def test_actuator_rate_from_property(self):
# Second part of the test.
# #######################
#
# The test is run again but this time, <rate_limit> will be read from a
# property instead of being read from a value hard coded in the aircraft
# definition file. It has been reported in the bug 1503 of FlightGear
# that for such a configuration the <actuator> output is constantly
# increasing even if the input is null. For this script the <actuator>
# output is stored in the property fcs/left-aileron-pos-rad. The
# function ScriptExecution will monitor that property and if it changes
# then the test is failed.
tree = et.parse(os.path.join(self.path_to_jsbsim_aircrafts, self.aircraft_name + ".xml"))
actuator_element = tree.getroot().find("flight_control/channel/actuator//rate_limit/..")
rate_element = actuator_element.find("rate_limit")
flight_control_element = tree.getroot().find("flight_control")
property = et.SubElement(flight_control_element, "property")
property.text = "fcs/rate-limit-value"
property.attrib["value"] = rate_element.text
actuator_element = flight_control_element.find("channel/actuator//rate_limit/..")
rate_element = actuator_element.find("rate_limit")
rate_element.attrib["sense"] = "decr"
rate_element.text = property.text
new_rate_element = et.SubElement(actuator_element, "rate_limit")
new_rate_element.attrib["sense"] = "incr"
new_rate_element.text = rate_element.text
tree.write(self.sandbox("aircraft", self.aircraft_name, self.aircraft_name + ".xml"))
fdm = CreateFDM(self.sandbox)
fdm.set_aircraft_path("aircraft")
self.ScriptExecution(fdm)
del fdm
示例9: test_no_output
def test_no_output(self):
fdm = CreateFDM(self.sandbox)
fdm.load_script(self.script_path)
fdm.run_ic()
ExecuteUntil(fdm, 10.)
self.assertFalse(self.sandbox.exists('output.csv'),
msg="Results have unexpectedly been written to 'output.csv'")
示例10: test_asl_override_vs_geod_lat
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)
示例11: test_gust_reset
def test_gust_reset(self):
fdm = CreateFDM(self.sandbox)
fdm.load_script(self.sandbox.path_to_jsbsim_file('scripts',
'c172_cruise_8K.xml'))
fdm['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 = pd.read_csv('output.csv', index_col=0)
fdm['simulation/randomseed'] = 0.0
fdm.reset_to_initial_conditions(1)
ExecuteUntil(fdm, 15.5)
current = pd.read_csv('output_0.csv', index_col=0)
# Check the data are matching i.e. the time steps are the same between
# the two data sets and that the output data are also the same.
self.assertTrue(isDataMatching(ref, current))
# Find all the data that are differing by more than 1E-8 between the
# two data sets.
diff = FindDifferences(ref, current, 1E-8)
self.longMessage = True
self.assertEqual(len(diff), 0, msg='\n'+diff.to_string())
示例12: Compare
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['simulation/randomseed'] = 0.0
fdm.run_ic()
ExecuteUntil(fdm, 50.0)
mod = pd.read_csv('output.csv', index_col=0)
# Check the data are matching i.e. the time steps are the same between
# the two data sets and that the output data are also the same.
self.assertTrue(isDataMatching(self.ref, mod))
# 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 = FindDifferences(self.ref, mod, 0.0)
self.assertEqual(len(diff), 0,
msg='\nTesting section "'+section+'"\n'+diff.to_string())
示例13: test_CAS_ic
def test_CAS_ic(self):
script_name = 'Short_S23_3.xml'
script_path = self.sandbox.path_to_jsbsim_file('scripts',
script_name)
# Add a Pitot angle to the Short S23
tree, aircraft_name, path_to_jsbsim_aircrafts = CopyAircraftDef(script_path, self.sandbox)
metrics_tag = tree.getroot().find('./metrics')
pitot_tag = et.SubElement(metrics_tag, 'pitot_angle')
pitot_tag.attrib['unit'] = 'DEG'
pitot_tag.text = '5.0'
tree.write(self.sandbox('aircraft', aircraft_name,
aircraft_name+'.xml'))
# Read the CAS specified in the IC file
tree = et.parse(self.sandbox.elude(script_path))
use_element = tree.getroot().find('use')
IC_file = use_element.attrib['initialize']
tree = et.parse(os.path.join(path_to_jsbsim_aircrafts,
append_xml(IC_file)))
vc_tag = tree.getroot().find('./vc')
VCAS = float(vc_tag.text)
if 'unit' in vc_tag.attrib and vc_tag.attrib['unit'] == 'FT/SEC':
VCAS /= 1.68781
# Run the IC and check that the model is initialized correctly
fdm = CreateFDM(self.sandbox)
fdm.set_aircraft_path('aircraft')
fdm.load_script(script_path)
fdm.run_ic()
self.assertAlmostEqual(fdm.get_property_value('ic/vc-kts'),
VCAS, delta=1E-7)
self.assertAlmostEqual(fdm.get_property_value('velocities/vc-kts'),
VCAS, delta=1E-7)
示例14: testFunctionWithIndexedProps
def testFunctionWithIndexedProps(self):
tree = et.parse(self.sandbox.path_to_jsbsim_file('engine',
'eng_PegasusXc.xml'))
# Define the function starter-max-power-W as a 'post' function
root = tree.getroot()
startPowFunc_tag = root.find("function/[@name='propulsion/engine[#]/starter-max-power-W']")
startPowFunc_tag.attrib['type']='post'
tree.write('eng_PegasusXc.xml')
# Copy the propeller file.
shutil.copy(self.sandbox.path_to_jsbsim_file('engine', 'prop_deHavilland5000.xml'),
'.')
fdm = CreateFDM(self.sandbox)
fdm.set_engine_path('.')
fdm.load_script(self.sandbox.path_to_jsbsim_file('scripts',
'Short_S23_1.xml'))
fdm.run_ic()
pm = fdm.get_property_manager()
self.assertTrue(pm.hasNode('propulsion/engine[0]/starter-max-power-W'))
self.assertTrue(pm.hasNode('propulsion/engine[1]/starter-max-power-W'))
self.assertTrue(pm.hasNode('propulsion/engine[2]/starter-max-power-W'))
self.assertTrue(pm.hasNode('propulsion/engine[3]/starter-max-power-W'))
while fdm.run():
rpm = [fdm['propulsion/engine[0]/engine-rpm'],
fdm['propulsion/engine[1]/engine-rpm'],
fdm['propulsion/engine[2]/engine-rpm'],
fdm['propulsion/engine[3]/engine-rpm']]
for i in range(4):
maxPower = max(0.0, 1.0-rpm[i]/400)*498.941*0.10471976*rpm[i]
self.assertAlmostEqual(fdm['propulsion/engine[%d]/starter-max-power-W' % (i,)],
maxPower)
示例15: test_output_from_file
def test_output_from_file(self):
tree = et.parse(self.sandbox.elude(self.script_path))
output_tag = et.SubElement(tree.getroot(), 'output')
output_tag.attrib['file'] = self.sandbox.elude(self.sandbox.path_to_jsbsim_file('tests', 'output.xml'))
tree.write(self.sandbox('c1722_0.xml'))
fdm = CreateFDM(self.sandbox)
fdm.load_script('c1722_0.xml')
fdm.run_ic()
ExecuteUntil(fdm, 10.)
self.assertTrue(self.sandbox.exists('output.csv'),
msg="The file 'output.csv' has not been created")