本文整理汇总了Python中JSBSim_utils.CreateFDM.get_delta_t方法的典型用法代码示例。如果您正苦于以下问题:Python CreateFDM.get_delta_t方法的具体用法?Python CreateFDM.get_delta_t怎么用?Python CreateFDM.get_delta_t使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSBSim_utils.CreateFDM
的用法示例。
在下文中一共展示了CreateFDM.get_delta_t方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestInputSocket
# 需要导入模块: from JSBSim_utils import CreateFDM [as 别名]
# 或者: from JSBSim_utils.CreateFDM import get_delta_t [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)
#.........这里部分代码省略.........