1212#Set up option parsing to get connection string
1313import argparse
1414parser = argparse .ArgumentParser (description = 'Tracks GPS position of your computer (Linux only). Connects to SITL on local PC by default.' )
15- parser .add_argument ('--connect' , default = '127.0.0.1:14550' ,
16- help = "vehicle connection target. Default '127.0.0.1:14550' " )
15+ parser .add_argument ('--connect' ,
16+ help = "vehicle connection target." )
1717args = parser .parse_args ()
1818
19+ connection_string = args .connect
20+ sitl = None
21+
22+ #Start SITL if no connection string specified
23+ if not args .connect :
24+ print "Starting copter simulator (SITL)"
25+ from dronekit_sitl import SITL
26+ sitl = SITL ()
27+ sitl .download ('copter' , '3.3' , verbose = True )
28+ sitl_args = ['-I0' , '--model' , 'quad' , '--home=-35.363261,149.165230,584,353' ]
29+ sitl .launch (sitl_args , await_ready = True , restart = True )
30+ connection_string = 'tcp:127.0.0.1:5760'
1931
2032# Connect to the Vehicle
21- print 'Connecting to vehicle on: %s' % args . connect
22- vehicle = connect (args . connect , wait_ready = True )
33+ print 'Connecting to vehicle on: %s' % connection_string
34+ vehicle = connect (connection_string , wait_ready = True )
2335
2436def setMode (mode ):
2537 # Now change the vehicle into auto mode
@@ -31,8 +43,7 @@ def updateGUI(label, value):
3143
3244def addObserverAndInit (name , cb ):
3345 """We go ahead and call our observer once at startup to get an initial value"""
34- cb (name )
35- vehicle .add_attribute_observer (name , cb )
46+ vehicle .add_attribute_listener (name , cb )
3647
3748root = Tk ()
3849root .wm_title ("microGCS - the worlds crummiest GCS" )
@@ -46,11 +57,15 @@ def addObserverAndInit(name, cb):
4657modeLabel = Label (frame , text = "mode" )
4758modeLabel .pack ()
4859
49- addObserverAndInit ('attitude' , lambda attr : updateGUI (attitudeLabel , vehicle .attitude ))
50- addObserverAndInit ('location' , lambda attr : updateGUI (locationLabel , vehicle . location ))
51- addObserverAndInit ('mode' , lambda attr : updateGUI (modeLabel , vehicle . mode ))
60+ addObserverAndInit ('attitude' , lambda vehicle , name , attitude : updateGUI (attitudeLabel , vehicle .attitude ))
61+ addObserverAndInit ('location' , lambda vehicle , name , location : updateGUI (locationLabel , str ( location . global_frame ) ))
62+ addObserverAndInit ('mode' , lambda vehicle , name , mode : updateGUI (modeLabel , mode ))
5263
5364Button (frame , text = "Auto" , command = lambda : setMode ("AUTO" )).pack ()
5465Button (frame , text = "RTL" , command = lambda : setMode ("RTL" )).pack ()
5566
56- root .mainloop ()
67+ root .mainloop ()
68+
69+ # Shut down simulator if it was started.
70+ if sitl is not None :
71+ sitl .stop ()
0 commit comments