diff --git a/src/drivers/camera_capture/camera_capture.cpp b/src/drivers/camera_capture/camera_capture.cpp index c47d27ba67..7d1183b2df 100644 --- a/src/drivers/camera_capture/camera_capture.cpp +++ b/src/drivers/camera_capture/camera_capture.cpp @@ -193,10 +193,8 @@ CameraCapture::publish_trigger() if (_pps_hrt_timestamp > 0) { - // Current RTC time (RTC time captured by the PPS module + elapsed time since capture) - uint64_t gps_utc_time = _pps_rtc_timestamp + hrt_elapsed_time(&_pps_hrt_timestamp); - // Current RTC time - elapsed time since capture interrupt event - trigger.timestamp_utc = gps_utc_time - hrt_elapsed_time(&trigger.timestamp); + // Last PPS RTC time + elapsed time to the camera capture interrupt + trigger.timestamp_utc = _pps_rtc_timestamp + (trigger.timestamp - _pps_hrt_timestamp); } else { // No PPS capture received, use RTC clock as fallback diff --git a/src/drivers/camera_capture/camera_capture.hpp b/src/drivers/camera_capture/camera_capture.hpp index 2618cf73ac..baeebb21a3 100644 --- a/src/drivers/camera_capture/camera_capture.hpp +++ b/src/drivers/camera_capture/camera_capture.hpp @@ -132,8 +132,8 @@ private: hrt_abstime _last_trig_time{0}; uint32_t _capture_overflows{0}; - uint64_t _pps_hrt_timestamp{0}; - uint64_t _pps_rtc_timestamp{0}; + hrt_abstime _pps_hrt_timestamp{0}; + uint64_t _pps_rtc_timestamp{0}; // Signal capture callback void capture_callback(uint32_t chan_index, hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow); diff --git a/src/drivers/camera_trigger/camera_trigger.cpp b/src/drivers/camera_trigger/camera_trigger.cpp index 0e0fbfa91e..8885e732f2 100644 --- a/src/drivers/camera_trigger/camera_trigger.cpp +++ b/src/drivers/camera_trigger/camera_trigger.cpp @@ -174,8 +174,8 @@ private: bool _turning_on{false}; matrix::Vector2f _last_shoot_position{0.f, 0.f}; bool _valid_position{false}; - uint64_t _pps_hrt_timestamp{0}; - uint64_t _pps_rtc_timestamp{0}; + hrt_abstime _pps_hrt_timestamp{0}; + uint64_t _pps_rtc_timestamp{0}; //Camera Auto Mount Pivoting Oblique Survey (CAMPOS) uint32_t _CAMPOS_num_poses{0}; diff --git a/src/drivers/pps_capture/PPSCapture.cpp b/src/drivers/pps_capture/PPSCapture.cpp index c151f99a35..a221aaf345 100644 --- a/src/drivers/pps_capture/PPSCapture.cpp +++ b/src/drivers/pps_capture/PPSCapture.cpp @@ -99,14 +99,12 @@ void PPSCapture::Run() pps_capture_s pps_capture; pps_capture.timestamp = _hrt_timestamp; // GPS UTC time when the GPIO interrupt was triggered - // UTC time + elapsed time since the UTC time was received - eleapsed time since the PPS interrupt - // event - uint64_t gps_utc_time = _last_gps_utc_timestamp + hrt_elapsed_time(&_last_gps_timestamp) - - hrt_elapsed_time(&_hrt_timestamp); + // Last UTC time received from the GPS + elapsed time to the PPS interrupt + uint64_t gps_utc_time = _last_gps_utc_timestamp + (_hrt_timestamp - _last_gps_timestamp); // (For ubx F9P) The rising edge of the PPS pulse is aligned to the top of second GPS time base. // So, remove the fraction of second and shift to the next second. The interrupt is triggered - // before the matching timestamp tranfered, which means the last received GPS time is always + // before the matching timestamp is received via a UART message, which means the last received GPS time is always // behind. pps_capture.rtc_timestamp = gps_utc_time - (gps_utc_time % USEC_PER_SEC) + USEC_PER_SEC; diff --git a/src/drivers/pps_capture/PPSCapture.hpp b/src/drivers/pps_capture/PPSCapture.hpp index 0f1d812019..d6545d9516 100644 --- a/src/drivers/pps_capture/PPSCapture.hpp +++ b/src/drivers/pps_capture/PPSCapture.hpp @@ -73,12 +73,9 @@ private: uORB::Publication _pps_capture_pub{ORB_ID(pps_capture)}; uORB::Subscription _sensor_gps_sub{ORB_ID(sensor_gps)}; - static constexpr unsigned USEC_IN_1_SEC{1000000}; // microseconds in 1 second - static constexpr unsigned MAX_POSITIVE_DRIFT{USEC_IN_1_SEC / 2}; // microseconds - hrt_abstime _hrt_timestamp{0}; - uint64_t _last_gps_timestamp{0}; - uint64_t _last_gps_utc_timestamp{0}; + hrt_abstime _last_gps_timestamp{0}; + uint64_t _last_gps_utc_timestamp{0}; }; diff --git a/src/modules/logger/logged_topics.cpp b/src/modules/logger/logged_topics.cpp index 70c9f7e91d..0a5aaf8188 100644 --- a/src/modules/logger/logged_topics.cpp +++ b/src/modules/logger/logged_topics.cpp @@ -172,6 +172,7 @@ void LoggedTopics::add_default_topics() add_optional_topic_multi("sensor_accel", 1000, 4); add_optional_topic_multi("sensor_baro", 1000, 4); add_topic_multi("sensor_gps", 1000, 2); + add_topic("pps_capture", 1000); add_optional_topic_multi("sensor_gyro", 1000, 4); add_optional_topic_multi("sensor_mag", 1000, 4); add_topic_multi("vehicle_imu", 500, 4);