Fix PPS based UTC timestamp in camera trigger and capture messages

The existing implementation has about 100ms difference to a reference clock. With the changes this error less than 25us.
- Use sensor_gps messages with hrt timestamps as RTC reference and not the system realtime clock. The PPS interrupt can then be aligned with the GPS clock system.
- Keep fallback based on system RTC when no PPS pulse was captured
This commit is contained in:
Michael Schaeuble
2021-11-11 11:05:03 +01:00
committed by Beat Küng
parent ebb657bcf4
commit 5ad8b84dec
6 changed files with 61 additions and 31 deletions
+14 -5
View File
@@ -174,7 +174,8 @@ private:
bool _turning_on{false};
matrix::Vector2f _last_shoot_position{0.f, 0.f};
bool _valid_position{false};
int32_t _rtc_drift_time{0};
uint64_t _pps_hrt_timestamp{0};
uint64_t _pps_rtc_timestamp{0};
//Camera Auto Mount Pivoting Oblique Survey (CAMPOS)
uint32_t _CAMPOS_num_poses{0};
@@ -828,16 +829,24 @@ CameraTrigger::engage(void *arg)
pps_capture_s pps_capture;
if (trig->_pps_capture_sub.update(&pps_capture)) {
trig->_rtc_drift_time = pps_capture.rtc_drift_time;
trig->_pps_hrt_timestamp = pps_capture.timestamp;
trig->_pps_rtc_timestamp = pps_capture.rtc_timestamp;
}
// Send camera trigger message. This messages indicates that we sent
// the camera trigger request. Does not guarantee capture.
camera_trigger_s trigger{};
timespec tv{};
px4_clock_gettime(CLOCK_REALTIME, &tv);
trigger.timestamp_utc = ts_to_abstime(&tv) + trig->_rtc_drift_time;
if (trig->_pps_hrt_timestamp > 0) {
// Current RTC time (RTC time captured by the PPS module + elapsed time since capture)
trigger.timestamp_utc = trig->_pps_rtc_timestamp + hrt_elapsed_time(&trig->_pps_hrt_timestamp);
} else {
// No PPS capture received, use RTC clock as fallback
timespec tv{};
px4_clock_gettime(CLOCK_REALTIME, &tv);
trigger.timestamp_utc = ts_to_abstime(&tv);
}
trigger.seq = trig->_trigger_seq;
trigger.feedback = false;