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

Logger Metadata: Provide format and unit/multiplier info for log messages #25861

Merged
merged 1 commit into from
Jan 16, 2024

Conversation

shancock884
Copy link
Contributor

@shancock884 shancock884 commented Jan 1, 2024

The aim of this PR is to enable information about the units of logger message fields to be included on the web pages.
(This was one of the things that I would have found useful as a newbie!)

  • The definitions of each character representing formats, units and multipliers are extracted from LogStructure.h, so there should be no additional lookup table to maintain.
  • The data is extracted by parsing the logging definition struct as well as looking for direct calls to the logger's Write/Message/Critical() functions.

The format, unit and multiplier are combined to derive the actual unit of the value as displayed by the tools:

  • If the format type has "* 100" or "longitude/latitude" in the name, the specified unit is used directly, and multiplier ignored.
  • Otherwise, the multiplier is used to derive the actual unit from the base unit. e.g. 1e-3 & m => mm

For the XML output:

  • Both the format and derived unit are included in the XML in new attributes
  • Added output of value enumerations in the XML - previously only bitmask enumerations were included

For the .md, .rst and .html output:

  • Added one new column (Units/Type) containing (in priority order) the derived unit, 'char[n]', 'bitmask' or 'enum'
  • I chose this because:
    ** some messages on the web page already require horizontal scrolling, and I didn't want to make this worse
    ** I thought that strings/bitmasks/enums were useful to know about, on such fields without units
    ** I felt that further information (such as the raw data type, base unit and multiplier) could be confusing.

Additionally, I added support for separating log descriptions for messages with same field list (such as the PIDx messages), so that in the future they can each have a different description without having to repeat the field lists. e.g.:

// @LoggerMessage: PIDR
// @Description: Proportional/Integral/Derivative gain values for Roll
// @LoggerMessage: PIDP
// @Description: Proportional/Integral/Derivative gain values for Pitch
// @Field ..... (etc)

I think I've understood correctly how both MAVExplorer and UAVLogViewer work in how they decode field values, such that the units presented are consistent with the values that these tools provide to users. My understanding is as follows:

  • Format types of "xxx * 100" or "longitude/latitude" apply a multiplier from the raw value to the value presented to the user. e.g. by the time the user sees the value latitude will be in deg, even though its raw state was a degE7 scaled integer.
  • The Multiplier does not alter the value presented to the user, but rather alters the unit (e.g. "s" * 1-e6 => "us").

I've tested this by running parse.py for each vehicle type (['Rover', 'Sub', 'Copter', 'Plane', 'Tracker', 'Blimp']) and checking the outputs look sensible, including looking at a selection of fields in some of my own recordings and comparing against the units shown by UAVLogViewer when selecting plot parameters.

In testing I found that the "--vehicle Blimp" option already generated an error before I started, so I have fixed this by adding Blimp to the lookup table in parse_enum.py.

I had some observations from this:

  • The message "TRMS" has more formats ("QBHH") than fields (3).
  • If the multiplier is not a 1e-3, 1e3 or 1e-6, UAVLogViewer shows just the base unit, which I think may be incorrect in some cases (for example it says PM.Load is "%", but I think its really "d%"). It seems that there is already an issue and perhaps a PR looking at this in any case.

This took me a bit of digging around, so feel to correct any misunderstandings, or let me know if further explanation is needed!

Copy link
Collaborator

@andyp1per andyp1per left a comment

Choose a reason for hiding this comment

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

Very cool!

The commit message needs to start with the subsystem so:
"autotest: "

@andyp1per
Copy link
Collaborator

@peterbarker is the guy who will need to review this properly!

Definitions of each character are extracted from LogStructure.h
Data is extracted by parsing the logging definition struct
Also parse WriteMessage() calls for messages not defined in struct
Add support to separate log descriptions for messages with same field list
Compute derived unit from combination of format, unit and multiplier
For XML output the format and derived unit into new attributes
Add enumerations to the XML output (bitmasks were already done)
For MD,RST,HTML, output either derived unit, 'char[n]', 'bitmask' or 'enum'
Fix support for Blimp by adding it to the parse_enum.py lookup table
@shancock884
Copy link
Contributor Author

