From: mfranz Date: Sun, 29 Oct 2006 12:34:26 +0000 (+0000) Subject: George PATTERSON: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1d15a9272b962f32c07f22f9ee56d014fffa2930;p=flightgear.git George PATTERSON: "Flightgear.py - Added the procedures view_next and view_prev demo.py - altered the wait five seconds to the new property path and allowed for the script to be started after five seconds of simulation file (/sim/time/elapsed-sec). - the section of code was changed to a pythonism as python does not support do-while loops, instead you break out of a continuous loop. - Commented out the fg.wait_for_prop_eq() method as I haven't rewritten that part of the code yet. Not sure of the best way to do that. Those lines may not be necessary any more." mf: removed trailing spaces; I updated the pyc, too, but I really think it shouldn't be in CVS at all.(?) --- diff --git a/scripts/python/FlightGear.py b/scripts/python/FlightGear.py index 9b71d57da..26afbe804 100644 --- a/scripts/python/FlightGear.py +++ b/scripts/python/FlightGear.py @@ -100,7 +100,7 @@ class FlightGear: except socket.error, msg: self.telnet = None raise socket.error, msg - + def __del__(self): # Ensure telnet connection is closed cleanly. self.quit(); @@ -130,7 +130,7 @@ class FlightGear: return 0 else: return value - + def __setitem__(self, key, value): """Set a FlightGear property value.""" self.telnet.set( key, value ) @@ -140,3 +140,12 @@ class FlightGear: if self.telnet: self.telnet.quit() self.telnet = None + + def view_next(self): + #move to next view + self.telnet.set( "/command/view/next", "true") + + def view_prev(self): + #move to next view + self.telnet.set( "/command/view/prev", "true") + diff --git a/scripts/python/FlightGear.pyc b/scripts/python/FlightGear.pyc index 65a976c2a..c58cba9a3 100644 Binary files a/scripts/python/FlightGear.pyc and b/scripts/python/FlightGear.pyc differ diff --git a/scripts/python/demo.py b/scripts/python/demo.py index 8f32c8232..a0e986c63 100644 --- a/scripts/python/demo.py +++ b/scripts/python/demo.py @@ -5,8 +5,12 @@ def main(): fg = FlightGear('localhost', 5500) # Wait five seconds for simulator to settle down - while fg['/sim/time/elapsed-ms'] < 5000: + while 1: + if fg['/sim/time/elapsed-sec'] > 5: + break time.sleep(1.0) + print fg['/sim/time/elapsed-sec'] + # parking brake on fg['/controls/parking-brake'] = 1 @@ -17,14 +21,14 @@ def main(): fg.view_next() fg['/sim/current-view/goal-heading-offset-deg'] = 180.0 - fg.wait_for_prop_eq('/sim/current-view/heading-offset-deg', 180.0) - + #fg.wait_for_prop_eq('/sim/current-view/heading-offset-deg', 180.0) + fg['/sim/current-view/goal-heading-offset-deg'] = 90.0 - fg.wait_for_prop_eq('/sim/current-view/heading-offset-deg', 90.0) - + #fg.wait_for_prop_eq('/sim/current-view/heading-offset-deg', 90.0) + fg['/sim/current-view/goal-heading-offset-deg'] = 0.0 - fg.wait_for_prop_eq('/sim/current-view/heading-offset-deg', 0.0) - + #fg.wait_for_prop_eq('/sim/current-view/heading-offset-deg', 0.0) + time.sleep(2.0) # Switch back to cockpit view @@ -34,9 +38,9 @@ def main(): # Flaps to take off position fg['/controls/flaps'] = 0.34 - fg.wait_for_prop_eq('/surface-positions/flap-pos-norm', 0.34) + #fg.wait_for_prop_eq('/surface-positions/flap-pos-norm', 0.34) fg.quit() - + if __name__ == '__main__': main()