Skip to content

Commit

Permalink
VE.Direct: use float rather than double
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
schlimmchen committed Apr 2, 2024
1 parent b299b9d commit 92a7f27
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions include/VictronMppt.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ class VictronMpptClass {
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();
Expand Down
16 changes: 8 additions & 8 deletions lib/VeDirectFrameHandler/VeDirectData.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/VeDirectFrameHandler/VeDirectMpptController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
6 changes: 3 additions & 3 deletions lib/VeDirectFrameHandler/VeDirectMpptController.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class MovingAverage {
_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:
Expand All @@ -47,5 +47,5 @@ class VeDirectMpptController : public VeDirectFrameHandler<veMpptStruct> {
private:
bool processTextDataDerived(std::string const& name, std::string const& value) final;
void frameValidEvent() final;
MovingAverage<double, 5> _efficiency;
MovingAverage<float, 5> _efficiency;
};
14 changes: 7 additions & 7 deletions src/VictronMppt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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; }
Expand All @@ -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);
}
Expand Down

0 comments on commit 92a7f27

Please sign in to comment.