@@ -159,15 +159,94 @@ def driveServo(self):
159159 time .sleep (1 )
160160
161161
162+ def driveInput (self ):
163+ print "Taking control of self.ManualControl"
164+ self .objMan .ManualControlCommand .metadata .access = UAVMetaDataObject .Access .READONLY
165+ self .objMan .ManualControlCommand .metadata .updated ()
166+
167+ print "Arming board using Yaw right"
168+ while (self .objMan .FlightStatus .Armed .value != 2 ):
169+ self .objMan .ManualControlCommand .Yaw .value = 1
170+ self .objMan .ManualControlCommand .updated ()
171+ self .objMan .ManualControlCommand .Throttle .value = - 1
172+ self .objMan .ManualControlCommand .updated ()
173+ time .sleep (1 )
174+
175+ if (self .objMan .FlightStatus .Armed .value == 2 ):
176+ print "Board is armed !"
177+ self .objMan .ManualControlCommand .Yaw .value = 0
178+ self .objMan .ManualControlCommand .updated ()
179+
180+ print "Applying Throttle"
181+ self .objMan .ManualControlCommand .Throttle .value = 0.01 # very small value for safety
182+ self .objMan .ManualControlCommand .updated ()
183+ time .sleep (0.3 )
184+
185+ count = 60
186+ print "Moving Pitch input"
187+ while (count > 0 ):
188+ count -= 1
189+ if self .objMan .ManualControlCommand .Pitch .value < 1 :
190+ self .objMan .ManualControlCommand .Pitch .value += 0.05
191+ self .objMan .ManualControlCommand .updated ()
192+ time .sleep (0.1 )
193+ if self .objMan .ManualControlCommand .Pitch .value > 1 :
194+ self .objMan .ManualControlCommand .Pitch .value = 0
195+ self .objMan .ManualControlCommand .updated ()
196+ time .sleep (0.1 )
197+
198+ self .objMan .ManualControlCommand .Pitch .value = 0
199+ self .objMan .ManualControlCommand .updated ()
200+ time .sleep (0.5 )
201+
202+ count = 60
203+ print "Moving Roll input"
204+ while (count > 0 ):
205+ count -= 1
206+ if self .objMan .ManualControlCommand .Roll .value < 1 :
207+ self .objMan .ManualControlCommand .Roll .value += 0.05
208+ self .objMan .ManualControlCommand .updated ()
209+ time .sleep (0.1 )
210+
211+ if self .objMan .ManualControlCommand .Roll .value > 1 :
212+ self .objMan .ManualControlCommand .Roll .value = 0
213+ self .objMan .ManualControlCommand .updated ()
214+ time .sleep (0.1 )
215+
216+ self .objMan .ManualControlCommand .Roll .value = 0
217+ self .objMan .ManualControlCommand .updated ()
218+ time .sleep (0.5 )
219+
220+ print "Setting Throttle to minimum"
221+ self .objMan .ManualControlCommand .Throttle .value = - 1
222+ self .objMan .ManualControlCommand .updated ()
223+ time .sleep (1 )
224+
225+ print "Disarming board using Yaw left"
226+ while (self .objMan .FlightStatus .Armed .value != 0 ):
227+ self .objMan .ManualControlCommand .Yaw .value = - 1
228+ self .objMan .ManualControlCommand .updated ()
229+ time .sleep (0.3 )
230+
231+ self .objMan .ManualControlCommand .Yaw .value = 0
232+ self .objMan .ManualControlCommand .updated ()
233+ time .sleep (1 )
234+
235+ print "Back to self.ManualControl, controlled by RC radio"
236+ self .objMan .ManualControlCommand .metadata .access = UAVMetaDataObject .Access .READWRITE
237+ self .objMan .ManualControlCommand .metadata .updated ()
238+
239+
162240def printUsage ():
163241 appName = os .path .basename (sys .argv [0 ])
164242 print
165243 print "usage:"
166- print " %s port o|w|g|s" % appName
244+ print " %s port o|w|g|s|i " % appName
167245 print " o: Show Attitude using an \" observer\" "
168246 print " w: Show Attitude waiting for updates from flight"
169247 print " g: Show Attitude performing get operations"
170248 print " s: Drive Servo"
249+ print " i: Take control over RC input"
171250 print
172251 print " for example: %s COM30 o" % appName
173252 print
@@ -182,7 +261,7 @@ def printUsage():
182261
183262 port , option = sys .argv [1 :]
184263
185- if option not in ["o" , "w" , "g" , "s" ]:
264+ if option not in ["o" , "w" , "g" , "s" , "i" ]:
186265 print "ERROR: Invalid option"
187266 printUsage ()
188267 sys .exit (2 )
@@ -202,6 +281,8 @@ def printUsage():
202281 demo .showAttitudeViaGet () # will not return
203282 if option == "s" :
204283 demo .driveServo () # will not return
284+ if option == "i" :
285+ demo .driveInput () # will not return
205286
206287 except KeyboardInterrupt :
207288 pass
0 commit comments