Adrian Mitevski / Mbed 2 deprecated mDot_LoRa_Sensornode

Dependencies:   mDot_LoRa_Sensornode_Flowmeter_impl mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

FlowMeter Class Reference

FlowMeter Class Reference

FlowMeter. More...

#include <FlowMeter.h>

Public Member Functions

 FlowMeter (InterruptIn *pin, FlowSensorProperties prop=UncalibratedSensor)
 Initializes a new flow meter object.
double getCurrentFlowrate ()
 Returns the current flow rate since last reset (in l/min).
double getCurrentVolume ()
 Returns the current volume since last reset (in l).
double getTotalFlowrate ()
 Returns the (linear) average flow rate in this flow meter instance (in l/min).
double getTotalVolume ()
 Returns the total volume flown trough this flow meter instance (in l).
void tick ()
 The tick method updates all internal calculations at the end of a measurement period.
void count (void)
 Increments the internal pulse counter. Serves as an interrupt callback routine.
void reset ()
 Prepares the flow meter for a fresh measurement. Resets all current values, but not the totals.
FlowMetersetTotalDuration (unsigned long totalDuration)
 Sets the total (overall) duration (i.e. after power up).
FlowMetersetTotalVolume (double totalVolume)
 Sets the total (overall) volume (i.e. after power up).
FlowMetersetTotalCorrection (double totalCorrection)
 Sets the total (overall) correction factor (i.e. after power up).
InterruptIn * getPin ()
 Returns the Arduino pin number that the flow sensor is connected to.
unsigned long getCurrentDuration ()
 Returns the duration of the current tick (in ms).
double getCurrentFrequency ()
 Returns the pulse rate in the current tick (in 1/s).
double getCurrentError ()
 Returns the error resulting from the current measurement (in %).
unsigned long getTotalDuration ()
 Returns the total run time of this flow meter instance (in ms).
double getTotalError ()
 Returns the (linear) average error of this flow meter instance (in %).

Protected Attributes

FlowSensorProperties _properties
 sensor properties (including calibration data)
unsigned long _currentDuration
 current tick duration (convenience, in ms)
double _currentFrequency
 current pulses per second (convenience, in 1/s)
double _currentFlowrate
 current flow rate (in l/tick), e.g.: 1 l / min = 1 pulse / s / (pulses / s / l / min)
double _currentVolume
 current volume (in l), e.g.: 1 l = 1 (l / min) / (60 * s)
double _currentCorrection
 currently applied correction factor
unsigned long _totalDuration
 total measured duration since begin of measurement (in ms)
double _totalVolume
 total volume since begin of measurement (in l)
double _totalCorrection
 accumulated correction factors
volatile unsigned long _currentPulses
 pulses within current sample period

Detailed Description

FlowMeter.

Definition at line 34 of file FlowMeter.h.


Constructor & Destructor Documentation

FlowMeter ( InterruptIn *  pin,
FlowSensorProperties  prop = UncalibratedSensor 
)

Initializes a new flow meter object.

Parameters:
pinThe pin that the flow sensor is connected to (has to be interrupt capable, default: INT0).
propThe properties of the actual flow sensor being used (default: UncalibratedSensor).

Definition at line 11 of file FlowMeter.cpp.


Member Function Documentation

void count ( void   )

Increments the internal pulse counter. Serves as an interrupt callback routine.

< this should be called from an interrupt service routine

Definition at line 79 of file FlowMeter.cpp.

unsigned long getCurrentDuration (  )

Returns the duration of the current tick (in ms).

< in ms

Definition at line 99 of file FlowMeter.cpp.

double getCurrentError (  )

Returns the error resulting from the current measurement (in %).

error (in %) = error * 100 error = correction rate - 1 correction rate = k-factor / correction

< in %

Definition at line 107 of file FlowMeter.cpp.

double getCurrentFlowrate (  )

Returns the current flow rate since last reset (in l/min).

< in l/min

Definition at line 31 of file FlowMeter.cpp.

double getCurrentFrequency (  )

Returns the pulse rate in the current tick (in 1/s).

< in 1/s

Definition at line 103 of file FlowMeter.cpp.

double getCurrentVolume (  )

Returns the current volume since last reset (in l).

< in l

Definition at line 35 of file FlowMeter.cpp.

InterruptIn * getPin (  )

Returns the Arduino pin number that the flow sensor is connected to.

Definition at line 95 of file FlowMeter.cpp.

unsigned long getTotalDuration (  )