shancock884 commented Jan 2, 2024

The commit message needs to start with the subsystem so: "autotest: "

Thanks. Commit message updated as proposed.

@shancock884 shancock884 marked this pull request as ready for review January 4, 2024 11:53
@amilcarlucas
Copy link
Contributor

Were is some extra info, would be nice if we could combine it in:

Message Description Log rate LOG_BITMASK field name bit value
ACC IMU accelerometer data SCHED_LOOP_RATE IMU_RAW 19 524288
AHR2 Backup AHRS data 25Hz if ATTITUDE_FAST is set, else 10Hz - - -
ATSC Scale factors for attitude controller SCHED_LOOP_RATE / 1 ATTITUDE_FAST and ATTITUDE_MED 1 and 0 3
ATSC Scale factors for attitude controller SCHED_LOOP_RATE / 2 ATTITUDE_FAST 0 2
ATSC Scale factors for attitude controller SCHED_LOOP_RATE / 4 ATTITUDE_MED 0 1
ATSC Scale factors for attitude controller SCHED_LOOP_RATE / 8 - - 0
ATT Canonical vehicle attitude SCHED_LOOP_RATE ATTITUDE_FAST 0 1
ATT Canonical vehicle attitude 10 Hz ATTITUDE_MED 1 2
BAT Gathered battery data ?? CURRENT 9 512
BCL Battery cell voltage information ?? CURRENT 9 512
BCN Beacon information 10Hz CTUN 4 16
CAM Camera shutter information on event CAMERA 15 32768
CMD Executed mission command information on event CMD 8 256
CTRL Attitude Control oscillation monitor diagnostics 10Hz CTUN 4 16
FTN Filter Tuning Message - per motor SCHED_LOOP_RATE FTN_FAST 21 2097152
FTN1 FFT Filter Tuning 25 Hz FTN_FAST 21 2097152
FTNS Filter Tuning Message SCHED_LOOP_RATE FTN_FAST 21 2097152
GPA GPS accuracy information ~ 5 Hz GPS 2 4
GPS Information received from GNSS systems attached to the autopilot ~ 5 Hz GPS 2 4
GRAW Raw uBlox datas ~ 5 Hz GPS 2 4
GRXH Raw uBlox data - header ~ 5 Hz GPS 2 4
GRXS Raw uBlox data - space-vehicle data ~ 5 Hz GPS 2 4
GYR IMU gyroscope data SCHED_LOOP_RATE IMU_RAW 19 524288
IMU Inertial Measurement Unit data SCHED_LOOP_RATE IMU_FAST and ATTITUDE_FAST 18 and 0 262145
IMU Inertial Measurement Unit data 25 Hz IMU 7 128
MAG Information received from compasses ?? COMPASS 13 8192
MAVC MAVLink command we have just executed on event CMD 8 256
MCU MCU voltage and temperature monitoring ?? CURRENT 9 512
MOTB Motor mixer information 10Hz MOTBAT 17 131072
OF Optical flow sensor data ?? OPTFLOW 11 2048
PIDA Proportional/Integral/Derivative gain values for Altitude SCHED_LOOP_RATE if ATTITUDE_FAST is set else 10Hz PID 12 4096
PIDE Proportional/Integral/Derivative gain values for East SCHED_LOOP_RATE if ATTITUDE_FAST is set else 10Hz NTUN and PID 12 and 5 4128
PIDN Proportional/Integral/Derivative gain values for North SCHED_LOOP_RATE if ATTITUDE_FAST is set else 10Hz NTUN and PID 12 and 5 4128
PIDP Proportional/Integral/Derivative gain values for Pitch SCHED_LOOP_RATE if ATTITUDE_FAST is set else 10Hz PID 12 4096
PIDR Proportional/Integral/Derivative gain values for Roll SCHED_LOOP_RATE if ATTITUDE_FAST is set else 10Hz PID 12 4096
PIDY Proportional/Integral/Derivative gain values for Yaw SCHED_LOOP_RATE if ATTITUDE_FAST is set else 10Hz PID 12 4096
PM autopilot system performance and general data dumping ground 1 Hz PM 3 8
POS Canonical vehicle position 25Hz if ATTITUDE_FAST is set, else 10Hz - - -
POWR System power information ?? CURRENT 9 512
PRX Proximity Filtered sensor data 10Hz CTUN 4 16
PRXR Proximity Raw sensor data 10Hz CTUN 4 16
PSCD Position Control Down 10Hz NTUN 5 32
PSCE Position Control East 10Hz NTUN 5 32
PSCN Position Control North 10Hz NTUN 5 32
RATE Desired and achieved vehicle attitude rates SCHED_LOOP_RATE / 1 ATTITUDE_FAST and ATTITUDE_MED 1 and 0 3
RATE Desired and achieved vehicle attitude rates SCHED_LOOP_RATE / 2 ATTITUDE_FAST 0 2
RATE Desired and achieved vehicle attitude rates SCHED_LOOP_RATE / 4 ATTITUDE_MED 0 1
RATE Desired and achieved vehicle attitude rates SCHED_LOOP_RATE / 8 - - 0
RCIN RC input channels to vehicle 10Hz RCIN 6 64
RCI2 (More) RC input channels to vehicle 10Hz RCIN 6 64
RCO2 Servo channel output values 15 to 18 10Hz RCOUT 10 1024
RCO3 Servo channel output values 19 to 32 10Hz RCOUT 10 1024
RCOU Servo channel output values 1 to 14 10Hz RCOUT 10 1024
RFND Rangefinder sensor information 10Hz CTUN 4 16
RSSI Received Signal Strength Indicator for RC receiver 10Hz RCIN 6 64
SIDD System ID data SCHED_LOOP_RATE / 1 ATTITUDE_FAST and ATTITUDE_MED 1 and 0 3
SIDD System ID data SCHED_LOOP_RATE / 2 ATTITUDE_FAST 0 2
SIDD System ID data SCHED_LOOP_RATE / 4 ATTITUDE_MED 0 1
SIDD System ID data SCHED_LOOP_RATE / 8 - - 0
SIDS System ID settings SCHED_LOOP_RATE / 1 ATTITUDE_FAST and ATTITUDE_MED 1 and 0 3
SIDS System ID settings SCHED_LOOP_RATE / 2 ATTITUDE_FAST 0 2
SIDS System ID settings SCHED_LOOP_RATE / 4 ATTITUDE_MED 0 1
SIDS System ID settings SCHED_LOOP_RATE / 8 - - 0
TERR Terrain database information ~ 5 Hz GPS 2 4
TRIG Camera shutter information on event CAMERA 15 32768
UBX1 uBlox-specific GPS information (part 1) ~ 5 Hz GPS 2 4
UBX2 uBlox-specific GPS information (part 2) ~ 5 Hz GPS 2 4
VIBE Processed (acceleration) vibration information 10Hz IMU or IMU_FAST or IMU_RAW 19 or 18 or 7 -
VSTB Motor mixer information SCHED_LOOP_RATE VIDEO_STABILISATION 20 1048576
WINC Winch 10Hz Any any any
XKF0 EKF3 beacon sensor diagnostics 25Hz if ATTITUDE_FAST is set, else 10Hz - - -
XKF1 EKF3 estimator outputs 25Hz if ATTITUDE_FAST is set, else 10Hz - - -
XKF2 EKF3 estimator secondary outputs 25Hz if ATTITUDE_FAST is set, else 10Hz - - -
XKF3 EKF3 innovations 25Hz if ATTITUDE_FAST is set, else 10Hz - - -
XKF4 EKF3 variances 25Hz if ATTITUDE_FAST is set, else 10Hz - - -
XKF5 EKF3 Sensor innovations (primary core) and general dumping ground 25Hz if ATTITUDE_FAST is set, else 10Hz - - -
XKFS EKF3 sensor selection 25Hz if ATTITUDE_FAST is set, else 10Hz - - -
XKQ EKF3 quaternion defining the rotation from NED to XYZ (autopilot) axes 25Hz if ATTITUDE_FAST is set, else 10Hz - - -
XKT EKF3 timing information 25Hz if ATTITUDE_FAST is set, else 10Hz - - -
XKV1 EKF3 State variances (primary core) 25Hz if ATTITUDE_FAST is set, else 10Hz - - -
XKV2 more EKF3 State Variances (primary core) 25Hz if ATTITUDE_FAST is set, else 10Hz - - -

@shancock884
Copy link
Contributor Author

@amilcarlucas - that seems like it could be useful information to include. I suppose the way to do it is to include something like this in the message definition comments, alongside the other info:

// @LogRate SCHED_LOOP_RATE if ATTITUDE_FAST is set else 10Hz
// @LogBitMaskField NTUN and PID

Personally I would prefer this to be raised in a separate proposal/issue, to avoid adding extra things into this PR, and to give others an opportunity to voice any strong opinions on the field naming and page rendering before implementation.

@amilcarlucas
Copy link
Contributor

Yes, I agree, let's get this one in first

@amilcarlucas
Copy link
Contributor

Where do the generated files get stored? Are they available on firmware.ardupilot.org ? They should.

@shancock884
Copy link
Contributor Author

Where do the generated files get stored? Are they available on firmware.ardupilot.org ? They should.

They end up here: https://autotest.ardupilot.org/LogMessages/ thanks to: Tools/scripts/build_log_message_documentation.sh

@amilcarlucas
Copy link
Contributor

amilcarlucas commented Jan 12, 2024

It would be better if they would also end up here:
https://firmware.ardupilot.org/Blimp/stable-4.4.4/
https://firmware.ardupilot.org/Copter/stable-4.4.4/
https://firmware.ardupilot.org/Plane/stable-4.4.4/
https://firmware.ardupilot.org/Rover/stable-4.4.4/
https://firmware.ardupilot.org/Tracker/stable-4.4.4/

