gz: set realtime clock at startup (#24530)

This commit is contained in:
Jacob Dahl
2025-03-17 23:19:10 -06:00
committed by GitHub
parent a88679a26f
commit b6597f2984
2 changed files with 11 additions and 1 deletions
+10 -1
View File
@@ -182,7 +182,16 @@ void GZBridge::clockCallback(const gz::msgs::Clock &msg)
struct timespec ts;
ts.tv_sec = msg.sim().sec();
ts.tv_nsec = msg.sim().nsec();
px4_clock_settime(CLOCK_MONOTONIC, &ts);
if (!_realtime_clock_set) {
// Set initial real time clock at startup
px4_clock_settime(CLOCK_REALTIME, &ts);
_realtime_clock_set = true;
} else {
// Keep monotonic clock synchronized
px4_clock_settime(CLOCK_MONOTONIC, &ts);
}
}
void GZBridge::opticalFlowCallback(const px4::msgs::OpticalFlow &msg)
@@ -162,6 +162,7 @@ private:
float _temperature{288.15}; // 15 degrees
bool _realtime_clock_set{false};
gz::transport::Node _node;
// GPS noise model