Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArduPilot: Prevent std::future_error in takeoff, and return attitude in euler angles #2212

Merged
merged 3 commits into from
Jan 23, 2024
Merged

ArduPilot: Prevent std::future_error in takeoff, and return attitude in euler angles #2212

merged 3 commits into from
Jan 23, 2024

Conversation

lamlaaaam
Copy link
Contributor

This PR addresses 2 issues when using MAVSDK with ArduPilot. These were tested on ArduPilot SITL Copter-4.4.4, using MAVSDK v2.0.1.

Takeoff crashes if the switch to Guided mode fails

Observation

When ArduPilot SITL starts up, it takes time before the GPS initializes and for the UAV to obtain a position estimate. During this time, if the takeoff command is given, an unhandled std::future_error exception is thrown.

Cause

Within Action_Impl::takeoff_async_apm, if set_flight_mode_async fails, it triggers the callback to set a failed result. However, it still calls send_takeoff_command, which triggers the same callback, and tries to set another result value for a fulfilled promise.

Fix

Just don't call the send_takeoff_command if switch to Guided mode fails.

NaN values received for attitude in euler angles

Observation

The values received for roll, pitch, yaw in the telemetry are NaN.

Cause

In TelemetryImpl::process_attitude, the values are extracted from the received telemetry message and correctly populated into a Telemetry::EulerAngle struct. However, this struct is then never used again. Instead, it grabs the quaternion version, and does a conversion to euler angles. I'm not sure what the actual reason causing the NaN is, but it's probably somewhere in the conversion.

Fix

Use the Telemetry::EulerAngle struct that was populated.

JonasVautherin
JonasVautherin previously approved these changes Jan 22, 2024
Copy link
Collaborator

@JonasVautherin JonasVautherin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice ones!

@JonasVautherin
Copy link
Collaborator

OpenSSL is timing out for now, let's try the CI again in a few hours 👍.

@JonasVautherin
Copy link
Collaborator

There is a styling issue to fix, though:

diff --git a/src/mavsdk/plugins/action/action_impl.cpp b/src/mavsdk/plugins/action/action_impl.cpp
index fae1052..e75dc7e 100644
--- a/src/mavsdk/plugins/action/action_impl.cpp
+++ b/src/mavsdk/plugins/action/action_impl.cpp
@@ -407,8 +407,7 @@ void ActionImpl::takeoff_async_apm(const Action::ResultCallback& callback) const
                     if (callback) {
                         callback(action_result);
                     }
-                }
-                else {
+                } else {
                     send_takeoff_command();
                 }
             });
Error: Process completed with exit code 1.

Copy link
Collaborator

@julianoes julianoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fixes, much appreciated!

@julianoes julianoes merged commit 504c977 into mavlink:main Jan 23, 2024
@lamlaaaam lamlaaaam deleted the v2.0.1-ardupilot-fix branch January 23, 2024 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants