DFReader: Read unit data from log and add dump_verbose function to DFMessage #911
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
(And thanks @peterbarker for pointing my at your units branch - it was useful to compare and update what I had started).