Use base class for Renault Twizy battery

This commit is contained in:
Jaakko Haakana 2025-05-20 00:17:13 +03:00
parent 60d5d79a97
commit 87a3042de4
2 changed files with 31 additions and 24 deletions

View file

@ -5,19 +5,6 @@
#include "../devboard/utils/events.h" #include "../devboard/utils/events.h"
#include "RENAULT-TWIZY.h" #include "RENAULT-TWIZY.h"
/* Do not change code below unless you are sure what you are doing */
static int16_t cell_temperatures_dC[7] = {0};
static int16_t current_dA = 0;
static uint16_t voltage_dV = 0;
static int16_t cellvoltages_mV[14] = {0};
static int16_t max_discharge_power = 0;
static int16_t max_recup_power = 0;
static int16_t max_charge_power = 0;
static uint16_t SOC = 0;
static uint16_t SOH = 0;
static uint16_t remaining_capacity_Wh = 0;
int16_t max_value(int16_t* entries, size_t len) { int16_t max_value(int16_t* entries, size_t len) {
int result = INT16_MIN; int result = INT16_MIN;
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
@ -38,7 +25,7 @@ int16_t min_value(int16_t* entries, size_t len) {
return result; return result;
} }
void update_values_battery() { void RenaultTwizyBattery::update_values() {
datalayer.battery.status.real_soc = SOC; datalayer.battery.status.real_soc = SOC;
datalayer.battery.status.soh_pptt = SOH; datalayer.battery.status.soh_pptt = SOH;
@ -65,7 +52,7 @@ void update_values_battery() {
max_value(cell_temperatures_dC, sizeof(cell_temperatures_dC) / sizeof(*cell_temperatures_dC)); max_value(cell_temperatures_dC, sizeof(cell_temperatures_dC) / sizeof(*cell_temperatures_dC));
} }
void handle_incoming_can_frame_battery(CAN_frame rx_frame) { void RenaultTwizyBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
switch (rx_frame.ID) { switch (rx_frame.ID) {
case 0x155: case 0x155:
@ -127,11 +114,11 @@ void handle_incoming_can_frame_battery(CAN_frame rx_frame) {
} }
} }
void transmit_can_battery(unsigned long currentMillis) { void RenaultTwizyBattery::transmit_can(unsigned long currentMillis) {
// we do not need to send anything to the battery for now // we do not need to send anything to the battery for now
} }
void setup_battery(void) { // Performs one time setup at startup void RenaultTwizyBattery::setup(void) { // Performs one time setup at startup
strncpy(datalayer.system.info.battery_protocol, "Renault Twizy", 63); strncpy(datalayer.system.info.battery_protocol, "Renault Twizy", 63);
datalayer.system.info.battery_protocol[63] = '\0'; datalayer.system.info.battery_protocol[63] = '\0';
datalayer.battery.info.number_of_cells = 14; datalayer.battery.info.number_of_cells = 14;

View file

@ -1,15 +1,35 @@
#ifndef RENAULT_TWIZY_BATTERY_H #ifndef RENAULT_TWIZY_BATTERY_H
#define RENAULT_TWIZY_BATTERY_H #define RENAULT_TWIZY_BATTERY_H
#include "../include.h" #include "../include.h"
#include "CanBattery.h"
#define BATTERY_SELECTED #define BATTERY_SELECTED
#define MAX_PACK_VOLTAGE_DV 579 // 57.9V at 100% SOC (with 70% SOH, new one might be higher) #define SELECTED_BATTERY_CLASS RenaultTwizyBattery
#define MIN_PACK_VOLTAGE_DV 480 // 48.4V at 13.76% SOC
#define MAX_CELL_DEVIATION_MV 150
#define MAX_CELL_VOLTAGE_MV 4200 //Battery is put into emergency stop if one cell goes over this value
#define MIN_CELL_VOLTAGE_MV 3400 //Battery is put into emergency stop if one cell goes below this value
void setup_battery(void); class RenaultTwizyBattery : public CanBattery {
void transmit_can_frame(CAN_frame* tx_frame, int interface); public:
virtual void setup(void);
virtual void handle_incoming_can_frame(CAN_frame rx_frame);
virtual void update_values();
virtual void transmit_can(unsigned long currentMillis);
private:
static const int MAX_PACK_VOLTAGE_DV = 579; // 57.9V at 100% SOC (with 70% SOH, new one might be higher)
static const int MIN_PACK_VOLTAGE_DV = 480; // 48.4V at 13.76% SOC
static const int MAX_CELL_DEVIATION_MV = 150;
static const int MAX_CELL_VOLTAGE_MV = 4200; //Battery is put into emergency stop if one cell goes over this value
static const int MIN_CELL_VOLTAGE_MV = 3400; //Battery is put into emergency stop if one cell goes below this value
int16_t cell_temperatures_dC[7] = {0};
int16_t current_dA = 0;
uint16_t voltage_dV = 0;
int16_t cellvoltages_mV[14] = {0};
int16_t max_discharge_power = 0;
int16_t max_recup_power = 0;
int16_t max_charge_power = 0;
uint16_t SOC = 0;
uint16_t SOH = 0;
uint16_t remaining_capacity_Wh = 0;
};
#endif #endif