SoftwarePLL.h
Go to the documentation of this file.
1 #ifndef SOFTWARE_PLL_H
2 #define SOFTWARE_PLL_H
3 
4 #ifdef _MSC_VER
5 #pragma warning(disable : 4996)
6 #endif
7 
8 #include <map>
9 #include <string>
10 #include <iostream>
11 #include <fstream>
12 #include <cstring>
13 #include <sstream>
14 #include <vector>
15 #include <cstdlib>
16 #include <iomanip>
17 #include <ctime>
18 #include <stdint.h>
19 
24 class SoftwarePLL
25 {
26 public:
27 
35  static SoftwarePLL& Instance(const std::string & id = "", int fifo_length = 7);
36 
40  ~SoftwarePLL();
41 
50  bool GetCorrectedTimeStamp(uint32_t& sec, uint32_t& nanoSec, uint32_t tick);
51 
60  bool UpdatePLL(uint32_t sec, uint32_t nanoSec, uint32_t curtick);
61 
67  bool IsInitialized() const { return IsInitialized_; }
68 
69 protected:
70 
76  void IsInitialized(bool val) { IsInitialized_ = val; }
77 
83  uint64_t FirstTick() const { return FirstTick_; }
84 
90  void FirstTick(uint64_t val) { FirstTick_ = val; }
91 
97  double FirstTimeStamp() const { return FirstTimeStamp_; }
98 
104  void FirstTimeStamp(double val) { FirstTimeStamp_ = val; }
105 
111  double InterpolationSlope() const { return InterpolationSlope_; }
112 
118  void InterpolationSlope(double val) { InterpolationSlope_ = val; }
119 
125  double AllowedTimeDeviation() const { return AllowedTimeDeviation_; }
126 
132  void AllowedTimeDeviation(double val) { AllowedTimeDeviation_ = val; }
133 
140 
147 
156  bool PushIntoFifo(double curTimeStamp, uint32_t curtick);// update tick fifo and update clock (timestamp) fifo;
157 
167  double ExtraPolateRelativeTimeStamp(uint32_t tick);
168 
169 private:
170 
172  const int FifoSize_;
173  static const double MaxAllowedTimeDeviation_;
174  static const uint32_t MaxExtrapolationCounter_;
175  std::vector<uint32_t> TickFifo_;
176  std::vector<double> ClockFifo_;
180  uint64_t FirstTick_;
181  uint32_t Lastcurtick_ = 0;
183  bool NearSameTimeStamp(double relTimeStamp1, double relTimeStamp2);
186  SoftwarePLL(int fifo_length = 7) : FifoSize_(fifo_length), TickFifo_(fifo_length,0), ClockFifo_(fifo_length,0), IsInitialized_(false), FirstTimeStamp_(0), FirstTick_(0), InterpolationSlope_(0)
187  {
189  NumberValInFifo_ = 0;
190  }
191  // verhindert, dass ein Objekt von ausserhalb von N erzeugt wird.
192  // protected, wenn man von der Klasse noch erben moechte
193  SoftwarePLL(const SoftwarePLL&); /* verhindert, dass eine weitere Instanz via
194  Kopier-Konstruktor erstellt werden kann */
195  SoftwarePLL & operator = (const SoftwarePLL &); //Verhindert weitere Instanz durch Kopie
196 
197  static std::map<std::string,SoftwarePLL*> _instances; // list of SoftwarePLL instances, mapped by id
198 };
199 
200 #endif
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.
Definition: SoftwarePLL.cpp:28
uint32_t Lastcurtick_
Definition: SoftwarePLL.h:181
class SoftwarePLL implements synchronisation between ticks and timestamp. See https://github.com/michael1309/SoftwarePLL/blob/master/README.md for details.
Definition: softwarePLL.h:20
bool PushIntoFifo(double curTimeStamp, uint32_t curtick)
Pushes measurement timestamp and sensor ticks to the fifo, updates tick fifo and clock (timestamp) fi...
Definition: SoftwarePLL.cpp:51
void AllowedTimeDeviation(double val)
Set the max. allowed time difference between estimated and measured receive timestamp in seconds...
Definition: SoftwarePLL.h:132
const int FifoSize_
Definition: SoftwarePLL.h:172
void InterpolationSlope(double val)
Sets the interpolated slope (gradient of the regression line)
Definition: SoftwarePLL.h:118
bool GetCorrectedTimeStamp(uint32_t &sec, uint32_t &nanoSec, uint32_t tick)
Computes the timestamp of a measurement from sensor ticks.
void FirstTimeStamp(double val)
Sets the first timestamp in the fifo buffer in seconds.
Definition: SoftwarePLL.h:104
uint64_t FirstTick_
Definition: SoftwarePLL.h:180
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().
Definition: SoftwarePLL.cpp:72
std::vector< uint32_t > TickFifo_
Definition: SoftwarePLL.h:175
double FirstTimeStamp_
Definition: SoftwarePLL.h:178
uint32_t ExtrapolationDivergenceCounter() const
Returns the counter of extrapolated divergences (number of times the estimated and measured receive t...
Definition: SoftwarePLL.h:139
static const uint32_t MaxExtrapolationCounter_
Definition: SoftwarePLL.h:174
void ExtrapolationDivergenceCounter(uint32_t val)
Sets the counter of extrapolated divergences (number of times the estimated and measured receive time...
Definition: SoftwarePLL.h:146
bool UpdatePLL(uint32_t sec, uint32_t nanoSec, uint32_t curtick)
Updates PLL internale State should be called only with network send timestamps.
Definition: SoftwarePLL.cpp:81
bool IsInitialized() const
Returns the initialization status, i.e. true, if SoftwarePLL is initialized, or false otherwise (inco...
Definition: SoftwarePLL.h:67
double AllowedTimeDeviation() const
Returns the max. allowed time difference between estimated and measured timestamp time in seconds...
Definition: SoftwarePLL.h:125
int NumberValInFifo_
Definition: SoftwarePLL.h:171
SoftwarePLL & operator=(const SoftwarePLL &)
double InterpolationSlope() const
Returns the interpolated slope (gradient of the regression line)
Definition: SoftwarePLL.h:111
double FirstTimeStamp() const
Returns the first timestamp in the fifo buffer in seconds.
Definition: SoftwarePLL.h:97
double AllowedTimeDeviation_
Definition: SoftwarePLL.h:179
bool UpdateInterpolationSlope()
uint64_t FirstTick() const
Returns the first sensor tick in the fifo buffer.
Definition: SoftwarePLL.h:83
std::vector< double > ClockFifo_
Definition: SoftwarePLL.h:176
uint32_t ExtrapolationDivergenceCounter_
Definition: SoftwarePLL.h:185
static std::map< std::string, SoftwarePLL * > _instances
Definition: SoftwarePLL.h:197
bool IsInitialized_
Definition: SoftwarePLL.h:177
void FirstTick(uint64_t val)
Sets the first sensor tick in the fifo buffer.
Definition: SoftwarePLL.h:90
double InterpolationSlope_
Definition: SoftwarePLL.h:182
static const double MaxAllowedTimeDeviation_
Definition: SoftwarePLL.h:173
SoftwarePLL(int fifo_length=7)
Definition: SoftwarePLL.h:186
void IsInitialized(bool val)
Sets the initialization status, i.e. true, if SoftwarePLL is initialized, or false otherwise (inconsi...
Definition: SoftwarePLL.h:76


sick_scan
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Wed May 5 2021 03:05:48