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

Publish battery voltage messages #29

Merged
merged 7 commits into from
Aug 26, 2017
Merged

Publish battery voltage messages #29

merged 7 commits into from
Aug 26, 2017

Conversation

jim-v
Copy link
Contributor

@jim-v jim-v commented Aug 24, 2017

Closes #12

@jim-v jim-v requested a review from rohbotics August 24, 2017 06:54
bstate.charge = std::numeric_limits<float>::quiet_NaN();
bstate.capacity = std::numeric_limits<float>::quiet_NaN();
bstate.design_capacity = std::numeric_limits<float>::quiet_NaN();
bstate.percentage = std::numeric_limits<float>::quiet_NaN();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put in a dumb percentage that goes between 0-100% between 22-28 volts ?

Copy link
Member

@rohbotics rohbotics left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, but see comments

@jim-v
Copy link
Contributor Author

jim-v commented Aug 25, 2017

@rohbotics, how is this?

bstate.capacity = std::numeric_limits<float>::quiet_NaN();
bstate.design_capacity = std::numeric_limits<float>::quiet_NaN();
if (bstate.voltage < 22.0) { // 18V = 0%, 22V = 12%
bstate.percentage = std::max(0.0, 2.0 * (bstate.voltage - 18.0));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bstate.percentage should be between 0 and 1. 0.02 * (bstate.voltage - 18.0) should make it work

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I think our lower voltage (0% level) should be 20V. at 18 you are at 9V per battery which is pretty low.

bstate.percentage = std::max(0.0, 2.0 * (bstate.voltage - 18.0));
}
else { // 22V = 12%, 24V = 42%, 26V = 72%. 27V = 87%
bstate.percentage = std::min(100.0, 12.0 + (bstate.voltage - 22.0) * 15.0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue, should be something like std::min(1.0, 0.12 + (bstate.voltage - 22.0) * 0.15);

@jim-v
Copy link
Contributor Author

jim-v commented Aug 26, 2017

@rohbotics, good point. I made it a simple linear function with 20V -> 0 and 28V -> 1

bstate.capacity = std::numeric_limits<float>::quiet_NaN();
bstate.design_capacity = std::numeric_limits<float>::quiet_NaN();
if (bstate.voltage < 20.0)
bstate.percentage = 0.0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use an if, when you could just use std::max(0.0, bstate.percentage), it would be cleaner I think.

Copy link
Member

@rohbotics rohbotics left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jim-v jim-v merged commit 2f98f60 into indigo-devel Aug 26, 2017
@jim-v jim-v deleted the battery-voltage branch November 12, 2017 18:31
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