Use base class for RJXZS BMS

This commit is contained in:
Jaakko Haakana 2025-05-20 08:32:37 +03:00
parent 8d093b798c
commit 52ffa5289b
2 changed files with 102 additions and 91 deletions

View file

@ -1,83 +1,11 @@
#include "../include.h" #include "../include.h"
#ifdef RJXZS_BMS #ifdef RJXZS_BMS
#include "../communication/can/comm_can.h"
#include "../datalayer/datalayer.h" #include "../datalayer/datalayer.h"
#include "../devboard/utils/events.h" #include "../devboard/utils/events.h"
#include "RJXZS-BMS.h" #include "RJXZS-BMS.h"
/* Do not change code below unless you are sure what you are doing */ void RjxzsBms::update_values() {
static unsigned long previousMillis10s = 0; // will store last time a 10s CAN Message was sent
//Actual content messages
CAN_frame RJXZS_1C = {.FD = false, .ext_ID = true, .DLC = 3, .ID = 0xF4, .data = {0x1C, 0x00, 0x02}};
CAN_frame RJXZS_10 = {.FD = false, .ext_ID = true, .DLC = 3, .ID = 0xF4, .data = {0x10, 0x00, 0x02}};
#define FIVE_MINUTES 60
static uint8_t mux = 0;
static bool setup_completed = false;
static uint16_t total_voltage = 0;
static int16_t total_current = 0;
static uint16_t total_power = 0;
static uint16_t battery_usage_capacity = 0;
static uint16_t battery_capacity_percentage = 0;
static uint16_t charging_capacity = 0;
static uint16_t charging_recovery_voltage = 0;
static uint16_t discharging_recovery_voltage = 0;
static uint16_t remaining_capacity = 0;
static int16_t host_temperature = 0;
static uint16_t status_accounting = 0;
static uint16_t equalization_starting_voltage = 0;
static uint16_t discharge_protection_voltage = 0;
static uint16_t protective_current = 0;
static uint16_t battery_pack_capacity = 0;
static uint16_t number_of_battery_strings = 0;
static uint16_t charging_protection_voltage = 0;
static int16_t protection_temperature = 0;
static bool temperature_below_zero_mod1_4 = false;
static bool temperature_below_zero_mod5_8 = false;
static bool temperature_below_zero_mod9_12 = false;
static bool temperature_below_zero_mod13_16 = false;
static uint16_t module_1_temperature = 0;
static uint16_t module_2_temperature = 0;
static uint16_t module_3_temperature = 0;
static uint16_t module_4_temperature = 0;
static uint16_t module_5_temperature = 0;
static uint16_t module_6_temperature = 0;
static uint16_t module_7_temperature = 0;
static uint16_t module_8_temperature = 0;
static uint16_t module_9_temperature = 0;
static uint16_t module_10_temperature = 0;
static uint16_t module_11_temperature = 0;
static uint16_t module_12_temperature = 0;
static uint16_t module_13_temperature = 0;
static uint16_t module_14_temperature = 0;
static uint16_t module_15_temperature = 0;
static uint16_t module_16_temperature = 0;
static uint16_t low_voltage_power_outage_protection = 0;
static uint16_t low_voltage_power_outage_delayed = 0;
static uint16_t num_of_triggering_protection_cells = 0;
static uint16_t balanced_reference_voltage = 0;
static uint16_t minimum_cell_voltage = 0;
static uint16_t maximum_cell_voltage = 0;
static uint16_t cellvoltages[MAX_AMOUNT_CELLS];
static uint8_t populated_cellvoltages = 0;
static uint16_t accumulated_total_capacity_high = 0;
static uint16_t accumulated_total_capacity_low = 0;
static uint16_t pre_charge_delay_time = 0;
static uint16_t LCD_status = 0;
static uint16_t differential_pressure_setting_value = 0;
static uint16_t use_capacity_to_automatically_reset = 0;
static uint16_t low_temperature_protection_setting_value = 0;
static uint16_t protecting_historical_logs = 0;
static uint16_t hall_sensor_type = 0;
static uint16_t fan_start_setting_value = 0;
static uint16_t ptc_heating_start_setting_value = 0;
static uint16_t default_channel_state = 0;
static uint8_t timespent_without_soc = 0;
static bool charging_active = false;
static bool discharging_active = false;
void update_values_battery() {
datalayer.battery.status.real_soc = battery_capacity_percentage * 100; datalayer.battery.status.real_soc = battery_capacity_percentage * 100;
if (battery_capacity_percentage == 0) { if (battery_capacity_percentage == 0) {
@ -166,7 +94,7 @@ void update_values_battery() {
datalayer.battery.status.cell_min_voltage_mV = minimum_cell_voltage; datalayer.battery.status.cell_min_voltage_mV = minimum_cell_voltage;
} }
void handle_incoming_can_frame_battery(CAN_frame rx_frame) { void RjxzsBms::handle_incoming_can_frame(CAN_frame rx_frame) {
/* /*
// All CAN messages recieved will be logged via serial // All CAN messages recieved will be logged via serial
@ -571,7 +499,7 @@ void handle_incoming_can_frame_battery(CAN_frame rx_frame) {
} }
} }
void transmit_can_battery(unsigned long currentMillis) { void RjxzsBms::transmit_can(unsigned long currentMillis) {
// Send 10s CAN Message // Send 10s CAN Message
if (currentMillis - previousMillis10s >= INTERVAL_10_S) { if (currentMillis - previousMillis10s >= INTERVAL_10_S) {
previousMillis10s = currentMillis; previousMillis10s = currentMillis;
@ -588,7 +516,7 @@ void transmit_can_battery(unsigned long currentMillis) {
} }
} }
void setup_battery(void) { // Performs one time setup at startup void RjxzsBms::setup(void) { // Performs one time setup at startup
strncpy(datalayer.system.info.battery_protocol, "RJXZS BMS, DIY battery", 63); strncpy(datalayer.system.info.battery_protocol, "RJXZS BMS, DIY battery", 63);
datalayer.system.info.battery_protocol[63] = '\0'; datalayer.system.info.battery_protocol[63] = '\0';
datalayer.battery.info.max_design_voltage_dV = MAX_PACK_VOLTAGE_DV; datalayer.battery.info.max_design_voltage_dV = MAX_PACK_VOLTAGE_DV;

View file

@ -3,22 +3,105 @@
#include <Arduino.h> #include <Arduino.h>
#include "../include.h" #include "../include.h"
/* Tweak these according to your battery build */ #include "CanBattery.h"
#define MAX_PACK_VOLTAGE_DV 5000 //5000 = 500.0V
#define MIN_PACK_VOLTAGE_DV 1500 #define BATTERY_SELECTED
#define MAX_CELL_VOLTAGE_MV 4250 //Battery is put into emergency stop if one cell goes over this value #define SELECTED_BATTERY_CLASS RjxzsBms
#define MIN_CELL_VOLTAGE_MV 2700 //Battery is put into emergency stop if one cell goes below this value
#define MAX_CELL_DEVIATION_MV 250 class RjxzsBms : public CanBattery {
#define MAX_DISCHARGE_POWER_ALLOWED_W 5000 public:
#define MAX_CHARGE_POWER_ALLOWED_W 5000 virtual void setup(void);
#define MAX_CHARGE_POWER_WHEN_TOPBALANCING_W 500 virtual void handle_incoming_can_frame(CAN_frame rx_frame);
#define RAMPDOWN_SOC 9000 // (90.00) SOC% to start ramping down from max charge power towards 0 at 100.00% virtual void update_values();
virtual void transmit_can(unsigned long currentMillis);
private:
/* Tweak these according to your battery build */
static const int MAX_PACK_VOLTAGE_DV = 5000; //5000 = 500.0V
static const int MIN_PACK_VOLTAGE_DV = 1500;
static const int MAX_CELL_VOLTAGE_MV = 4250; //Battery is put into emergency stop if one cell goes over this value
static const int MIN_CELL_VOLTAGE_MV = 2700; //Battery is put into emergency stop if one cell goes below this value
static const int MAX_CELL_DEVIATION_MV = 250;
static const int MAX_DISCHARGE_POWER_ALLOWED_W = 5000;
static const int MAX_CHARGE_POWER_ALLOWED_W = 5000;
static const int MAX_CHARGE_POWER_WHEN_TOPBALANCING_W = 500;
static const int RAMPDOWN_SOC =
9000; // (90.00) SOC% to start ramping down from max charge power towards 0 at 100.00%
unsigned long previousMillis10s = 0; // will store last time a 10s CAN Message was sent
//Actual content messages
CAN_frame RJXZS_1C = {.FD = false, .ext_ID = true, .DLC = 3, .ID = 0xF4, .data = {0x1C, 0x00, 0x02}};
CAN_frame RJXZS_10 = {.FD = false, .ext_ID = true, .DLC = 3, .ID = 0xF4, .data = {0x10, 0x00, 0x02}};
static const int FIVE_MINUTES = 60;
uint8_t mux = 0;
bool setup_completed = false;
uint16_t total_voltage = 0;
int16_t total_current = 0;
uint16_t total_power = 0;
uint16_t battery_usage_capacity = 0;
uint16_t battery_capacity_percentage = 0;
uint16_t charging_capacity = 0;
uint16_t charging_recovery_voltage = 0;
uint16_t discharging_recovery_voltage = 0;
uint16_t remaining_capacity = 0;
int16_t host_temperature = 0;
uint16_t status_accounting = 0;
uint16_t equalization_starting_voltage = 0;
uint16_t discharge_protection_voltage = 0;
uint16_t protective_current = 0;
uint16_t battery_pack_capacity = 0;
uint16_t number_of_battery_strings = 0;
uint16_t charging_protection_voltage = 0;
int16_t protection_temperature = 0;
bool temperature_below_zero_mod1_4 = false;
bool temperature_below_zero_mod5_8 = false;
bool temperature_below_zero_mod9_12 = false;
bool temperature_below_zero_mod13_16 = false;
uint16_t module_1_temperature = 0;
uint16_t module_2_temperature = 0;
uint16_t module_3_temperature = 0;
uint16_t module_4_temperature = 0;
uint16_t module_5_temperature = 0;
uint16_t module_6_temperature = 0;
uint16_t module_7_temperature = 0;
uint16_t module_8_temperature = 0;
uint16_t module_9_temperature = 0;
uint16_t module_10_temperature = 0;
uint16_t module_11_temperature = 0;
uint16_t module_12_temperature = 0;
uint16_t module_13_temperature = 0;
uint16_t module_14_temperature = 0;
uint16_t module_15_temperature = 0;
uint16_t module_16_temperature = 0;
uint16_t low_voltage_power_outage_protection = 0;
uint16_t low_voltage_power_outage_delayed = 0;
uint16_t num_of_triggering_protection_cells = 0;
uint16_t balanced_reference_voltage = 0;
uint16_t minimum_cell_voltage = 0;
uint16_t maximum_cell_voltage = 0;
uint16_t cellvoltages[MAX_AMOUNT_CELLS];
uint8_t populated_cellvoltages = 0;
uint16_t accumulated_total_capacity_high = 0;
uint16_t accumulated_total_capacity_low = 0;
uint16_t pre_charge_delay_time = 0;
uint16_t LCD_status = 0;
uint16_t differential_pressure_setting_value = 0;
uint16_t use_capacity_to_automatically_reset = 0;
uint16_t low_temperature_protection_setting_value = 0;
uint16_t protecting_historical_logs = 0;
uint16_t hall_sensor_type = 0;
uint16_t fan_start_setting_value = 0;
uint16_t ptc_heating_start_setting_value = 0;
uint16_t default_channel_state = 0;
uint8_t timespent_without_soc = 0;
bool charging_active = false;
bool discharging_active = false;
};
/* Do not modify any rows below*/ /* Do not modify any rows below*/
#define BATTERY_SELECTED
#define NATIVECAN_250KBPS #define NATIVECAN_250KBPS
void setup_battery(void);
void transmit_can_frame(CAN_frame* tx_frame, int interface);
#endif #endif