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

GCS_MAVLink: Add FLIGHT_INFORMATION message #25489

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

Conversation

nexton-winjeel
Copy link
Contributor

@nexton-winjeel nexton-winjeel commented Nov 8, 2023

Adds a new FLIGHT_DURATION the FLIGHT_INFORMATION message to report the time that the vehicle armed and took off (if known).

This message is needed if connecting a GCS to a vehicle that is already armed/flying, as otherwise these times can't be accurately determined.

Also adds an accessor to AP_Arming to record the arming time.

Requires: ArduPilot/mavlink#336

@IamPete1
Copy link
Member

IamPete1 commented Nov 8, 2023

I wonder if the new metrics would be useful as part of AP_Stats, you can get flight time from there, but currently you have to pull the param value.

@peterbarker
Copy link
Contributor

@nexton-winjeel I think this PR is now no-longer-required as we're going to use FLIGHT_INFORMATION instead, correct?

@nexton-winjeel nexton-winjeel marked this pull request as draft April 5, 2024 02:17
@nexton-winjeel
Copy link
Contributor Author

@peterbarker: It's not required as-is, but I'll convert it to use FLIGHT_INFORMATION instead of the now non-existent FLIGHT_DURATION. Will get to it early next week.

@peterbarker
Copy link
Contributor

@peterbarker: It's not required as-is, but I'll convert it to use FLIGHT_INFORMATION instead of the now non-existent FLIGHT_DURATION. Will get to it early next week.

Long week?

@nexton-winjeel nexton-winjeel force-pushed the upstream/add-FLIGHT_DURATION-message branch from 0becf38 to c987d57 Compare May 22, 2024 23:56
@nexton-winjeel nexton-winjeel changed the title GCS_MAVLink: Add FLIGHT_DURATION message GCS_MAVLink: Add FLIGHT_INFORMATION message May 22, 2024
@nexton-winjeel
Copy link
Contributor Author

Long week?

Very. Still not my oldest open PR though...

@nexton-winjeel nexton-winjeel marked this pull request as ready for review May 23, 2024 00:00
@nexton-winjeel nexton-winjeel force-pushed the upstream/add-FLIGHT_DURATION-message branch from c987d57 to faff94b Compare July 25, 2024 01:34
@nexton-winjeel nexton-winjeel force-pushed the upstream/add-FLIGHT_DURATION-message branch from faff94b to d0af9b8 Compare July 25, 2024 01:42
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.

Would be nice to get the message updates down from mavlink/mavlink.

I don't think we need to tie this with AP_Stats now. It's not a huge amount of shared state.

libraries/GCS_MAVLink/GCS_Common.cpp Outdated Show resolved Hide resolved
Comment on lines 5992 to 5993
// We send time since boot (in micros) rather than a UTC timestamp, as this
// works better with SITL when SIM_SPEEDUP > 1
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is out of date once the patches to the mavlink message upstream are brought back.

Instead it should read something like the fields are misnamed...

Also, the flag value is a little problematic with the problematic ARMING_REQUIRE flag on Rover and Plane. There's always an argument that they're not really armed in that state, but just pretend to be.... but still, how does this message work for an ARMING_REQUIRE 0 vehicle?

Copy link
Contributor Author

@nexton-winjeel nexton-winjeel Jul 31, 2024

Choose a reason for hiding this comment

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

[...] There's always an argument that they're not really armed in that state, but just pretend to be...

They will set the MAV_MODE_FLAG_SAFETY_ARMED flag of the base_mode field of the HEARTBEAT message, so as far as a GCS knows, they are armed.

[...] how does this message work for an ARMING_REQUIRE 0 vehicle?

It will report arming time as 0 if AP_Arming::arm() is never called. This field shouldn't be treated as a proxy for "is armed", it needs to be read in conjunction with the arming state reported in the HEARTBEAT.

libraries/GCS_MAVLink/GCS.h Outdated Show resolved Hide resolved
@peterbarker
Copy link
Contributor

Closes #25284

@nexton-winjeel nexton-winjeel force-pushed the upstream/add-FLIGHT_DURATION-message branch from d0af9b8 to f4312c8 Compare July 31, 2024 05:57

Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the whitespace changes.

Fix the whitespace problems as you change the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@nexton-winjeel nexton-winjeel force-pushed the upstream/add-FLIGHT_DURATION-message branch from f4312c8 to 3447e4f Compare August 4, 2024 23:59
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.

