Whenever I try changing modes in the air, drone-kit python script continues to leave the copter in GUIDED mode. I essential want my python script to allow my drone to fly through a certain location and switch its mode to LOITER in the air and stay in the air for a certain period of time.
Here is a small piece of my script:
print "Going towards location"
vehicle.mode = VehicleMode("LOITER")
def goto(dNorth, dEast, gotoFunction=vehicle.simple_goto):
targetLocation=get_location_metres(currentLocation, dNorth, dEast)
while (vehicle.mode.name=="GUIDED") and (get_distance_metres(vehicle.home_location,vehicle.location.global_frame)<radius) and (vehicle.location.global_relative_frame.alt<alt_limit):
#Stop action if we are no longer in guided mode or outside radius.
print "Distance to target: ", remainingDistance
if remainingDistance<=targetDistance*0.1: #Just below target, in case of undershoot.
print "Reached target"
vehicle.mode = VehicleMode("LOITER") print vehicle.mode
This part isn't going to work because it takes a bit for the vehicle to change modes and then confirm the mode change.