当前位置: 首页>>代码示例>>Python>>正文


Python JSBSim_utils.SandBox类代码示例

本文整理汇总了Python中JSBSim_utils.SandBox的典型用法代码示例。如果您正苦于以下问题:Python SandBox类的具体用法?Python SandBox怎么用?Python SandBox使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SandBox类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestDebugLvl

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))
开发者ID:davidsummers,项目名称:jsbsim,代码行数:30,代码来源:CheckDebugLvl.py

示例2: TestGustReset

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))
开发者ID:ToninoTarsi,项目名称:jsbsim,代码行数:28,代码来源:TestGustReset.py

示例3: CheckScripts

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
开发者ID:davidsummers,项目名称:jsbsim,代码行数:25,代码来源:CheckScripts.py

示例4: TestScriptOutput

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)
开发者ID:davidsummers,项目名称:jsbsim,代码行数:54,代码来源:TestScriptOutput.py

示例5: setUp

    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)
开发者ID:shield09,项目名称:jsbsim,代码行数:7,代码来源:CheckFGBug1503.py

示例6: setUp

    def setUp(self):
        self.sandbox = SandBox()

        self.fdm = CreateFDM(self.sandbox)
        self.script_path = self.sandbox.path_to_jsbsim_file("scripts", "c1722.xml")

        # Read the time step 'dt' from the script file
        self.tree = et.parse(self.sandbox.elude(self.script_path))
        root = self.tree.getroot()
        use_tag = root.find("./use")
        aircraft_name = use_tag.attrib["aircraft"]
        self.run_tag = root.find("./run")
        self.dt = float(self.run_tag.attrib["dt"])

        # Read the date at which the trim will be run
        event_tags = root.findall("./run/event")
        for event in event_tags:
            if event.attrib["name"] == "Trim":
                cond_tag = event.find("./condition")
                self.trim_date = float(string.split(cond_tag.text)[-1])
                break

        # Read the output rate and the output file from the aircraft file
        aircraft_path = self.sandbox.path_to_jsbsim_file("aircraft", aircraft_name, append_xml(aircraft_name))
        tree = et.parse(self.sandbox.elude(aircraft_path))
        output_tag = tree.getroot().find("./output")
        self.output_file = self.sandbox(output_tag.attrib["name"])
        self.rateHz = float(output_tag.attrib["rate"])
        self.rate = int(1.0 / (self.rateHz * self.dt))
开发者ID:shield09,项目名称:jsbsim,代码行数:29,代码来源:CheckOutputRate.py

示例7: setUp

    def setUp(self):
        self.sandbox = SandBox()
        script_path = self.sandbox.path_to_jsbsim_file('scripts', 'c1722.xml')

        # The aircraft c172x does not contain an <input> tag so we need
        # to add one.
        tree, aircraft_name, b = CopyAircraftDef(script_path, self.sandbox)
        self.root = tree.getroot()
        input_tag = et.SubElement(self.root, 'input')
        input_tag.attrib['port']='1137'
        tree.write(self.sandbox('aircraft', aircraft_name,  aircraft_name+'.xml'))

        self.fdm = CreateFDM(self.sandbox)
        self.fdm.set_aircraft_path('aircraft')
        self.fdm.load_script(script_path)
        self.fdm.run_ic()
        self.fdm.hold()

        # Execute JSBSim in a separate thread
        self.cond = threading.Condition()
        self.thread = JSBSimThread(self.fdm, self.cond, 5., time.time())
        self.thread.start()

        # Wait for the thread to be started before connecting a telnet session
        self.cond.acquire()
        self.cond.wait()
        self.tn = telnetlib.Telnet("localhost", 1137)
        self.cond.release()
开发者ID:deutschlion,项目名称:JSBSim.js,代码行数:28,代码来源:TestInputSocket.py

示例8: TestCosineGust

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')
开发者ID:davidsummers,项目名称:jsbsim,代码行数:46,代码来源:TestCosineGust.py

示例9: CheckTrim

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
开发者ID:shield09,项目名称:jsbsim,代码行数:45,代码来源:CheckTrim.py

示例10: CheckAircrafts

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
开发者ID:davidsummers,项目名称:jsbsim,代码行数:42,代码来源:CheckAircrafts.py

示例11: TestHoldDown

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)
开发者ID:shield09,项目名称:jsbsim,代码行数:22,代码来源:TestHoldDown.py

示例12: TestOrbitCheckCase

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))
开发者ID:davidsummers,项目名称:jsbsim,代码行数:23,代码来源:RunCheckCases.py

示例13: CheckMomentsUpdate

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))
开发者ID:ToninoTarsi,项目名称:jsbsim,代码行数:24,代码来源:CheckMomentsUpdate.py

示例14: ResetOutputFiles

class ResetOutputFiles(unittest.TestCase):
    def setUp(self):
        self.sandbox = SandBox()

    def tearDown(self):
        self.sandbox.erase()

    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'),
#.........这里部分代码省略.........
开发者ID:davidsummers,项目名称:jsbsim,代码行数:101,代码来源:ResetOutputFiles.py

示例15: ScriptExecution

import os, time, sys, string
import xml.etree.ElementTree as et
from multiprocessing import Process
from scipy import stats
from JSBSim_utils import SandBox, CreateFDM, append_xml, CopyAircraftDef

def ScriptExecution(fdm, script_path, time_limit = 1E+9):
    fdm.load_script(script_path)
    fdm.run_ic()

    while fdm.run() and fdm.get_sim_time() < time_limit:
        if fdm.get_property_value('fcs/left-aileron-pos-rad') != 0.0:
            sys.exit(-1)

sandbox = SandBox()

# 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.
script_path = sandbox.path_to_jsbsim_file('scripts', 'c1724.xml')
fdm = CreateFDM(sandbox)
start_time = time.time()
ScriptExecution(fdm, script_path)
exec_time = time.time() - start_time

# Since we will alter the aircraft definition file, we need make a copy of it
# and all the files it is refering to.

tree, aircraft_name, path_to_jsbsim_aircrafts = CopyAircraftDef(script_path, sandbox)

# Now the copy of the aircraft definition file will be altered: the <rate_limit>
开发者ID:ToninoTarsi,项目名称:jsbsim,代码行数:30,代码来源:CheckFGBug1503.py


注:本文中的JSBSim_utils.SandBox类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。