-
Notifications
You must be signed in to change notification settings - Fork 166
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
Add ramped charge value for Tesla #100
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3aa3d8e
Add ramped charge value for Tesla
dalathegreat 19e3372
Raise max voltage per cell LFP
dalathegreat 1e91bd6
Tweak ramp if-statement
dalathegreat 2f6d6cf
Fix division error
dalathegreat 6801e83
Rework ramp logic
dalathegreat bf292a1
Add discharge SOC% safety
dalathegreat 36deffd
Rework ramp logic
dalathegreat e2d3c4f
Rework discharge calculation
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,8 +156,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 | ||
|
@@ -193,12 +193,17 @@ void update_values_tesla_model_3_battery() { //This function maps all the value | |
} else { | ||
max_target_discharge_power = temporaryvariable; | ||
} | ||
if (SOC < 20) { // When battery is lower than 0.20% , set allowed discharge W to 0 | ||
max_target_discharge_power = 0; | ||
} | ||
|
||
//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! | ||
max_target_charge_power = MAXCHARGEPOWERALLOWED; | ||
if (soc_vi > 950) { // When battery is between 95-99.99% real SOC, ramp the value between Max<->0 | ||
max_target_charge_power = MAXCHARGEPOWERALLOWED * (1 - (soc_vi - 950) / 50.0); | ||
} | ||
if (SOC == 10000) { // When battery is defined as 100% full, set allowed charge W to 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of two separate
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good improvement, fixed in 36deffd |
||
max_target_charge_power = 0; | ||
} | ||
|
||
stat_batt_power = (volts * amps); //TODO: check if scaling is OK | ||
|
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
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.
Instead of hardcoding the value 20 (representing 0.20%), shouldn’t this be based on
MINPERCENTAGE
?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.
I would also change these lines into one
if, else if
statement that defines themax_target_discharge_power
, rather than two separateif
statements.Additionally let's define
MAXDISCHARGEPOWERALLOWED
as60000
.Suggested code:
This also removes the need for the
temporaryvariable
.Additionally I would like to suggest to define, in another pull request, a convention how SOC and other percentages are defined, either
20.0%
as200
(as is the case forMINPERCENTAGE
andsoc_vi
), or20.00%
as2000
(as is the case forSOC
), such that we don't make conversion mistakes.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.
@lenvm fixed in e2d3c4f , I decided against using MINPERCENTAGE, and going for the simpler if SOC=0 check, since that is what other battery types use! Nice bonus with the temporaryvariable removed!