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

Prevent discharging more power from battery with nearly 0% power #1600

Conversation

AngelicosPhosphoros
Copy link
Contributor

@AngelicosPhosphoros AngelicosPhosphoros commented Jun 6, 2022

Summary

SUMMARY: Bugfixes "Prevent discharging too much power from nearly empty batteries"

Purpose of change

Consider the situation when charging from large storage battery (80 MJ) with 10 kJ remaining. It would have 0% power level (10*100 / 80_000) so our "prev_charge_level" would -800 and we would lower amount by 810.

Essentially free energy when it shouldn't be so I ensure that we cannot charge more power than remaining.

Describe the solution

Just ensure that we never try to lower our power amount more than we have.

Describe alternatives you've considered

Testing

Only run autotests because change is trivial.

Additional context

@Coolthulhu Coolthulhu self-assigned this Jun 8, 2022
@Coolthulhu Coolthulhu merged commit 8d77cdd into cataclysmbnteam:upload Jun 10, 2022
@Coolthulhu
Copy link
Member

Tiny nit: functional style assignments (variables that could be consted with no changes to the code) are preferred to "procedural" ones.

@AngelicosPhosphoros AngelicosPhosphoros deleted the improve_vehicle_charging branch June 10, 2022 22:38
@AngelicosPhosphoros
Copy link
Contributor Author

Tiny nit: functional style assignments (variables that could be consted with no changes to the code) are preferred to "procedural" ones.

Here it was already like that and I found putting everything into one expression too bulky in that case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants