本文整理汇总了Python中JSBSim_utils.CreateFDM.hold方法的典型用法代码示例。如果您正苦于以下问题:Python CreateFDM.hold方法的具体用法?Python CreateFDM.hold怎么用?Python CreateFDM.hold使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSBSim_utils.CreateFDM
的用法示例。
在下文中一共展示了CreateFDM.hold方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_no_input
# 需要导入模块: from JSBSim_utils import CreateFDM [as 别名]
# 或者: from JSBSim_utils.CreateFDM import hold [as 别名]
def test_no_input(self):
fdm = CreateFDM(self.sandbox)
fdm.load_script(self.script_path)
fdm.run_ic()
fdm.hold()
with self.assertRaises(socket.error):
TelnetInterface(fdm, 5., 1137)
示例2: test_script_input
# 需要导入模块: from JSBSim_utils import CreateFDM [as 别名]
# 或者: from JSBSim_utils.CreateFDM import hold [as 别名]
def test_script_input(self):
tree = et.parse(self.sandbox.elude(self.script_path))
input_tag = et.SubElement(tree.getroot(), 'input')
input_tag.attrib['port'] = '1138'
tree.write(self.sandbox('c1722_1.xml'))
fdm = CreateFDM(self.sandbox)
fdm.load_script('c1722_1.xml')
fdm.run_ic()
fdm.hold()
tn = TelnetInterface(fdm, 5., 1138)
self.sanityCheck(tn)
示例3: test_input_socket
# 需要导入模块: from JSBSim_utils import CreateFDM [as 别名]
# 或者: from JSBSim_utils.CreateFDM import hold [as 别名]
def test_input_socket(self):
# The aircraft c172x does not contain an <input> tag so we need
# to add one.
tree, aircraft_name, b = CopyAircraftDef(self.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'))
fdm = CreateFDM(self.sandbox)
fdm.set_aircraft_path('aircraft')
fdm.load_script(self.script_path)
fdm.run_ic()
fdm.hold()
tn = TelnetInterface(fdm, 5., 1137)
self.sanityCheck(tn)
# Check the aircraft name and its version
msg = string.split(tn.sendCommand("info"), '\n')
self.assertEqual(string.strip(string.split(msg[2], ':')[1]),
string.strip(self.root.attrib['name']))
self.assertEqual(string.strip(string.split(msg[1], ':')[1]),
string.strip(self.root.attrib['version']))
# Check that the simulation time is 0.0
self.assertEqual(float(string.strip(string.split(msg[3], ':')[1])), 0.0)
self.assertEqual(tn.getSimTime(), 0.0)
self.assertEqual(tn.getPropertyValue("simulation/sim-time-sec"), 0.0)
# Check that 'iterate' iterates the correct number of times
tn.sendCommand("iterate 19")
self.assertEqual(tn.getSimTime(), 19. * tn.getDeltaT())
self.assertAlmostEqual(tn.getPropertyValue("simulation/sim-time-sec"),
tn.getSimTime(), delta=1E-5)
# Wait a little bit and make sure that the simulation time has not
# changed meanwhile thus confirming that the simulation is on hold.
tn.wait(0.1)
self.assertEqual(tn.getSimTime(), 19. * tn.getDeltaT())
self.assertAlmostEqual(tn.getPropertyValue("simulation/sim-time-sec"),
tn.getSimTime(), delta=1E-5)
# Modify the tank[0] contents via the "send" command
half_contents = 0.5 * tn.getPropertyValue("propulsion/tank/contents-lbs")
tn.sendCommand("set propulsion/tank/contents-lbs " + str(half_contents))
self.assertEqual(tn.getPropertyValue("propulsion/tank/contents-lbs"),
half_contents)
# Check the resume/hold commands
tn.setRealTime(True)
t = tn.getSimTime()
tn.sendCommand("resume")
tn.wait(0.5)
self.assertNotEqual(tn.getSimTime(), t)
tn.wait(0.5)
tn.sendCommand("hold")
tn.setRealTime(False)
t = tn.getSimTime()
self.assertAlmostEqual(tn.getPropertyValue("simulation/sim-time-sec"),
t, delta=1E-5)
# Wait a little bit and make sure that the simulation time has not
# changed meanwhile thus confirming that the simulation is on hold.
tn.wait(0.1)
self.assertEqual(tn.getSimTime(), t)
self.assertAlmostEqual(tn.getPropertyValue("simulation/sim-time-sec"),
t, delta=1E-5)
示例4: TestInputSocket
# 需要导入模块: from JSBSim_utils import CreateFDM [as 别名]
# 或者: from JSBSim_utils.CreateFDM import hold [as 别名]
class TestInputSocket(unittest.TestCase):
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()
def tearDown(self):
self.tn.close()
self.thread.quit = True
self.thread.join()
self.sandbox.erase()
def sendCommand(self, command):
self.cond.acquire()
self.tn.write(command+"\n")
# Wait for a time step to be executed before reading the output from telnet
self.cond.wait()
msg = self.tn.read_very_eager()
self.cond.release()
self.thread.join(0.1)
return msg
def getSimTime(self):
self.cond.acquire()
self.cond.wait()
t = self.fdm.get_sim_time()
self.cond.release()
return t
def getDeltaT(self):
self.cond.acquire()
self.cond.wait()
dt = self.fdm.get_delta_t()
self.cond.release()
return dt
def getPropertyValue(self, property):
msg = string.split(self.sendCommand("get "+property),'\n')
return float(string.split(msg[0], '=')[1])
def test_input_socket(self):
# Check that the connection has been established
self.cond.acquire()
self.cond.wait()
out = self.tn.read_very_eager()
self.cond.release()
self.assertTrue(string.split(out, '\n')[0] == 'Connected to JSBSim server',
msg="Not connected to the JSBSim server.\nGot message '%s' instead" % (out,))
# Check that "help" returns the minimum set of commands that will be
# tested
self.assertEqual(sorted(map(lambda x : string.strip(string.split(x, '{')[0]),
string.split(self.sendCommand("help"), '\n')[2:-2])),
['get', 'help', 'hold', 'info', 'iterate', 'quit', 'resume', 'set'])
# Check the aircraft name and its version
msg = string.split(self.sendCommand("info"), '\n')
self.assertEqual(string.strip(string.split(msg[2], ':')[1]),
string.strip(self.root.attrib['name']))
self.assertEqual(string.strip(string.split(msg[1], ':')[1]),
string.strip(self.root.attrib['version']))
# Check that the simulation time is 0.0
self.assertEqual(float(string.strip(string.split(msg[3], ':')[1])), 0.0)
self.assertEqual(self.getSimTime(), 0.0)
self.assertEqual(self.getPropertyValue("simulation/sim-time-sec"), 0.0)
# Check that 'iterate' iterates the correct number of times
self.sendCommand("iterate 19")
self.assertEqual(self.getSimTime(), 19. * self.getDeltaT())
self.assertAlmostEqual(self.getPropertyValue("simulation/sim-time-sec"),
self.getSimTime(), delta=1E-5)
# Wait a little bit and make sure that the simulation time has not
# changed meanwhile thus confirming that the simulation is on hold.
self.thread.join(0.1)
#.........这里部分代码省略.........