forked from tbnobody/OpenDTU
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
supporting I2C CAN Bus, MCP2515 and CAN0 for batteries and charger
- Loading branch information
1 parent
ed51c3e
commit db20f07
Showing
44 changed files
with
918 additions
and
446 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#pragma once | ||
|
||
#ifdef USE_SURPLUSPOWER | ||
|
||
template <typename T> | ||
class WeightedAVG { | ||
public: | ||
WeightedAVG(int16_t factor) | ||
: _countMax(factor) | ||
, _count(0), _countNum(0), _avgV(0), _minV(0), _maxV(0), _lastV(0) {} | ||
|
||
void addNumber(const T& num) { | ||
if (_count == 0){ | ||
_count++; | ||
_avgV = num; | ||
_minV = num; | ||
_maxV = num; | ||
_countNum = 1; | ||
} else { | ||
if (_count < _countMax) | ||
_count++; | ||
_avgV = (_avgV * (_count - 1) + num) / _count; | ||
if (num < _minV) _minV = num; | ||
if (num > _maxV) _maxV = num; | ||
_countNum++; | ||
} | ||
_lastV = num; | ||
} | ||
|
||
void reset(void) { _count = 0; _avgV = 0; _minV = 0; _maxV = 0; _lastV = 0; _countNum = 0; } | ||
void reset(const T& num) { _count = 0; addNumber(num); } | ||
T getAverage() const { return _avgV; } | ||
T getMin() const { return _minV; } | ||
T getMax() const { return _maxV; } | ||
T getLast() const { return _lastV; } | ||
int32_t getCounts() const { return _countNum; } | ||
|
||
private: | ||
int16_t _countMax; // weighting factor (10 => 1/10 => 10%) | ||
int16_t _count; // counter (0 - _countMax) | ||
int32_t _countNum; // counts the amount of added numbers | ||
T _avgV; // average value | ||
T _minV; // minimum value | ||
T _maxV; // maximum value | ||
T _lastV; // last value | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#pragma once | ||
|
||
#ifdef USE_SURPLUSPOWER | ||
|
||
#include <Arduino.h> | ||
#include <frozen/string.h> | ||
#include "Statistic.h" | ||
|
||
|
||
class SurplusPowerClass { | ||
public: | ||
SurplusPowerClass() = default; | ||
~SurplusPowerClass() = default; | ||
|
||
bool useSurplusPower(void) const; | ||
int32_t calcSurplusPower(int32_t const requestedPower); | ||
|
||
private: | ||
enum class SurplusState : uint8_t { | ||
IDLE = 0, | ||
TRY_MORE = 1, | ||
REDUCE_POWER = 2, | ||
IN_TARGET = 3, | ||
MAXIMUM_POWER = 4, | ||
}; | ||
|
||
enum class Text : uint8_t { | ||
Q_NODATA = 0, | ||
Q_EXCELLENT = 1, | ||
Q_GOOD = 2, | ||
Q_BAD = 3, | ||
T_HEAD = 4 | ||
}; | ||
|
||
frozen::string const& getStatusText(SurplusPowerClass::SurplusState state); | ||
frozen::string const& getText(SurplusPowerClass::Text tNr); | ||
void handleQualityCounter(void); | ||
|
||
// to handle regulation | ||
SurplusState _surplusState = SurplusState::IDLE; // actual regulation state | ||
float _absorptionVoltage = -1.0f; // from MPPT | ||
float _floatVoltage = -1.0f; // from MPPT | ||
int32_t _powerStep = 50; // power step size in W (default) | ||
int32_t _surplusPower = 0; // actual surplus power | ||
int32_t _inTargetTime = 0; // records the time we hit the target power | ||
WeightedAVG<float> _avgMPPTVoltage {3}; // the average helps to smooth the regulation | ||
|
||
// to handle the quality counter | ||
int8_t _qualityCounter = 0; // quality counter | ||
WeightedAVG<float> _qualityAVG {20}; // quality counter average | ||
int32_t _lastAddPower = 0; // last power step | ||
}; | ||
|
||
extern SurplusPowerClass SurplusPower; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.