mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-16 18:23:33 +08:00
dds: clean up timesync
This commit is contained in:
@@ -54,29 +54,19 @@ static constexpr uint8_t TIMESYNC_MAX_TIMEOUTS = 10;
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
static void on_time(uxrSession *session, int64_t current_time, int64_t received_timestamp, int64_t transmit_timestamp,
|
||||
int64_t originate_timestamp, void *args)
|
||||
static void on_time(uxrSession *session, int64_t current_time, int64_t client_transmit_timestamp,
|
||||
int64_t agent_receive_timestamp, int64_t originate_timestamp, void *args)
|
||||
{
|
||||
// latest round trip time (RTT)
|
||||
int64_t rtt = current_time - originate_timestamp;
|
||||
|
||||
// HRT to AGENT
|
||||
int64_t offset_1 = (received_timestamp - originate_timestamp) - (rtt / 2);
|
||||
int64_t offset_2 = (transmit_timestamp - current_time) - (rtt / 2);
|
||||
|
||||
session->time_offset = (offset_1 + offset_2) / 2;
|
||||
|
||||
if (args) {
|
||||
Timesync *timesync = static_cast<Timesync *>(args);
|
||||
timesync->update(current_time / 1000, transmit_timestamp, originate_timestamp);
|
||||
timesync->update(current_time / 1000, agent_receive_timestamp, originate_timestamp);
|
||||
|
||||
session->time_offset = -timesync->offset() * 1000; // us -> ns
|
||||
}
|
||||
}
|
||||
|
||||
static void on_time_no_sync(uxrSession *session, int64_t current_time, int64_t received_timestamp,
|
||||
int64_t transmit_timestamp,
|
||||
int64_t originate_timestamp, void *args)
|
||||
static void on_time_no_sync(uxrSession *session, int64_t current_time, int64_t client_transmit_timestamp,
|
||||
int64_t agent_receive_timestamp, int64_t originate_timestamp, void *args)
|
||||
{
|
||||
session->time_offset = 0;
|
||||
}
|
||||
@@ -693,7 +683,6 @@ void UxrceddsClient::run()
|
||||
if (_synchronize_timestamps && hrt_elapsed_time(&last_sync_session) > 1_s) {
|
||||
|
||||
if (uxr_sync_session(&session, 10) && _timesync.sync_converged()) {
|
||||
//PX4_INFO("synchronized with time offset %-5" PRId64 "ns", session.time_offset);
|
||||
last_sync_session = hrt_absolute_time();
|
||||
|
||||
if (_param_uxrce_dds_syncc.get() > 0) {
|
||||
@@ -702,10 +691,10 @@ void UxrceddsClient::run()
|
||||
}
|
||||
|
||||
if (!_timesync_converged && _timesync.sync_converged()) {
|
||||
PX4_INFO("time sync converged");
|
||||
PX4_DEBUG("time sync converged");
|
||||
|
||||
} else if (_timesync_converged && !_timesync.sync_converged()) {
|
||||
PX4_WARN("time sync no longer converged");
|
||||
PX4_DEBUG("time sync no longer converged");
|
||||
}
|
||||
|
||||
_timesync_converged = _timesync.sync_converged();
|
||||
|
||||
Reference in New Issue
Block a user