Is there a way to take off using a Guided mode WP?

Simply put, after arming, I would like to be able to take off by switching to Guided mode and setting a new WP that sets the desired altitude. However this doesn’t seem to work: (the code below is a Python script running in MP)

def newWP(lat, lng, alt):
    wp = MissionPlanner.Utilities.Locationwp()
    MissionPlanner.Utilities.Locationwp.lat.SetValue(wp, lat)
    MissionPlanner.Utilities.Locationwp.lng.SetValue(wp, lng)
    MissionPlanner.Utilities.Locationwp.alt.SetValue(wp, alt)
    return wp

Script.ChangeMode("GUIDED")
MAV.setGuidedModeWP(newWP(cs.lat, cs.lng, altitude))
waitToReachLocation(cs.lat, cs.lng, altitude) 

The above doesn’t work. The craft doesn’t lift off the ground.
Or perhaps, is there some way to accomplish this in Guided mode without using waypoints?

Any ideas? Is it not possible to programmatically takeoff in Guided mode?

You need to give a takeoff command with altitude as an argument

Thanks @james_pattison, that makes sense conceptually but is there support for it in Python scripts? I am not seeing a corresponding API for it, like there is for example for setting a guided waypoint, or changing the flight mode, etc. I would love to have something like:

MAV.Takeoff(altitude)

Perhaps a question for @Michael_Oborne?

https://dronekit-python.readthedocs.io/en/latest/

That’s DroneKit… I am running python scripts in MissionPlanner. I believe the available APIs are quite different, but perhaps I am wrong?..

Anyway, looks like this might work:

MAV.doCommand(MAVLink.MAV_CMD.TAKEOFF, 0, 0, 0, 0, 0, 0, altitude);

Wading through the examples in the MP repo, it looks like there may be a way to do this using Locationwp() with a custom id for takeoff, but it’s not working for me. Those examples use APIs that are no longer available or take different parameters, such as MAV.setWPCurrent, and MAV.setWPACK.

using locationwp is for in mission commands

for a just takeoff, doCommand is the correct method

1 Like

Thanks @Michael_Oborne for confirming.
How about a MAV.Takeoff(altitude) function in the next version… could be a nice intuitive addition to the Python APIs available from MP scripts. wink wink