mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-13 21:13:34 +08:00
Time synchronization message update: 1. field prev_utc_usec renamed to a more human-readable name; 2. UTC is no longer required, but rather recommended
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
#
|
||||
# Global time synchronization.
|
||||
# Should be UTC time, not GPS time nor local time.
|
||||
# Preferred time is UTC.
|
||||
# Any node that publishes timestamped data must use this time reference.
|
||||
# This message is not intended for unicast transfers.
|
||||
#
|
||||
# Please refer to the specification to learn about time synchronization algorithm.
|
||||
#
|
||||
|
||||
uint16 MAX_PUBLICATION_PERIOD_MS = 1100
|
||||
uint16 MIN_PUBLICATION_PERIOD_MS = 350
|
||||
uint16 MAX_PUBLICATION_PERIOD_MS = 1100 # Milliseconds
|
||||
uint16 MIN_PUBLICATION_PERIOD_MS = 350 # Milliseconds
|
||||
|
||||
uint16 PUBLISHER_TIMEOUT_MS = 10000
|
||||
uint16 PUBLISHER_TIMEOUT_MS = 10000 # Milliseconds
|
||||
|
||||
# UTC time in microseconds when the PREVIOUS GlobalTimeSync message was transmitted.
|
||||
# Time in microseconds when the PREVIOUS GlobalTimeSync message was transmitted.
|
||||
# If this message is the first one, this field must be zero.
|
||||
uint64 prev_utc_usec
|
||||
uint64 previous_transmission_timestamp_usec # Microseconds
|
||||
|
||||
@@ -56,11 +56,12 @@ int GlobalTimeSyncMaster::IfaceMaster::publish(TransferID tid, MonotonicTime cur
|
||||
const bool long_period = since_prev_pub.toMSec() >= protocol::GlobalTimeSync::MAX_PUBLICATION_PERIOD_MS;
|
||||
|
||||
protocol::GlobalTimeSync msg;
|
||||
msg.prev_utc_usec = long_period ? 0 : prev_tx_utc_.toUSec();
|
||||
msg.previous_transmission_timestamp_usec = long_period ? 0 : prev_tx_utc_.toUSec();
|
||||
prev_tx_utc_ = UtcTime();
|
||||
|
||||
UAVCAN_TRACE("GlobalTimeSyncMaster", "Publishing %llu iface=%i tid=%i",
|
||||
static_cast<unsigned long long>(msg.prev_utc_usec), int(iface_index_), int(tid.get()));
|
||||
static_cast<unsigned long long>(msg.previous_transmission_timestamp_usec),
|
||||
int(iface_index_), int(tid.get()));
|
||||
return pub_.broadcast(msg, tid);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ namespace uavcan
|
||||
|
||||
void GlobalTimeSyncSlave::adjustFromMsg(const ReceivedDataStructure<protocol::GlobalTimeSync>& msg)
|
||||
{
|
||||
UAVCAN_ASSERT(msg.prev_utc_usec > 0);
|
||||
const UtcDuration adjustment = UtcTime::fromUSec(msg.prev_utc_usec) - prev_ts_utc_;
|
||||
UAVCAN_ASSERT(msg.previous_transmission_timestamp_usec > 0);
|
||||
const UtcDuration adjustment = UtcTime::fromUSec(msg.previous_transmission_timestamp_usec) - prev_ts_utc_;
|
||||
|
||||
UAVCAN_TRACE("GlobalTimeSyncSlave", "Adjustment: usec=%lli snid=%i iface=%i suppress=%i",
|
||||
static_cast<long long>(adjustment.toUSec()),
|
||||
@@ -58,7 +58,7 @@ void GlobalTimeSyncSlave::processMsg(const ReceivedDataStructure<protocol::Globa
|
||||
{
|
||||
if (state_ == Adjust)
|
||||
{
|
||||
const bool msg_invalid = msg.prev_utc_usec == 0;
|
||||
const bool msg_invalid = msg.previous_transmission_timestamp_usec == 0;
|
||||
const bool wrong_tid = prev_tid_.computeForwardDistance(msg.getTransferID()) != 1;
|
||||
const bool wrong_timing = since_prev_msg.toMSec() > protocol::GlobalTimeSync::MAX_PUBLICATION_PERIOD_MS;
|
||||
if (msg_invalid || wrong_tid || wrong_timing)
|
||||
|
||||
@@ -37,9 +37,9 @@ TEST(GlobalTimeSyncSlave, Basic)
|
||||
* The slave must only register the timestamp and adjust nothing
|
||||
*/
|
||||
uavcan::protocol::GlobalTimeSync gts;
|
||||
gts.prev_utc_usec = 0;
|
||||
gts.previous_transmission_timestamp_usec = 0;
|
||||
gts_pub.broadcast(gts);
|
||||
gts.prev_utc_usec = master_clock.utc;
|
||||
gts.previous_transmission_timestamp_usec = master_clock.utc;
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(10));
|
||||
ASSERT_EQ(0, slave_clock.utc);
|
||||
ASSERT_EQ(1000000, master_clock.utc);
|
||||
@@ -54,7 +54,7 @@ TEST(GlobalTimeSyncSlave, Basic)
|
||||
* Slave must adjust now
|
||||
*/
|
||||
gts_pub.broadcast(gts);
|
||||
gts.prev_utc_usec = master_clock.utc;
|
||||
gts.previous_transmission_timestamp_usec = master_clock.utc;
|
||||
nodes.spinBoth(uavcan::MonotonicDuration());
|
||||
ASSERT_EQ(1000000, slave_clock.utc);
|
||||
ASSERT_EQ(1000000, master_clock.utc);
|
||||
@@ -72,7 +72,7 @@ TEST(GlobalTimeSyncSlave, Basic)
|
||||
* Will update
|
||||
*/
|
||||
gts_pub.broadcast(gts);
|
||||
gts.prev_utc_usec = master_clock.utc;
|
||||
gts.previous_transmission_timestamp_usec = master_clock.utc;
|
||||
nodes.spinBoth(uavcan::MonotonicDuration());
|
||||
ASSERT_EQ(2000000, slave_clock.utc);
|
||||
ASSERT_EQ(2000000, master_clock.utc);
|
||||
@@ -88,7 +88,7 @@ TEST(GlobalTimeSyncSlave, Basic)
|
||||
* Will adjust
|
||||
*/
|
||||
gts_pub.broadcast(gts);
|
||||
gts.prev_utc_usec = master_clock.utc;
|
||||
gts.previous_transmission_timestamp_usec = master_clock.utc;
|
||||
nodes.spinBoth(uavcan::MonotonicDuration());
|
||||
ASSERT_EQ(3000000, slave_clock.utc);
|
||||
ASSERT_EQ(3000000, master_clock.utc);
|
||||
@@ -117,9 +117,9 @@ TEST(GlobalTimeSyncSlave, Basic)
|
||||
/*
|
||||
* Update step, no adjustment yet
|
||||
*/
|
||||
gts.prev_utc_usec = 0;
|
||||
gts.previous_transmission_timestamp_usec = 0;
|
||||
gts_pub2.broadcast(gts);
|
||||
gts.prev_utc_usec = master2_clock.utc;
|
||||
gts.previous_transmission_timestamp_usec = master2_clock.utc;
|
||||
nodes.spinBoth(uavcan::MonotonicDuration());
|
||||
ASSERT_EQ(4000000, slave_clock.utc);
|
||||
ASSERT_EQ(100, master2_clock.utc);
|
||||
@@ -142,7 +142,7 @@ TEST(GlobalTimeSyncSlave, Basic)
|
||||
/*
|
||||
* Another master will be ignored now
|
||||
*/
|
||||
gts.prev_utc_usec = 99999999;
|
||||
gts.previous_transmission_timestamp_usec = 99999999;
|
||||
// Update
|
||||
gts_pub.broadcast(gts);
|
||||
nodes.spinBoth(uavcan::MonotonicDuration());
|
||||
|
||||
Reference in New Issue
Block a user