comparison include/VirtualClock.h @ 141:44d07fa9bd03 ClockSync

Ultra-basic feedback for clock sync works^CIssues: response time of the IIR filter is too slow, requires PID and better filtering algorithm.
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 14 Sep 2015 15:42:11 +0100
parents e77e2e712fbc
children 134bff10e561
comparison
equal deleted inserted replaced
140:5edc6d0713ef 141:44d07fa9bd03
1 #ifndef VIRTUAL_CLOCK_H_INCLUDED 1 #ifndef VIRTUAL_CLOCK_H_INCLUDED
2 #define VIRTUAL_CLOCK_H_INCLUDED 2 #define VIRTUAL_CLOCK_H_INCLUDED
3 3
4 #include "math.h"
4 #include "stats.hpp" 5 #include "stats.hpp"
5 #include "Clock.h" 6 #include "Clock.h"
7 #ifdef USE_JUCE
8 #else
9 #include <BeagleRT.h>
10 #endif /* USE_JUCE */
6 11
7 class VirtualClock{ 12 class VirtualClock{
8 private: 13 private:
9 myClock_t startTime; 14 myClock_t startTime;
15 myClock_t startTimeOffset;
10 myClock_t lastSync; 16 myClock_t lastSync;
11 bool firstRun; 17 bool firstRun;
18 double elapsedPeriods;
19 double elapsedPeriodsOffset;
12 double period; 20 double period;
13 MovingAverage<double> movingAverage; 21 MovingAverage<double> movingAverage;
14 public: 22 public:
15 void init(); 23 void init();
16 VirtualClock(); 24 VirtualClock();
19 */ 27 */
20 void sync(); 28 void sync();
21 /** 29 /**
22 Call this method asynchronously, passing a number of equally spaced events that have elapsed since the last call. 30 Call this method asynchronously, passing a number of equally spaced events that have elapsed since the last call.
23 */ 31 */
24 void sync(double count); 32 void sync(double numPeriods);
25 /** 33 /**
26 Get the current time according to the VirtualClock. 34 Get the current time according to the VirtualClock.
27 35
28 @return Time elapsed since the first call to sync(), in period units. 36 @return Time elapsed since the first call to sync(), in period units.
29 */ 37 */
32 Get the length of the period. 40 Get the length of the period.
33 41
34 Get the length of the period (difference between calls to sync() after various filtering operations) 42 Get the length of the period (difference between calls to sync() after various filtering operations)
35 */ 43 */
36 double getPeriod(); 44 double getPeriod();
45 /**
46 * Add an offset to the number of elapsed periods.
47 *
48 * Add an offset to the number of elapsed periods. It also compensates for the corresponding time offset.
49 */
50 void addOffset(double periodOffset);
37 }; 51 };
38 52
39 #endif /* VIRTUAL_CLOCK_H_INCLUDED */ 53 #endif /* VIRTUAL_CLOCK_H_INCLUDED */