Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MEB max 1A issue / Add automatic precharge / Add basic OBD functionality #791

Merged
merged 42 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e35be65
Fix issue with % in log output conflicting with templating character
mvgalen Jan 2, 2025
4ec273e
Change pct to %.
mvgalen Jan 2, 2025
7f62d70
Revert "Fix crash caused by percentage char"
mvgalen Jan 2, 2025
4b19db2
Revert "Remove percentage sign from logging"
mvgalen Jan 2, 2025
dccfca1
Add Automatic Precharge Control for modified HIA4V1 boards
mvgalen Dec 21, 2024
f6c73e9
Change default state of bms_Status to INACTIVE and only switch to ACT…
mvgalen Dec 21, 2024
7d431f6
Improve handling of bms_status for DOUBLE_BATTERY
mvgalen Dec 21, 2024
cc4229f
Remove unused ifdef blocks, remove unwanted change.
mvgalen Dec 22, 2024
0512d02
Fix bugs in printf logging code & add version to log
mvgalen Jan 3, 2025
af296ac
Move logging of version/data/time to setup()
mvgalen Jan 4, 2025
76695da
Fix code formatting.
mvgalen Jan 4, 2025
21031bf
Add DTC request every second.
mvgalen Jan 6, 2025
5568617
Add dump_frame to log function
mvgalen Jan 6, 2025
8dfbee5
Add CAN include.
mvgalen Jan 6, 2025
ce949b2
Fix extended addressing mode of DTC msg. Add missing break.
mvgalen Jan 6, 2025
7b69f9e
Addition of transmit_obd_can_frame and handle_obd_frame functions
mvgalen Jan 11, 2025
7a52024
Use refactored obd functions.
mvgalen Jan 11, 2025
f9132df
Disable precharge bit if not precharging.
mvgalen Jan 13, 2025
5854fc2
Fix code formatting
mvgalen Jan 13, 2025
a637db8
Fix battery current calculation.
mvgalen Jan 13, 2025
eefa972
Limit risk of array overruns.
mvgalen Jan 13, 2025
0c2aa47
Fix code formatting
mvgalen Jan 13, 2025
673c400
Only set values when msg not in init state.
mvgalen Jan 13, 2025
74cb21e
Only switch to STANDBY if nof cells is clear
mvgalen Jan 13, 2025
5db3eaa
Log when unsupported checksum is requested.
mvgalen Jan 13, 2025
8e118a7
Fix code formatting
mvgalen Jan 13, 2025
a0c5e63
Some small improvements.
mvgalen Jan 14, 2025
437efe1
Code formatting fix.
mvgalen Jan 14, 2025
9ddf83c
Fix code formatting.
mvgalen Jan 14, 2025
d0418dc
Merge branch 'main' into feature/automatic-precharge
mvgalen Jan 14, 2025
fbd9fe6
Merge remote-tracking branch 'origin/main' into feature/automatic-pre…
mvgalen Jan 14, 2025
3f09989
Fix code formatting.
mvgalen Jan 14, 2025
4608d6a
Remove inadvertedly added BRS bit from CanFrame.
mvgalen Jan 14, 2025
28351f8
Remove inadvertedly added BRS check from comm_can
mvgalen Jan 14, 2025
57fbe69
Do not set CAN_STILL_ALIVE from reset_all_events
mvgalen Jan 14, 2025
753b506
Revert "Change default state of bms_Status to INACTIVE and only switc…
mvgalen Jan 14, 2025
9410b87
Changes due to review comments
mvgalen Jan 14, 2025
d5228ef
Revert bms_status printing.
mvgalen Jan 14, 2025
40fbdc5
Fix code formatting.
mvgalen Jan 14, 2025
1c8f241
Fix inadvertedly removed bracket.
mvgalen Jan 14, 2025
a592066
Remove #define PRECHARGE_CONTROL & move dump_can_frame within #ifdef …
mvgalen Jan 14, 2025
1dcc6fe
Fix code formatting.
mvgalen Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Software/Software.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "src/communication/contactorcontrol/comm_contactorcontrol.h"
#include "src/communication/equipmentstopbutton/comm_equipmentstopbutton.h"
#include "src/communication/nvm/comm_nvm.h"
#include "src/communication/precharge_control/precharge_control.h"
#include "src/communication/rs485/comm_rs485.h"
#include "src/communication/seriallink/comm_seriallink.h"
#include "src/datalayer/datalayer.h"
Expand Down Expand Up @@ -120,6 +121,10 @@ void setup() {

init_contactors();

#ifdef PRECHARGE_CONTROL
init_precharge_control();
#endif // PRECHARGE_CONTROL

init_rs485();

init_serialDataLink();
Expand Down Expand Up @@ -247,6 +252,9 @@ void core_loop(void* task_time_us) {
previousMillis10ms = millis();
led_exe();
handle_contactors(); // Take care of startup precharge/contactor closing
#ifdef PRECHARGE_CONTROL
handle_precharge_control();
#endif // PRECHARGE_CONTROL
}
END_TIME_MEASUREMENT_MAX(time_10ms, datalayer.system.status.time_10ms_us);

Expand Down Expand Up @@ -298,6 +306,30 @@ void core_loop(void* task_time_us) {
if (check_pause_2s.elapsed()) {
emulator_pause_state_transmit_can_battery();
}
static bms_status_enum previous_state = FAULT;
if (previous_state != datalayer.battery.status.bms_status) {
switch (datalayer.battery.status.bms_status) {
case ACTIVE:
logging.printf("BMS state changed to: OK\n");
mvgalen marked this conversation as resolved.
Show resolved Hide resolved
break;
case UPDATING:
logging.printf("BMS state changed to: UPDATING\n");
break;
case FAULT:
logging.printf("BMS state changed to: FAULT\n");
break;
case INACTIVE:
logging.printf("BMS state changed to: INACTIVE\n");
break;
case STANDBY:
logging.printf("BMS state changed to: STANDBY\n");
break;
default:
logging.printf("BMS state changed to: ??\n");
break;
}
previous_state = datalayer.battery.status.bms_status;
}

vTaskDelayUntil(&xLastWakeTime, xFrequency);
}
Expand Down
3 changes: 3 additions & 0 deletions Software/USER_SETTINGS.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
/* Shunt/Contactor settings */
//#define BMW_SBOX // SBOX relay control & battery current/voltage measurement

/* Automatic Precharge settings. If you have a battery that expects an external voltage applied before opening contactors (within the battery), configure this section */
//#define PRECHARGE_CONTROL //Enable this line to control a modified HIA4V1 (see wiki) by PWM on the PRECHARGE_PIN.

/* Other options */
//#define LOG_TO_SD //Enable this line to log diagnostic data to SD card
//#define DEBUG_VIA_USB //Enable this line to have the USB port output serial diagnostic data while program runs (WARNING, raises CPU load, do not use for production)
Expand Down
4 changes: 4 additions & 0 deletions Software/src/battery/BMW-I3-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ void handle_incoming_can_frame_battery(CAN_frame rx_frame) {
battery_request_open_contactors_fast = (rx_frame.data.u8[6] & 0x0C) >> 2;
battery_charging_condition_delta = (rx_frame.data.u8[6] & 0xF0) >> 4;
battery_DC_link_voltage = rx_frame.data.u8[7];
if (datalayer.battery.status.bms_status == INACTIVE)
mvgalen marked this conversation as resolved.
Show resolved Hide resolved
datalayer.battery.status.bms_status = ACTIVE;
break;
case 0x1FA: //BMS [1000ms] Status Of High-Voltage Battery - 1
battery_status_error_isolation_external_Bordnetz = (rx_frame.data.u8[0] & 0x03);
Expand Down Expand Up @@ -711,6 +713,8 @@ void handle_incoming_can_frame_battery2(CAN_frame rx_frame) {
battery2_request_open_contactors_fast = (rx_frame.data.u8[6] & 0x0C) >> 2;
battery2_charging_condition_delta = (rx_frame.data.u8[6] & 0xF0) >> 4;
battery2_DC_link_voltage = rx_frame.data.u8[7];
if (datalayer.battery2.status.bms_status == INACTIVE)
datalayer.battery2.status.bms_status = ACTIVE;
break;
case 0x1FA: //BMS [1000ms] Status Of High-Voltage Battery - 1
battery2_status_error_isolation_external_Bordnetz = (rx_frame.data.u8[0] & 0x03);
Expand Down
2 changes: 2 additions & 0 deletions Software/src/battery/BMW-IX-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ void handle_incoming_can_frame_battery(CAN_frame rx_frame) {
min_soc_state = (rx_frame.data.u8[8] << 8 | rx_frame.data.u8[9]);
avg_soc_state = (rx_frame.data.u8[6] << 8 | rx_frame.data.u8[7]);
max_soc_state = (rx_frame.data.u8[10] << 8 | rx_frame.data.u8[11]);
if (datalayer.battery.status.bms_status == INACTIVE)
datalayer.battery.status.bms_status = ACTIVE;
}

if (rx_frame.DLC =
Expand Down
4 changes: 4 additions & 0 deletions Software/src/battery/BYD-ATTO-3-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ void handle_incoming_can_frame_battery(CAN_frame rx_frame) {
battery_highprecision_SOC = ((rx_frame.data.u8[5] & 0x0F) << 8) | rx_frame.data.u8[4]; // 03 E0 = 992 = 99.2%
battery_lowest_temperature = (rx_frame.data.u8[1] - 40); //Best guess for now
battery_highest_temperature = (rx_frame.data.u8[3] - 40); //Best guess for now
if (datalayer.battery.status.bms_status == INACTIVE)
datalayer.battery.status.bms_status = ACTIVE;
break;
case 0x47B: //01,FF,FF,FF,FF,FF,FF,FF - Static, values never changes between logs
break;
Expand Down Expand Up @@ -564,6 +566,8 @@ void handle_incoming_can_frame_battery2(CAN_frame rx_frame) {
battery2_highprecision_SOC = ((rx_frame.data.u8[5] & 0x0F) << 8) | rx_frame.data.u8[4]; // 03 E0 = 992 = 99.2%
battery2_lowest_temperature = (rx_frame.data.u8[1] - 40); //Best guess for now
battery2_highest_temperature = (rx_frame.data.u8[3] - 40); //Best guess for now
if (datalayer.battery2.status.bms_status == INACTIVE)
datalayer.battery2.status.bms_status = ACTIVE;
break;
case 0x47B: //01,FF,FF,FF,FF,FF,FF,FF - Static, values never changes between logs
break;
Expand Down
2 changes: 2 additions & 0 deletions Software/src/battery/CELLPOWER-BMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ void handle_incoming_can_frame_battery(CAN_frame rx_frame) {
battery_SOH_percentage = (uint8_t)rx_frame.data.u8[4];
battery_SOC_percentage = (uint8_t)rx_frame.data.u8[5];
battery_remaining_dAh = (uint16_t)((rx_frame.data.u8[7] << 8) | rx_frame.data.u8[6]);
if (datalayer.battery.status.bms_status == INACTIVE)
datalayer.battery.status.bms_status = ACTIVE;
break;
case 0x3A4: //PDO3_TX - 200ms
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
Expand Down
2 changes: 2 additions & 0 deletions Software/src/battery/CHADEMO-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ void handle_incoming_can_frame_battery(CAN_frame rx_frame) {

datalayer.battery.status.CAN_battery_still_alive =
CAN_STILL_ALIVE; //We are getting CAN messages from the vehicle, inform the watchdog
if (datalayer.battery.status.bms_status == INACTIVE)
datalayer.battery.status.bms_status = ACTIVE;

switch (rx_frame.ID) {
case 0x100:
Expand Down
2 changes: 2 additions & 0 deletions Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ void handle_incoming_can_frame_battery(CAN_frame rx_frame) {
BMU_Current = ((((((rx_frame.data.u8[2] * 256.0) + rx_frame.data.u8[3])) - 32768)) * 0.01);
BMU_PackVoltage = ((rx_frame.data.u8[4] * 256.0 + rx_frame.data.u8[5]) * 0.1);
BMU_Power = (BMU_Current * BMU_PackVoltage);
if (datalayer.battery.status.bms_status == INACTIVE)
datalayer.battery.status.bms_status = ACTIVE;
break;
case 0x6e1: //BMU message, 25ms - Battery temperatures and voltages
case 0x6e2:
Expand Down
2 changes: 2 additions & 0 deletions Software/src/battery/JAGUAR-IPACE-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ void handle_incoming_can_frame_battery(CAN_frame rx_frame) {
HVBatteryContactorStatus = ((rx_frame.data.u8[0] & 0x80) >> 7);
HVBattHVILError = ((rx_frame.data.u8[0] & 0x40) >> 6);
HVILBattIsolationError = ((rx_frame.data.u8[0] & 0x20) >> 5);
if (datalayer.battery.status.bms_status == INACTIVE)
datalayer.battery.status.bms_status = ACTIVE;
break;
case 0x100:
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
Expand Down
2 changes: 2 additions & 0 deletions Software/src/battery/KIA-E-GMP-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,8 @@ void handle_incoming_can_frame_battery(CAN_frame rx_frame) {
allowedDischargePower = ((rx_frame.data.u8[5] << 8) + rx_frame.data.u8[6]);
SOC_BMS = rx_frame.data.u8[2] * 5; //100% = 200 ( 200 * 5 = 1000 )

if (datalayer.battery.status.bms_status == INACTIVE)
datalayer.battery.status.bms_status = ACTIVE;
} else if (poll_data_pid == 2) {
// set cell voltages data, start bite, data length from start, start cell
set_cell_voltages(rx_frame, 2, 6, 0);
Expand Down
2 changes: 2 additions & 0 deletions Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ void handle_incoming_can_frame_battery(CAN_frame rx_frame) {
startedUp = true;
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
SOC_Display = rx_frame.data.u8[0] * 5; //100% = 200 ( 200 * 5 = 1000 )
if (datalayer.battery.status.bms_status == INACTIVE)
datalayer.battery.status.bms_status = ACTIVE;
break;
case 0x594:
startedUp = true;
Expand Down
2 changes: 2 additions & 0 deletions Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ void handle_incoming_can_frame_battery(CAN_frame rx_frame) {
available_charge_power = ((rx_frame.data.u8[2] << 8) | rx_frame.data.u8[3]);
available_discharge_power = ((rx_frame.data.u8[4] << 8) | rx_frame.data.u8[5]);
battery_current_high_byte = rx_frame.data.u8[7];
if (datalayer.battery.status.bms_status == INACTIVE)
datalayer.battery.status.bms_status = ACTIVE;
} else if (poll_data_pid == 2) { //21 02
cellvoltages_mv[0] = (rx_frame.data.u8[2] * 20);
cellvoltages_mv[1] = (rx_frame.data.u8[3] * 20);
Expand Down
Loading
Loading