comparison include/VirtualClock.h @ 149:134bff10e561 ClockSync

Added simple one-variable one-measurement Kalman filter, Pid controller(which output is not used). Virtual clock is now much more precise and reactive for period. Still it is lagging behind a bit on the overall offset.
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 21 Sep 2015 03:12:21 +0100
parents 44d07fa9bd03
children ebbfb154351a
comparison
equal deleted inserted replaced
148:6cd38e261027 149:134bff10e561
2 #define VIRTUAL_CLOCK_H_INCLUDED 2 #define VIRTUAL_CLOCK_H_INCLUDED
3 3
4 #include "math.h" 4 #include "math.h"
5 #include "stats.hpp" 5 #include "stats.hpp"
6 #include "Clock.h" 6 #include "Clock.h"
7 #include "IirFilter.h"
8 #include "Kalman.h"
7 #ifdef USE_JUCE 9 #ifdef USE_JUCE
8 #else 10 #else
9 #include <BeagleRT.h> 11 #include <BeagleRT.h>
10 #endif /* USE_JUCE */ 12 #endif /* USE_JUCE */
11 13
12 class VirtualClock{ 14 class VirtualClock{
13 private: 15 private:
14 myClock_t startTime; 16 myClock_t startTime;
15 myClock_t startTimeOffset; 17 myClock_t startTimeOffset;
16 myClock_t lastSync; 18 myClock_t lastSyncTime;
19 // myClock_t lastSyncEstimatedTime;
20 double lastSyncEstimatedTime;
17 bool firstRun; 21 bool firstRun;
18 double elapsedPeriods; 22 double elapsedPeriods;
19 double elapsedPeriodsOffset; 23 double elapsedPeriodsOffset;
24 double blockPeriod;
20 double period; 25 double period;
21 MovingAverage<double> movingAverage; 26 MovingAverage<double> movingAverage;
27 IirFilter iir;
28 KalmanOne kalman;
22 public: 29 public:
23 void init(); 30 void init(float initialValueUs);
24 VirtualClock(); 31 VirtualClock();
25 /** 32 /**
26 Call this method at regular intervals to sync che virtual clock 33 Call this method at regular intervals to sync che virtual clock
27 */ 34 */
28 void sync(); 35 void sync();