-
Notifications
You must be signed in to change notification settings - Fork 24
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
Conversation
src/motor_hardware.cc
Outdated
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(); |
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.
Can we put in a dumb percentage that goes between 0-100% between 22-28 volts ?
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.
Good, but see comments
@rohbotics, how is this? |
src/motor_hardware.cc
Outdated
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)); |
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.
bstate.percentage
should be between 0 and 1. 0.02 * (bstate.voltage - 18.0)
should make it work
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.
Also I think our lower voltage (0% level) should be 20V. at 18 you are at 9V per battery which is pretty low.
src/motor_hardware.cc
Outdated
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); |
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.
Same issue, should be something like std::min(1.0, 0.12 + (bstate.voltage - 22.0) * 0.15);
@rohbotics, good point. I made it a simple linear function with 20V -> 0 and 28V -> 1 |
src/motor_hardware.cc
Outdated
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; |
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.
Why use an if, when you could just use std::max(0.0, bstate.percentage), it would be cleaner I think.
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.
LGTM
Closes #12