# Syncing time with ROS2 computer and flight controller

**URL:** <https://discuss.px4.io/t/syncing-time-with-ros2-computer-and-flight-controller/39928>\
**Category:** ROS 1 / ROS 2\
**Created:** [July 29, 2024, 10:10pm UTC](https://discuss.px4.io/t/syncing-time-with-ros2-computer-and-flight-controller/39928 "2024-07-29T22:10:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![px4\_robot](https://discuss.px4.io/user_avatar/discuss.px4.io/px4_robot/32/14999_2.png) [@px4\_robot](https://discuss.px4.io/u/px4_robot)\
**Post date:** [July 29, 2024, 10:10pm UTC](https://discuss.px4.io/t/syncing-time-with-ros2-computer-and-flight-controller/39928/1 "2024-07-29T22:10:19Z")

</div>

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](https://discuss.px4.io/t/ground-station-qgc-pi-pixhawk-time-sync-using-gps/16976/2)

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)](https://docs.px4.io/main/en/advanced_config/parameter_reference.html#uxrce-dds-client) 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?

---

<div class="post-metadata">

**Author:** ![Benja](https://discuss.px4.io/user_avatar/discuss.px4.io/benja/32/11872_2.png) [@Benja](https://discuss.px4.io/u/Benja)\
**Post date:** [August 26, 2024, 10:46pm UTC](https://discuss.px4.io/t/syncing-time-with-ros2-computer-and-flight-controller/39928/2 "2024-08-26T22:46:03Z")

</div>

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](https://docs.px4.io/main/en/advanced_config/parameter_reference.html#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](https://docs.px4.io/main/en/advanced_config/parameter_reference.html#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](https://mavlink.io/en/services/timesync.html) feature.

> [@px4\_robot](#):
>
> 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?

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

> [@px4\_robot](#):
>
> 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?

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.

---

<div class="post-metadata">

**Author:** ![px4\_robot](https://discuss.px4.io/user_avatar/discuss.px4.io/px4_robot/32/14999_2.png) [@px4\_robot](https://discuss.px4.io/u/px4_robot)\
**Post date:** [August 27, 2024, 4:13am UTC](https://discuss.px4.io/t/syncing-time-with-ros2-computer-and-flight-controller/39928/3 "2024-08-27T04:13:25Z")

</div>

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](https://docs.px4.io/main/en/advanced_config/parameter_reference.html#UXRCE_DDS_SYNCT) 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](https://docs.px4.io/main/en/advanced_config/parameter_reference.html#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?

---

<div class="post-metadata">

**Author:** ![Benja](https://discuss.px4.io/user_avatar/discuss.px4.io/benja/32/11872_2.png) [@Benja](https://discuss.px4.io/u/Benja)\
**Post date:** [August 27, 2024, 8:23pm UTC](https://discuss.px4.io/t/syncing-time-with-ros2-computer-and-flight-controller/39928/4 "2024-08-27T20:23:13Z")

</div>

> [@px4\_robot](#):
>
> (1) on 1.14 (and 1.15 when [UXRCE\_DDS\_SYCT](https://docs.px4.io/main/en/advanced_config/parameter_reference.html#UXRCE_DDS_SYNCT) 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.

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

> [@px4\_robot](#):
>
> (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](https://docs.px4.io/main/en/advanced_config/parameter_reference.html#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.

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.

> [@px4\_robot](#):
>
> (3) If I go with the approach mentioned in (1), is the best way to get this time synced message data a ros2 bag?

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.

---

<div class="post-metadata">

**Author:** ![sibujacob](https://discuss.px4.io/user_avatar/discuss.px4.io/sibujacob/32/9673_2.png) [@sibujacob](https://discuss.px4.io/u/sibujacob)\
**Post date:** [September 3, 2024, 11:00am UTC](https://discuss.px4.io/t/syncing-time-with-ros2-computer-and-flight-controller/39928/5 "2024-09-03T11:00:10Z")

</div>

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

> [@System time EPOCH is showing UTC instead of local time | Is it possible to change to local](https://discuss.px4.io/t/system-time-epoch-is-showing-utc-instead-of-local-time-is-it-possible-to-change-to-local/33234):
>
> Hi, Would like to know if it is possible to change the Unix Epoch Clock to local time . While I try to set the time ( system\_time set ) through the PX4 QGC nsh console to local time, it still shows the UTC time. All my logs currently show the utc time and not local time even though the radio telemetry ( Herelink) shows the current local time .
