mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-05 02:39:57 +02:00
Add feature to changing SOC method in UI on BYD Atto3
This commit is contained in:
parent
c450de308f
commit
c6363f9467
5 changed files with 44 additions and 13 deletions
|
@ -151,21 +151,22 @@ void BydAttoBattery::
|
||||||
datalayer_battery->status.voltage_dV = BMS_voltage * 10;
|
datalayer_battery->status.voltage_dV = BMS_voltage * 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_ESTIMATED_SOC
|
if (SOC_method == MEASURED) {
|
||||||
// When the battery is crashed hard, it locks itself and SOC becomes unavailable.
|
// Pack is not crashed, we can use periodically transmitted SOC
|
||||||
// We instead estimate the SOC% based on the battery voltage.
|
datalayer_battery->status.real_soc = battery_highprecision_SOC * 10;
|
||||||
// This is a bad solution, you wont be able to use 100% of the battery
|
|
||||||
if (battery_type == EXTENDED_RANGE) {
|
|
||||||
datalayer_battery->status.real_soc = estimateSOCextended(datalayer_battery->status.voltage_dV);
|
|
||||||
}
|
}
|
||||||
if (battery_type == STANDARD_RANGE) {
|
else
|
||||||
datalayer_battery->status.real_soc = estimateSOCstandard(datalayer_battery->status.voltage_dV);
|
{
|
||||||
|
// When the battery is crashed hard, it locks itself and SOC becomes unavailable.
|
||||||
|
// We instead estimate the SOC% based on the battery voltage.
|
||||||
|
// This is a bad solution, you wont be able to use 100% of the battery
|
||||||
|
if (battery_type == EXTENDED_RANGE) {
|
||||||
|
datalayer_battery->status.real_soc = estimateSOCextended(datalayer_battery->status.voltage_dV);
|
||||||
|
}
|
||||||
|
if (battery_type == STANDARD_RANGE) {
|
||||||
|
datalayer_battery->status.real_soc = estimateSOCstandard(datalayer_battery->status.voltage_dV);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SOC_method = ESTIMATED;
|
|
||||||
#else // Pack is not crashed, we can use periodically transmitted SOC
|
|
||||||
datalayer_battery->status.real_soc = battery_highprecision_SOC * 10;
|
|
||||||
SOC_method = MEASURED;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
datalayer_battery->status.current_dA = -BMS_current;
|
datalayer_battery->status.current_dA = -BMS_current;
|
||||||
|
|
||||||
|
@ -292,6 +293,12 @@ void BydAttoBattery::
|
||||||
stateMachineClearCrash = STARTED;
|
stateMachineClearCrash = STARTED;
|
||||||
datalayer_bydatto->UserRequestCrashReset = false;
|
datalayer_bydatto->UserRequestCrashReset = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Change SOC method if requested from webserver datalayer
|
||||||
|
if (datalayer_bydatto->ChangeSOCMethod) {
|
||||||
|
SOC_method = !SOC_method; // Toggle the SOC method
|
||||||
|
datalayer_bydatto->ChangeSOCMethod = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -691,6 +698,11 @@ void BydAttoBattery::setup(void) { // Performs one time setup at startup
|
||||||
datalayer_battery->info.max_cell_voltage_mV = MAX_CELL_VOLTAGE_MV;
|
datalayer_battery->info.max_cell_voltage_mV = MAX_CELL_VOLTAGE_MV;
|
||||||
datalayer_battery->info.min_cell_voltage_mV = MIN_CELL_VOLTAGE_MV;
|
datalayer_battery->info.min_cell_voltage_mV = MIN_CELL_VOLTAGE_MV;
|
||||||
datalayer_battery->info.max_cell_voltage_deviation_mV = MAX_CELL_DEVIATION_MV;
|
datalayer_battery->info.max_cell_voltage_deviation_mV = MAX_CELL_DEVIATION_MV;
|
||||||
|
#ifdef USE_ESTIMATED_SOC // Initial setup for selected SOC method
|
||||||
|
SOC_method = ESTIMATED;
|
||||||
|
#else
|
||||||
|
SOC_method = MEASURED;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -57,6 +57,13 @@ class BydAttoBattery : public CanBattery {
|
||||||
|
|
||||||
void reset_crash() { datalayer_bydatto->UserRequestCrashReset = true; }
|
void reset_crash() { datalayer_bydatto->UserRequestCrashReset = true; }
|
||||||
|
|
||||||
|
#ifndef USE_ESTIMATED_SOC
|
||||||
|
// Changing SOC method in UI is only enabled if we initially use measured SOC
|
||||||
|
bool supports_change_SOC_method() { return true; }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void change_SOC_method() { datalayer_bydatto->ChangeSOCMethod = true; }
|
||||||
|
|
||||||
BatteryHtmlRenderer& get_status_renderer() { return renderer; }
|
BatteryHtmlRenderer& get_status_renderer() { return renderer; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -81,6 +88,7 @@ class BydAttoBattery : public CanBattery {
|
||||||
unsigned long previousMillis100 = 0; // will store last time a 100ms CAN Message was send
|
unsigned long previousMillis100 = 0; // will store last time a 100ms CAN Message was send
|
||||||
unsigned long previousMillis200 = 0; // will store last time a 200ms CAN Message was send
|
unsigned long previousMillis200 = 0; // will store last time a 200ms CAN Message was send
|
||||||
bool SOC_method = false;
|
bool SOC_method = false;
|
||||||
|
bool ChangeSOCMethod = false;
|
||||||
uint8_t counter_50ms = 0;
|
uint8_t counter_50ms = 0;
|
||||||
uint8_t counter_100ms = 0;
|
uint8_t counter_100ms = 0;
|
||||||
uint8_t frame6_counter = 0xB;
|
uint8_t frame6_counter = 0xB;
|
||||||
|
|
|
@ -29,6 +29,7 @@ class Battery {
|
||||||
virtual bool supports_set_fake_voltage() { return false; }
|
virtual bool supports_set_fake_voltage() { return false; }
|
||||||
virtual bool supports_manual_balancing() { return false; }
|
virtual bool supports_manual_balancing() { return false; }
|
||||||
virtual bool supports_real_BMS_status() { return false; }
|
virtual bool supports_real_BMS_status() { return false; }
|
||||||
|
virtual bool supports_change_SOC_method() { return false; }
|
||||||
|
|
||||||
virtual void clear_isolation() {}
|
virtual void clear_isolation() {}
|
||||||
virtual void reset_BMS() {}
|
virtual void reset_BMS() {}
|
||||||
|
@ -40,6 +41,7 @@ class Battery {
|
||||||
virtual void reset_BECM() {}
|
virtual void reset_BECM() {}
|
||||||
virtual void request_open_contactors() {}
|
virtual void request_open_contactors() {}
|
||||||
virtual void request_close_contactors() {}
|
virtual void request_close_contactors() {}
|
||||||
|
virtual void change_SOC_method() {}
|
||||||
|
|
||||||
virtual void set_fake_voltage(float v) {}
|
virtual void set_fake_voltage(float v) {}
|
||||||
virtual float get_voltage() { static_cast<float>(datalayer.battery.status.voltage_dV) / 10.0; }
|
virtual float get_voltage() { static_cast<float>(datalayer.battery.status.voltage_dV) / 10.0; }
|
||||||
|
|
|
@ -171,6 +171,9 @@ typedef struct {
|
||||||
/** User requesting crash reset via WebUI*/
|
/** User requesting crash reset via WebUI*/
|
||||||
bool UserRequestCrashReset = false;
|
bool UserRequestCrashReset = false;
|
||||||
/** bool */
|
/** bool */
|
||||||
|
/** User changing SOC method via WebUI*/
|
||||||
|
bool ChangeSOCMethod = false;
|
||||||
|
/** bool */
|
||||||
/** Which SOC method currently used. 0 = Estimated, 1 = Measured */
|
/** Which SOC method currently used. 0 = Estimated, 1 = Measured */
|
||||||
bool SOC_method = 0;
|
bool SOC_method = 0;
|
||||||
/** uint16_t */
|
/** uint16_t */
|
||||||
|
|
|
@ -56,6 +56,12 @@ std::vector<BatteryCommand> battery_commands = {
|
||||||
[](Battery* b) {
|
[](Battery* b) {
|
||||||
b->reset_SOH();
|
b->reset_SOH();
|
||||||
}},
|
}},
|
||||||
|
{"changeSOC", "Change SOC method",
|
||||||
|
"change SOC method? This will toggle between ESTIMATED and MEASURED SOC methods.",
|
||||||
|
[](Battery* b) { return b && b->supports_change_SOC_method(); },
|
||||||
|
[](Battery* b) {
|
||||||
|
b->change_SOC_method();
|
||||||
|
}},
|
||||||
};
|
};
|
||||||
|
|
||||||
String advanced_battery_processor(const String& var) {
|
String advanced_battery_processor(const String& var) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue