Rampdown improvement and safety checks

This commit is contained in:
freddanastrom 2025-07-18 10:30:09 +02:00
parent 1477ea2f81
commit fe7e4de3de
2 changed files with 14 additions and 10 deletions

View file

@ -172,18 +172,21 @@ void BydAttoBattery::
datalayer_battery->status.remaining_capacity_Wh = static_cast<uint32_t>( datalayer_battery->status.remaining_capacity_Wh = static_cast<uint32_t>(
(static_cast<double>(datalayer_battery->status.real_soc) / 10000) * datalayer_battery->info.total_capacity_Wh); (static_cast<double>(datalayer_battery->status.real_soc) / 10000) * datalayer_battery->info.total_capacity_Wh);
datalayer_battery->status.max_discharge_power_W = MAXPOWER_DISCHARGE_W; //TODO: Map from CAN later on if (SOC_method == ESTIMATED && battery_estimated_SOC * 0.1 < RAMPDOWN_SOC && RAMPDOWN_SOC > 0) {
// If using estimated SOC, ramp down max discharge power as SOC decreases.
rampdown_power = RAMPDOWN_POWER_ALLOWED * ((battery_estimated_SOC * 0.1) / RAMPDOWN_SOC);
if (rampdown_power < MAXPOWER_DISCHARGE_W) { // Never allow more than MAXPOWER_DISCHARGE_W
datalayer_battery->status.max_discharge_power_W = rampdown_power;
} else {
datalayer_battery->status.max_discharge_power_W = MAXPOWER_DISCHARGE_W; //TODO: Map from CAN later on
}
} else {
datalayer_battery->status.max_discharge_power_W = MAXPOWER_DISCHARGE_W; //TODO: Map from CAN later on
}
datalayer_battery->status.max_charge_power_W = BMS_allowed_charge_power * 10; //TODO: Scaling unknown, *10 best guess datalayer_battery->status.max_charge_power_W = BMS_allowed_charge_power * 10; //TODO: Scaling unknown, *10 best guess
if (SOC_method ==
ESTIMATED) { // If we are using estimated SOC, maximum discharge power is ramped down towards the end.
if (battery_estimated_SOC * 0.1 < RAMPDOWN_SOC) {
datalayer.battery.status.max_discharge_power_W =
RAMPDOWN_POWER_ALLOWED * ((battery_estimated_SOC * 0.1) / RAMPDOWN_SOC);
}
}
datalayer_battery->status.cell_max_voltage_mV = BMS_highest_cell_voltage_mV; datalayer_battery->status.cell_max_voltage_mV = BMS_highest_cell_voltage_mV;
datalayer_battery->status.cell_min_voltage_mV = BMS_lowest_cell_voltage_mV; datalayer_battery->status.cell_min_voltage_mV = BMS_lowest_cell_voltage_mV;

View file

@ -20,7 +20,7 @@
// Ramp down settings that are used when SOC is estimated from voltage // Ramp down settings that are used when SOC is estimated from voltage
static const int RAMPDOWN_SOC = 100; // SOC to start ramping down from. Value set here is scaled by 10 (100 = 10.0%) static const int RAMPDOWN_SOC = 100; // SOC to start ramping down from. Value set here is scaled by 10 (100 = 10.0%)
static const int RAMPDOWN_POWER_ALLOWED = static const int RAMPDOWN_POWER_ALLOWED =
10000; // The power to start ramping down from, can be set to a lower value if you want to limit the power at the end of discharge even further 10000; // Power to start ramp down from, set a lower value to limit the power even further as SOC decreases
/* Do not modify the rows below */ /* Do not modify the rows below */
#ifdef BYD_ATTO_3_BATTERY #ifdef BYD_ATTO_3_BATTERY
@ -134,6 +134,7 @@ class BydAttoBattery : public CanBattery {
uint8_t BMS_unknown13 = 0; uint8_t BMS_unknown13 = 0;
uint8_t battery_frame_index = 0; uint8_t battery_frame_index = 0;
uint16_t battery_cellvoltages[CELLCOUNT_EXTENDED] = {0}; uint16_t battery_cellvoltages[CELLCOUNT_EXTENDED] = {0};
uint16_t rampdown_power = 0;
uint16_t poll_state = POLL_FOR_BATTERY_SOC; uint16_t poll_state = POLL_FOR_BATTERY_SOC;
uint16_t pid_reply = 0; uint16_t pid_reply = 0;