本文整理汇总了Python中JSBSim_utils.CreateFDM.run_ic方法的典型用法代码示例。如果您正苦于以下问题:Python CreateFDM.run_ic方法的具体用法?Python CreateFDM.run_ic怎么用?Python CreateFDM.run_ic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSBSim_utils.CreateFDM
的用法示例。
在下文中一共展示了CreateFDM.run_ic方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_trim_on_ground
# 需要导入模块: from JSBSim_utils import CreateFDM [as 别名]
# 或者: from JSBSim_utils.CreateFDM import run_ic [as 别名]
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: test_hold_down_with_gnd_reactions
# 需要导入模块: from JSBSim_utils import CreateFDM [as 别名]
# 或者: from JSBSim_utils.CreateFDM import run_ic [as 别名]
def test_hold_down_with_gnd_reactions(self):
fdm = CreateFDM(self.sandbox)
fdm.load_script(self.sandbox.path_to_jsbsim_file('scripts',
'c1721.xml'))
fdm.run_ic()
ExecuteUntil(fdm, 0.25)
fdm['forces/hold-down'] = 1.0
h0 = fdm['position/h-sl-ft']
pitch = fdm['attitude/pitch-rad']
roll = fdm['attitude/roll-rad']
heading = fdm['attitude/heading-true-rad']
while fdm['simulation/sim-time-sec'] < 2.0:
fdm.run()
self.assertAlmostEqual(fdm['accelerations/pdot-rad_sec2'], 0.0)
self.assertAlmostEqual(fdm['accelerations/qdot-rad_sec2'], 0.0)
self.assertAlmostEqual(fdm['accelerations/rdot-rad_sec2'], 0.0)
self.assertAlmostEqual(fdm['accelerations/udot-ft_sec2'], 0.0)
self.assertAlmostEqual(fdm['accelerations/vdot-ft_sec2'], 0.0)
self.assertAlmostEqual(fdm['accelerations/wdot-ft_sec2'], 0.0)
self.assertAlmostEqual(fdm['position/h-sl-ft'], h0, delta=1E-6)
self.assertAlmostEqual(fdm['attitude/pitch-rad'], pitch)
self.assertAlmostEqual(fdm['attitude/roll-rad'], roll)
self.assertAlmostEqual(fdm['attitude/heading-true-rad'], heading)
示例3: testAircrafts
# 需要导入模块: from JSBSim_utils import CreateFDM [as 别名]
# 或者: from JSBSim_utils.CreateFDM import run_ic [as 别名]
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
示例4: test_gust_reset
# 需要导入模块: from JSBSim_utils import CreateFDM [as 别名]
# 或者: from JSBSim_utils.CreateFDM import run_ic [as 别名]
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())
示例5: test_output
# 需要导入模块: from JSBSim_utils import CreateFDM [as 别名]
# 或者: from JSBSim_utils.CreateFDM import run_ic [as 别名]
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())
示例6: test_steer_with_fcs
# 需要导入模块: from JSBSim_utils import CreateFDM [as 别名]
# 或者: from JSBSim_utils.CreateFDM import run_ic [as 别名]
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)
示例7: test_FG_reset
# 需要导入模块: from JSBSim_utils import CreateFDM [as 别名]
# 或者: from JSBSim_utils.CreateFDM import run_ic [as 别名]
def test_FG_reset(self):
# This test reproduces how FlightGear resets. The important thing is
# that the property manager is managed by FlightGear. So it is not
# deleted when the JSBSim instance is killed.
pm = jsbsim.FGPropertyManager(new_instance=True)
self.assertFalse(pm.hasNode('fdm/jsbsim/ic/lat-geod-deg'))
fdm = CreateFDM(self.sandbox, pm)
fdm.load_model('ball')
self.assertAlmostEqual(fdm['ic/lat-geod-deg'], 0.0)
fdm['ic/lat-geod-deg'] = 45.0
fdm.run_ic()
del fdm
# Check that the property ic/lat-geod-deg has survived the JSBSim
# instance.
self.assertTrue(pm.hasNode('fdm/jsbsim/ic/lat-geod-deg'))
# Re-use the property manager just as FlightGear does.
fdm = CreateFDM(self.sandbox, pm)
self.assertAlmostEqual(fdm['ic/lat-geod-deg'], 45.0)
del fdm
示例8: testKinematicTiming
# 需要导入模块: from JSBSim_utils import CreateFDM [as 别名]
# 或者: from JSBSim_utils.CreateFDM import run_ic [as 别名]
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']
示例9: test_CAS_ic
# 需要导入模块: from JSBSim_utils import CreateFDM [as 别名]
# 或者: from JSBSim_utils.CreateFDM import run_ic [as 别名]
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)
self.addPitotTube(tree.getroot(), 5.0)
tree.write(self.sandbox('aircraft', aircraft_name,
aircraft_name+'.xml'))
# Read the CAS specified in the IC file
tree = et.parse(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 # Converts in kts
# 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['ic/vc-kts'], VCAS, delta=1E-7)
self.assertAlmostEqual(fdm['velocities/vc-kts'], VCAS, delta=1E-7)
示例10: testOrbit
# 需要导入模块: from JSBSim_utils import CreateFDM [as 别名]
# 或者: from JSBSim_utils.CreateFDM import run_ic [as 别名]
def testOrbit(self):
script_name = 'ball_orbit.xml'
script_path = self.sandbox.path_to_jsbsim_file('scripts', script_name)
self.AddAccelerometersToAircraft(script_path)
# The time step is too small in ball_orbit so let's increase it to 0.1s
# for a quicker run
tree = et.parse(script_path)
run_tag = tree.getroot().find('./run')
run_tag.attrib['dt'] = '0.1'
tree.write(script_name)
fdm = CreateFDM(self.sandbox)
fdm.set_aircraft_path('aircraft')
fdm.load_script(script_name)
# Switch the accel on
fdm['fcs/accelerometer/on'] = 1.0
fdm.run_ic()
while fdm.run():
self.assertAlmostEqual(fdm['fcs/accelerometer/X'], 0.0, delta=1E-8)
self.assertAlmostEqual(fdm['fcs/accelerometer/Y'], 0.0, delta=1E-8)
self.assertAlmostEqual(fdm['fcs/accelerometer/Z'], 0.0, delta=1E-8)
self.assertAlmostEqual(fdm['accelerations/a-pilot-x-ft_sec2'], 0.0,
delta=1E-8)
self.assertAlmostEqual(fdm['accelerations/a-pilot-y-ft_sec2'], 0.0,
delta=1E-8)
self.assertAlmostEqual(fdm['accelerations/a-pilot-z-ft_sec2'], 0.0,
delta=1E-8)
del fdm
示例11: testFunctionWithIndexedProps
# 需要导入模块: from JSBSim_utils import CreateFDM [as 别名]
# 或者: from JSBSim_utils.CreateFDM import run_ic [as 别名]
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)
示例12: testDebugLvl
# 需要导入模块: from JSBSim_utils import CreateFDM [as 别名]
# 或者: from JSBSim_utils.CreateFDM import run_ic [as 别名]
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())
示例13: LoadScript
# 需要导入模块: from JSBSim_utils import CreateFDM [as 别名]
# 或者: from JSBSim_utils.CreateFDM import run_ic [as 别名]
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)
示例14: Compare
# 需要导入模块: from JSBSim_utils import CreateFDM [as 别名]
# 或者: from JSBSim_utils.CreateFDM import run_ic [as 别名]
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())
示例15: test_direct_steer
# 需要导入模块: from JSBSim_utils import CreateFDM [as 别名]
# 或者: from JSBSim_utils.CreateFDM import run_ic [as 别名]
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)