mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-05 02:39:57 +02:00
Add skeleton for MG5 battery integration
This commit is contained in:
parent
bcaf3ab5b4
commit
8eeae699e5
5 changed files with 169 additions and 2 deletions
|
@ -13,6 +13,7 @@
|
|||
//#define IMIEV_CZERO_ION_BATTERY
|
||||
//#define KIA_HYUNDAI_64_BATTERY
|
||||
//#define KIA_E_GMP_BATTERY
|
||||
//#define MG_5_BATTERY
|
||||
//#define NISSAN_LEAF_BATTERY
|
||||
//#define PYLON_BATTERY
|
||||
//#define RENAULT_KANGOO_BATTERY
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
#include "KIA-HYUNDAI-64-BATTERY.h"
|
||||
#endif
|
||||
|
||||
#ifdef MG_5_BATTERY
|
||||
#include "MG-5-BATTERY.h"
|
||||
#endif
|
||||
|
||||
#ifdef NISSAN_LEAF_BATTERY
|
||||
#include "NISSAN-LEAF-BATTERY.h"
|
||||
#endif
|
||||
|
|
150
Software/src/battery/MG-5-BATTERY.cpp
Normal file
150
Software/src/battery/MG-5-BATTERY.cpp
Normal file
|
@ -0,0 +1,150 @@
|
|||
#include "../include.h"
|
||||
#ifdef MG_5_BATTERY_H
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
#include "MG-5-BATTERY.h"
|
||||
|
||||
/* TODO:
|
||||
- Get contactor closing working
|
||||
- Figure out which CAN messages need to be sent towards the battery to keep it alive
|
||||
- Map all values from battery CAN messages
|
||||
- Most important ones
|
||||
*/
|
||||
|
||||
/* 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 int BMS_SOC = 0;
|
||||
|
||||
CAN_frame_t MG_5_100 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x100,
|
||||
.data = {0x00, 0x00, 0x00, 0x00, 0x80, 0x10, 0x00, 0x00}};
|
||||
|
||||
void update_values_battery() { //This function maps all the values fetched via CAN to the correct parameters used for modbus
|
||||
|
||||
datalayer.battery.status.real_soc;
|
||||
|
||||
datalayer.battery.status.voltage_dV;
|
||||
|
||||
datalayer.battery.status.current_dA;
|
||||
|
||||
datalayer.battery.info.total_capacity_Wh;
|
||||
|
||||
datalayer.battery.status.remaining_capacity_Wh;
|
||||
|
||||
datalayer.battery.status.max_discharge_power_W;
|
||||
|
||||
datalayer.battery.status.max_charge_power_W;
|
||||
|
||||
datalayer.battery.status.active_power_W;
|
||||
|
||||
datalayer.battery.status.temperature_min_dC;
|
||||
|
||||
datalayer.battery.status.temperature_max_dC;
|
||||
|
||||
#ifdef DEBUG_VIA_USB
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void receive_can_battery(CAN_frame_t rx_frame) {
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
switch (rx_frame.MsgID) {
|
||||
case 0x171: //Following messages were detected on a MG5 battery BMS
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; // Let system know battery is sending CAN
|
||||
break;
|
||||
case 0x172:
|
||||
break;
|
||||
case 0x173:
|
||||
break;
|
||||
case 0x293:
|
||||
break;
|
||||
case 0x295:
|
||||
break;
|
||||
case 0x297:
|
||||
break;
|
||||
case 0x29B:
|
||||
break;
|
||||
case 0x29C:
|
||||
break;
|
||||
case 0x2A0:
|
||||
break;
|
||||
case 0x2A2:
|
||||
break;
|
||||
case 0x322:
|
||||
break;
|
||||
case 0x334:
|
||||
break;
|
||||
case 0x33F:
|
||||
break;
|
||||
case 0x391:
|
||||
break;
|
||||
case 0x393:
|
||||
break;
|
||||
case 0x3AB:
|
||||
break;
|
||||
case 0x3AC:
|
||||
break;
|
||||
case 0x3B8:
|
||||
break;
|
||||
case 0x3BA:
|
||||
break;
|
||||
case 0x3BC:
|
||||
break;
|
||||
case 0x3BE:
|
||||
break;
|
||||
case 0x3C0:
|
||||
break;
|
||||
case 0x3C2:
|
||||
break;
|
||||
case 0x400:
|
||||
break;
|
||||
case 0x402:
|
||||
break;
|
||||
case 0x418:
|
||||
break;
|
||||
case 0x44C:
|
||||
break;
|
||||
case 0x620:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
void send_can_battery() {
|
||||
unsigned long currentMillis = millis();
|
||||
//Send 10ms message
|
||||
if (currentMillis - previousMillis10 >= INTERVAL_10_MS) {
|
||||
// Check if sending of CAN messages has been delayed too much.
|
||||
if ((currentMillis - previousMillis10 >= INTERVAL_10_MS_DELAYED) && (currentMillis > BOOTUP_TIME)) {
|
||||
set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis10));
|
||||
}
|
||||
previousMillis10 = currentMillis;
|
||||
|
||||
ESP32Can.CANWriteFrame(&MG_5_100);
|
||||
}
|
||||
// Send 100ms CAN Message
|
||||
if (currentMillis - previousMillis100 >= INTERVAL_100_MS) {
|
||||
previousMillis100 = currentMillis;
|
||||
|
||||
//ESP32Can.CANWriteFrame(&MG_5_100);
|
||||
}
|
||||
}
|
||||
|
||||
void setup_battery(void) { // Performs one time setup at startup
|
||||
#ifdef DEBUG_VIA_USB
|
||||
Serial.println("MG 5 battery selected");
|
||||
#endif
|
||||
|
||||
datalayer.battery.info.max_design_voltage_dV = 4040; // Over this charging is not possible
|
||||
datalayer.battery.info.min_design_voltage_dV = 3100; // Under this discharging is disabled
|
||||
}
|
||||
|
||||
#endif
|
12
Software/src/battery/MG-5-BATTERY.h
Normal file
12
Software/src/battery/MG-5-BATTERY.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef MG_5_BATTERY_H
|
||||
#define MG_5_BATTERY_H
|
||||
#include <Arduino.h>
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define BATTERY_SELECTED
|
||||
#define MAX_CELL_DEVIATION_MV 150
|
||||
|
||||
void setup_battery(void);
|
||||
|
||||
#endif
|
|
@ -448,8 +448,8 @@ String processor(const String& var) {
|
|||
#ifdef KIA_E_GMP_BATTERY
|
||||
content += "Kia/Hyundai EGMP platform";
|
||||
#endif
|
||||
#ifdef NISSAN_LEAF_BATTERY
|
||||
content += "Nissan LEAF";
|
||||
#ifdef MG_5_BATTERY
|
||||
content += "MG 5";
|
||||
#endif
|
||||
#ifdef RENAULT_KANGOO_BATTERY
|
||||
content += "Renault Kangoo";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue