21 #define GRT_DLL_EXPORTS 28 this->analysisMode = analysisMode;
29 this->thresholdCrossingMode = thresholdCrossingMode;
30 this->detectionTimeoutMode = detectionTimeoutMode;
31 this->searchWindowSize = searchWindowSize;
32 this->searchTimeoutDuration = searchTimeoutDuration;
33 this->offsetFilterSize = offsetFilterSize;
34 this->lowerThreshold = lowerThreshold;
35 this->upperThreshold = upperThreshold;
36 this->hysteresisThreshold = hysteresisThreshold;
39 thresholdCrossingDetected =
false;
41 searchWindowIndex = 0;
42 currentSearchState = SEARCHING_FOR_FIRST_THRESHOLD_CROSSING;
48 this->analysisValue = rhs.analysisValue;
49 this->lowerThreshold = rhs.lowerThreshold;
50 this->upperThreshold = rhs.upperThreshold;
51 this->hysteresisThreshold = rhs.hysteresisThreshold;
52 this->enableSearch = rhs.enableSearch;
53 this->thresholdCrossingDetected = rhs.thresholdCrossingDetected;
54 this->analysisMode = rhs.analysisMode;
55 this->thresholdCrossingMode = rhs.thresholdCrossingMode;
56 this->searchTimeoutCounter = rhs.searchTimeoutCounter;
57 this->searchTimeoutDuration = rhs.searchTimeoutDuration;
58 this->searchWindowSize = rhs.searchWindowSize;
59 this->searchWindowIndex = rhs.searchWindowIndex;
60 this->offsetFilterSize = rhs.offsetFilterSize;
61 this->currentSearchState = rhs.currentSearchState;
62 this->movingAverageFilter = rhs.movingAverageFilter;
63 this->derivative = rhs.derivative;
72 this->analysisValue = rhs.analysisValue;
73 this->lowerThreshold = rhs.lowerThreshold;
74 this->upperThreshold = rhs.upperThreshold;
75 this->hysteresisThreshold = rhs.hysteresisThreshold;
76 this->enableSearch = rhs.enableSearch;
77 this->thresholdCrossingDetected = rhs.thresholdCrossingDetected;
78 this->analysisMode = rhs.analysisMode;
79 this->thresholdCrossingMode = rhs.thresholdCrossingMode;
80 this->searchTimeoutCounter = rhs.searchTimeoutCounter;
81 this->searchTimeoutDuration = rhs.searchTimeoutDuration;
82 this->searchWindowSize = rhs.searchWindowSize;
83 this->searchWindowIndex = rhs.searchWindowIndex;
84 this->offsetFilterSize = rhs.offsetFilterSize;
85 this->currentSearchState = rhs.currentSearchState;
86 this->movingAverageFilter = rhs.movingAverageFilter;
87 this->derivative = rhs.derivative;
94 thresholdCrossingDetected =
false;
97 Float offset = movingAverageFilter.
filter( x );
100 if( !enableSearch ){
return thresholdCrossingDetected; }
104 bool upperThresholdCrossingFound =
false;
105 bool lowerThresholdCrossingFound =
false;
107 switch( analysisMode ){
108 case RAW_DATA_ANALYSIS_MODE:
111 case MOVING_OFFSET_ANALYSIS_MODE:
112 analysisValue = x - offset;
114 case DERIVATIVE_ANALYSIS_MODE:
115 analysisValue = deriv;
120 if( currentSearchState == NO_SEARCH_GATE_TIME_OUT ){
122 switch( detectionTimeoutMode ){
123 case TIMEOUT_COUNTER:
125 if (searchTimeoutCounter.
getMilliSeconds() >= (
signed long)searchTimeoutDuration){
126 currentSearchState = SEARCHING_FOR_FIRST_THRESHOLD_CROSSING;
127 searchTimeoutCounter.
stop();
130 case HYSTERESIS_THRESHOLD:
131 switch ( thresholdCrossingMode ) {
132 case UPPER_THRESHOLD_CROSSING:
133 if( analysisValue <= hysteresisThreshold ){
134 currentSearchState = SEARCHING_FOR_FIRST_THRESHOLD_CROSSING;
137 case LOWER_THRESHOLD_CROSSING:
138 if( analysisValue >= hysteresisThreshold ){
139 currentSearchState = SEARCHING_FOR_FIRST_THRESHOLD_CROSSING;
151 if( thresholdCrossingMode == UPPER_THRESHOLD_CROSSING || thresholdCrossingMode == LOWER_THRESHOLD_CROSSING || thresholdCrossingMode == UPPER_OR_LOWER_THRESHOLD_CROSSING ){
153 switch ( thresholdCrossingMode ) {
154 case UPPER_THRESHOLD_CROSSING:
155 if( analysisValue >= upperThreshold ){
156 upperThresholdCrossingFound =
true;
157 thresholdCrossingDetected =
true;
158 currentSearchState = NO_SEARCH_GATE_TIME_OUT;
159 searchTimeoutCounter.
start();
162 case LOWER_THRESHOLD_CROSSING:
163 if( analysisValue <= lowerThreshold ){
164 lowerThresholdCrossingFound =
true;
165 thresholdCrossingDetected =
true;
166 currentSearchState = NO_SEARCH_GATE_TIME_OUT;
167 searchTimeoutCounter.
start();
170 case UPPER_OR_LOWER_THRESHOLD_CROSSING:
171 if( analysisValue >= upperThreshold ){
172 upperThresholdCrossingFound =
true;
173 thresholdCrossingDetected =
true;
174 currentSearchState = NO_SEARCH_GATE_TIME_OUT;
175 searchTimeoutCounter.
start();
176 }
else if( analysisValue <= lowerThreshold ){
177 lowerThresholdCrossingFound =
true;
178 thresholdCrossingDetected =
true;
179 currentSearchState = NO_SEARCH_GATE_TIME_OUT;
180 searchTimeoutCounter.
start();
186 return thresholdCrossingDetected ?
true :
false;
190 if( currentSearchState == SEARCHING_FOR_SECOND_THRESHOLD_CROSSING ){
191 if( ++searchWindowIndex == searchWindowSize ){
192 currentSearchState = SEARCHING_FOR_FIRST_THRESHOLD_CROSSING;
193 searchWindowIndex = 0;
198 if( currentSearchState == NO_SEARCH_GATE_TIME_OUT ){
200 if (searchTimeoutCounter.
getMilliSeconds() >= (
signed long)searchTimeoutDuration){
201 currentSearchState = SEARCHING_FOR_FIRST_THRESHOLD_CROSSING;
202 searchTimeoutCounter.
stop();
207 if( analysisValue >= upperThreshold ){ upperThresholdCrossingFound =
true; }
208 if( analysisValue <= lowerThreshold ){ lowerThresholdCrossingFound =
true; }
209 if( !upperThresholdCrossingFound && !lowerThresholdCrossingFound &&
210 currentSearchState != NO_SEARCH_GATE_TIME_OUT ){
return false; }
212 switch ( currentSearchState ) {
213 case SEARCHING_FOR_FIRST_THRESHOLD_CROSSING:
214 if( thresholdCrossingMode == UPPER_THEN_LOWER_THRESHOLD_CROSSING && upperThresholdCrossingFound ){
215 searchWindowIndex = 0;
216 currentSearchState = SEARCHING_FOR_SECOND_THRESHOLD_CROSSING;
219 if( thresholdCrossingMode == LOWER_THEN_UPPER_THRESHOLD_CROSSING && lowerThresholdCrossingFound ){
220 searchWindowIndex = 0;
221 currentSearchState = SEARCHING_FOR_SECOND_THRESHOLD_CROSSING;
225 case SEARCHING_FOR_SECOND_THRESHOLD_CROSSING:
226 if( thresholdCrossingMode == UPPER_THEN_LOWER_THRESHOLD_CROSSING && lowerThresholdCrossingFound ){
227 currentSearchState = NO_SEARCH_GATE_TIME_OUT;
228 searchWindowIndex = 0;
229 searchTimeoutCounter.
start();
230 thresholdCrossingDetected =
true;
233 if( thresholdCrossingMode == LOWER_THEN_UPPER_THRESHOLD_CROSSING && upperThresholdCrossingFound ){
234 currentSearchState = NO_SEARCH_GATE_TIME_OUT;
235 searchWindowIndex = 0;
236 searchTimeoutCounter.
start();
237 thresholdCrossingDetected =
true;
246 return thresholdCrossingDetected ?
true :
false;
252 derivative.
init(Derivative::FIRST_DERIVATIVE, 1, 1,
true, 5);
254 movingAverageFilter.
init(offsetFilterSize, 1);
257 currentSearchState = NO_SEARCH_GATE_TIME_OUT;
261 thresholdCrossingDetected =
false;
263 searchWindowIndex = 0;
264 searchTimeoutCounter.
stop();
270 currentSearchState = NO_SEARCH_GATE_TIME_OUT;
271 searchTimeoutCounter.
start();
276 return thresholdCrossingDetected;
288 return thresholdCrossingMode;
292 return searchWindowSize;
296 return offsetFilterSize;
300 return searchWindowIndex;
308 return searchTimeoutDuration;
312 return analysisValue;
316 return upperThreshold;
320 return lowerThreshold;
324 return hysteresisThreshold;
328 this->enableSearch = enableSearch;
333 this->analysisMode = analysisMode;
338 this->thresholdCrossingMode = thresholdCrossingMode;
343 this->detectionTimeoutMode = detectionTimeoutMode;
348 this->searchWindowSize = searchWindowSize;
353 this->offsetFilterSize = offsetFilterSize;
358 this->searchTimeoutDuration = searchTimeoutDuration;
363 this->lowerThreshold = lowerThreshold;
368 this->upperThreshold = upperThreshold;
373 this->hysteresisThreshold = hysteresisThreshold;
UINT getThresholdCrossingMode() const
bool triggerSearchTimeout()
bool setUpperThreshold(const Float upperThreshold)
bool update(const Float x)
Float getAnalysisValue() const
bool setOffsetFilterSize(const UINT offsetFilterSize)
bool setSearchWindowSize(const UINT searchWindowSize)
bool setDetectionTimeoutMode(const UINT detectionTimeoutMode)
bool getThresholdCrossingDetected() const
bool init(const UINT filterSize, const UINT numDimensions)
This class implements a threshold crossing detector.
bool setHysteresisThreshold(const Float hysteresisThreshold)
signed long getMilliSeconds()
Float computeDerivative(const Float x)
bool getEnableSearch() const
UINT getSearchWindowIndex() const
UINT getOffsetFilterSize() const
UINT getSearchTimeoutDuration() const
bool setAnalysisMode(const UINT analysisMode)
UINT getSearchWindowSize() const
~ThresholdCrossingDetector()
bool setLowerThreshold(const Float lowerThreshold)
Float filter(const Float x)
ThresholdCrossingDetector & operator=(const ThresholdCrossingDetector &rhs)
bool setEnableSearch(const bool enableSearch)
bool setThresholdCrossingMode(const UINT thresholdCrossingMode)
Float getHysteresisThreshold() const
UINT getAnalysisMode() const
bool setSearchTimeoutDuration(const UINT searchTimeoutDuration)
ThresholdCrossingDetector(UINT analysisMode=RAW_DATA_ANALYSIS_MODE, UINT thresholdCrossingMode=UPPER_THRESHOLD_CROSSING, UINT detectionTimeoutMode=TIMEOUT_COUNTER, Float lowerThreshold=-1, Float upperThreshold=1, Float hysteresisThreshold=0, UINT searchWindowSize=20, UINT searchTimeoutDuration=1000, UINT offsetFilterSize=10)
bool init(const UINT derivativeOrder, const Float delta, const UINT numDimensions, const bool filterData, const UINT filterSize)
UINT getSearchTimeoutCounter()
Float getLowerThreshold() const
Float getUpperThreshold() const