1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// 
// 
// 

#include "driver_VenturiFlowMeter.h"

void VenturiFlowMeter::Init(t_VenturiSensorModel model)
{
	_LowPass = 0.8;
	_model = model;
	VenturiFlux = 0;
	Integral = 0;

}

float VenturiFlowMeter::GetFlow(float pressure, float temperature)
{
	if (_model == SpiroquantH_R122P04)
	{
		float vf = SpiroquantH_R122P04_Convert(pressure);
		VenturiFlux = (_LowPass * VenturiFlux) + ((1 - _LowPass) * vf);
		return VenturiFlux;
	}

	if (_model == ALPE_1551)
	{
		float vf = ALPE_1551_Convert(pressure);
		VenturiFlux = (_LowPass * VenturiFlux) + ((1 - _LowPass) * vf);
		return VenturiFlux;
	}

	if (_model == VENTURI_CUSTOM)
	{
		float vf = VenturiCustom_Convert(pressure);
		VenturiFlux = (_LowPass * VenturiFlux) + ((1 - _LowPass) * vf);
		return VenturiFlux;
	}

}
float VenturiFlowMeter::SpiroquantH_R122P04_Convert(float pressure)
{
	float dp = pressure;
	float sign = 1;
	if (dp < 0) {
		sign = -1;
		dp = dp * -1;
	};
	float vf= 0.1513 * (dp * dp * dp) - 3.3424 * (dp * dp) + 41.657 * dp;
	vf = vf * sign;
	Integral += vf;
	return vf;
}
float VenturiFlowMeter::ALPE_1551_Convert(float pressure)
{
	float dp = pressure;
	float sign = 1;
	if (dp < 0) {
		sign = -1;
		dp = dp * -1;
	};
	float vf = -0.0647130 * (dp * dp * dp * dp) + 1.4481369 * (dp * dp * dp)
		- 11.2548243 * (dp * dp) + 43.6025093 * dp;
	vf = vf * sign;


	Integral += vf;
	return vf;
}
float VenturiFlowMeter::VenturiCustom_Convert(float pressure)
{
	float dp = pressure;
	float sign = 1;
	if (dp < 0) {
		sign = -1;
		dp = dp * -1;
	};
	float vf = CustomCoefficients[4] * (dp * dp * dp * dp) + CustomCoefficients[3] * (dp * dp * dp)
		+ CustomCoefficients[2] * (dp * dp) + CustomCoefficients[1] * dp + CustomCoefficients[0];
	vf = vf * sign;


	Integral += vf;
	return vf;
}

bool VenturiFlowMeter::setLowpass(float lowpass)<--- The function 'setLowpass' is never used.
{
	if ((lowpass >= 0) && (lowpass <= 1))
	{
		_LowPass = lowpass;
		return true;
	}
	else
		return false;
}

float VenturiFlowMeter::GetIntegral()
{
	return Integral;
}

void VenturiFlowMeter::ResetIntegral()
{
	Integral = 0;
}

bool VenturiFlowMeter::VenturiSetCoefficient(int index, float value)
{
	if ((index >= 0) && (index < 5))
	{
		CustomCoefficients[index] = value;
		return true;
	}
	else
		return false;
}

//                  #     # ### 
//                  ##    #  #  
//                  # #   #  #  
//                  #  #  #  #  
//                  #   # #  #  
//                  #    ##  #  
//                  #     # ### 
//
// Nuclear Instruments 2020 - All rights reserved
// Any commercial use of this code is forbidden
// Contact info@nuclearinstruments.eu