Returns the total run time of this flow meter instance (in ms).

< in ms

Definition at line 114 of file FlowMeter.cpp.

double getTotalError (  )

Returns the (linear) average error of this flow meter instance (in %).

average error (in %) = average error * 100 average error = average correction rate - 1 average correction rate = k-factor / corrections over time * total time

Definition at line 118 of file FlowMeter.cpp.

double getTotalFlowrate (  )

Returns the (linear) average flow rate in this flow meter instance (in l/min).

< in l/min

Definition at line 39 of file FlowMeter.cpp.

double getTotalVolume (  )

Returns the total volume flown trough this flow meter instance (in l).

< in l

Definition at line 43 of file FlowMeter.cpp.

void reset (  )

Prepares the flow meter for a fresh measurement. Resets all current values, but not the totals.

< reset pulse counter

Definition at line 83 of file FlowMeter.cpp.

FlowMeter * setTotalCorrection ( double  totalCorrection )

Sets the total (overall) correction factor (i.e. after power up).

Definition at line 135 of file FlowMeter.cpp.

FlowMeter * setTotalDuration ( unsigned long  totalDuration )

Sets the total (overall) duration (i.e. after power up).

Definition at line 125 of file FlowMeter.cpp.

FlowMeter * setTotalVolume ( double  totalVolume )

Sets the total (overall) volume (i.e. after power up).

Definition at line 130 of file FlowMeter.cpp.

void tick (  )

The tick method updates all internal calculations at the end of a measurement period.

We're calculating flow and volume data over time. The actual pulses have to be sampled using the count method (i.e. via an interrupt service routine).

Flow sensor formulae:

Let K: pulses per second per unit of measure (i.e. (1/s)/(l/min)), f: pulse frequency (1/s), Q: flow rate (l/min), p: sensor pulses (no dimension/unit), t: time since last measurements (s).

K = f / Q | units: (1/s) / (l/min) = (1/s) / (l/min) <=> | Substitute p / t for f in order to allow for different measurement intervals K = (p / t) / Q | units: ((1/s)/(l/min)) = (1/s) / (l/min) <=> | Solve for Q: Q = (p / t) / K | untis: l/min = 1/s / (1/s / (l/min)) <=> | Volume in l: V = Q / 60 | units: l = (l/min) / (min)

The property K is sometimes stated in pulses per liter or pulses per gallon. In these cases the unit of measure has to be converted accordingly (e.g. from gal/s to l/min). See file G34_Flow_rate_to_frequency.jpg for reference.

Parameters:
durationThe tick duration (in ms).

< normalised duration (in s, i.e. per 1000ms)

< normalised frequency (in 1/s)

< reset pulse counter after successfull sampling

< decile of current flow relative to sensor capacity

< combine constant k-factor and m-factor for decile

< get flow rate (in l/min) from normalised frequency and combined correction factor

< get volume (in l) from normalised flow rate and normalised time

< store current tick duration (convenience, in ms)

< store current pulses per second (convenience, in 1/s)

< accumulate total duration (in ms)

< accumulate total volume (in l)

< accumulate corrections over time

Definition at line 47 of file FlowMeter.cpp.


Field Documentation

double _currentCorrection [protected]

currently applied correction factor

Definition at line 112 of file FlowMeter.h.

unsigned long _currentDuration [protected]

current tick duration (convenience, in ms)

Definition at line 108 of file FlowMeter.h.

double _currentFlowrate [protected]

current flow rate (in l/tick), e.g.: 1 l / min = 1 pulse / s / (pulses / s / l / min)

Definition at line 110 of file FlowMeter.h.

double _currentFrequency [protected]

current pulses per second (convenience, in 1/s)

Definition at line 109 of file FlowMeter.h.

volatile unsigned long _currentPulses [protected]

pulses within current sample period

Definition at line 118 of file FlowMeter.h.

double _currentVolume [protected]

current volume (in l), e.g.: 1 l = 1 (l / min) / (60 * s)

Definition at line 111 of file FlowMeter.h.

sensor properties (including calibration data)

Definition at line 106 of file FlowMeter.h.

double _totalCorrection [protected]

accumulated correction factors

Definition at line 116 of file FlowMeter.h.

unsigned long _totalDuration [protected]

total measured duration since begin of measurement (in ms)

Definition at line 114 of file FlowMeter.h.

double _totalVolume [protected]

total volume since begin of measurement (in l)

Definition at line 115 of file FlowMeter.h.