@@ -159,15 +159,105 @@ 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+ self .objMan .ManualControlCommand .Connected .value = True
167+ self .objMan .ManualControlCommand .updated ()
168+
169+ print "Arming board using Yaw right"
170+ # FIXME: Seems there is a issue with ArmedField.ARMED, 2 equals to the ARMED state
171+ while (self .objMan .FlightStatus .Armed .value != 2 ):
172+ self .objMan .ManualControlCommand .Yaw .value = 1
173+ self .objMan .ManualControlCommand .updated ()
174+ self .objMan .ManualControlCommand .Throttle .value = - 1
175+ self .objMan .ManualControlCommand .updated ()
176+ time .sleep (1 )
177+
178+ if (self .objMan .FlightStatus .Armed .value == 2 ):
179+ print "Board is armed !"
180+ self .objMan .ManualControlCommand .Yaw .value = 0
181+ self .objMan .ManualControlCommand .updated ()
182+
183+ print "Applying Throttle"
184+ self .objMan .ManualControlCommand .Throttle .value = 0.01 # very small value for safety
185+ # Assuming board do not control a helicopter, Thrust value will be equal to Throttle value.
186+ # Because a 'high' value can be read from latest real RC input value,
187+ # initial value is set now to zero for safety reasons.
188+ self .objMan .ManualControlCommand .Thrust .value = 0
189+ # self.objMan.ManualControlCommand.Throttle.value = self.objMan.ManualControlCommand.Thrust.value
190+ self .objMan .ManualControlCommand .updated ()
191+ time .sleep (0.3 )
192+
193+ count = 60
194+ print "Moving Pitch input"
195+ while (count > 0 ):
196+ count -= 1
197+ if self .objMan .ManualControlCommand .Pitch .value < 1 :
198+ self .objMan .ManualControlCommand .Pitch .value += 0.05
199+ self .objMan .ManualControlCommand .updated ()
200+ time .sleep (0.1 )
201+ if self .objMan .ManualControlCommand .Pitch .value > 1 :
202+ self .objMan .ManualControlCommand .Pitch .value = 0
203+ self .objMan .ManualControlCommand .updated ()
204+ time .sleep (0.1 )
205+
206+ self .objMan .ManualControlCommand .Pitch .value = 0
207+ self .objMan .ManualControlCommand .updated ()
208+ time .sleep (0.5 )
209+
210+ count = 60
211+ print "Moving Roll input"
212+ while (count > 0 ):
213+ count -= 1
214+ if self .objMan .ManualControlCommand .Roll .value < 1 :
215+ self .objMan .ManualControlCommand .Roll .value += 0.05
216+ self .objMan .ManualControlCommand .updated ()
217+ time .sleep (0.1 )
218+
219+ if self .objMan .ManualControlCommand .Roll .value > 1 :
220+ self .objMan .ManualControlCommand .Roll .value = 0
221+ self .objMan .ManualControlCommand .updated ()
222+ time .sleep (0.1 )
223+
224+ self .objMan .ManualControlCommand .Roll .value = 0
225+ self .objMan .ManualControlCommand .updated ()
226+ time .sleep (0.5 )
227+
228+ print "Setting Throttle to minimum"
229+ self .objMan .ManualControlCommand .Throttle .value = - 1
230+ self .objMan .ManualControlCommand .updated ()
231+ time .sleep (1 )
232+
233+ print "Disarming board using Yaw left"
234+ # FIXME: Seems there is a issue with ArmedField.DISARMED, 0 equals to the DISARMED state
235+ while (self .objMan .FlightStatus .Armed .value != 0 ):
236+ self .objMan .ManualControlCommand .Yaw .value = - 1
237+ self .objMan .ManualControlCommand .updated ()
238+ time .sleep (0.3 )
239+
240+ self .objMan .ManualControlCommand .Yaw .value = 0
241+ self .objMan .ManualControlCommand .updated ()
242+ time .sleep (1 )
243+
244+ print "Back to self.ManualControl, controlled by RC radio"
245+ self .objMan .ManualControlCommand .metadata .access = UAVMetaDataObject .Access .READWRITE
246+ self .objMan .ManualControlCommand .metadata .updated ()
247+ self .objMan .ManualControlCommand .Connected .value = False
248+ self .objMan .ManualControlCommand .updated ()
249+
250+
162251def printUsage ():
163252 appName = os .path .basename (sys .argv [0 ])
164253 print
165254 print "usage:"
166- print " %s port o|w|g|s" % appName
255+ print " %s port o|w|g|s|i " % appName
167256 print " o: Show Attitude using an \" observer\" "
168257 print " w: Show Attitude waiting for updates from flight"
169258 print " g: Show Attitude performing get operations"
170259 print " s: Drive Servo"
260+ print " i: Take control over RC input"
171261 print
172262 print " for example: %s COM30 o" % appName
173263 print
@@ -182,7 +272,7 @@ def printUsage():
182272
183273 port , option = sys .argv [1 :]
184274
185- if option not in ["o" , "w" , "g" , "s" ]:
275+ if option not in ["o" , "w" , "g" , "s" , "i" ]:
186276 print "ERROR: Invalid option"
187277 printUsage ()
188278 sys .exit (2 )
@@ -202,6 +292,8 @@ def printUsage():
202292 demo .showAttitudeViaGet () # will not return
203293 if option == "s" :
204294 demo .driveServo () # will not return
295+ if option == "i" :
296+ demo .driveInput () # will not return
205297
206298 except KeyboardInterrupt :
207299 pass
0 commit comments