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

mavutil: Return mode as 'Mode(msg.custom_mode)' for high-latency streams #779

Merged
merged 1 commit into from
Mar 6, 2023

Conversation

dernatsch
Copy link

Before, when reading high-latency messages that came from PX4, mavutil threw an exception because after the check for PX4, msg.base_mode was read immediately. It was not regarded that the HIGH_LATENCY2 message does not contain a base_mode field.

This introduces a fix where the mode string for all HIGH_LATENCY2 messages is returned as Mode(msg.custom_mode).

@peterbarker
Copy link
Contributor

This also looks like we will no longer map the base mode to a string on ArduPilot.

Could you put your two new lines just within the PX4 bloc there, please - just stop us reading those attributes within that block if the message is a HIGH_LATENCY2

Apologies for the breakage - we really should have picked this up.

@stephendade FYI

@dernatsch dernatsch force-pushed the high-latency-mode-string branch from 5b81644 to bdb30c1 Compare March 2, 2023 09:49
@dernatsch
Copy link
Author

@peterbarker Just changed it. Is this what you had in mind? :)

@dernatsch dernatsch force-pushed the high-latency-mode-string branch from bdb30c1 to c6318c9 Compare March 2, 2023 09:59
@stephendade
Copy link
Contributor

FYI in ArduPilot, we do send the base_mode in the custom0 field of HIGH_LATNENCY2, as we need base_mode to determine if the vehicle's armed.

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.

LGTM

mavutil.py Outdated
@@ -2272,14 +2272,19 @@ def mode_mapping_bynumber(mav_type):

def mode_string_v10(msg):
'''mode string for 1.0 protocol, from heartbeat'''
if msg.get_type() == "HIGH_LATENCY2":
return f"Mode({msg.custom_mode})"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't use fstrings - python2 :-(

Really looking forward to dropping Py2 - I like fstrings.

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.

Ah, sorry - still have the f-string :-/

@dernatsch dernatsch force-pushed the high-latency-mode-string branch from c6318c9 to 0f20b0b Compare March 4, 2023 18:23
Before, when reading HIGH_LATENCY2 messages that came from a PX4
controller mavutil threw an exception because after the check for PX4,
`msg.base_mode` was read immediately. It was not regarded that the
`HIGH_LATENCY2` message does not contain a `base_mode` field.

This introduces a fix where the mode string for HIGH_LATENCY2 messages
from a PX4 controller is returned as `Mode(msg.custom_mode)`.
@dernatsch dernatsch force-pushed the high-latency-mode-string branch from 0f20b0b to c0b3528 Compare March 4, 2023 18:25
@dernatsch
Copy link
Author

@peterbarker No worries, changed it to the way it's done at the bottom of the function. Hope it's alright now. :)

@peterbarker peterbarker merged commit d78a586 into ArduPilot:master Mar 6, 2023
@peterbarker
Copy link
Contributor

Merged, thanks @dernatsch

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