That way even stable (older) releases would have consistent documentation. The same applies to the apm.pdef.xml files.

@amilcarlucas
Copy link
Contributor

Can you add html anchors to each message so that they can be referenced directly from an external link?

@shancock884
Copy link
Contributor Author

Can you add html anchors to each message so that they can be referenced directly from an external link?

It looks like anchors may already be created, e.g.: https://ardupilot.org/copter/docs/logmessages.html#gpa

@tridge tridge merged commit c0a503d into ArduPilot:master Jan 16, 2024
40 checks passed
@shancock884 shancock884 deleted the log-message-show-units branch January 16, 2024 09:03
@amilcarlucas
Copy link
Contributor

@Hwurzburg what do you think about versioning this, like I posted three posts up?

@Hwurzburg
Copy link
Collaborator

@amilcarlucas I dont think that has a lot of value for normal users....since they dont mess with logs much..unlike parameters which does have a lot of value for versioning...and devs/sophisticated users dont really need it, they can git blame if they really need to find when a log message was added/changed..
I am not against it if someone want to devote the time automating it, but I dont think it adds a lot of value for most users...

@amilcarlucas
Copy link
Contributor

If it gets automatically generated by the release script and stored at https://firmware.ardupilot.org/Blimp/stable-4.4.4/ together with a apm.pdef.xml file for that version it will help some developers. And does not need any wiki change.

@Hwurzburg
Copy link
Collaborator

when its implemented I can add a note in the wiki about how to find the old versions

@amilcarlucas
Copy link
Contributor

@rmackay9 are you OK with this? Should I implement it?

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.

None yet

8 participants