mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 18:29:48 +02:00
Add initial Santa Fe struct
This commit is contained in:
parent
3a6a36b24e
commit
cf77f4676b
6 changed files with 216 additions and 0 deletions
|
@ -29,6 +29,10 @@
|
|||
#include "RENAULT-ZOE-BATTERY.h" //See this file for more Zoe battery settings
|
||||
#endif
|
||||
|
||||
#ifdef SANTA_FE_PHEV_BATTERY
|
||||
#include "SANTA-FE-PHEV-BATTERY.h" //See this file for more Santa Fe PHEV battery settings
|
||||
#endif
|
||||
|
||||
#ifdef TESLA_MODEL_3_BATTERY
|
||||
#include "TESLA-MODEL-3-BATTERY.h" //See this file for more Tesla battery settings
|
||||
#endif
|
||||
|
|
164
Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp
Normal file
164
Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp
Normal file
|
@ -0,0 +1,164 @@
|
|||
#include "SANTA-FE-PHEV-BATTERY.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
/* Credits go to maciek16c for these findings!
|
||||
https://github.com/maciek16c/hyundai-santa-fe-phev-battery
|
||||
https://openinverter.org/forum/viewtopic.php?p=62256
|
||||
*/
|
||||
|
||||
/* 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 SOC_1 = 0;
|
||||
static int SOC_2 = 0;
|
||||
static int SOC_3 = 0;
|
||||
|
||||
CAN_frame_t SANTAFE_200 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x200,
|
||||
.data = {0x00, 0x00, 0x00, 0x00, 0x80, 0x30, 0x00, 0x00}};
|
||||
CAN_frame_t SANTAFE_2A1 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x2A1,
|
||||
.data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x02}};
|
||||
CAN_frame_t SANTAFE_2F0 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x2F0,
|
||||
.data = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00}};
|
||||
CAN_frame_t SANTAFE_523 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x523,
|
||||
.data = {0x60, 0x00, 0x60, 0, 0, 0, 0, 0}};
|
||||
|
||||
void update_values_santafe_phev_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--;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_VIA_USB
|
||||
Serial.print("SOC% candidate 1: ");
|
||||
Serial.println(SOC_1);
|
||||
Serial.print("SOC% candidate 2: ");
|
||||
Serial.println(SOC_2);
|
||||
Serial.print("SOC% candidate 3: ");
|
||||
Serial.println(SOC_3);
|
||||
#endif
|
||||
}
|
||||
|
||||
void receive_can_santafe_phev_battery(CAN_frame_t rx_frame) {
|
||||
CANstillAlive = 12;
|
||||
switch (rx_frame.MsgID) {
|
||||
case 0x200:
|
||||
break;
|
||||
case 0x201:
|
||||
break;
|
||||
case 0x202:
|
||||
break;
|
||||
case 0x203:
|
||||
break;
|
||||
case 0x2A0:
|
||||
break;
|
||||
case 0x2A1:
|
||||
break;
|
||||
case 0x2A2:
|
||||
break;
|
||||
case 0x2B0:
|
||||
break;
|
||||
case 0x2B5:
|
||||
break;
|
||||
case 0x2F0:
|
||||
break;
|
||||
case 0x2F1:
|
||||
break;
|
||||
case 0x523:
|
||||
break;
|
||||
case 0x524:
|
||||
break;
|
||||
case 0x620:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
void send_can_santafe_phev_battery() {
|
||||
unsigned long currentMillis = millis();
|
||||
//Send 10ms message
|
||||
if (currentMillis - previousMillis10 >= interval10) {
|
||||
previousMillis10 = currentMillis;
|
||||
|
||||
ESP32Can.CANWriteFrame(&SANTAFE_200);
|
||||
|
||||
ESP32Can.CANWriteFrame(&SANTAFE_2A1);
|
||||
|
||||
ESP32Can.CANWriteFrame(&SANTAFE_2F0);
|
||||
}
|
||||
// Send 100ms CAN Message
|
||||
if (currentMillis - previousMillis100 >= interval100) {
|
||||
previousMillis100 = currentMillis;
|
||||
|
||||
ESP32Can.CANWriteFrame(&SANTAFE_523);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t CalculateCRC8(CAN_frame_t rx_frame) {
|
||||
uint8_t crc = 0;
|
||||
|
||||
for (int framepos = 0; framepos < 8; framepos++) {
|
||||
crc ^= rx_frame.data[framepos];
|
||||
|
||||
for (int j = 0; j < 8; j++) {
|
||||
if ((crc & 0x80) != 0) {
|
||||
crc = (crc << 1) ^ 0x1;
|
||||
} else {
|
||||
crc <<= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
34
Software/src/battery/SANTA-FE-PHEV-BATTERY.h
Normal file
34
Software/src/battery/SANTA-FE-PHEV-BATTERY.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
#ifndef SANTA_FE_PHEV_BATTERY_H
|
||||
#define SANTA_FE_PHEV_BATTERY_H
|
||||
#include <Arduino.h>
|
||||
#include "../../USER_SETTINGS.h"
|
||||
#include "../devboard/config.h" // Needed for all defines
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define ABSOLUTE_MAX_VOLTAGE \
|
||||
4030 // 403.0V,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
|
||||
|
||||
// These parameters need to be mapped for the Gen24
|
||||
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 uint8_t bms_status;
|
||||
extern uint8_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 bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false
|
||||
extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false
|
||||
|
||||
void update_values_santafe_phev_battery();
|
||||
void receive_can_santafe_phev_battery(CAN_frame_t rx_frame);
|
||||
void send_can_santafe_phev_battery();
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue