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

AHRS: add ability to configure AHRS via mavlink commands #28485

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

valbv
Copy link

@valbv valbv commented Oct 28, 2024

It's for the ability to send commands to EAHRS like "Enable/Disable GNSS", "Start/Stop magnitometer calibration in flight" and everything that device can receive

@Ryanf55
Copy link
Collaborator

Ryanf55 commented Oct 28, 2024

Nice. If you can, feel free to add one such packet so that this code is used by a driver.
We prefer all code is used.

@valbv valbv marked this pull request as draft October 28, 2024 10:40
@valbv valbv force-pushed the eahrscommands branch 3 times, most recently from b19d652 to c4ca633 Compare November 29, 2024 19:14
@valbv
Copy link
Author

valbv commented Nov 29, 2024

Linked PR in MAVLink repo:
ArduPilot/mavlink#376

@valbv valbv marked this pull request as ready for review November 29, 2024 19:21
@valbv valbv force-pushed the eahrscommands branch 5 times, most recently from 5f30de1 to 8faccc4 Compare December 5, 2024 18:57
Copy link
Contributor

@peterbarker peterbarker left a comment

Choose a reason for hiding this comment

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

I'd prefer to have something at the AHRS-backend level rather than at the EAHRS level for this. Turning GNSS off is a thing for EKF3, for example, just not in master right now.

@valbv
Copy link
Author

valbv commented Dec 10, 2024

@peterbarker , where can I find the code you were talking about (Turning GNSS off for EKF3)?
I want to avoid conflicts in the names of methods.

I looked through the branches in the repository and requests, but I couldn't find it

@Ryanf55
Copy link
Collaborator

Ryanf55 commented Dec 10, 2024

Check the code path of aux function 65 "GPS Disable": https://ardupilot.org/copter/docs/common-auxiliary-functions.html

@valbv
Copy link
Author

valbv commented Dec 15, 2024

Did I get the idea right, you want to see something like this?

@valbv valbv requested a review from peterbarker December 17, 2024 05:26
libraries/AP_AHRS/AP_AHRS.h Outdated Show resolved Hide resolved
libraries/AP_ExternalAHRS/AP_ExternalAHRS.h Outdated Show resolved Hide resolved
@Ryanf55
Copy link
Collaborator

Ryanf55 commented Dec 17, 2024

yea, this is nice and portable between the EARHS drivers. Just making sure for commands we have a way to undo them (ie turn GNSS on/off in flight to test dead reckoning)

@valbv
Copy link
Author

valbv commented Dec 17, 2024

Yes, we used set_gnss_state method-logic for the dead reckoning tests with EAHRS

@valbv valbv requested a review from Ryanf55 December 17, 2024 22:39
Copy link
Collaborator

@Ryanf55 Ryanf55 left a comment

Choose a reason for hiding this comment

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

Nice, yea I'm overall on board with the approach here. I haven't tested it yet.

#if AP_AHRS_EXTERNAL_ENABLED
case EKFType::EXTERNAL:
return external.set_gnss_state(enabled);
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

The code paths that aux function 105 takes could be used to disable GPS in EKF2/3.
105

Not required for the PR.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I'll create a next request with these changes

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I'll create a next request with these changes

... not sure I understand this response.

We have an existing mechanism for enabling/disabling gnss use, we should use it here.

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure that I understood what I need right, but I added the GPS disabling for EKF2/3

libraries/GCS_MAVLink/GCS_Common.cpp Outdated Show resolved Hide resolved
@peterbarker
Copy link
Contributor

This is looking nicer than the write-bytes approach.

I'm going to mark this for DevCall for discussion.

@Ryanf55
Copy link
Collaborator

Ryanf55 commented Dec 23, 2024

Nothing to add from me, I'm in favor of this change and believe it sets up a nice pattern for adding future generic commands to the EKF/EAHRS.

#if AP_AHRS_EXTERNAL_ENABLED
case EKFType::EXTERNAL:
return external.set_gnss_state(enabled);
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I'll create a next request with these changes

... not sure I understand this response.

We have an existing mechanism for enabling/disabling gnss use, we should use it here.

