MAVSDK: Offboard doesnt want to enable after a is_active() check.

MavSDK version v0.35.1

I am having an issue where the offboard does not want to enable. It seems like a few things…a race condition with a bad check (mavsdk side) and a bad way of checking the state of offboard (my side).

I was checking if the _offboard->is_active() but that was always true (because _mode != Mode::NotActive - it was PositionNed) before calling _offboard->start()…this was not a good way of doing it because even when the is_active switched to false so I could start the offboard (which happened periodically randomly) it would respond back with a failure because

        if (_mode == Mode::NotActive) {
            return Offboard::Result::NoSetpointSet;

(offboard_impl.cpp)^^

How I fixed it:

In process_heartbeat() i changed _mode != Mode::NotActive to _mode == Mode::NotActive . This caused the race condition of the NotActive being set too quickly to not happen anymore…

AND

I, instead of checking is_active(), I check that _flightMode != Telemetry::FlightMode::Offboard and this allowed it to go into the offboard mode and respect my movement commands.

My code is here.

I am not sure if the changes I made are proper and dont want to PR them without a discussion about this issue first.

I also have been conversing with @JonasVautherin here about this issue if you would like some more context.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15

Most upvoted comments

Funny enough I just ran into this in the PX4 integration tests here: https://github.com/PX4/PX4-Autopilot/blob/82d6cc3dba3bbc8d6fbd0a3449e7d67560d4a67d/test/mavsdk_tests/autopilot_tester.cpp#L425-L426

I received “NoSetpoint” like you said so.

I think calling start makes sense, but I also think its valuable for start to return the success or failure of switching from whatever mode its in to Offboard mode.

Yes, I think we should probably add that. So we try to start offboard mode and then we wait until it’s actually active. Once it’s active, we return.

And in the same way we could have is_active check both, if setpoints are sent and if the mode is offboard.

Yes, I swapped from is_active to just using the telemetry mode instead, since it would be more accurate. I think there should be a secondary call in offboard mode that is is_active() which returns what it returns now…and is_enabled or somehing like that which returns offboard mode is on or not.

Sure, my user code is here: https://github.com/mcelhennyi/NXP-HoverGames-2/blob/ebc11e9577710f4cf036a230838d943761f902f8/code/src/system/agent/Agent.cpp#L305