Need to fix that type, but LGTM otherwise.

#if AP_MAVLINK_MSG_FLIGHT_INFORMATION_ENABLED
void GCS_MAVLINK::send_flight_information()
{
const uint32_t time_boot_us = AP_HAL::millis64();
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
const uint32_t time_boot_us = AP_HAL::millis64();
const uint64_t time_boot_us = AP_HAL::millis64();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

switch (current_landed_state) {
case MAV_LANDED_STATE_IN_AIR:
case MAV_LANDED_STATE_TAKEOFF:
case MAV_LANDED_STATE_LANDING: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't really need to open braces if you're not declaring variables.

Doesn't need to be fixed, just maybe leave them out in future

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Defensive programming habit. Fixed while I was in there...

@@ -135,3 +135,7 @@
#ifndef AP_MAVLINK_MAV_CMD_SET_HAGL_ENABLED
#define AP_MAVLINK_MAV_CMD_SET_HAGL_ENABLED (BOARD_FLASH_SIZE > 1024)
#endif

#ifndef AP_MAVLINK_MSG_FLIGHT_INFORMATION_ENABLED
#define AP_MAVLINK_MSG_FLIGHT_INFORMATION_ENABLED 1
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the flash size cost of this new feature?

Will it cause us to start overflowing on smaller boards?

Should we add it into minimize_common.inc? (@andyp1per and @Hwurzburg might have ideas on that)

We don't need to change this as part of this PR.

Copy link
Contributor Author

@nexton-winjeel nexton-winjeel Aug 7, 2024

Choose a reason for hiding this comment

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

What's the flash size cost of this new feature?

~728 bytes (tested on CubeOrange).

          Target          Text (B)  Data (B)  BSS (B)  Total Flash Used (B)  Free Flash (B)  External Flash Used (B)
          ----------------------------------------------------------------------------------------------------------
Disabled: bin/arducopter   1840268      3920   258372               1844188          121876  Not Applicable 
Enabled:  bin/arducopter   1840996      3920   258372               1844916          121148  Not Applicable  

Copy link
Collaborator

@Hwurzburg Hwurzburg left a comment

Choose a reason for hiding this comment

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

I think this should be disabled by def and a build option...not going to be used by 95% of users....or at least disabled in minimize include...also needs file for build server and features list added

@peterbarker
Copy link
Contributor

I think this should be disabled by def and a build option...not going to be used by 95% of users....or at least disabled in minimize include...also needs file for build server and features list added

This is going to be a good/useful message for a lot of people. I plan on patching MAVProxy for it to fix the resetting-flight-time problem it has.

@nexton-winjeel please add an entry into minimize_common.inc so this isn't built on the tiny boards. Also entries to extract_features.py and build_options.py so users can turn the feature on/off as desired.

@nexton-winjeel nexton-winjeel force-pushed the upstream/add-FLIGHT_DURATION-message branch from 3447e4f to ea6e560 Compare August 7, 2024 00:25
@nexton-winjeel
Copy link
Contributor Author

@nexton-winjeel please add an entry into minimize_common.inc so this isn't built on the tiny boards. Also entries to extract_features.py and build_options.py so users can turn the feature on/off as desired.

Done.

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.

We need a mapping in GCS_MAVLINK::mavlink_id_to_ap_message_id for this message

Also a fix for ms vs us

Consider grabbing my patch from my pr/Winjeel/upstream/add-FLIGHT_DURATION-message branch


mavlink_msg_flight_information_send(
chan,
time_boot_us,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is actually a time_boot_ms field...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@peterbarker
Copy link
Contributor

peterbarker commented Aug 14, 2024

In-progress MAVProxy support is here: ArduPilot/MAVProxy#1438

Works , but I've broken other stuff in a refactor

@peterbarker
Copy link
Contributor

Ping @nexton-winjeel - might still be viable for 4.6 - but even than had better be soon :-)

@nexton-winjeel nexton-winjeel force-pushed the upstream/add-FLIGHT_DURATION-message branch from ea6e560 to 8ba89e2 Compare October 18, 2024 04:34
@nexton-winjeel nexton-winjeel force-pushed the upstream/add-FLIGHT_DURATION-message branch from 8ba89e2 to bd9b7cd Compare October 18, 2024 04:38
@nexton-winjeel
Copy link
Contributor Author

@peterbarker: Can I get you to review this again?

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.

7 participants