-
Notifications
You must be signed in to change notification settings - Fork 161
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
New feature: Test fake battery #94
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7767d39
Add fake battery skeleton
dalathegreat edf0329
Add RGB LED test
dalathegreat a2536e2
Uncomment test mode by default
dalathegreat cc2f2e9
Add FAKE_BATTERY to workflows
dalathegreat 2621e29
Refactor LED defines
dalathegreat d4290cc
Silly typo
dalathegreat 8dbf396
Merge branch 'main' into feature/test-mode
dalathegreat b2fc162
Run pre-commit formatting
dalathegreat b7af32a
Change uint8_t to bool
dalathegreat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include "TEST-FAKE-BATTERY.h" | ||
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" | ||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.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 unsigned long previousMillis10s = 0; // will store last time a 1s 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 int interval10s = 10000; // interval (ms) at which send CAN Messages | ||
|
||
void print_units(char* header, int value, char* units) { | ||
Serial.print(header); | ||
Serial.print(value); | ||
Serial.print(units); | ||
} | ||
|
||
void update_values_test_battery() { /* This function puts fake values onto the parameters sent towards the inverter */ | ||
bms_status = ACTIVE; //Always be in Active mode | ||
|
||
LEDcolor = TEST_ALL_COLORS; // Cycle the LED thru all available colors | ||
|
||
SOC = 5000; // 50.00% | ||
|
||
StateOfHealth = 9900; // 99.00% | ||
|
||
battery_voltage = 3700; // 370.0V | ||
|
||
battery_current = 0; // 0 A | ||
|
||
capacity_Wh = 30000; // 30kWh | ||
|
||
remaining_capacity_Wh = 15000; // 15kWh | ||
|
||
cell_max_voltage = 3750; | ||
|
||
cell_min_voltage = 3730; | ||
|
||
stat_batt_power = 0; // 0W | ||
|
||
temperature_min = 50; // 5.0*C | ||
|
||
temperature_max = 60; // 6.0*C | ||
|
||
max_target_discharge_power = 5000; // 5kW | ||
|
||
max_target_charge_power = 5000; // 5kW | ||
|
||
/*Finally print out values to serial if configured to do so*/ | ||
#ifdef DEBUG_VIA_USB | ||
Serial.println("FAKE Values going to inverter"); | ||
print_units("SOH%: ", (StateOfHealth * 0.01), "% "); | ||
print_units(", SOC%: ", (SOC * 0.01), "% "); | ||
print_units(", Voltage: ", (battery_voltage * 0.1), "V "); | ||
print_units(", Max discharge power: ", max_target_discharge_power, "W "); | ||
print_units(", Max charge power: ", max_target_charge_power, "W "); | ||
print_units(", Max temp: ", (temperature_max * 0.1), "°C "); | ||
print_units(", Min temp: ", (temperature_min * 0.1), "°C "); | ||
print_units(", Max cell voltage: ", cell_max_voltage, "mV "); | ||
print_units(", Min cell voltage: ", cell_min_voltage, "mV "); | ||
Serial.println(""); | ||
#endif | ||
} | ||
|
||
void receive_can_test_battery(CAN_frame_t rx_frame) { | ||
switch (rx_frame.MsgID) { | ||
case 0xABC: | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
void send_can_test_battery() { | ||
unsigned long currentMillis = millis(); | ||
// Send 100ms CAN Message | ||
if (currentMillis - previousMillis100 >= interval100) { | ||
previousMillis100 = currentMillis; | ||
// Put fake messages here incase you want to test sending CAN | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#ifndef TEST_FAKE_BATTERY_H | ||
#define TEST_FAKE_BATTERY_H | ||
#include <Arduino.h> | ||
#include "../../USER_SETTINGS.h" | ||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" | ||
|
||
#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 | ||
|
||
// These parameters need to be mapped for the inverter | ||
extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) | ||
extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) | ||
extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) | ||
extern uint16_t battery_current; //A+1, Goes thru convert2unsignedint16 function (5.0A = 50, -5.0A = 65485) | ||
extern uint16_t capacity_Wh; //Wh, 0-60000 | ||
extern uint16_t remaining_capacity_Wh; //Wh, 0-60000 | ||
extern uint16_t max_target_discharge_power; //W, 0-60000 | ||
extern uint16_t max_target_charge_power; //W, 0-60000 | ||
extern uint16_t bms_status; //Enum, 0-5 | ||
extern uint16_t bms_char_dis_status; //Enum, 0-2 | ||
extern uint16_t stat_batt_power; //W, Goes thru convert2unsignedint16 function (5W = 5, -5W = 65530) | ||
extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) | ||
extern uint16_t temperature_max; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) | ||
extern uint16_t cell_max_voltage; //mV, 0-4350 | ||
extern uint16_t cell_min_voltage; //mV, 0-4350 | ||
extern uint8_t batteryAllowsContactorClosing; //Bool, 1=true, 0=false | ||
extern uint8_t LEDcolor; //Enum, 0-2 | ||
// Definitions for bms_status | ||
#define STANDBY 0 | ||
#define INACTIVE 1 | ||
#define DARKSTART 2 | ||
#define ACTIVE 3 | ||
#define FAULT 4 | ||
#define UPDATING 5 | ||
// LED colors | ||
#define GREEN 0 | ||
#define YELLOW 1 | ||
#define RED 2 | ||
#define BLUE 3 | ||
#define TEST_ALL_COLORS 10 | ||
|
||
void update_values_test_battery(); | ||
void receive_can_test_battery(CAN_frame_t rx_frame); | ||
void send_can_test_battery(); | ||
|
||
#endif |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me it seems a bit strange that the led states are defined twice: once in Software.ino, and once in the battery file. Perhaps not blocking for this PR, but for the future it may be useful to define these states once in a separate header file, which can then be included by both Software.ino and the battery file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great suggestion, I refactored this and put it in a header in commit 2621e29 EDIT: and fixed a typo in d4290cc