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
SoftwarePLL
class SoftwarePLL implements synchronisation between ticks and timestamp. See https://github....
Definition: softwarePLL.h:20
SoftwarePLL::AllowedTimeDeviation
double AllowedTimeDeviation() const
Returns the max. allowed time difference between estimated and measured timestamp time in seconds.
Definition: SoftwarePLL.h:125
SoftwarePLL::SoftwarePLL
SoftwarePLL()
Definition: softwarePLL.h:111
SoftwarePLL::~SoftwarePLL
~SoftwarePLL()
Definition: softwarePLL.h:29
SoftwarePLL::Lastcurtick_
uint32_t Lastcurtick_
Definition: SoftwarePLL.h:181
SoftwarePLL::NearSameTimeStamp
bool NearSameTimeStamp(double relTimeStamp1, double relTimeStamp2)
Definition: SoftwarePLL.cpp:153
SoftwarePLL::FirstTick
uint64_t FirstTick() const
Returns the first sensor tick in the fifo buffer.
Definition: SoftwarePLL.h:83
SoftwarePLL::ExtraPolateRelativeTimeStamp
double ExtraPolateRelativeTimeStamp(uint32_t tick)
Extrapolates and returns the measurement timestamp in seconds relative to FirstTimeStamp....
Definition: SoftwarePLL.cpp:72
SoftwarePLL::AllowedTimeDeviation
void AllowedTimeDeviation(double val)
Set the max. allowed time difference between estimated and measured receive timestamp in seconds.
Definition: SoftwarePLL.h:132
SoftwarePLL::GetCorrectedTimeStamp
bool GetCorrectedTimeStamp(uint32_t &sec, uint32_t &nanoSec, uint32_t tick)
Computes the timestamp of a measurement from sensor ticks.
Definition: SoftwarePLL.cpp:138
SoftwarePLL::FifoSize_
const int FifoSize_
Definition: SoftwarePLL.h:172
SoftwarePLL::FirstTimeStamp_
double FirstTimeStamp_
Definition: SoftwarePLL.h:178
SoftwarePLL::PushIntoFifo
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
SoftwarePLL::InterpolationSlope
void InterpolationSlope(double val)
Sets the interpolated slope (gradient of the regression line)
Definition: SoftwarePLL.h:118
SoftwarePLL::FirstTick_
uint64_t FirstTick_
Definition: SoftwarePLL.h:180
SoftwarePLL::ExtrapolationDivergenceCounter
void ExtrapolationDivergenceCounter(uint32_t val)
Sets the counter of extrapolated divergences (number of times the estimated and measured receive time...
Definition: SoftwarePLL.h:146
SoftwarePLL::NumberValInFifo_
int NumberValInFifo_
Definition: SoftwarePLL.h:171
SoftwarePLL::operator=
SoftwarePLL & operator=(const SoftwarePLL &)
SoftwarePLL::FirstTimeStamp
void FirstTimeStamp(double val)
Sets the first timestamp in the fifo buffer in seconds.
Definition: SoftwarePLL.h:104
SoftwarePLL::ExtrapolationDivergenceCounter
uint32_t ExtrapolationDivergenceCounter() const
Returns the counter of extrapolated divergences (number of times the estimated and measured receive t...
Definition: SoftwarePLL.h:139
SoftwarePLL::TickFifo_
std::vector< uint32_t > TickFifo_
Definition: SoftwarePLL.h:175
SoftwarePLL::AllowedTimeDeviation_
double AllowedTimeDeviation_
Definition: SoftwarePLL.h:179
SoftwarePLL::UpdateInterpolationSlope
bool UpdateInterpolationSlope()
Definition: SoftwarePLL.cpp:166
SoftwarePLL::UpdatePLL
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
SoftwarePLL::FirstTimeStamp
double FirstTimeStamp() const
Returns the first timestamp in the fifo buffer in seconds.
Definition: SoftwarePLL.h:97
SoftwarePLL::MaxExtrapolationCounter_
static const uint32_t MaxExtrapolationCounter_
Definition: SoftwarePLL.h:174
SoftwarePLL::FirstTick
void FirstTick(uint64_t val)
Sets the first sensor tick in the fifo buffer.
Definition: SoftwarePLL.h:90
SoftwarePLL::IsInitialized_
bool IsInitialized_
Definition: SoftwarePLL.h:177
SoftwarePLL::IsInitialized
bool IsInitialized() const
Returns the initialization status, i.e. true, if SoftwarePLL is initialized, or false otherwise (inco...
Definition: SoftwarePLL.h:67
SoftwarePLL::ExtrapolationDivergenceCounter_
uint32_t ExtrapolationDivergenceCounter_
Definition: SoftwarePLL.h:185
SoftwarePLL::InterpolationSlope_
double InterpolationSlope_
Definition: SoftwarePLL.h:182
SoftwarePLL::_instances
static std::map< std::string, SoftwarePLL * > _instances
Definition: SoftwarePLL.h:197
SoftwarePLL::ClockFifo_
std::vector< double > ClockFifo_
Definition: SoftwarePLL.h:176
SoftwarePLL::IsInitialized
void IsInitialized(bool val)
Sets the initialization status, i.e. true, if SoftwarePLL is initialized, or false otherwise (inconsi...
Definition: SoftwarePLL.h:76
SoftwarePLL::InterpolationSlope
double InterpolationSlope() const
Returns the interpolated slope (gradient of the regression line)
Definition: SoftwarePLL.h:111
SoftwarePLL::Instance
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
SoftwarePLL::MaxAllowedTimeDeviation_
static const double MaxAllowedTimeDeviation_
Definition: SoftwarePLL.h:173
SoftwarePLL::SoftwarePLL
SoftwarePLL(int fifo_length=7)
Definition: SoftwarePLL.h:186


sick_scan
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Thu Sep 8 2022 02:30:19