Syncing time with ROS2 computer and flight controller

Hi,

My flight controller is also communicating to an onboard computer via XRCE-DDS. My flight controller also has an external GPS.

How do I configure the time sync

I am using Ubuntu 22 on onboard computer with ROS2
I am using PX4 1.14

My understanding is the following

The flight controller will read Unix epoch time from GPS. I assume this default behavior? Source: Ground station(QGC) <=> Pi <=> Pixhawk time sync using GPS? - #2 by JulianOes

However, When using XRCE-DDS I believe there is a parameter UXRCE_DDS_SYNCC that will also sync the clock on the pixhawk to the onboard computer running the XCRCE-DDS agent. - However I do not have access to this parameter in Q Ground Control. The only DDS parameters I can see are: UXRCE_DDS_CFG, UXRCE_DDS_DOM_ID, and UXRCE_DDS_KEY. However from the documentation Parameter Reference | PX4 Guide (main) I see that UXRCE_DDS_SYNCT is enabled by default (even though I do not see it).

My questions are:

  1. Will the flight controller by default sync to GPS time

  2. How do I know what my flight controller clock is synching to? Is it syncing to GPS UTC time, Or am I syncing the time to the onboard computer via DDS?

  3. Why can I not see all XRCE-DDS parameter and only be able to see 3 of them (UXRCE_DDS_CFG, UXRCE_DDS_DOM_ID, and UXRCE_DDS_KEY)

  4. Is there a way to sync my onboard computer to the GPS time - This is the best approach I think - but I could not find a way to configure this via parameters. Is this possible?

Hi @px4_robot,

First of all, you are using PX4 1.14 but referring to the documentation for main.
UXRCE_DDS_SYNCC and UXRCE_DDS_SYNCT have been added after 1.14 and you can find them on the 1.15 branch and associated tags (v1.15.0-rc1 for the latest).

UXRCE_DDS_SYNCC, if enabled, makes the flight controller set its system clock to the companion computer UTC timestamp. It is useful when the flight controller does not have GPS or other sources (MAVLINK) to infer UTC time but the onboard computer does. This function does not exist in 1.14 therefore the flight controller will use GPS time if available.

UXRCE_DDS_SYNCT, if enabled, will just perform message timestamp synchronization between flight controller and companion computer. This function is always ON on 1.14 (it’s quite uncommon to want to disable it). You can think of it as the uxrce_dds equivalent of MAVLink time synchronization feature.

In 1.14 you will always sync to GPS time. Note that timestamp synchronization is different from system clock synchronization.

I don’t think this is possible at the moment. It would be a useful feature for companion computer that does not have network connection to use for time synchronization.

Hi @Benja

Thank you so much for your reply!

Can you tell me if my understanding of these points are correct?

(1) on 1.14 (and 1.15 when UXRCE_DDS_SYCT is true) The messages from the flight controller have their timestamp adjusted with the estimated time offset between the flight controller and the onboard computer. Thus all the ROS2 messages would have a timestamp based on the time of the onboard computer.

(2) If I wanted to correlate events observed in my flight log that were not published with a ros2 message and compare them to events that happened on my onboard computer that were also not published with a ros2 message - this would be impossible on 1.14 because the flight logs would be on GPS time due to system clock synchronization. However, if I was on 1.15 with UXRCE_DDS_SYNCT enabled, the system clock synchronization with GPS time would be ignored and the events in my flight log would have the time synced with my onboard PC.

(3) If I go with the approach mentioned in (1), is the best way to get this time synced message data a ros2 bag?

That’s correct. For example if an IMU message has PX4 timestamp of 60 seconds (because PX4 timestamp time 0 correspond to the board booting, more or less) and the board booted at ROS time 10000000000 seconds (calculated by the time synchronization routine), then if such IMU message is sent to ROS it will have header.stamp equal to 10000000060

At the same time a ROS message with timestamp 10000000100s will be published inside PX4 with timestamp 100s.

This is a simplification: the actual time offset is dynamically computed to account for clock drifts

well, it depends on the level of accuracy you want to achieve. GPS time and your companion computer time should not be super different assuming the companion computer can do time synchronization over Ethernet for example.
UXRCE_DDS_SYNCT was designed for application where the flight controller has no GPS so I’m not sure about the final behavior when you have both of them.

As long as you have the /fcu/out/timesync_status message logged in ROS you can get the offset out of its fields an apply to either logged ROS topics or logged PX4 topics. Once you remap everything in the same time reference you can do your comparison.

Hi,
just curious to know whether there is any parameter within Px4 v1.13.3 to sync UTC time .