Skip to content

Commit

Permalink
Fixed enum. Fixed config typo.
Browse files Browse the repository at this point in the history
added some vars for future BMS IMBALANCE fault codes.
  • Loading branch information
Relys committed Oct 15, 2023
1 parent 70ee05e commit ef854ff
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/AppConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ boolean AppConfiguration::readPreferences() {
config.ledFrequency = doc["ledFrequency"] | "KHZ800";
config.lightBarLedFrequency = doc["lightBarLedFrequency"] | "KHZ800";
config.isLightBarReversed = doc["isLightBarReversed"] | false;
config.isLightBarReversed = doc["isLightBarLedTypeDifferent"] | false;
config.isLightBarLedTypeDifferent = doc["isLightBarLedTypeDifferent"] | false;
config.idleLightTimeout = doc["idleLightTimeout"] | 60000;
config.mallGrab = doc["mallGrab"] | false;
config.logLevel = doc["logLevel"] | Logger::SILENT;
Expand Down
15 changes: 8 additions & 7 deletions src/BMSController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
#define BMS_ON_PIN 16
#endif

BMSController::BMSController() {}
BMSController::BMSController(VescData *vescData)
{
this->vescData = vescData;
}

void BMSController::init(CanBus* canbus) {
canbus_=canbus;
Expand Down Expand Up @@ -70,7 +73,6 @@ void BMSController::broadcastVESCBMS()

canbus_->bmsI(relay->getCurrentMilliamps() / 1000.0f > 0.0f ? relay->getCurrentMilliamps() / 1000.0f : 0.0f);


boolean isBalancing;
boolean isCharging=relay->isCharging();
if (isCharging && relay->getBmsReportedSOC()>=99)
Expand Down Expand Up @@ -126,8 +128,8 @@ void BMSController::broadcastVESCBMS()

if(isBatteryCellOvercharged(cellMillivolts,cellSeries)) fault_state=BMS_FAULT_CODE_CELL_SOFT_OVER_VOLTAGE;
if(isBatteryCellUndercharged(cellMillivolts,cellSeries)) fault_state=BMS_FAULT_CODE_CELL_SOFT_UNDER_VOLTAGE;
//FAULT CODE not yet finalized
//if(isBatteryCellImbalanced(cellMillivolts,cellSeries)) fault_state=BMS_FAULT_CODE_CELL_IMBALANCE;
//if(batteryCellVariance(cellMillivolts,cellSeries)>=cellMaxVarianceSoft) fault_state=BMS_FAULT_CODE_CELL_SOFT_IMBALANCE;
//if(batteryCellVariance(cellMillivolts,cellSeries)>=cellMaxVarianceHard) fault_state=BMS_FAULT_CODE_CELL_HARD_IMBALANCE;
if(isBatteryCellTempMax(thermTemps,cellThermistors)) fault_state = (isCharging) ? BMS_FAULT_CODE_CHARGE_OVER_TEMP_CELLS : BMS_FAULT_CODE_DISCHARGE_OVER_TEMP_CELLS;
if(isBatteryCellTempMin(thermTemps,cellThermistors)) fault_state = (isCharging) ? BMS_FAULT_CODE_CHARGE_UNDER_TEMP_CELLS : BMS_FAULT_CODE_DISCHARGE_UNDER_TEMP_CELLS;
const int8_t bmsTemp=thermTemps[4];
Expand Down Expand Up @@ -156,7 +158,7 @@ boolean BMSController::isBatteryCellUndercharged(const uint16_t* cellMillivolts,
return false;
}

boolean BMSController::isBatteryCellImbalanced(const uint16_t* cellMillivolts, int numCells)
float BMSController::batteryCellVariance(const uint16_t* cellMillivolts, int numCells)
{
// Calculate the mean
float sum = 0.0;
Expand All @@ -172,8 +174,7 @@ boolean BMSController::isBatteryCellImbalanced(const uint16_t* cellMillivolts, i
}
variance /= numCells;

if(variance>=cellMaxVariance) return true;
return false;
return variance;
}

boolean BMSController::isBatteryCellTempMax(const int8_t* thermTemps, int temp_max)
Expand Down
11 changes: 8 additions & 3 deletions src/BMSController.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
#include "settings.h"
#include "ArduinoJson.h"
#include "CanBus.h"
#include "VescData.h"
#include "VescCanConstants.h"

//https://github.com/lolwheel/Owie/commit/8f10e0897eda7f6e3ca40afeaff909a97b9f7751

// UART RX is connected to the *BMS* White line for OneWheel Pint.
class BMSController {
public:
BMSController();
BMSController(VescData *vescData);
VescData *vescData;
void init(CanBus*);
void loop();
BmsRelay *relay;
Expand All @@ -29,7 +32,7 @@ class BMSController {

boolean isBatteryCellOvercharged(const uint16_t*, int);
boolean isBatteryCellUndercharged(const uint16_t*, int);
boolean isBatteryCellImbalanced(const uint16_t*, int);
float batteryCellVariance(const uint16_t*, int);
boolean isBatteryCellTempMax(const int8_t*, int);
boolean isBatteryCellTempMin(const int8_t*, int);
boolean isBMSTempMax(const int8_t);
Expand Down Expand Up @@ -57,5 +60,7 @@ class BMSController {
float cellTempMin=10;
float bmsTempMax=60;
float bmsTempMin=10;
float cellMaxVariance=0.0001;
float cellMaxVarianceSoft=0.00001f;
float cellMaxVarianceHard=0.00005f;
boolean chargeOnly=true;
};
2 changes: 1 addition & 1 deletion src/ILedController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define LOG_TAG_LED "ILedController"

// Pattern types supported:
enum Pattern { NONE, RAINBOW_CYCLE, TRANS_PRIDE, THEATER_CHASE, COLOR_WIPE, CYLON, FADE, RESCUE_FLASH_LIGHT, PULSE, SLIDE, BATTERY_INDICATOR};
enum Pattern { NONE, RAINBOW_CYCLE, THEATER_CHASE, COLOR_WIPE, CYLON, FADE, RESCUE_FLASH_LIGHT, PULSE, SLIDE, BATTERY_INDICATOR, TRANS_PRIDE};
// Patern directions supported:
enum Direction { FORWARD, REVERSE };

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ LightBarController *lightbar = new LightBarController();
void localLogger(Logger::Level level, const char *module, const char *message);

#if defined(CANBUS_ENABLED) && defined(BMS_TX_PIN) && defined(BMS_ON_PIN)
BMSController *bmsController = new BMSController();
BMSController *bmsController = new BMSController(&vescData);
#endif

void setup() {
Expand Down

0 comments on commit ef854ff

Please sign in to comment.