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

DFReader: Read unit data from log and add dump_verbose function to DFMessage #911

Merged
merged 1 commit into from
Jan 27, 2024

Conversation

shancock884
Copy link
Contributor

@shancock884 shancock884 commented Jan 26, 2024

The main aim of this PR is to make the DF log reader 'unit aware', by reading the UNIT and MULT messages from the log, and then storing the resulting units as part of the format definition.
In order to test it, the update also adds a dump_verbose method which is used by mavlogdump (and later MAVExplorer dump command, with separate PR) when the --verbose argument is used.
(Previously verbose outputs were only available with Mavlink/TLog files)

Note that the multipliers specified in the MULT/FMTU messages do not alter data values (so nothing should be unexpectedly different to any users or other tools), but rather amend the unit with a suitable prefix. e.g.: Ah * 1e-3 => mAh.
This is in line with the logic used to populate the wiki.

Implementation notes:

Cache units and multipliers in unit_lookup and mult_lookup lookup tables when first scanning the DFBinary or DFText file.
When applying the FMTU message to the format, compute and store the derived unit for each field as DFFormat class attribute.
Added get_unit method on DFFormat to return unit if defined or empty string if not.

Create dump_verbose function on DFMessage class, which outputs both value and unit for each field.
Also show the deg or deg/s value for rad or rad/s fields

Separate code to detect quiet nan into a utility function, so it can be used by both __str__ and dump_verbose functions.

Improve display precision of values which have a multiplier attached to their format....
For things like latitude/longitude, I noticed that Python was printing unexpectedly long numbers, e.g.:
>>> 401952592*1e-7 # gives: 40.195259199999995
And I found that by converting the multiplier to a divisor, you get a much cleaner value displayed:
>>> 401952592/1e7 # gives 40.1952592

mavlogdump.py updated to call the dump_verbose method when --verbose specified
I have used hasattr to check the new method exists, in case of misaligned files - probably not so important for mavlogdump.py, as this and DFReader.py are both part of same Python package, but I thought it was safer when doing the same in MavExplorer, as its packaged in MAVProxy.

Testing

Tested with both DF binary and DF text files, using mavlogdump. An example of the output follows:

$ mavlogdump.py --verbose ArduPlane-Soaring-00000045.BIN --types POS
2024-01-07 11:46:53.019: POS
    TimeUS: 8025122 µs
    Lat: -35.362938 deglatitude
    Lng: 149.165085 deglongitude
    Alt: -0.14999999105930328 m
    RelHomeAlt: -0.15874642133712769 m
    RelOriginAlt: qnan m

$ mavlogdump.py --verbose ArduPlane-Soaring-00000045.log --types BAT
2024-01-07 11:46:46.799: BAT
    TimeUS: 1805111 µs
    Inst: 0 instance
    Volt: 12.6 V
    VoltR: 0.0 V
    Curr: 0.0 A
    CurrTot: 0.0 mAh
    EnrgTot: 0.0 W.h
    Temp: 0.0 degC
    Res: 0.0 Ohm
    RemPct: 100 %
    H: 1

(And thanks @peterbarker for pointing my at your units branch - it was useful to compare and update what I had started).

…Message

Cache units and multipliers in lookup tables when first scanning the file
Handles both DFBinary and DFText files
Store derived unit for each field as DFFormat class attribute
Create get_unit method on DFFormat to return unit if defined or empty string

Create dump_verbose function on DFMessage class, which outputs both value and
unit for each field
Also show the deg or deg/s value for rad or rad/s fields

Separate code to detect quiet nan into a utility function, so it can be used
by both __str__ and dump_verbose

Improve display precision of values with a format multiplier, e.g.:
(401952592*1e-7 => 40.195259199999995 vs 401952592/1e7 => 40.1952592)

mavlogdump.py updated to call the dump_verbose method when --verbose specified
Use hasattr to check method exists, in case of misaligned files
@shancock884 shancock884 marked this pull request as ready for review January 26, 2024 13:05
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.

This is no slower than master.

@@ -379,6 +379,9 @@ def match_type(mtype, patterns):
elif args.verbose and istlog:
mavutil.dump_message_verbose(sys.stdout, m)
print("")
elif args.verbose and hasattr(m,"dump_verbose"):
m.dump_verbose(sys.stdout)
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should go via dump_message_verbose here, even 'though we do have an object (that we control) to call methods on.

@peterbarker peterbarker merged commit e39879a into ArduPilot:master Jan 27, 2024
12 checks passed
@peterbarker
Copy link
Contributor

Merged, thanks!

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.

2 participants