-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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
uORB: add timestamp field to uORB msgs #10178
Conversation
The timestamp field is in every message already. The generator automatically adds it. |
I know @mhkabir. But that was removed as well if you check it on the PR. It needs to be on the msg definition, and not auto-generated so what I described above works. |
Unfortunately, px4fmu-v2 is again killing the progress. Have to check what's causing |
Looks good so far. Note that you don't have to go through the modules since there is no change for them, execpt for the debug_*.msg topics. |
@mhkabir this is needed for ros rtps bridge that nuno is working on. We can not depend on some magic in the generator (which is only in px4 but in none of the ros generator)s |
ddf2531
to
15133c8
Compare
pxh> listener sensor_baro
TOPIC: sensor_baro instance 0 #1
sensor_baro_s
(0.004982 seconds ago)
timestamp: 33179575
error_count: 0
device_id: 478459
pressure: 955.936
temperature: 32.000 So it seems good. Though now something might be wrong with uLog (http://ci.px4.io:8080/blue/organizations/jenkins/PX4_misc%2FFirmware-SITL_tests/detail/PR-10178/3/pipeline#step-129-log-262) |
In my experience, the timestamp field is a major blocking point for new users (both students and experienced programmers): they do not see that the timestamp field is automatically generated and has to be filled manually. What about leaving the automatically generated timestamp, but automatically filling it upon call to publish()? I think this would disambiguate the meaning of the timestamp field. Now it is unclear whether this field refers to the moment the message was published, or to the timestamp of the data contained in the message. If it was automatically field upon at publish time, |
This is probably the right change short term, but longer term what we really need is a timestamp metadata field that corresponds with the actual orb publish. When a sample timestamp is needed it should be added and set explicitly. Think about it from the perspective of log review and replay. What you're plotting is quite often not what the rest of the system actually saw at that particular time. This is also why things like ekf2_timestmaps are needed. EDIT: this was written before @jlecoeur's well timed input. |
I see your point but currently ROS IDL generators require the timestamps to be explicitly set on the msg definitions, and not autogenerated.
@jlecoeur the problem here is not about filling it or not, it's about having the timestamp explicitly defined on the msg definition. Though I agree with you regarding the ambiguity of the the definition of a timestamp, the current thing that this PR solves is not how the timestamp is set, but rather how it is exposed. |
This is only because the timestamp (uorb metadata) was manually added to microcdr and urtps, which was a bit of a hack. A solution that would both be simpler now and better for PX4 long term is to leave the uORB metadata side alone and remove the manual timestamp additions for RTPS.
Then in the small number of cases where you actually need the sample timestamp (IMU) you add that field explicitly in the .msg (timestamp_sample). Later in PX4 we can push the timestamping into orb_publish itself and cleanup the replay system. |
The thing is, on the ROS side, you don't actually have a sample timestamp: the ROS stamp (which is set on the header, pretty much similar to uORB) represents the time since Unix epoch and it matches the sample time - so in the end, they do represent the same thing, there is no convention for splitting sample time and time since system epoch. So, in that sense, I don't actually think we should have a explicit separation between them. |
@jlecoeur there already exist those fields in several msgs as they are. They thing here is about exposing the timestamp field as something readable by the ROS IDL generator. ROS itself exposes the timestamp field through the Header, and that's the sort of convention compatibility we are looking for here, since, again, there's no actual splitting difference between the msg pub time and the sample time in ROS. |
This is now solved with the latest commit: http://ci.px4.io:8080/blue/organizations/jenkins/PX4_misc%2FFirmware-SITL_tests/detail/PR-10178/6/pipeline/ |
Blocked by FMUv2 flash overflow |
I'll try to find some space on FMUv2. |
Thanks @dagar! |
…the struct size matches
9d8355e
to
7e85a97
Compare
By magic, now px4fmu-v2 doesn't complain. @dagar can we bring this in? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more detail, otherwise this is good to go.
try: | ||
assert 'timestamp' in field_name_list | ||
except AssertionError: | ||
print("[ERROR] uORB topic files generator:\n\tgenerate_output_from_file:\tNo 'timestamp' field found in " + spec.short_name + " msg definition!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice error message 👍
Can you also ensure that the type is uint64_t
, our logging infrastructure depends on that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
@@ -43,6 +43,7 @@ | |||
import filecmp | |||
import argparse | |||
import sys | |||
import numpy as np |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you add this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah sorry. This was when I was comparing types. Will remove.
for field in spec.parsed_fields(): | ||
field_name_and_type.update({field.name:field.type}) | ||
# assert if the timestamp field exists | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can change this to one line like:
if 'timestamp' not in field_name_and_type:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually do think it is a better practice to use a try catch approach for this kind of assertions, rather than using if/else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally yes, but not if you catch it with the next line.
Not a big deal to me however.
5ce5bce
to
cefe103
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get it in.
for field in spec.parsed_fields(): | ||
field_name_and_type.update({field.name:field.type}) | ||
# assert if the timestamp field exists | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally yes, but not if you catch it with the next line.
Not a big deal to me however.
Describe problem solved by the proposed pull request
In order to properly generate micro-RTPS agent code and headers compatible with both ROS2 and the micro-RTPS client, the uORB
.msg
require to have atimestamp
field on their definition.Describe your preferred solution
Basically add the timestamp field to each of the uORB topics and removes the auto-generated one. Also, whenever possible, I added the timesync between the mavlink propagated timestamp and the system time (to be reviewed).
Additional context
This still needs to be reviewed per module and check what are the repercussions, if at all, on each one, including logs and replay.
@thomasgubler @bkueng FYI. First suggestions and reviews are welcomed, though I still have to walk through the source code and check for duplicated/redundant timestamps and also how each timestamp is being used and how it will influence this PR.