KSquare Utilities
KKLSC::FlowMeterTracker Class Reference

Class that keeps track the Flow-Meter-Counter values by scan-lines; using these values it will compute estimated flow rate. More...

#include <FlowMeterTracker.h>

Public Types

typedef FlowMeterTrackerFlowMeterTrackerPtr
 

Public Member Functions

 FlowMeterTracker ()
 
 FlowMeterTracker (const FlowMeterTracker &entry)
 
 ~FlowMeterTracker ()
 
void AddEntry (kkuint32 _scanLineNum, kkuint32 _counterValue)
 
float ComputeFlowRateFromFlowRateRatio (float _flowRateRatio)
 
float ComputeFlowRateRatioFromFlowRate (float _flowRate)
 
bool FlowMeterPresent () const
 
float FlowRateDefault () const
 
float FlowRateInstantaneous ()
 
float FlowRateRatioDefault () const
 
void FlowRateRatioDefaultChanged (float _flowRateRatioDefault)
 
float FlowRateTrend ()
 
void GetFlowRateInstantaneous (float &flowRate, float &flowRateRatio)
 
void GetFlowRateTrend (float &flowRate, float &flowRateRatio)
 
kkint32 HistoryTableSize () const
 
float ImagingWidthMeters () const
 
kkint32 ImagingWidthPixels () const
 
void Initialize (bool _flowMeterPresent, float _flowRateRatioDefault, kkint32 _historyTableSize, float _scanRate, float _imagingWidthMeters, kkint32 _imagingWidthPixels, float _ticsPerMeter)
 
kkint32 MemoryConsumedEstimated ()
 
void ScanRateChanged (float _newScanRate)
 
float TicsPerMeter () const
 

Detailed Description

Class that keeps track the Flow-Meter-Counter values by scan-lines; using these values it will compute estimated flow rate.

Glossary
FlowRate(FR) = Rate of water flow in (Meters/Sec)
FlowRateRatio(FRR) = Number TemporalPixel's per SpatialPixel with respect to physical distance; aka FlowRateFactor. (TP's/SP's)
ScanRate(SR) = Number of camera scan lines captured per second. (ScanLines/Sec) or (TP's/Sec)
SpatialPixel(SP) = From the image chambers width perspective;
TemporalPixel(TP) = One scan line; The physical distance a pixel covers with respect to flow is dependent
on both scan rate and flow rate. TP = (FRR)(SP).
ChamberWidthSpatialy (CWS) Distance across Imaging Chamber width as measured in meters (m).
ChamberWidthPixels (CWP) Number of pixels imaged across the imaging chamber. (1 + CropLeft - CropRight). (SP's)
ChamberWidthTemporal (CWT) Time it would take for Camera to cover same distance in direction of flow.
FlowRateRatio = ((CWS)(SR)) / ((FR)(CWP)).
FlowRate = ((CWS)(SR)) / ((FRR)(CWP))

Definition at line 44 of file FlowMeterTracker.h.

Member Typedef Documentation

Constructor & Destructor Documentation

FlowMeterTracker::FlowMeterTracker ( )

Definition at line 29 of file FlowMeterTracker.cpp.

29  :
30  flowMeterPresent (false),
31  flowRateDefault (1.0f),
32  flowRateRatioDefault (1.0f),
33  history (NULL),
34  historyTableSize (-1),
35  historyLastIdxAdded (-1),
36  historyOldestIdx (-1),
37  imagingWidthMeters (0.0635f),
38  imagingWidthPixels (2048),
39  scanRate (0.0f),
40  ticsPerMeter (10.0f)
41 {
42 }
FlowMeterTracker::FlowMeterTracker ( const FlowMeterTracker entry)

Definition at line 46 of file FlowMeterTracker.cpp.

46  :
47  flowMeterPresent (entry.flowMeterPresent),
48  flowRateDefault (entry.flowRateDefault),
49  flowRateRatioDefault (entry.flowRateRatioDefault),
50  history (NULL),
51  historyTableSize (entry.historyTableSize),
52  historyLastIdxAdded (entry.historyLastIdxAdded),
53  historyOldestIdx (entry.historyOldestIdx),
54  imagingWidthMeters (entry.imagingWidthMeters),
55  imagingWidthPixels (entry.imagingWidthPixels),
56  scanRate (entry.scanRate),
57  ticsPerMeter (entry.ticsPerMeter)
58 {
59  history = new Entry[historyTableSize];
60  for (kkint32 x = 0; x < historyTableSize; ++x)
61  history[x] = entry.history[x];
62 }
__int32 kkint32
Definition: KKBaseTypes.h:88
FlowMeterTracker::~FlowMeterTracker ( )

Definition at line 67 of file FlowMeterTracker.cpp.

68 {
69  delete history;
70  history = NULL;
71 }

Member Function Documentation

void FlowMeterTracker::AddEntry ( kkuint32  _scanLineNum,
kkuint32  _counterValue 
)

Definition at line 128 of file FlowMeterTracker.cpp.

131 {
132  if (historyLastIdxAdded < 0)
133  {
134  historyLastIdxAdded = 0;
135  historyOldestIdx = 0;
136  }
137  else
138  {
139  ++historyLastIdxAdded;
140  if (historyLastIdxAdded >= historyTableSize)
141  historyLastIdxAdded = 0;
142  if (historyLastIdxAdded == historyOldestIdx)
143  {
144  ++historyOldestIdx;
145  if (historyOldestIdx >= historyTableSize)
146  historyOldestIdx = 0;
147  }
148  }
149  history[historyLastIdxAdded].scanLineNum = _scanLineNum;
150  history[historyLastIdxAdded].counterValue = _counterValue;
151 } /* AddEntry */
float FlowMeterTracker::ComputeFlowRateFromFlowRateRatio ( float  _flowRateRatio)

Definition at line 254 of file FlowMeterTracker.cpp.

Referenced by FlowRateRatioDefaultChanged(), Initialize(), and ScanRateChanged().

255 {
256  if ((_flowRateRatio == 0.0f) || (imagingWidthPixels == 0.0f))
257  return flowRateDefault;
258 
259  //float flowRate = (imagingWidthMeters * scanRate) / (_flowRateRatio * imagingWidthPixels);
260  float flowRate = (_flowRateRatio * scanRate * imagingWidthMeters) / imagingWidthPixels;
261 
262  return flowRate;
263 }
float FlowMeterTracker::ComputeFlowRateRatioFromFlowRate ( float  _flowRate)

Definition at line 267 of file FlowMeterTracker.cpp.

Referenced by GetFlowRateInstantaneous(), and GetFlowRateTrend().

268 {
269  if ((_flowRate == 0.0f) || (imagingWidthPixels == 0.0f))
270  return flowRateRatioDefault;
271 
272  //float flowRateRatio = (imagingWidthMeters * scanRate) / (_flowRate * imagingWidthPixels);
273  float flowRateRatio = (_flowRate * imagingWidthPixels) / (imagingWidthMeters * scanRate);
274 
275  return flowRateRatio;
276 }
bool KKLSC::FlowMeterTracker::FlowMeterPresent ( ) const
inline

Definition at line 76 of file FlowMeterTracker.h.

76 {return flowMeterPresent;}
float KKLSC::FlowMeterTracker::FlowRateDefault ( ) const
inline

Definition at line 77 of file FlowMeterTracker.h.

77 {return flowRateDefault;}
float FlowMeterTracker::FlowRateInstantaneous ( )

Computes flow rate using the two most current count entries.

Definition at line 163 of file FlowMeterTracker.cpp.

Referenced by GetFlowRateInstantaneous().

164 {
165  if ((historyLastIdxAdded == historyOldestIdx) || (ticsPerMeter == 0.0f) || (scanRate == 0.0f))
166  return flowRateDefault;
167 
168  kkint32 prevIdx = historyLastIdxAdded - 1;
169  if (prevIdx < 0)
170  prevIdx = historyTableSize - 1;
171 
172  EntryPtr lastPtr = history + historyLastIdxAdded;
173  EntryPtr prevPtr = history + prevIdx;
174 
175  kkint32 tics = lastPtr->counterValue - prevPtr->counterValue;
176  kkint32 scanLines = lastPtr->scanLineNum - prevPtr->scanLineNum;
177 
178  float meters = tics / ticsPerMeter;
179  float secs = scanLines / scanRate;
180 
181  return meters / secs;
182 } /* FlowRateInstantaneous */
__int32 kkint32
Definition: KKBaseTypes.h:88
float KKLSC::FlowMeterTracker::FlowRateRatioDefault ( ) const
inline

Definition at line 78 of file FlowMeterTracker.h.

78 {return flowRateRatioDefault;}
void FlowMeterTracker::FlowRateRatioDefaultChanged ( float  _flowRateRatioDefault)

Definition at line 111 of file FlowMeterTracker.cpp.

References ComputeFlowRateFromFlowRateRatio().

112 {
113  flowRateRatioDefault = _flowRateRatioDefault;
114  flowRateDefault = ComputeFlowRateFromFlowRateRatio (flowRateRatioDefault);
115 }
float ComputeFlowRateFromFlowRateRatio(float _flowRateRatio)
float FlowMeterTracker::FlowRateTrend ( )

Computes flow rate using full range of history table.

Definition at line 187 of file FlowMeterTracker.cpp.

Referenced by GetFlowRateTrend().

188 {
189  if ((historyLastIdxAdded == historyOldestIdx) || (ticsPerMeter == 0.0f) || (scanRate == 0.0f))
190  return flowRateDefault;
191 
192  EntryPtr lastPtr = history + historyLastIdxAdded;
193  EntryPtr prevPtr = history + historyOldestIdx;
194 
195  kkint32 tics = lastPtr->counterValue - prevPtr->counterValue;
196  kkint32 scanLines = lastPtr->scanLineNum - prevPtr->scanLineNum;
197 
198  if ((tics == 0) || (scanLines == 0))
199  return 0.0f;
200 
201  float meters = tics / ticsPerMeter;
202  float secs = scanLines / scanRate;
203 
204  return meters / secs;
205 } /* FlowRateTrend */
__int32 kkint32
Definition: KKBaseTypes.h:88
void FlowMeterTracker::GetFlowRateInstantaneous ( float &  flowRate,
float &  flowRateRatio 
)

Definition at line 210 of file FlowMeterTracker.cpp.

References ComputeFlowRateRatioFromFlowRate(), and FlowRateInstantaneous().

213 {
214  if (!flowMeterPresent)
215  {
216  flowRate = flowRateDefault;
217  flowRateRatio = flowRateRatioDefault;
218  return;
219  }
220 
221  flowRate = FlowRateInstantaneous ();
222  flowRateRatio = ComputeFlowRateRatioFromFlowRate (flowRate);
223 
224  return;
225 }
float ComputeFlowRateRatioFromFlowRate(float _flowRate)
void FlowMeterTracker::GetFlowRateTrend ( float &  flowRate,
float &  flowRateRatio 
)

Definition at line 228 of file FlowMeterTracker.cpp.

References ComputeFlowRateRatioFromFlowRate(), and FlowRateTrend().

231 {
232  if ((!flowMeterPresent) || (this->historyLastIdxAdded < 0) || (historyLastIdxAdded == this->historyOldestIdx))
233  {
234  flowRate = flowRateDefault;
235  flowRateRatio = flowRateRatioDefault;
236  return;
237  }
238 
239  if (!flowMeterPresent)
240  {
241  flowRate = flowRateDefault;
242  flowRateRatio = flowRateRatioDefault;
243  return;
244  }
245 
246  flowRate = FlowRateTrend ();
247  flowRateRatio = ComputeFlowRateRatioFromFlowRate (flowRate);
248 
249  return;
250 }
float ComputeFlowRateRatioFromFlowRate(float _flowRate)
kkint32 KKLSC::FlowMeterTracker::HistoryTableSize ( ) const
inline

Definition at line 79 of file FlowMeterTracker.h.

79 {return historyTableSize;}
float KKLSC::FlowMeterTracker::ImagingWidthMeters ( ) const
inline

Definition at line 80 of file FlowMeterTracker.h.

80 {return imagingWidthMeters;}
kkint32 KKLSC::FlowMeterTracker::ImagingWidthPixels ( ) const
inline

Definition at line 81 of file FlowMeterTracker.h.

81 {return imagingWidthPixels;}
void FlowMeterTracker::Initialize ( bool  _flowMeterPresent,
float  _flowRateRatioDefault,
kkint32  _historyTableSize,
float  _scanRate,
float  _imagingWidthMeters,
kkint32  _imagingWidthPixels,
float  _ticsPerMeter 
)
Parameters
[in]_flowMeterPresentIndicates if there is a Flow Meter or will FlowRate and FlowRateRatio be derived from configuration; see _flowRateRatioDefault.
[in]_flowRateRatioDefaultWhen flow meter s not present or unable to compute FlowRate will utilize this value to return FlowRate and FlowRateRatio.
[in]_historyTableSizeThe number of FlowMeter readings that will be tracked.
[in]_scanRateScan-Lines per second that camera is operating at.
[in]_imagingWidthMetersWidth in meters that is being imaged.
[in]_imagingWidthPixelsNumber of pixels that is being imaged; this is the same as distance refereed to by _imagingWidthMeters.
[in]_ticsPerMeterThe number counter ticks that occur per meter; this value will help compute FlowRate.

Definition at line 74 of file FlowMeterTracker.cpp.

References ComputeFlowRateFromFlowRateRatio().

82 {
83  flowMeterPresent = _flowMeterPresent;
84  flowRateRatioDefault = _flowRateRatioDefault;
85  scanRate = _scanRate;
86  imagingWidthMeters = _imagingWidthMeters;
87  imagingWidthPixels = _imagingWidthPixels;
88  ticsPerMeter = _ticsPerMeter;
89 
90  historyTableSize = _historyTableSize;
91  delete history;
92  history = new Entry[historyTableSize];
93  historyLastIdxAdded = -1;
94  historyOldestIdx = -1;
95 
96  flowRateDefault = ComputeFlowRateFromFlowRateRatio (flowRateRatioDefault);
97 }
float ComputeFlowRateFromFlowRateRatio(float _flowRateRatio)
kkint32 FlowMeterTracker::MemoryConsumedEstimated ( )

Definition at line 101 of file FlowMeterTracker.cpp.

102 {
103  kkint32 mem = sizeof (*this);
104  if (historyTableSize > 0)
105  mem += sizeof (Entry) * historyTableSize;
106  return mem;
107 }
__int32 kkint32
Definition: KKBaseTypes.h:88
void FlowMeterTracker::ScanRateChanged ( float  _newScanRate)

Definition at line 119 of file FlowMeterTracker.cpp.

References ComputeFlowRateFromFlowRateRatio().

120 {
121  scanRate = _newScanRate;
122  flowRateDefault = ComputeFlowRateFromFlowRateRatio (flowRateRatioDefault);
123 }
float ComputeFlowRateFromFlowRateRatio(float _flowRateRatio)
float KKLSC::FlowMeterTracker::TicsPerMeter ( ) const
inline

Definition at line 82 of file FlowMeterTracker.h.

82 {return ticsPerMeter;}

The documentation for this class was generated from the following files: