VE.Direct: use float rather than double

double precision floating point numbers are not needed to handle
VE.Direct values. handling double is implemented in software and hence
*much* more resource intensive.
This commit is contained in:
Bernhard Kirchen 2024-03-29 20:56:50 +01:00 committed by Bernhard Kirchen
parent b299b9dc6c
commit 92a7f27919
5 changed files with 22 additions and 22 deletions

View File

@ -34,13 +34,13 @@ public:
int32_t getPanelPowerWatts() const;
// sum of total yield of all MPPT charge controllers in kWh
double getYieldTotal() const;
float getYieldTotal() const;
// sum of today's yield of all MPPT charge controllers in kWh
double getYieldDay() const;
float getYieldDay() const;
// minimum of all MPPT charge controllers' output voltages in V
double getOutputVoltage() const;
float getOutputVoltage() const;
private:
void loop();

View File

@ -10,9 +10,9 @@ typedef struct {
uint16_t PID = 0; // product id
char SER[VE_MAX_VALUE_LEN]; // serial number
char FW[VE_MAX_VALUE_LEN]; // firmware release number
double V = 0; // battery voltage in V
double I = 0; // battery current in A
double E = 0; // efficiency in percent (calculated, moving average)
float V = 0; // battery voltage in V
float I = 0; // battery current in A
float E = 0; // efficiency in percent (calculated, moving average)
frozen::string const& getPidAsString() const; // product ID as string
} veStruct;
@ -21,17 +21,17 @@ struct veMpptStruct : veStruct {
uint8_t MPPT; // state of MPP tracker
int32_t PPV; // panel power in W
int32_t P; // battery output power in W (calculated)
double VPV; // panel voltage in V
double IPV; // panel current in A (calculated)
float VPV; // panel voltage in V
float IPV; // panel current in A (calculated)
bool LOAD; // virtual load output state (on if battery voltage reaches upper limit, off if battery reaches lower limit)
uint8_t CS; // current state of operation e.g. OFF or Bulk
uint8_t ERR; // error code
uint32_t OR; // off reason
uint32_t HSDS; // day sequence number 1...365
double H19; // yield total kWh
double H20; // yield today kWh
float H19; // yield total kWh
float H20; // yield today kWh
int32_t H21; // maximum power today W
double H22; // yield yesterday kWh
float H22; // yield yesterday kWh
int32_t H23; // maximum power yesterday W
frozen::string const& getMpptAsString() const; // state of mppt as string

View File

@ -76,7 +76,7 @@ void VeDirectMpptController::frameValidEvent() {
}
if (_tmpFrame.PPV > 0) {
_efficiency.addNumber(static_cast<double>(_tmpFrame.P * 100) / _tmpFrame.PPV);
_efficiency.addNumber(static_cast<float>(_tmpFrame.P * 100) / _tmpFrame.PPV);
_tmpFrame.E = _efficiency.getAverage();
}
}

View File

@ -24,9 +24,9 @@ public:
_index = (_index + 1) % WINDOW_SIZE;
}
double getAverage() const {
float getAverage() const {
if (_count == 0) { return 0.0; }
return static_cast<double>(_sum) / _count;
return static_cast<float>(_sum) / _count;
}
private:
@ -47,5 +47,5 @@ public:
private:
bool processTextDataDerived(std::string const& name, std::string const& value) final;
void frameValidEvent() final;
MovingAverage<double, 5> _efficiency;
MovingAverage<float, 5> _efficiency;
};

View File

@ -158,9 +158,9 @@ int32_t VictronMpptClass::getPanelPowerWatts() const
return sum;
}
double VictronMpptClass::getYieldTotal() const
float VictronMpptClass::getYieldTotal() const
{
double sum = 0;
float sum = 0;
for (const auto& upController : _controllers) {
if (!upController->isDataValid()) { continue; }
@ -170,9 +170,9 @@ double VictronMpptClass::getYieldTotal() const
return sum;
}
double VictronMpptClass::getYieldDay() const
float VictronMpptClass::getYieldDay() const
{
double sum = 0;
float sum = 0;
for (const auto& upController : _controllers) {
if (!upController->isDataValid()) { continue; }
@ -182,13 +182,13 @@ double VictronMpptClass::getYieldDay() const
return sum;
}
double VictronMpptClass::getOutputVoltage() const
float VictronMpptClass::getOutputVoltage() const
{
double min = -1;
float min = -1;
for (const auto& upController : _controllers) {
if (!upController->isDataValid()) { continue; }
double volts = upController->getData().V;
float volts = upController->getData().V;
if (min == -1) { min = volts; }
min = std::min(min, volts);
}