mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 02:09:30 +02:00
Merge branch 'main' into feature/double-lilygo
This commit is contained in:
commit
44fa2ba3b0
8 changed files with 175 additions and 26 deletions
128
CODE_OF_CONDUCT.md
Normal file
128
CODE_OF_CONDUCT.md
Normal file
|
@ -0,0 +1,128 @@
|
|||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
We as members, contributors, and leaders pledge to make participation in our
|
||||
community a harassment-free experience for everyone, regardless of age, body
|
||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||
identity and expression, level of experience, education, socio-economic status,
|
||||
nationality, personal appearance, race, religion, or sexual identity
|
||||
and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||
diverse, inclusive, and healthy community.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our
|
||||
community include:
|
||||
|
||||
* Demonstrating empathy and kindness toward other people
|
||||
* Being respectful of differing opinions, viewpoints, and experiences
|
||||
* Giving and gracefully accepting constructive feedback
|
||||
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
* Focusing on what is best not just for us as individuals, but for the
|
||||
overall community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
* The use of sexualized language or imagery, and sexual attention or
|
||||
advances of any kind
|
||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or email
|
||||
address, without their explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of
|
||||
acceptable behavior and will take appropriate and fair corrective action in
|
||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||
or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||
decisions when appropriate.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when
|
||||
an individual is officially representing the community in public spaces.
|
||||
Examples of representing our community include using an official e-mail address,
|
||||
posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported to the community leaders responsible for enforcement at
|
||||
dalathegreat@gmail.com.
|
||||
All complaints will be reviewed and investigated promptly and fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the
|
||||
reporter of any incident.
|
||||
|
||||
## Enforcement Guidelines
|
||||
|
||||
Community leaders will follow these Community Impact Guidelines in determining
|
||||
the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||
unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing
|
||||
clarity around the nature of the violation and an explanation of why the
|
||||
behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series
|
||||
of actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No
|
||||
interaction with the people involved, including unsolicited interaction with
|
||||
those enforcing the Code of Conduct, for a specified period of time. This
|
||||
includes avoiding interactions in community spaces as well as external channels
|
||||
like social media. Violating these terms may lead to a temporary or
|
||||
permanent ban.
|
||||
|
||||
### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including
|
||||
sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public
|
||||
communication with the community for a specified period of time. No public or
|
||||
private interaction with the people involved, including unsolicited interaction
|
||||
with those enforcing the Code of Conduct, is allowed during this period.
|
||||
Violating these terms may lead to a permanent ban.
|
||||
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community
|
||||
standards, including sustained inappropriate behavior, harassment of an
|
||||
individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within
|
||||
the community.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 2.0, available at
|
||||
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
||||
|
||||
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
||||
enforcement ladder](https://github.com/mozilla/diversity).
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at
|
||||
https://www.contributor-covenant.org/faq. Translations are available at
|
||||
https://www.contributor-covenant.org/translations.
|
|
@ -50,12 +50,7 @@ This video explains all the above mentioned steps:
|
|||
https://youtu.be/_mH2AjnAjDk
|
||||
|
||||
## Dependencies 📖
|
||||
This code uses the following libraries, already located in the lib folder for an easy start:
|
||||
- ESP32-Arduino-CAN (https://github.com/miwagner/ESP32-Arduino-CAN/) slightly modified for this usecase
|
||||
- eModbus library (https://github.com/eModbus/eModbus)
|
||||
- Adafruit Neopixel (https://github.com/adafruit/Adafruit_NeoPixel)
|
||||
- mackelec SerialDataLink (https://github.com/mackelec/SerialDataLink)
|
||||
- pierremolinaro acan2515 (https://github.com/pierremolinaro/acan2515)
|
||||
This code uses two libraries, ESP32-Arduino-CAN (https://github.com/miwagner/ESP32-Arduino-CAN/) slightly modified for this usecase, and the eModbus library (https://github.com/eModbus/eModbus). Both these are already located in the Software folder for an easy start.
|
||||
|
||||
It is also based on the info found in the following excellent repositories/websites:
|
||||
- https://gitlab.com/pelle8/gen24
|
||||
|
|
|
@ -11,15 +11,12 @@
|
|||
#include "src/lib/eModbus-eModbus/Logging.h"
|
||||
#include "src/lib/eModbus-eModbus/ModbusServerRTU.h"
|
||||
#include "src/lib/eModbus-eModbus/scripts/mbServerFCs.h"
|
||||
#include "src/lib/mackelec-SerialDataLink/SerialDataLink.h"
|
||||
#include "src/lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
|
||||
#include "src/lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
// Interval settings
|
||||
int intervalUpdateValues = 4800; // Interval at which to update inverter values / Modbus registers
|
||||
const int interval1 = 1; // Interval for 1ms tasks
|
||||
const int interval10 = 10; // Interval for 10ms tasks
|
||||
unsigned long previousMillis1ms = 0;
|
||||
unsigned long previousMillis10ms = 50;
|
||||
unsigned long previousMillisUpdateVal = 0;
|
||||
|
||||
|
@ -131,9 +128,12 @@ void loop() {
|
|||
#ifdef DUAL_CAN
|
||||
receive_can2();
|
||||
#endif
|
||||
<<<<<<< HEAD
|
||||
#ifdef SERIAL_LINK_RECEIVER
|
||||
receive_serial();
|
||||
#endif
|
||||
=======
|
||||
>>>>>>> main
|
||||
|
||||
// Process
|
||||
if (millis() - previousMillis10ms >= interval10) // Every 10ms
|
||||
|
@ -156,9 +156,12 @@ void loop() {
|
|||
#ifdef DUAL_CAN
|
||||
send_can2();
|
||||
#endif
|
||||
<<<<<<< HEAD
|
||||
#ifdef SERIAL_LINK_TRANSMITTER
|
||||
send_serial();
|
||||
#endif
|
||||
=======
|
||||
>>>>>>> main
|
||||
}
|
||||
|
||||
// Initialization functions
|
||||
|
@ -226,6 +229,7 @@ void init_modbus() {
|
|||
pinMode(PIN_5V_EN, OUTPUT);
|
||||
digitalWrite(PIN_5V_EN, HIGH);
|
||||
|
||||
<<<<<<< HEAD
|
||||
#if defined(SERIAL_LINK_RECEIVER) || defined(SERIAL_LINK_TRANSMITTER)
|
||||
Serial2.begin(9600, SERIAL_8N1, RS485_RX_PIN, RS485_TX_PIN); // If the Modbus RTU port will be used for serial link
|
||||
#if defined(BYD_MODBUS) || defined(LUNA2000_MODBUS)
|
||||
|
@ -233,6 +237,8 @@ void init_modbus() {
|
|||
#endif
|
||||
#endif
|
||||
|
||||
=======
|
||||
>>>>>>> main
|
||||
#ifdef BYD_MODBUS
|
||||
// Init Static data to the RTU Modbus
|
||||
handle_static_data_modbus_byd();
|
||||
|
@ -304,6 +310,9 @@ void inform_user_on_battery() {
|
|||
#ifdef TEST_FAKE_BATTERY
|
||||
Serial.println("Test mode with fake battery selected");
|
||||
#endif
|
||||
#if !defined(ABSOLUTE_MAX_VOLTAGE)
|
||||
#error No battery selected! Choose one from the USER_SETTINGS.h file
|
||||
#endif
|
||||
}
|
||||
|
||||
// Functions
|
||||
|
@ -399,6 +408,7 @@ void send_can() {
|
|||
#endif
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
#ifdef SERIAL_LINK_RECEIVER
|
||||
//---- Receives serial data and transfers to the Inverter
|
||||
void receive_serial() {
|
||||
|
@ -421,6 +431,8 @@ void send_serial() {
|
|||
}
|
||||
#endif
|
||||
|
||||
=======
|
||||
>>>>>>> main
|
||||
#ifdef DUAL_CAN
|
||||
void receive_can2() { // This function is similar to receive_can, but just takes care of inverters in the 2nd bus.
|
||||
// Depending on which inverter is selected, we forward this to their respective CAN routines
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#endif
|
||||
|
||||
#ifdef SERIAL_LINK_RECEIVER
|
||||
#include "SERIAL-LINK-RECEIVER-FROM-BATTERY.h"
|
||||
#include "SERIAL-LINK-RECEIVER-FROM-BATTERY.h" //See this file for more Serial-battery settings
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -241,6 +241,15 @@ void update_values_leaf_battery() { /* This function maps all the values fetched
|
|||
max_target_discharge_power = 0;
|
||||
}
|
||||
|
||||
//Check if SOC% is plausible
|
||||
if (battery_voltage >
|
||||
(ABSOLUTE_MAX_VOLTAGE - 100)) { // When pack voltage is close to max, and SOC% is still low, raise FAULT
|
||||
if (LB_SOC < 650) {
|
||||
bms_status = FAULT;
|
||||
Serial.println("ERROR: SOC% reported by battery not plausible. Restart battery!");
|
||||
}
|
||||
}
|
||||
|
||||
if (LB_Full_CHARGE_flag) { //Battery reports that it is fully charged stop all further charging incase it hasn't already
|
||||
max_target_charge_power = 0;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ CAN_frame_t TESLA_221_2 = {
|
|||
.MsgID = 0x221,
|
||||
.data = {0x61, 0x15, 0x01, 0x00, 0x00, 0x00, 0x20, 0xBA}}; //Contactor Frame 221 - hv_up_for_drive
|
||||
|
||||
static uint32_t temporaryvariable = 0;
|
||||
static uint32_t total_discharge = 0;
|
||||
static uint32_t total_charge = 0;
|
||||
static uint16_t volts = 0; // V
|
||||
|
@ -156,8 +155,8 @@ static const char* hvilStatusState[] = {"NOT OK",
|
|||
#define MIN_CELL_VOLTAGE_NCA_NCM 2950 //Battery is put into emergency stop if one cell goes below this value
|
||||
#define MAX_CELL_DEVIATION_NCA_NCM 500 //LED turns yellow on the board if mv delta exceeds this value
|
||||
|
||||
#define MAX_CELL_VOLTAGE_LFP 3450 //Battery is put into emergency stop if one cell goes over this value
|
||||
#define MIN_CELL_VOLTAGE_LFP 2800 //Battery is put into emergency stop if one cell goes over this value
|
||||
#define MAX_CELL_VOLTAGE_LFP 3500 //Battery is put into emergency stop if one cell goes over this value
|
||||
#define MIN_CELL_VOLTAGE_LFP 2800 //Battery is put into emergency stop if one cell goes below this value
|
||||
#define MAX_CELL_DEVIATION_LFP 150 //LED turns yellow on the board if mv delta exceeds this value
|
||||
|
||||
void update_values_tesla_model_3_battery() { //This function maps all the values fetched via CAN to the correct parameters used for modbus
|
||||
|
@ -186,19 +185,22 @@ void update_values_tesla_model_3_battery() { //This function maps all the value
|
|||
|
||||
remaining_capacity_Wh = (expected_energy_remaining * 100); //Scale up 60.3kWh -> 60300Wh
|
||||
|
||||
//Calculate the allowed discharge power, cap it if it gets too large
|
||||
temporaryvariable = (max_discharge_current * volts);
|
||||
if (temporaryvariable > 60000) {
|
||||
max_target_discharge_power = 60000;
|
||||
} else {
|
||||
max_target_discharge_power = temporaryvariable;
|
||||
// Define the allowed discharge power
|
||||
max_target_discharge_power = (max_discharge_current * volts);
|
||||
// Cap the allowed discharge power if battery is empty, or discharge power is higher than the maximum discharge power allowed
|
||||
if (SOC == 0) {
|
||||
max_target_discharge_power = 0;
|
||||
} else if (max_target_discharge_power > MAXDISCHARGEPOWERALLOWED) {
|
||||
max_target_discharge_power = MAXDISCHARGEPOWERALLOWED;
|
||||
}
|
||||
|
||||
//The allowed charge power behaves strangely. We instead estimate this value
|
||||
if (SOC == 10000) {
|
||||
max_target_charge_power = 0; //When battery is 100% full, set allowed charge W to 0
|
||||
} else {
|
||||
max_target_charge_power = 15000; //Otherwise we can push 15kW into the pack!
|
||||
if (SOC == 10000) { // When scaled SOC is 100%, set allowed charge power to 0
|
||||
max_target_charge_power = 0;
|
||||
} else if (soc_vi > 950) { // When real SOC is between 95-99.99%, ramp the value between Max<->0
|
||||
max_target_charge_power = MAXCHARGEPOWERALLOWED * (1 - (soc_vi - 950) / 50.0);
|
||||
} else { // No limits, max charging power allowed
|
||||
max_target_charge_power = MAXCHARGEPOWERALLOWED;
|
||||
}
|
||||
|
||||
stat_batt_power = (volts * amps); //TODO: check if scaling is OK
|
||||
|
|
|
@ -7,7 +7,10 @@
|
|||
|
||||
#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 2450 // 245.0V if battery voltage goes under this, discharging further is disabled
|
||||
#define ABSOLUTE_MIN_VOLTAGE 2450 // 245.0V if battery voltage goes under this, discharging further is disabled
|
||||
#define MAXCHARGEPOWERALLOWED 15000 // 15000W we use a define since the value supplied by Tesla is always 0
|
||||
#define MAXDISCHARGEPOWERALLOWED \
|
||||
60000 // 60000W we need to cap this value to max 60kW, most inverters overflow otherwise
|
||||
|
||||
// These parameters need to be mapped for the Inverter
|
||||
extern uint16_t SOC;
|
||||
|
|
|
@ -189,7 +189,7 @@ void update_values_can_solax() { //This function maps all the values fetched fr
|
|||
|
||||
//BMS_PackTemps (strange name, since it has voltages?)
|
||||
SOLAX_1876.data.u8[2] = (uint8_t)cell_max_voltage; //TODO: scaling OK?
|
||||
SOLAX_1876.data.u8[3] = (cell_min_voltage >> 8);
|
||||
SOLAX_1876.data.u8[3] = (cell_max_voltage >> 8);
|
||||
|
||||
SOLAX_1876.data.u8[6] = (uint8_t)cell_min_voltage; //TODO: scaling OK?
|
||||
SOLAX_1876.data.u8[7] = (cell_min_voltage >> 8);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue