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

[WIP] uORB::Publication automatically set timestamp #13970

Closed
wants to merge 1 commit into from

Conversation

dagar
Copy link
Member

@dagar dagar commented Jan 17, 2020

WORK IN PROGRESS

The eventual goal is the timestamp field of a uORB messsage to be metadata that corresponds (atomically) with the message being published and available to the rest of the system. This is an incremental step in that direction that removes a lot of the current potential misuse. Things like setting the timestamp to an inappropriate value (like a much older sample timestamp passed through), setting it much earlier than actual publication, or even just forgetting to set it at all.

Ideally this would be pushed into the uORB::DeviceNode internals and the timestamp set in the same critical section as the message copy, however we're currently in an odd position with the timestamp not strictly required in every message. This needs to be revisited with ROS2 taken into account, including the possibility of directly into a std_msgs/Header equivalent.

For example in #13955 the accel and gyro sensor message are updated to have a dedicated timestamp_sample field that we set as closely as possible to time corresponding to the contained data.

@dagar dagar force-pushed the pr-uorb_timestamp branch from c545256 to df1a945 Compare March 12, 2020 14:00
@TSC21
Copy link
Member

TSC21 commented Mar 12, 2020

@dagar what are we missing here to bring it in?

Copy link
Member

@TSC21 TSC21 left a comment

Choose a reason for hiding this comment

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

Tests seem to be failing...

* @param timestamp
* @param data The uORB message struct we are updating.
*/
bool publish(const hrt_abstime &timestamp, T &data)
Copy link
Member

Choose a reason for hiding this comment

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

Why not instead

Suggested change
bool publish(const hrt_abstime &timestamp, T &data)
bool publish(T &data, hrt_abstime &timestamp = hrt_absolute_time())

* Publish the struct
* @param data The uORB message struct we are updating.
*/
bool publish(const hrt_abstime timestamp, T &data)
Copy link
Member

Choose a reason for hiding this comment

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

same as above

@dagar
Copy link
Member Author

dagar commented Mar 12, 2020

@dagar what are we missing here to bring it in?

Finding out why the tests are broken and carefully reviewing special cases where setting the timestamp manually has mattered historically.

  • sensor pipeline sensor_accel/gyro -> sensor_combined
  • mavlink receiver setting timestamps with time sync
  • replay (currently uses the old api, but it would good to understand any requirements for manual timestamping to transition later)
  • possible testing special cases?
  • anything else?

Note, this isn't the complete solution, but I see it as an incremental step that brings us closer. I ultimately want the timestamp to be set in the same critical section where the published data is copied into the buffer. I want the publication timestamp to be as close as possible to the actual time it is available to subscribers in the system.

EDIT: If we can guarantee that timestamp is the first 8 bytes of every single message this could be pushed into uORB::DeviceNode.

https://github.com/PX4/Firmware/blob/69b38c9cedde2f1827203c8b752786414fac9001/src/modules/uORB/uORBDeviceNode.cpp#L275-L283

@TSC21
Copy link
Member

TSC21 commented Mar 12, 2020

EDIT: If we can guarantee that timestamp is the first 8 bytes of every single message this could be pushed into uORB::DeviceNode.

https://github.com/PX4/Firmware/blob/69b38c9cedde2f1827203c8b752786414fac9001/src/modules/uORB/uORBDeviceNode.cpp#L275-L283

What do we gain from pushing to uORB::DeviceNode? The "close as possible to the actual time it is available to subscribers in the system" you said? I feel that as soon as we do that we will be constraining ourselves.

@dagar
Copy link
Member Author

dagar commented Mar 12, 2020

What do we gain from pushing to uORB::DeviceNode? The "close as possible to the actual time it is available to subscribers in the system" you said?

We get a trustworthy timestamp that is actual publication metadata and can't be screwed up.

I feel that as soon as we do that we will be constraining ourselves.

I don't think so. We might have some side mechanism for very special cases like replay that might need to set it manually, but for everything else we can rely on uORB to do it perfectly.

@stale
Copy link

stale bot commented Aug 1, 2020

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

@stale stale bot added the stale label Aug 1, 2020
@dagar dagar closed this Aug 3, 2020
@LorenzMeier LorenzMeier deleted the pr-uorb_timestamp branch January 18, 2021 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants