Repository navigation
Conversation
|
I seriously do not think this is worth the extra complexity and code in main codepaths just to have the clock on the handset shifted by a few seconds. I think the main benefit of 0x03 GPS TIME is to have the clock on the handset not be 2000-Jan-01, not to have a precise atomic clock at the handset. While I do find your code to be well written, just jamming special case code in main code paths isn't worth the minor benefit of the clock being corrected by 6s. This offset is also sub 1s at higher telemetry rates, isn't it? |
|
Valid points. When I first got this working with Betaflight, I also assumed an approximate time would be good enough. However, several users on Discord and GitHub have since requested the ability to sync telemetry logs precisely with external systems, where a variable, multi-second delay becomes problematic. That's what led me to go down this rabbit hole of figuring out how to correct for the drift in a clean and logical way. I do not have a good sense for how much of an impact this has on receiver performance, and am cognizant of the RAM/flash issues especially on ESP82xx based receivers. We could probably move the correction entirely to the TX side, as I estimate the RX side correction is minimal (i.e. <500ms, mostly due to GPS polling rate and telem packet scheduling). I haven't gone to the effort of outputting the various delays to debug values yet, but certainly could if needed. Would moving all of the correction to the TX side be acceptable? As an aside, at least for the Betaflight implementation, the 0x03 packet is only sent at most once every 30s, and only when disarmed. The RTC clock should not need constant correction once set, and the GPS Time packet is pretty heavy. |
|
Way to go, @ot0tot ! This could well solve the synchronization issue for good. @CapnBry: Re: "a few seconds", the difference can be up to tens of seconds in my tests, and to make things worse it's variable (depends on packet rate and other stuff). This makes it difficult to synchronize the telemetry recorded in the transmitter with the data shown in the OSD (recorded in the goggles or groundstation), for example). Besides the code path concern being mitigated by the fact this only runs every 30s and only when the drone is disarmed like @ot0tot stated, another idea would be to make a specific setting to the ELRS configurator to completely turn this off, with the default set to off -- this way, there would be zero run-time impact to anyone not explicitly turning it on. The added complexity to the source code remains, of course, but I think it would be a small price to pay for precise time syncing (and I imagine knowing the OTA delay could be interesting for other uses too). |
Just to clarify: yes, setting the packet rate to 500Hz and the telemetry rate to 1:8 or more frequent, I was able to obtain sub-second precision. But it's extremely time-consuming and inconvenient to set this and then reset it back after the transmitter clock gets set, having it done automatically would certainly be much better. |
|
I guess my main complaint is that is slams very highly specific edge case code into the main processing bits. We already have a problem with functions that continue to grow and be packed full of just very specific weird one-off stuff and makes working with those functions more complicated. Sure, it only adds 10 lines of code here, or 5 lines there, but we've been working to remove all these sort of things and rearchitect the code to not rely on this sort of "just shove it in loop()" implementation. This also does some cascading time math that stops short of having to deal with midnight UTC, which is a time that happens while flying. |
It's not going to happen while flying -- in fact none of this code is going to be executed during flight since (if I understand it correctly) the packets that would trigger it are never sent while the drone is armed -- only when it's disarmed.
From the point of runtime inclusion, see above. From the point of pure presence in the code, perhaps put it behind a compile-time option (ie bracketed by a #ifdef/#endif pair or similar)? |
EdgeTX recently added support for setting the handset RTC from CRSF GPS Time frames (EdgeTX/edgetx#7317), and I recently added support to Betaflight to forward these frames also (betaflight/betaflight#15167). In testing, however, the handset RTC ends up 2–9 seconds behind actual UTC. I believe most of this is due to the delay between when the GPS time message is received and when it is enqueued, sent, and read at the handset. Using normal packets, the 11-byte GPS Time frame would take 3 telem packets to send, which depending on packet rate, telemetry ratio, retries, etc, could add appreciable delay.
I think the most common use case for this is when the RTC battery is low/dead or people want accurate time on the handset to sync logs between multiple platforms. Thus having an accurate RTC is desirable.
This PR adds timestamps on the RX side between when the GPS time message is received and when it leaves the telemetry queue, adds an offset to compensate for the delay between the RX sending the packet and the TX registering the telem packet is being received based on packet rate and TOA, and a timestamp at the TX from when the first chunk is received and when HasFinishedData() fires, which accounts for the time it takes to send the 2-3 telem packets including any retries due to the stubborn sender.
Tested and working with latest Betaflight master.