本文整理汇总了Python中JSBSim_utils.SandBox.erase方法的典型用法代码示例。如果您正苦于以下问题:Python SandBox.erase方法的具体用法?Python SandBox.erase怎么用?Python SandBox.erase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSBSim_utils.SandBox
的用法示例。
在下文中一共展示了SandBox.erase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CheckScripts
# 需要导入模块: from JSBSim_utils import SandBox [as 别名]
# 或者: from JSBSim_utils.SandBox import erase [as 别名]
class CheckScripts(unittest.TestCase):
def setUp(self):
self.sandbox = SandBox()
self.scripts = 0
def tearDown(self):
print "Tested %g scripts" % (self.scripts,)
self.sandbox.erase()
def testScripts(self):
script_path = self.sandbox.path_to_jsbsim_file('scripts')
for f in os.listdir(self.sandbox.elude(script_path)):
fullpath = os.path.join(self.sandbox.elude(script_path), f)
# Does f contains a JSBSim script ?
if not CheckXMLFile(fullpath, 'runscript'):
continue
fdm = CreateFDM(self.sandbox)
self.assertTrue(fdm.load_script(os.path.join(script_path, f)),
msg="Failed to load script %s" % (fullpath,))
fdm.run_ic()
self.scripts += 1
del fdm
示例2: TestDebugLvl
# 需要导入模块: from JSBSim_utils import SandBox [as 别名]
# 或者: from JSBSim_utils.SandBox import erase [as 别名]
class TestDebugLvl(unittest.TestCase):
def setUp(self):
self.sandbox = SandBox('check_cases', 'orbit')
def tearDown(self):
self.sandbox.erase()
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))
示例3: TestGustReset
# 需要导入模块: from JSBSim_utils import SandBox [as 别名]
# 或者: from JSBSim_utils.SandBox import erase [as 别名]
class TestGustReset(unittest.TestCase):
def setUp(self):
self.sandbox = SandBox()
def tearDown(self):
self.sandbox.erase()
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))
示例4: TestScriptOutput
# 需要导入模块: from JSBSim_utils import SandBox [as 别名]
# 或者: from JSBSim_utils.SandBox import erase [as 别名]
class TestScriptOutput(unittest.TestCase):
def setUp(self):
self.sandbox = SandBox()
self.script_path = self.sandbox.path_to_jsbsim_file('scripts',
'c1722.xml')
def tearDown(self):
self.sandbox.erase()
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'")
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")
def test_output(self):
tree = et.parse(self.sandbox.elude(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(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_tag.attrib['name']),
msg="The file 'output.csv' has not been created")
orig = pd.read_csv(self.sandbox('JSBout172B.csv'))
test = pd.read_csv(self.sandbox('test.csv'))
self.assertEqual(np.max(orig['Time']-test['Time']), 0.0)
pname = '/fdm/jsbsim/' + property_tag.text
self.assertEqual(np.max(orig[pname]-test[pname]), 0.0)
示例5: TestCosineGust
# 需要导入模块: from JSBSim_utils import SandBox [as 别名]
# 或者: from JSBSim_utils.SandBox import erase [as 别名]
class TestCosineGust(unittest.TestCase):
def setUp(self):
self.sandbox = SandBox()
def tearDown(self):
self.sandbox.erase()
def testMagnitude(self):
fdm = CreateFDM(self.sandbox)
fdm.load_script(self.sandbox.path_to_jsbsim_file('scripts',
'c172_cruise_8K.xml'))
fdm.run_ic()
t = 0.0
startup_duration = 5.0
steady_duration = 1.0
end_duration = 5.0
start_time = 10.0
magnitude = 30.0
end_time = start_time + startup_duration + steady_duration + end_duration
while fdm.get_property_value('simulation/run_id') == 0:
fdm.run()
wn = fdm.get_property_value('atmosphere/total-wind-north-fps')
we = fdm.get_property_value('atmosphere/total-wind-east-fps')
wd = fdm.get_property_value('atmosphere/total-wind-down-fps')
if t >= start_time and t <= end_time:
wmag = math.sqrt(wn*wn + we*we + wd*wd)
t -= start_time
if t <= startup_duration:
self.assertAlmostEqual(0.5 * magnitude * (1.0 - math.cos(math.pi*t/startup_duration)),
wmag, delta=1E-3)
else:
t -= startup_duration
if t <= steady_duration:
self.assertAlmostEqual(magnitude, wmag, delta=1E-8)
else:
t -= steady_duration
if t <= end_duration:
self.assertAlmostEqual(0.5 * magnitude * (1.0 + math.cos(math.pi*t/end_duration)),
wmag, delta=1E-3)
t = fdm.get_property_value('simulation/sim-time-sec')
示例6: CheckTrim
# 需要导入模块: from JSBSim_utils import SandBox [as 别名]
# 或者: from JSBSim_utils.SandBox import erase [as 别名]
class CheckTrim(unittest.TestCase):
def setUp(self):
self.sandbox = SandBox()
def tearDown(self):
self.sandbox.erase()
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')
aircraft_path = self.sandbox.elude(self.sandbox.path_to_jsbsim_file('aircraft'))
fdm.load_ic(os.path.join(aircraft_path, '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)
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
示例7: CheckAircrafts
# 需要导入模块: from JSBSim_utils import SandBox [as 别名]
# 或者: from JSBSim_utils.SandBox import erase [as 别名]
class CheckAircrafts(unittest.TestCase):
def setUp(self):
self.sandbox = SandBox()
def tearDown(self):
self.sandbox.erase()
def testAircrafts(self):
aircraft_path = self.sandbox.elude(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, append_xml(d))
# 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))
break
del fdm
示例8: TestHoldDown
# 需要导入模块: from JSBSim_utils import SandBox [as 别名]
# 或者: from JSBSim_utils.SandBox import erase [as 别名]
class TestHoldDown(unittest.TestCase):
def setUp(self):
self.sandbox = SandBox()
def tearDown(self):
self.sandbox.erase()
def test_static_hold_down(self):
fdm = CreateFDM(self.sandbox)
fdm.load_model('J246')
aircraft_path = self.sandbox.elude(self.sandbox.path_to_jsbsim_file('aircraft'))
fdm.load_ic(os.path.join(aircraft_path, 'J246', 'LC39'), False)
fdm.set_property_value('forces/hold-down', 1.0)
fdm.run_ic()
h0 = fdm.get_property_value('position/h-sl-ft')
t = 0.0
while t < 420.0:
fdm.run()
t = fdm.get_property_value('simulation/sim-time-sec')
self.assertAlmostEqual(fdm.get_property_value('position/h-sl-ft'),
h0, delta=1E-5)
示例9: TestOrbitCheckCase
# 需要导入模块: from JSBSim_utils import SandBox [as 别名]
# 或者: from JSBSim_utils.SandBox import erase [as 别名]
class TestOrbitCheckCase(unittest.TestCase):
def setUp(self):
self.sandbox = SandBox('check_cases', 'orbit')
def tearDown(self):
self.sandbox.erase()
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))
示例10: CheckMomentsUpdate
# 需要导入模块: from JSBSim_utils import SandBox [as 别名]
# 或者: from JSBSim_utils.SandBox import erase [as 别名]
class CheckMomentsUpdate(unittest.TestCase):
def setUp(self):
self.sandbox = SandBox()
def tearDown(self):
self.sandbox.erase()
def test_moments_update(self):
script_path = self.sandbox.path_to_jsbsim_file('scripts', 'weather-balloon.xml')
fdm = CreateFDM(self.sandbox)
fdm.load_script(script_path)
fdm.run_ic()
# Moves the radio sonde to modify the CG location
fdm.set_property_value('inertia/pointmass-location-X-inches', 5.0)
# Check that the moment is immediately updated accordingly
fdm.run()
Fbz = fdm.get_property_value('forces/fbz-buoyancy-lbs')
CGx = fdm.get_property_value('inertia/cg-x-in') / 12.0 # Converts from in to ft
Mby = fdm.get_property_value('moments/m-buoyancy-lbsft')
self.assertTrue(abs(Fbz * CGx + Mby) < 1E-7,
msg="Fbz*CGx = %f and Mby = %f do not match" % (-Fbz*CGx, Mby))
示例11: TestPitotAngle
# 需要导入模块: from JSBSim_utils import SandBox [as 别名]
# 或者: from JSBSim_utils.SandBox import erase [as 别名]
class TestPitotAngle(unittest.TestCase):
def setUp(self):
self.sandbox = SandBox()
def tearDown(self):
self.sandbox.erase()
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)
def test_pitot_angle(self):
script_name = 'ball_chute.xml'
script_path = self.sandbox.path_to_jsbsim_file('scripts', script_name)
# Add a Pitot angle to the Cessna 172
tree, aircraft_name, path_to_jsbsim_aircrafts = CopyAircraftDef(script_path, self.sandbox)
root = tree.getroot()
metrics_tag = root.find('./metrics')
pitot_tag = et.SubElement(metrics_tag, 'pitot_angle')
pitot_tag.attrib['unit'] = 'DEG'
pitot_tag.text = '5.0'
contact_tag = root.find('./ground_reactions/contact')
contact_tag.attrib['type'] = 'STRUCTURE'
tree.write(self.sandbox('aircraft', aircraft_name,
aircraft_name+'.xml'))
fdm = CreateFDM(self.sandbox)
fdm.set_aircraft_path('aircraft')
fdm.load_model('ball')
pitot_angle = float(pitot_tag.text) * math.pi / 180.
weight = fdm.get_property_value('inertia/weight-lbs')
spring_tag = contact_tag.find('./spring_coeff')
spring_coeff = float(spring_tag.text)
print "Weight=%d Spring=%d" % (weight, spring_coeff)
fdm.set_property_value('ic/h-sl-ft', weight / spring_coeff)
fdm.set_property_value('forces/hold-down', 1.0)
fdm.run_ic()
ExecuteUntil(fdm, 10.)
for i in xrange(36):
for j in xrange(-9, 10):
angle = math.pi * i / 18.0
angle2 = math.pi * j / 18.0
ca2 = math.cos(angle2)
fdm.set_property_value('atmosphere/wind-north-fps',
10. * math.cos(angle) * ca2)
fdm.set_property_value('atmosphere/wind-east-fps',
10. * math.sin(angle) * ca2)
fdm.set_property_value('atmosphere/wind-down-fps',
10. * math.sin(angle2))
fdm.run()
vg = fdm.get_property_value('velocities/vg-fps')
self.assertAlmostEqual(vg, 0.0, delta=1E-7)
vt = fdm.get_property_value('velocities/vt-fps')
self.assertAlmostEqual(vt, 10., delta=1E-7)
mach = vt / fdm.get_property_value('atmosphere/a-fps')
P = fdm.get_property_value('atmosphere/P-psf')
pt = P * math.pow(1+0.2*mach*mach, 3.5)
psl = fdm.get_property_value('atmosphere/P-sl-psf')
rhosl = fdm.get_property_value('atmosphere/rho-sl-slugs_ft3')
A = math.pow((pt-P)/psl+1.0, 1.0/3.5)
alpha = fdm.get_property_value('aero/alpha-rad')
beta = fdm.get_property_value('aero/beta-rad')
#.........这里部分代码省略.........
示例12: TestAccelerometer
# 需要导入模块: from JSBSim_utils import SandBox [as 别名]
# 或者: from JSBSim_utils.SandBox import erase [as 别名]
class TestAccelerometer(unittest.TestCase):
def setUp(self):
self.sandbox = SandBox()
def tearDown(self):
self.sandbox.erase()
def AddAccelerometersToAircraft(self, script_path):
tree, aircraft_name, b = CopyAircraftDef(script_path, self.sandbox)
system_tag = et.SubElement(tree.getroot(), 'system')
system_tag.attrib['file'] = 'accelerometers'
tree.write(self.sandbox('aircraft', aircraft_name, aircraft_name+'.xml'))
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(self.sandbox.elude(script_path))
run_tag = tree.getroot().find('./run')
run_tag.attrib['dt'] = '0.1'
tree.write(self.sandbox(script_name))
fdm = CreateFDM(self.sandbox)
fdm.set_aircraft_path('aircraft')
fdm.load_script(script_name)
# Switch the accel on
fdm.set_property_value('fcs/accelerometer/on', 1.0)
fdm.run_ic()
while fdm.run():
self.assertAlmostEqual(fdm.get_property_value('fcs/accelerometer/X'),
0.0, delta=1E-8)
self.assertAlmostEqual(fdm.get_property_value('fcs/accelerometer/Y'),
0.0, delta=1E-8)
self.assertAlmostEqual(fdm.get_property_value('fcs/accelerometer/Z'),
0.0, delta=1E-8)
self.assertAlmostEqual(fdm.get_property_value('accelerations/a-pilot-x-ft_sec2'),
0.0, delta=1E-8)
self.assertAlmostEqual(fdm.get_property_value('accelerations/a-pilot-y-ft_sec2'),
0.0, delta=1E-8)
self.assertAlmostEqual(fdm.get_property_value('accelerations/a-pilot-z-ft_sec2'),
0.0, delta=1E-8)
del fdm
def testOnGround(self):
script_name = 'c1721.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_script(script_path)
# Switch the accel on
fdm.set_property_value('fcs/accelerometer/on', 1.0)
# Use the standard gravity (i.e. GM/r^2)
fdm.set_property_value('simulation/gravity-model', 0)
# Simplifies the transformation to compare the accelerometer with the
# gravity
fdm.set_property_value('ic/psi-true-rad', 0.0)
fdm.run_ic()
for i in xrange(500):
fdm.run()
ax = fdm.get_property_value('accelerations/udot-ft_sec2')
ay = fdm.get_property_value('accelerations/vdot-ft_sec2')
az = fdm.get_property_value('accelerations/wdot-ft_sec2')
g = fdm.get_property_value('accelerations/gravity-ft_sec2')
theta = fdm.get_property_value('attitude/theta-rad')
# There is a lag of one time step between the computations of the
# accelerations and the update of the accelerometer
fdm.run()
fax = fdm.get_property_value('fcs/accelerometer/X')
fay = fdm.get_property_value('fcs/accelerometer/Y')
faz = fdm.get_property_value('fcs/accelerometer/Z')
fax -= ax
faz -= az
self.assertAlmostEqual(fay, 0.0, delta=1E-6)
self.assertAlmostEqual(fax / (g * math.sin(theta)), 1.0, delta=1E-5)
self.assertAlmostEqual(faz / (g * math.cos(theta)), -1.0, delta=1E-7)
del fdm
def testSteadyFlight(self):
script_name = 'c1722.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_script(script_path)
# Switch the accel on
#.........这里部分代码省略.........
示例13: TestFuelTanksInertia
# 需要导入模块: from JSBSim_utils import SandBox [as 别名]
# 或者: from JSBSim_utils.SandBox import erase [as 别名]
class TestFuelTanksInertia(unittest.TestCase):
def setUp(self):
self.sandbox = SandBox()
def tearDown(self):
self.sandbox.erase()
def test_fuel_tanks_inertia(self):
script_path = self.sandbox.path_to_jsbsim_file('scripts', 'c1722.xml')
# The aircraft c172x does not contain an <inertia_factor> tag so we need
# to add one.
tree, aircraft_name, b = CopyAircraftDef(script_path, self.sandbox)
tank_tag = tree.getroot().find('./propulsion/tank')
inertia_factor = et.SubElement(tank_tag, 'inertia_factor')
inertia_factor.text = '1.0'
tree.write(self.sandbox('aircraft', aircraft_name, aircraft_name+'.xml'))
fdm = CreateFDM(self.sandbox)
fdm.set_aircraft_path('aircraft')
fdm.load_script(script_path)
fdm.run_ic()
contents0 = fdm.get_property_value('propulsion/tank/contents-lbs')
ixx0 = fdm.get_property_value('propulsion/tank/local-ixx-slug_ft2')
iyy0 = fdm.get_property_value('propulsion/tank/local-iyy-slug_ft2')
izz0 = fdm.get_property_value('propulsion/tank/local-izz-slug_ft2')
# Remove half of the tank contents and check that the inertias are
# updated accordingly
fdm.set_property_value('propulsion/tank/contents-lbs', 0.5*contents0)
contents = fdm.get_property_value('propulsion/tank/contents-lbs')
ixx = fdm.get_property_value('propulsion/tank/local-ixx-slug_ft2')
iyy = fdm.get_property_value('propulsion/tank/local-iyy-slug_ft2')
izz = fdm.get_property_value('propulsion/tank/local-izz-slug_ft2')
self.assertTrue(abs(contents-0.5*contents0) < 1E-7,
msg="The tank content (%f lbs) should be %f lbs" % (contents, 0.5*contents0))
self.assertTrue(abs(ixx-0.5*ixx0) < 1E-7,
msg="The tank inertia Ixx (%f slug*ft^2) should be %f slug*ft^2" % (ixx, 0.5*ixx0))
self.assertTrue(abs(iyy-0.5*iyy0) < 1E-7,
msg="The tank inertia Iyy (%f slug*ft^2) should be %f slug*ft^2" % (iyy, 0.5*iyy0))
self.assertTrue(abs(izz-0.5*izz0) < 1E-7,
msg="The tank inertia Izz (%f slug*ft^2) should be %f slug*ft^2" % (izz, 0.5*izz0))
# Execute the script and check that the fuel inertias have been updated
# along with the consumption.
ExecuteUntil(fdm, 200.0)
contents = fdm.get_property_value('propulsion/tank/contents-lbs')
ixx = fdm.get_property_value('propulsion/tank/local-ixx-slug_ft2')
iyy = fdm.get_property_value('propulsion/tank/local-iyy-slug_ft2')
izz = fdm.get_property_value('propulsion/tank/local-izz-slug_ft2')
contents_ratio = contents / contents0
ixx_ratio = ixx / ixx0
iyy_ratio = iyy / iyy0
izz_ratio = izz / izz0
self.assertTrue(abs(contents_ratio - ixx_ratio) < 1E-7,
msg="Ixx does not vary as the tank content does\nIxx ratio=%f\nContents ratio=%f" % (ixx_ratio, contents_ratio))
self.assertTrue(abs(contents_ratio - iyy_ratio) < 1E-7,
msg="Iyy does not vary as the tank content does\nIyy ratio=%f\nContents ratio=%f" % (iyy_ratio, contents_ratio))
self.assertTrue(abs(contents_ratio - izz_ratio) < 1E-7,
msg="Izz does not vary as the tank content does\nIzz ratio=%f\nContents ratio=%f" % (izz_ratio, contents_ratio))
示例14: TestSimTimeReset
# 需要导入模块: from JSBSim_utils import SandBox [as 别名]
# 或者: from JSBSim_utils.SandBox import erase [as 别名]
class TestSimTimeReset(unittest.TestCase):
def setUp(self):
self.sandbox = SandBox()
def tearDown(self):
self.sandbox.erase()
def test_no_script(self):
fdm = CreateFDM(self.sandbox)
aircraft_path = self.sandbox.path_to_jsbsim_file('aircraft')
fdm.set_aircraft_path(aircraft_path)
fdm.load_model('c172x')
aircraft_path = os.path.join(self.sandbox.elude(aircraft_path), 'c172x')
fdm.load_ic(os.path.join(aircraft_path, 'reset01.xml'), False)
fdm.run_ic()
self.assertEqual(fdm.get_property_value('simulation/sim-time-sec'), 0.0)
ExecuteUntil(fdm, 5.0)
t = fdm.get_property_value('simulation/sim-time-sec')
fdm.set_property_value('simulation/do_simple_trim', 1)
self.assertEqual(fdm.get_property_value('simulation/sim-time-sec'), t)
fdm.reset_to_initial_conditions(1)
self.assertEqual(fdm.get_property_value('simulation/sim-time-sec'), 0.0)
del fdm
def test_script_start_time_0(self):
script_name = 'ball_orbit.xml'
script_path = self.sandbox.path_to_jsbsim_file('scripts', script_name)
fdm = CreateFDM(self.sandbox)
fdm.load_script(script_path)
fdm.run_ic()
self.assertEqual(fdm.get_property_value('simulation/sim-time-sec'), 0.0)
ExecuteUntil(fdm, 5.0)
fdm.reset_to_initial_conditions(1)
self.assertEqual(fdm.get_property_value('simulation/sim-time-sec'), 0.0)
del fdm
def test_script_start_time(self):
script_name = 'ball_orbit.xml'
script_path = self.sandbox.path_to_jsbsim_file('scripts', script_name)
tree = et.parse(self.sandbox.elude(script_path))
run_tag = tree.getroot().find('./run')
run_tag.attrib['start'] = '1.2'
tree.write(self.sandbox(script_name))
fdm = CreateFDM(self.sandbox)
fdm.load_script(script_name)
fdm.run_ic()
self.assertEqual(fdm.get_property_value('simulation/sim-time-sec'), 1.2)
ExecuteUntil(fdm, 5.0)
fdm.reset_to_initial_conditions(1)
self.assertEqual(fdm.get_property_value('simulation/sim-time-sec'), 1.2)
del fdm
def test_script_no_start_time(self):
script_name = 'ball_orbit.xml'
script_path = self.sandbox.path_to_jsbsim_file('scripts', script_name)
tree = et.parse(self.sandbox.elude(script_path))
run_tag = tree.getroot().find('./run')
# Remove the parameter 'start' from the tag <run>
del run_tag.attrib['start']
tree.write(self.sandbox(script_name))
fdm = CreateFDM(self.sandbox)
fdm.load_script(script_name)
fdm.run_ic()
self.assertEqual(fdm.get_property_value('simulation/sim-time-sec'), 0.0)
ExecuteUntil(fdm, 5.0)
fdm.reset_to_initial_conditions(1)
self.assertEqual(fdm.get_property_value('simulation/sim-time-sec'), 0.0)
del fdm
示例15: CheckFGBug1503
# 需要导入模块: from JSBSim_utils import SandBox [as 别名]
# 或者: from JSBSim_utils.SandBox import erase [as 别名]
class CheckFGBug1503(unittest.TestCase):
def setUp(self):
self.sandbox = SandBox()
self.script_path = self.sandbox.path_to_jsbsim_file("scripts", "c1724.xml")
# Since we will alter the aircraft definition file, we need make a copy
# of it and of all the files it is refering to.
self.tree, self.aircraft_name, self.path_to_jsbsim_aircrafts = CopyAircraftDef(self.script_path, self.sandbox)
def tearDown(self):
self.sandbox.erase()
def ScriptExecution(self, fdm, time_limit=1e9):
fdm.load_script(self.script_path)
fdm.run_ic()
while fdm.run() and fdm.get_sim_time() < time_limit:
aileron_pos = fdm.get_property_value("fcs/left-aileron-pos-rad")
self.assertTrue(
aileron_pos == 0.0,
msg="Failed running the script %s at time step %f\nProperty fcs/left-aileron-pos-rad is non-zero (%f)"
% (self.script_path, fdm.get_sim_time(), aileron_pos),
)
def CheckRateValue(self, fdm, output_prop, rate_value):
aileron_course = []
t0 = fdm.get_sim_time()
while fdm.run() and fdm.get_sim_time() <= t0 + 1.0:
aileron_course += [(fdm.get_sim_time(), fdm.get_property_value(output_prop))]
# Thanks to a linear regression on the values, we can check that the
# value is following a slope equal to the rate limit. The correlation
# coefficient r_value is also checked to verify that the output is
# evolving linearly.
slope, intercept, r_value, p_value, std_err = stats.linregress(aileron_course)
self.assertTrue(
abs(slope - rate_value) < 1e-9 and abs(1.0 - abs(r_value)) < 1e-9, msg="The actuator rate is not linear"
)
def CheckRateLimit(self, input_prop, output_prop, incr_limit, decr_limit):
fdm = CreateFDM(self.sandbox)
fdm.set_aircraft_path("aircraft")
self.ScriptExecution(fdm, 1.0)
fdm.set_property_value(input_prop, 1.0)
self.CheckRateValue(fdm, output_prop, incr_limit)
fdm.set_property_value(input_prop, 0.0)
self.CheckRateValue(fdm, output_prop, decr_limit)
# 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
def test_regression_bug_1503(self):
# First, the execution time of the script c1724.xml is measured. It will
# be used as a reference to check if JSBSim hangs or not.
fdm = CreateFDM(self.sandbox)
start_time = time.time()
self.ScriptExecution(fdm)
exec_time = time.time() - start_time
del fdm
# Now the copy of the aircraft definition file will be altered: the
# <rate_limit> element is split in two: one with the 'decr' sense, the
# other with 'incr' sense.
actuator_element = self.tree.getroot().find("flight_control/channel/actuator//rate_limit/..")
rate_element = actuator_element.find("rate_limit")
rate_element.attrib["sense"] = "decr"
new_rate_element = et.SubElement(actuator_element, "rate_limit")
new_rate_element.attrib["sense"] = "incr"
new_rate_element.text = str(float(rate_element.text) * 0.5)
self.tree.write(self.sandbox("aircraft", self.aircraft_name, self.aircraft_name + ".xml"))
# Run the script with the modified aircraft
fdm = CreateFDM(self.sandbox)
fdm.set_aircraft_path("aircraft")
# A new process is created that launches the script. We wait for 10
# times the reference execution time for the script completion. Beyond
# that time, if the process is not completed, it is terminated and the
# test is failed.
p = Process(target=self.ScriptExecution, args=(fdm,))
p.start()
p.join(exec_time * 10.0) # Wait 10 times the reference time
alive = p.is_alive()
if alive:
p.terminate()
self.assertFalse(alive, msg="The script has hanged")
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
#.........这里部分代码省略.........