mavlink / MAVSDK-Java

MAVSDK client for Java.
68 stars 40 forks source link

Set Guided mode with MAVSDK-java #130

Closed TeoVal138 closed 1 year ago

TeoVal138 commented 1 year ago

Hello everyone, I'm developing an android mobile app with mavsdk-java to control my ardupilot drone, in this days I've been trying to set the guided mode in order to takeoff autonomously. Can you please tell me what can I do?

Many thanks in advance

JonasVautherin commented 1 year ago

I think that the equivalent to "guided" in PX4 is "offboard". Did you try the offboard plugin? Not sure if it works with Ardupilot though :thinking:. Worth trying with a simulator! :blush:

TeoVal138 commented 1 year ago

Hi Jonas, Thank you for the support 😊 I was trying with a simulator to use offboard but the "system.getOffboard().start()" method doesn't respond and "system.getOffboard().isActive()" is always set to false so I think it's off limits unfortunately. For a while I tried with the Shell plugin but I didn't find anything useful in the online forums, do you happen to know if I could actually use it to change the flight modes and if so what command should I use?

JonasVautherin commented 1 year ago

Calling offboard.start() should just change the flight mode, see here:

_system_impl->set_flight_mode(FlightMode::Offboard)

which ends up translating that to an Ardupilot flight mode here:

make_command_ardupilot_mode(flight_mode, component_id);

which e.g. for a copter will translate to Guided here:

        case FlightMode::Offboard:
            return ardupilot::CopterMode::Guided;

So I think it should work.

The problem is that at least the last part is not available in MAVSDK v1.4.16 (latest release, see here), only on the main branch.

I see ~two~ three solutions for you (none of them ideal, unfortunately):

  1. You build MAVSDK from source (from the C++ core up to MAVSDK-Java)
  2. You wait until MAVSDK v2 is out, but that may take time. It is being tracked here.
  3. You fix v1.4.16 and open a PR, such that we can release v1.4.17 with the changes you need. You can get inspiration from the main branch (where I believe it should work), but honestly I don't know how easy that will be. Could be quite straightforward, I think.
TeoVal138 commented 1 year ago

Thank you Jonas I will try to follow your advice! 😊 So no other mavsdk-java plugin would allow me to switch modes right? I'm not just talking about the guided mode set but also about the other modes set

JonasVautherin commented 1 year ago

The MAVSDK plugins set the mode as required. For instance the mission plugin will set the mission mode, the action plugin will set the RTL, takeoff, land mode, etc.