Comment on lines 399 to 402
bool AP_ExternalAHRS::write_bytes(const char *bytes, uint8_t len)
{
if (!backend) {
return false;
}
return backend->write_bytes(bytes, len);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

No longer needed

Copy link
Author

Choose a reason for hiding this comment

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

Done

@@ -121,6 +121,9 @@ class AP_ExternalAHRS {
bool get_accel(Vector3f &accel);
void send_status_report(class GCS_MAVLINK &link) const;
bool get_variances(float &velVar, float &posVar, float &hgtVar, Vector3f &magVar, float &tasVar) const;
void set_data_sending_state(bool enabled);
void set_gnss_state(bool enabled);
bool write_bytes(const char *bytes, uint8_t len);
Copy link
Contributor

Choose a reason for hiding this comment

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

remove

Copy link
Author

Choose a reason for hiding this comment

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

Done

@@ -220,6 +220,9 @@ class AP_ExternalAHRS_InertialLabs : public AP_ExternalAHRS_backend {
void update_thread();
bool check_uart();
bool check_header(const ILabsHeader *h) const;
bool write_bytes(const char *bytes, uint8_t len) override;
Copy link
Contributor

Choose a reason for hiding this comment

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

No longer an override; should be private

Copy link
Author

Choose a reason for hiding this comment

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

Done

@@ -42,6 +42,9 @@ class AP_ExternalAHRS_backend {
virtual bool pre_arm_check(char *failure_msg, uint8_t failure_msg_len) const = 0;
virtual void get_filter_status(nav_filter_status &status) const {}
virtual bool get_variances(float &velVar, float &posVar, float &hgtVar, Vector3f &magVar, float &tasVar) const { return false; }
virtual void set_data_sending_state(bool enabled) {}
virtual void set_gnss_state(bool enabled) {}
virtual bool write_bytes(const char *bytes, uint8_t len) { return false; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
virtual bool write_bytes(const char *bytes, uint8_t len) { return false; }

Copy link
Author

Choose a reason for hiding this comment

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

Done

{
switch (packet.command) {
case MAV_CMD_AHRS_START:
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{

etc.

Copy link
Author

Choose a reason for hiding this comment

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

Done


void AP_ExternalAHRS_InertialLabs::set_data_sending_state(bool enabled)
{
if (enabled)
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: bracket should be on the same line as the if

Copy link
Author

Choose a reason for hiding this comment

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

Done

@rmackay9
Copy link
Contributor

Hi @valbv,

Thanks for this. What's the purpose of disabling an EAHRS? I guess it's to test a complete failure of the external AHRS system? I wonder what testing has been done for this?

@@ -137,4 +137,14 @@ void AP_AHRS_External::get_control_limits(float &ekfGndSpdLimit, float &ekfNavVe
ekfNavVelGainScaler = 0.5;
}

void AP_AHRS_External::set_data_sending_state(bool enabled)
Copy link
Contributor

Choose a reason for hiding this comment

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

let's put some comments above the methods..

Copy link
Collaborator

Choose a reason for hiding this comment

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

To elaborate, at minimum, copy the comments across all the headers. Although the clasess inherit/override methods, not everyone's editor propogates the description, so AP generally copies comments.

Copy link
Author

Choose a reason for hiding this comment

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

Done

@@ -87,6 +87,9 @@ class AP_AHRS_External : public AP_AHRS_Backend {
void send_ekf_status_report(class GCS_MAVLINK &link) const override;

void get_control_limits(float &ekfGndSpdLimit, float &controlScaleXY) const override;

void set_data_sending_state(bool enabled) override;
Copy link
Contributor

Choose a reason for hiding this comment

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

comments here too would be nice

Copy link
Author

Choose a reason for hiding this comment

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

Done

@peterbarker peterbarker changed the title ExternalAHRS: Add the ability to send commands to the EAHRS AHRS: add ability to configure AHRS via mavlink commands Dec 23, 2024
@rmackay9
Copy link
Contributor

More comments would be nice, there are very few which makes it difficult to review but also it will be even more difficult for future developers trying to figure out how to use the various methods

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants