Switch into offboard mode with RC switch, detect it with MAVSDK-Python

I’d like to implement a following feature, with MAVSDK-Python and PX4:

  1. switch FC to offboard mode with RC switch (I configured it with QGC)
  2. in a pythion script that’s running on the companion computer, detect that FC went into offboard mode, to start controlling it afterwards

Is it possible? Currently my attempts do not work. I’m using this code:

import asyncio
from mavsdk import System
from mavsdk.offboard import (OffboardError, VelocityBodyYawspeed)

async def run():
    # Init the drone
    drone = System(mavsdk_server_address='localhost', port=50051)
    await drone.connect()

    async for state in drone.core.connection_state():
        print("connecting")
        if state.is_connected:
            print(f"-- connected to drone!")
            break

    await drone.offboard.set_velocity_body(
        VelocityBodyYawspeed(0.0, 0.0, 0.0, 0.0))

    while True:
        offboard = await drone.offboard.is_active()
        print("check offboard", offboard)
        await asyncio.sleep(1)

As an effect, after I switch to offboard mode with RC switch:

  • the mode switch fails with “No offboard signal”,
  • drone.offboard.is_active() always returns False.

When I try to switch to offboard mode from a python script with drone.offboard.start(), that works fine, and offboard examples from MAVSDK-Python work fine.

browsing a bit, looks like it’s not possible?

Looks like one of the things I’d like to do “some day”. If you need something urgently, consider github sponsoring.

Or you could just “always control the vehicle”. The script won’t actually take control until you enter offboard mode.

Or you could just “always control the vehicle”. The script won’t actually take control until you enter offboard mode.

That did not work for me but I did not spend much time on debugging. maybe I just was not sending setpoints frequently enough to be treated as heartbeat messages?

That did not work for me but I did not spend much time on debugging. maybe I just was not sending setpoints frequently enough to be treated as heartbeat messages?

Probably. Check docs, but I think you have to be sending them at 2Hz for at least a second before you switch modes in order to be able to switch mode