Add skeleton for i3 battery

This commit is contained in:
Daniel 2023-08-02 19:06:48 +03:00
parent f47ce6761b
commit 4ff907b4a8
4 changed files with 144 additions and 2 deletions

View file

@ -13,6 +13,10 @@
#include "RENAULT-ZOE-BATTERY.h" //See this file for more Zoe battery settings
#endif
#ifdef BMW_I3_BATTERY
#include "BMW-I3-BATTERY.h" //See this file for more i3 battery settings
#endif
#ifdef IMIEV_ION_CZERO_BATTERY
#include "IMIEV-CZERO-ION-BATTERY.h" //See this file for more triplet battery settings
#endif

View file

@ -0,0 +1,84 @@
#include "BMW-I3-BATTERY.h"
#include "ESP32CAN.h"
#include "CAN_config.h"
/* Do not change code below unless you are sure what you are doing */
static unsigned long previousMillis10 = 0; // will store last time a 10ms CAN Message was send
static unsigned long previousMillis100 = 0; // will store last time a 100ms CAN Message was send
static const int interval10 = 10; // interval (ms) at which send CAN Messages
static const int interval100 = 100; // interval (ms) at which send CAN Messages
static uint8_t CANstillAlive = 12; //counter for checking if CAN is still alive
#define LB_MAX_SOC 1000 //BMS never goes over this value. We use this info to rescale SOC% sent to Inverter
#define LB_MIN_SOC 0 //BMS never goes below this value. We use this info to rescale SOC% sent to Inverter
static int BMS_SOC = 0;
void update_values_i3_battery()
{ //This function maps all the values fetched via CAN to the correct parameters used for modbus
bms_status = ACTIVE; //Startout in active mode
SOC;
battery_voltage;
battery_current;
capacity_Wh = BATTERY_WH_MAX;
remaining_capacity_Wh;
max_target_discharge_power;
max_target_charge_power;
stat_batt_power;
temperature_min;
temperature_max;
/* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/
if(!CANstillAlive)
{
bms_status = FAULT;
Serial.println("No CAN communication detected for 60s. Shutting down battery control.");
}
else
{
CANstillAlive--;
}
if(printValues)
{ //values heading towards the inverter
Serial.print("SOC%: ");
Serial.println(BMS_SOC);
}
}
void receive_can_i3_battery(CAN_frame_t rx_frame)
{
CANstillAlive = 12;
switch (rx_frame.MsgID)
{
case 0x5D8:
break;
default:
break;
}
}
void send_can_i3_battery()
{
unsigned long currentMillis = millis();
// Send 100ms CAN Message
if (currentMillis - previousMillis100 >= interval100)
{
previousMillis100 = currentMillis;
}
//Send 10ms message
if (currentMillis - previousMillis10 >= interval10)
{
previousMillis10 = currentMillis;
}
}

41
Software/BMW-I3-BATTERY.h Normal file
View file

@ -0,0 +1,41 @@
#ifndef BMW_I3_BATTERY_H
#define BMW_I3_BATTERY_H
#include <Arduino.h>
#include "ESP32CAN.h"
#define BATTERY_WH_MAX 24000 //Battery size in Wh (Maximum value Fronius accepts is 60000 [60kWh] you can use larger batteries but do set value over 60000
#define ABSOLUTE_MAX_VOLTAGE 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge)
#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled
#define MAXPERCENTAGE 800 //80.0% , Max percentage the battery will charge to (App will show 100% once this value is reached)
#define MINPERCENTAGE 200 //20.0% , Min percentage the battery will discharge to (App will show 0% once this value is reached)
static byte printValues = 1; //Should debug values be printed to serial output?
// These parameters need to be mapped for the inverter
extern uint16_t SOC;
extern uint16_t StateOfHealth;
extern uint16_t battery_voltage;
extern uint16_t battery_current;
extern uint16_t capacity_Wh;
extern uint16_t remaining_capacity_Wh;
extern uint16_t max_target_discharge_power;
extern uint16_t max_target_charge_power;
extern uint16_t bms_status;
extern uint16_t bms_char_dis_status;
extern uint16_t stat_batt_power;
extern uint16_t temperature_min;
extern uint16_t temperature_max;
extern uint16_t CANerror;
extern uint8_t batteryAllowsContactorClosing;
// Definitions for BMS status
#define STANDBY 0
#define INACTIVE 1
#define DARKSTART 2
#define ACTIVE 3
#define FAULT 4
#define UPDATING 5
void update_values_i3_battery();
void receive_can_i3_battery(CAN_frame_t rx_frame);
void send_can_i3_battery();
#endif

View file

@ -1,7 +1,8 @@
/* Select battery used */
#define BATTERY_TYPE_LEAF // See NISSAN-LEAF-BATTERY.h for more LEAF battery settings
//#define BATTERY_TYPE_LEAF // See NISSAN-LEAF-BATTERY.h for more LEAF battery settings
//#define TESLA_MODEL_3_BATTERY // See TESLA-MODEL-3-BATTERY.h for more Tesla battery settings
//#define RENAULT_ZOE_BATTERY // See RENAULT-ZOE-BATTERY.h for more Zoe battery settings
#define BMW_I3_BATTERY // See BMW-I3-BATTERY.h for more i3 battery settings
//#define IMIEV_ION_CZERO_BATTERY // See IMIEV-CZERO-ION-BATTERY.h for more triplet battery settings
//#define KIA_HYUNDAI_64_BATTERY // See KIA-HYUNDAI-64-BATTERY.h for more battery settings
//#define CHADEMO // See CHADEMO.h for more Chademo related settings
@ -171,6 +172,9 @@ void setup()
#ifdef RENAULT_ZOE_BATTERY
Serial.println("Renault Zoe / Kangoo battery selected");
#endif
#ifdef BMW_I3_BATTERY
Serial.println("BMW i3 battery selected");
#endif
#ifdef IMIEV_ION_CZERO_BATTERY
Serial.println("Mitsubishi i-MiEV / Citroen C-Zero / Peugeot Ion battery selected");
#endif
@ -216,6 +220,9 @@ void handle_can()
#ifdef RENAULT_ZOE_BATTERY
receive_can_zoe_battery(rx_frame);
#endif
#ifdef BMW_I3_BATTERY
receive_can_i3_battery(rx_frame);
#endif
#ifdef IMIEV_ION_CZERO_BATTERY
receive_can_imiev_battery(rx_frame);
#endif
@ -259,6 +266,9 @@ void handle_can()
#ifdef RENAULT_ZOE_BATTERY
send_can_zoe_battery();
#endif
#ifdef BMW_I3_BATTERY
send_can_i3_battery();
#endif
#ifdef IMIEV_ION_CZERO_BATTERY
send_can_imiev_battery();
#endif
@ -281,6 +291,9 @@ void handle_inverter()
#ifdef RENAULT_ZOE_BATTERY
update_values_zoe_battery(); //Map the values to the correct registers
#endif
#ifdef BMW_I3_BATTERY
update_values_i3_battery(); //Map the values to the correct registers
#endif
#ifdef IMIEV_ION_CZERO_BATTERY
update_values_imiev_battery(); //Map the values to the correct registers
#endif