def tracking (vstate):
print vstate
#The vehicle process images and maintains all data ready to fly in the following state.
#However, it does not send attitude messages as the vehicle is still under manual control.
red1Good = red2Good = False # Set True when returned target offset is reliable.
bearing = offset = 0
target = None # Initialise tuple returned from video stream
# Initialise the FPS counter.
#fps = FPS().start()
while vstate == "tracking":
# grab the frame from the threaded video stream and return left line offset
# We do this to know if we have a 'lock' (goodTarget) as we come off of manual control.
target = vs.readfollow()
bearing = target[0]
red1Good = target[1]
offset = target[2]
red2Good = target[3]
# Print location information for `vehicle` in all frames (default printer)
#print "Global Location: %s" % vehicle.location.global_frame
#print "Global Location (relative altitude): %s" % vehicle.location.global_relative_frame
#print "Local Location: %s" % vehicle.location.local_frame #NEDprint "Local Location: %s" % vehicle.location.local_frame
# print tof_sensor.get_distance()
# update the FPS counter
#fps.update()
# Check if operator has transferred to autopilot using TX switch.
if vehicle.mode == "GUIDED_NOGPS":
# print "In Guided mode..."
if ( red1Good and red2Good ) == True:
# print "In guided mode, setting following..."
vstate = "following"
else:
# print "In guided mode, setting lost..."
vstate = "lost"
# stop the timer and display FPS information
#fps.stop()
#print('Elasped time in tracking state: {:.2f}'.format(fps.elapsed()))
#print('Approx. FPS: {:.2f}'.format(fps.fps()))
# time.sleep(1)
return vstate
#-------------- FUNCTION DEFINITION TO FLY IN VEHICLE STATE FOLLOWING---------------------
评论列表
文章目录