mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 18:29:48 +02:00
Add event for all battery types, can overrun
This commit is contained in:
parent
0c62bf16df
commit
d0efc4f3fc
9 changed files with 79 additions and 42 deletions
|
@ -14,14 +14,15 @@ static unsigned long previousMillis640 = 0; // will store last time a 600ms C
|
|||
static unsigned long previousMillis1000 = 0; // will store last time a 1000ms CAN Message was send
|
||||
static unsigned long previousMillis5000 = 0; // will store last time a 5000ms CAN Message was send
|
||||
static unsigned long previousMillis10000 = 0; // will store last time a 10000ms CAN Message was send
|
||||
static const int interval20 = 20; // interval (ms) at which send CAN Messages
|
||||
static const int interval100 = 100; // interval (ms) at which send CAN Messages
|
||||
static const int interval200 = 200; // interval (ms) at which send CAN Messages
|
||||
static const int interval500 = 500; // interval (ms) at which send CAN Messages
|
||||
static const int interval640 = 640; // interval (ms) at which send CAN Messages
|
||||
static const int interval1000 = 1000; // interval (ms) at which send CAN Messages
|
||||
static const int interval5000 = 5000; // interval (ms) at which send CAN Messages
|
||||
static const int interval10000 = 10000; // interval (ms) at which send CAN Messages
|
||||
static const uint8_t interval20 = 20; // interval (ms) at which send CAN Messages
|
||||
static const uint8_t interval100 = 100; // interval (ms) at which send CAN Messages
|
||||
static const uint8_t interval200 = 200; // interval (ms) at which send CAN Messages
|
||||
static const uint16_t interval500 = 500; // interval (ms) at which send CAN Messages
|
||||
static const uint16_t interval640 = 640; // interval (ms) at which send CAN Messages
|
||||
static const uint16_t interval1000 = 1000; // interval (ms) at which send CAN Messages
|
||||
static const uint16_t interval5000 = 5000; // interval (ms) at which send CAN Messages
|
||||
static const uint16_t interval10000 = 10000; // interval (ms) at which send CAN Messages
|
||||
static const uint8_t interval20overrun = 30; // interval (ms) at when a 20ms CAN send is considered delayed
|
||||
static uint8_t CANstillAlive = 12; // counter for checking if CAN is still alive
|
||||
static uint16_t CANerror = 0; // counter on how many CAN errors encountered
|
||||
#define MAX_CAN_FAILURES 500 // Amount of malformed CAN messages to allow before raising a warning
|
||||
|
@ -562,9 +563,9 @@ void send_can_battery() {
|
|||
if (battery_awake) {
|
||||
//Send 20ms message
|
||||
if (currentMillis - previousMillis20 >= interval20) {
|
||||
|
||||
if (currentMillis - previousMillis20 >= interval20 + 10) {
|
||||
set_event(EVENT_CAN_OVERRUN, interval20);
|
||||
// Check if sending of CAN messages has been delayed too much.
|
||||
if ((currentMillis - previousMillis20 >= interval20overrun) && (currentMillis > 1000)) {
|
||||
set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis20));
|
||||
}
|
||||
previousMillis20 = currentMillis;
|
||||
|
||||
|
|
|
@ -6,11 +6,12 @@
|
|||
#include "CHADEMO-BATTERY.h"
|
||||
|
||||
/* Do not change code below unless you are sure what you are doing */
|
||||
static unsigned long previousMillis100 = 0; // will store last time a 100ms CAN Message was send
|
||||
static const int interval100 = 100; // interval (ms) at which send CAN Messages
|
||||
const int rx_queue_size = 10; // Receive Queue size
|
||||
static uint8_t CANstillAlive = 12; //counter for checking if CAN is still alive
|
||||
static uint8_t errorCode = 0; //stores if we have an error code active from battery control logic
|
||||
static unsigned long previousMillis100 = 0; // will store last time a 100ms CAN Message was send
|
||||
static const uint8_t interval100 = 100; // interval (ms) at which send CAN Messages
|
||||
static const uint8_t interval100overrun = 120; // interval (ms) at when a 100ms CAN send is considered delayed
|
||||
const int rx_queue_size = 10; // Receive Queue size
|
||||
static uint8_t CANstillAlive = 12; //counter for checking if CAN is still alive
|
||||
static uint8_t errorCode = 0; //stores if we have an error code active from battery control logic
|
||||
|
||||
CAN_frame_t CHADEMO_108 = {.FIR = {.B =
|
||||
{
|
||||
|
@ -195,6 +196,10 @@ void send_can_battery() {
|
|||
unsigned long currentMillis = millis();
|
||||
// Send 100ms CAN Message
|
||||
if (currentMillis - previousMillis100 >= interval100) {
|
||||
// Check if sending of CAN messages has been delayed too much.
|
||||
if ((currentMillis - previousMillis100 >= interval100overrun) && (currentMillis > 1000)) {
|
||||
set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis100));
|
||||
}
|
||||
previousMillis100 = currentMillis;
|
||||
|
||||
ESP32Can.CANWriteFrame(&CHADEMO_108);
|
||||
|
|
|
@ -14,10 +14,10 @@ static uint8_t errorCode = 0; //stores if we have an error code active fro
|
|||
static uint8_t BMU_Detected = 0;
|
||||
static uint8_t CMU_Detected = 0;
|
||||
|
||||
static unsigned long previousMillis10 = 0; // will store last time a 10ms CAN Message was sent
|
||||
static unsigned long previousMillis100 = 0; // will store last time a 100ms CAN Message was sent
|
||||
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 unsigned long previousMillis10 = 0; // will store last time a 10ms CAN Message was sent
|
||||
static unsigned long previousMillis100 = 0; // will store last time a 100ms CAN Message was sent
|
||||
static const uint8_t interval100 = 100; // interval (ms) at which send CAN Messages
|
||||
static const uint8_t interval100overrun = 120; // interval (ms) at when a 100ms CAN send is considered delayed
|
||||
|
||||
static int pid_index = 0;
|
||||
static int cmu_id = 0;
|
||||
|
@ -228,7 +228,13 @@ void send_can_battery() {
|
|||
unsigned long currentMillis = millis();
|
||||
// Send 100ms CAN Message
|
||||
if (currentMillis - previousMillis100 >= interval100) {
|
||||
// Check if sending of CAN messages has been delayed too much.
|
||||
if ((currentMillis - previousMillis100 >= interval100overrun) && (currentMillis > 1000)) {
|
||||
set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis100));
|
||||
}
|
||||
previousMillis100 = currentMillis;
|
||||
|
||||
// Send CAN goes here...
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,8 +8,9 @@
|
|||
/* Do not change code below unless you are sure what you are doing */
|
||||
static unsigned long previousMillis100 = 0; // will store last time a 100ms CAN Message was send
|
||||
static unsigned long previousMillis10ms = 0; // will store last time a 10s CAN Message was send
|
||||
static const int interval100 = 100; // interval (ms) at which send CAN Messages
|
||||
static const int interval10ms = 10; // interval (ms) at which send CAN Messages
|
||||
static const uint8_t interval100 = 100; // interval (ms) at which send CAN Messages
|
||||
static const uint8_t interval10ms = 10; // interval (ms) at which send CAN Messages
|
||||
static const uint8_t interval10overrun = 15; // interval (ms) at when a 10ms CAN send is considered delayed
|
||||
static uint8_t CANstillAlive = 12; //counter for checking if CAN is still alive
|
||||
|
||||
#define MAX_CELL_VOLTAGE 4250 //Battery is put into emergency stop if one cell goes over this value
|
||||
|
@ -541,7 +542,11 @@ void send_can_battery() {
|
|||
}
|
||||
// Send 10ms CAN Message
|
||||
if (currentMillis - previousMillis10ms >= interval10ms) {
|
||||
previousMillis10ms = currentMillis;
|
||||
// Check if sending of CAN messages has been delayed too much.
|
||||
if ((currentMillis - previousMillis10 >= interval10overrun) && (currentMillis > 1000)) {
|
||||
set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis10));
|
||||
}
|
||||
previousMillis10 = currentMillis;
|
||||
|
||||
switch (counter_200) {
|
||||
case 0:
|
||||
|
|
|
@ -709,9 +709,9 @@ void send_can_battery() {
|
|||
}
|
||||
//Send 10ms message
|
||||
if (currentMillis - previousMillis10 >= interval10) {
|
||||
|
||||
if (currentMillis - previousMillis10 >= interval10overrun) {
|
||||
set_event(EVENT_CAN_OVERRUN, interval10);
|
||||
// Check if sending of CAN messages has been delayed too much.
|
||||
if ((currentMillis - previousMillis10 >= interval10overrun) && (currentMillis > 1000)) {
|
||||
set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis10));
|
||||
}
|
||||
previousMillis10 = currentMillis;
|
||||
|
||||
|
|
|
@ -36,9 +36,9 @@ static unsigned long previousMillis10 = 0; // will store last time a 10ms CAN
|
|||
static unsigned long previousMillis100 = 0; // will store last time a 100ms CAN Message was sent
|
||||
static unsigned long previousMillis1000 = 0; // will store last time a 1000ms CAN Message was sent
|
||||
static unsigned long GVL_pause = 0;
|
||||
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 const int interval1000 = 1000; // interval (ms) at which send CAN Messages
|
||||
static const uint8_t interval100 = 100; // interval (ms) at which send CAN Messages
|
||||
static const uint8_t interval1000 = 1000; // interval (ms) at which send CAN Messages
|
||||
static const uint8_t interval100overrun = 120; // interval (ms) at when a 100ms CAN send is considered delayed
|
||||
|
||||
void update_values_battery() { //This function maps all the values fetched via CAN to the correct parameters used for modbus
|
||||
system_SOH_pptt = (LB_SOH * 100); //Increase range from 99% -> 99.00%
|
||||
|
@ -142,6 +142,10 @@ void send_can_battery() {
|
|||
unsigned long currentMillis = millis();
|
||||
// Send 100ms CAN Message
|
||||
if (currentMillis - previousMillis100 >= interval100) {
|
||||
// Check if sending of CAN messages has been delayed too much.
|
||||
if ((currentMillis - previousMillis100 >= interval100overrun) && (currentMillis > 1000)) {
|
||||
set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis100));
|
||||
}
|
||||
previousMillis100 = currentMillis;
|
||||
//ESP32Can.CANWriteFrame(&ZOE_423);
|
||||
}
|
||||
|
|
|
@ -15,11 +15,12 @@ TODO: Map all values from battery CAN messages
|
|||
*/
|
||||
|
||||
/* 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
|
||||
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 const uint8_t interval10overrun = 15; // interval (ms) at when a 10ms CAN send is considered delayed
|
||||
static uint8_t CANstillAlive = 12; //counter for checking if CAN is still alive
|
||||
|
||||
static int SOC_1 = 0;
|
||||
static int SOC_2 = 0;
|
||||
|
@ -130,6 +131,10 @@ void send_can_battery() {
|
|||
unsigned long currentMillis = millis();
|
||||
//Send 10ms message
|
||||
if (currentMillis - previousMillis10 >= interval10) {
|
||||
// Check if sending of CAN messages has been delayed too much.
|
||||
if ((currentMillis - previousMillis10 >= interval10overrun) && (currentMillis > 1000)) {
|
||||
set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis10));
|
||||
}
|
||||
previousMillis10 = currentMillis;
|
||||
|
||||
SANTAFE_200.data.u8[6] = (counter_200 << 1);
|
||||
|
|
|
@ -8,9 +8,10 @@
|
|||
/* Do not change code below unless you are sure what you are doing */
|
||||
/* Credits: Most of the code comes from Per Carlen's bms_comms_tesla_model3.py (https://gitlab.com/pelle8/batt2gen24/) */
|
||||
|
||||
static unsigned long previousMillis30 = 0; // will store last time a 30ms CAN Message was send
|
||||
static const int interval30 = 30; // interval (ms) at which send CAN Messages
|
||||
static uint8_t stillAliveCAN = 6; //counter for checking if CAN is still alive
|
||||
static unsigned long previousMillis30 = 0; // will store last time a 30ms CAN Message was send
|
||||
static const uint8_t interval30 = 30; // interval (ms) at which send CAN Messages
|
||||
static const uint8_t interval30overrun = 40; // interval (ms) at which a 30ms CAN message is considered overrun
|
||||
static uint8_t stillAliveCAN = 6; //counter for checking if CAN is still alive
|
||||
|
||||
CAN_frame_t TESLA_221_1 = {
|
||||
.FIR = {.B =
|
||||
|
@ -585,6 +586,10 @@ the first, for a few cycles, then stop all messages which causes the contactor
|
|||
unsigned long currentMillis = millis();
|
||||
//Send 30ms message
|
||||
if (currentMillis - previousMillis30 >= interval30) {
|
||||
// Check if sending of CAN messages has been delayed too much.
|
||||
if ((currentMillis - previousMillis30 >= interval30overrun) && (currentMillis > 1000)) {
|
||||
set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis30));
|
||||
}
|
||||
previousMillis30 = currentMillis;
|
||||
|
||||
if (inverterAllowsContactorClosing == 1) {
|
||||
|
|
|
@ -5,11 +5,12 @@
|
|||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
/* Do not change code below unless you are sure what you are doing */
|
||||
static unsigned long previousMillis100 = 0; // will store last time a 100ms CAN Message was send
|
||||
static unsigned long previousMillis60s = 0; // will store last time a 60s CAN Message was send
|
||||
static const int interval100 = 100; // interval (ms) at which send CAN Messages
|
||||
static const int interval60s = 60000; // interval (ms) at which send CAN Messages
|
||||
static uint8_t CANstillAlive = 12; //counter for checking if CAN is still alive
|
||||
static unsigned long previousMillis100 = 0; // will store last time a 100ms CAN Message was send
|
||||
static unsigned long previousMillis60s = 0; // will store last time a 60s CAN Message was send
|
||||
static const uint8_t interval100 = 100; // interval (ms) at which send CAN Messages
|
||||
static const uint8_t interval100overrun = 120; // interval (ms) at when a 100ms CAN send is considered delayed
|
||||
static const uint16_t interval60s = 60000; // interval (ms) at which send CAN Messages
|
||||
static uint8_t CANstillAlive = 12; //counter for checking if CAN is still alive
|
||||
|
||||
#define MAX_CELL_VOLTAGE 4210 //Battery is put into emergency stop if one cell goes over this value
|
||||
#define MIN_CELL_VOLTAGE 2700 //Battery is put into emergency stop if one cell goes below this value
|
||||
|
@ -360,7 +361,12 @@ void send_can_battery() {
|
|||
unsigned long currentMillis = millis();
|
||||
// Send 100ms CAN Message
|
||||
if (currentMillis - previousMillis100 >= interval100) {
|
||||
// Check if sending of CAN messages has been delayed too much.
|
||||
if ((currentMillis - previousMillis100 >= interval100overrun) && (currentMillis > 1000)) {
|
||||
set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis100));
|
||||
}
|
||||
previousMillis100 = currentMillis;
|
||||
|
||||
ESP32Can.CANWriteFrame(&VOLVO_536); //Send 0x536 Network managing frame to keep BMS alive
|
||||
ESP32Can.CANWriteFrame(&VOLVO_372); //Send 0x372 ECMAmbientTempCalculated
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue