42 for(std::map<std::string,SoftwarePLL*>::iterator iter =
_instances.begin(); iter !=
_instances.end(); )
44 if(iter->second ==
this)
75 tempTick = tick-(uint32_t)(0xFFFFFFFF &
FirstTick());
86 double start = sec + nanoSec * 1E-9;
107 bool timeStampVerified =
false;
110 timeStampVerified =
true;
116 if (timeStampVerified ==
false)
147 sec = (uint32_t)corrTime;
148 double frac = corrTime - sec;
149 nanoSec = (uint32_t)(1E9 * frac);
155 double dTAbs = fabs(relTimeStamp1 - relTimeStamp2);
173 std::vector<uint64_t> tickFifoUnwrap;
174 std::vector<double> clockFifoUnwrap;
177 uint64_t tickOffset = 0;
178 clockFifoUnwrap[0] = 0.00;
179 tickFifoUnwrap[0] = 0;
183 uint64_t tickDivisor = 0x100000000;
191 tickOffset += tickDivisor;
203 sum_xy += tickFifoUnwrap[i] * clockFifoUnwrap[i];
204 sum_x += tickFifoUnwrap[i];
205 sum_y += clockFifoUnwrap[i];
206 sum_xx += tickFifoUnwrap[i] * tickFifoUnwrap[i];
210 double m = (FifoSize_ * sum_xy - sum_x * sum_y) / (FifoSize_ * sum_xx - sum_x*sum_x);
215 double yesti = m * tickFifoUnwrap[i];
223 if (matchCnt == FifoSize_)
bool NearSameTimeStamp(double relTimeStamp1, double relTimeStamp2)
static SoftwarePLL & Instance(const std::string &id="", int fifo_length=7)
Creates an instance of SoftwarePLL or returns an existing one, given its id.
class SoftwarePLL implements synchronisation between ticks and timestamp. See https://github.com/michael1309/SoftwarePLL/blob/master/README.md for details.
bool PushIntoFifo(double curTimeStamp, uint32_t curtick)
Pushes measurement timestamp and sensor ticks to the fifo, updates tick fifo and clock (timestamp) fi...
bool GetCorrectedTimeStamp(uint32_t &sec, uint32_t &nanoSec, uint32_t tick)
Computes the timestamp of a measurement from sensor ticks.
double ExtraPolateRelativeTimeStamp(uint32_t tick)
Extrapolates and returns the measurement timestamp in seconds relative to FirstTimeStamp. The timestamp of a measurement in seconds can be estimated from sensor ticks by ExtraPolateRelativeTimeStamp(tick) + FirstTimeStamp().
std::vector< uint32_t > TickFifo_
uint32_t ExtrapolationDivergenceCounter() const
static const uint32_t MaxExtrapolationCounter_
bool UpdatePLL(uint32_t sec, uint32_t nanoSec, uint32_t curtick)
Updates PLL internale State should be called only with network send timestamps.
bool IsInitialized() const
double AllowedTimeDeviation() const
double InterpolationSlope() const
double FirstTimeStamp() const
bool UpdateInterpolationSlope()
uint64_t FirstTick() const
std::vector< double > ClockFifo_
static std::map< std::string, SoftwarePLL * > _instances
static const double MaxAllowedTimeDeviation_