Skip to content

First message(s) published by diagnostic updater have empty hardware_id #666

Description

@wentasah

Even if updater.setHardwareID() is called before updater.add(), the first published message has hardware_id empty. Only the messages published later from the timer callback have hardware_id set.

The consequence of this behaviour is that tools like foxglove or ros2_console_tools can show one diagnostic entry twice, each with different status. See the screenshot below:

Image

This happens in Jazzy, but from looking at the source code, the it's likely the same in newer distros.

This can be reproduced as follows:

  1. In one terminal run:

    ros2 topic echo /diagnostics --filter 'm.status[0].name == "diagnostic_updater_example: Function updater"' | grep hardware_id```
    
  2. In the second terminal run:

    ros2 run diagnostic_updater example
    

Received output:

  hardware_id: ''
  hardware_id: ''
  hardware_id: ''
  hardware_id: ''
  hardware_id: Device-27-46
  hardware_id: Device-27-46
  hardware_id: Device-27-46
  hardware_id: Device-27-46

Expected output:

  hardware_id: Device-27-46
  hardware_id: Device-27-46
  hardware_id: Device-27-46
  hardware_id: Device-27-46
  hardware_id: Device-27-46
  hardware_id: Device-27-46
  hardware_id: Device-27-46
  hardware_id: Device-27-46

The fix is probably simple. I just don't have time right now to prepare and test it.

Received output (without grep filtering)

For completeness, the full output without filtering the hardware_id is below.

header:
  stamp:
    sec: 1788283543
    nanosec: 462839642
  frame_id: ''
status:
- level: "\0"
  name: 'diagnostic_updater_example: Function updater'
  message: Node starting up
  hardware_id: ''
  values: []
---
header:
  stamp:
    sec: 1788283543
    nanosec: 462852992
  frame_id: ''
status:
- level: "\0"
  name: 'diagnostic_updater_example: Function updater'
  message: Doing important initialization stuff.
  hardware_id: ''
  values: []
- level: "\0"
  name: 'diagnostic_updater_example: Method updater'
  message: Doing important initialization stuff.
  hardware_id: ''
  values: []
- level: "\0"
  name: 'diagnostic_updater_example: Bound check'
  message: Doing important initialization stuff.
  hardware_id: ''
  values: []
---
header:
  stamp:
    sec: 1788283543
    nanosec: 963490803
  frame_id: ''
status:
- level: "\x02"
  name: 'diagnostic_updater_example: Function updater'
  message: Buckle your seat belt. Launch in 0.000000 seconds!
  hardware_id: Device-27-46
  values:
  - key: Diagnostic Name
    value: dummy
  - key: Time to Launch
    value: '0'
  - key: Geeky thing to say
    value: The square of the time to launch 0.000000 is 0.000000
- level: "\x01"
  name: 'diagnostic_updater_example: Method updater'
  message: This is a silly updater.
  hardware_id: Device-27-46
  values:
  - key: Stupidicity of this updater
    value: '1000'
- level: "\x02"
  name: 'diagnostic_updater_example: Bound check'
  message: Too low
  hardware_id: Device-27-46
  values:
  - key: Low-Side Margin
    value: '-5'
  - key: Top-Side Margin
    value: '10'
- level: "\x02"
  name: 'diagnostic_updater_example: topic1 topic status'
  message: No events recorded.; Too low
  hardware_id: Device-27-46
  values:
  - key: Events in window
    value: '0'
  - key: Events since startup
    value: '0'
  - key: Duration of window (s)
    value: '0.000190'
  - key: Actual frequency (Hz)
    value: '0.000000'
  - key: Minimum acceptable frequency (Hz)
    value: '0.450000'
  - key: Maximum acceptable frequency (Hz)
    value: '2.200000'
  - key: Low-Side Margin
    value: '-5'
---

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions