MAVSDK-Python: Can't change takeoff altitude using set_takeoff_altitude()

Hey guys, I tried to change the altitude in takeoff_and_land.py through the following code but ran into an error. Looks like a bug. Would be grateful for insights and help on this!

#!/usr/bin/env python3

import asyncio
import time

from mavsdk import start_mavlink
from mavsdk import connect as mavsdk_connect

start_mavlink()
drone = mavsdk_connect(host="127.0.0.1")


async def run():

    print("Waiting for drone...")
    async for state in drone.core.connection_state():
        if state.is_connected:
            print(f"Drone discovered with UUID: {state.uuid}")
            break

    print("-- Arming")
    await drone.action.arm()

    print("-- Taking off")
    await drone.action.set_takeoff_altitude(100)
    print (await drone.action.get_takeoff_altitude())
    await drone.action.takeoff()
    await asyncio.sleep(30)
    
    print("-- Landing")
    await drone.action.land()



loop = asyncio.get_event_loop()
loop.run_until_complete(run())

Terminal output:

python3 takeoff_and_land.py
Waiting for drone...
Drone discovered with UUID: 5283920058631409231
-- Arming
-- Taking off
Traceback (most recent call last):
 File "takeoff_and_land.py", line 36, in <module>
   loop.run_until_complete(run())
 File "/usr/lib/python3.6/asyncio/base_events.py", line 484, in run_until_complete
   return future.result()
 File "takeoff_and_land.py", line 25, in run
   await drone.action.set_takeoff_altitude(100)
 File "/usr/local/lib/python3.6/dist-packages/mavsdk/plugins/action.py", line 331, in set_takeoff_altitude
   raise ActionError(result, "set_takeoff_altitude()", altitude)
mavsdk.plugins.action.ActionError: UNKNOWN: ''; origin: set_takeoff_altitude(); params: (100,)

About this issue

Most upvoted comments

I had the same issues but I used some other work around by setting the takeoff height parameter, MIS_TAKEOFF_ALT

await drone.param.set_float_param("MIS_TAKEOFF_ALT", 20.0)

20.0 metres was the height in my case. That should suffice for now.