-
Notifications
You must be signed in to change notification settings - Fork 16.8k
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
AP_BattMonitor: Remove double cast in mah calculation #19540
AP_BattMonitor: Remove double cast in mah calculation #19540
Conversation
@@ -51,6 +51,8 @@ class AP_BattMonitor_UAVCAN : public AP_BattMonitor_Backend | |||
static void handle_battery_info_aux_trampoline(AP_UAVCAN* ap_uavcan, uint8_t node_id, const BattInfoAuxCb &cb); | |||
static void handle_mppt_stream_trampoline(AP_UAVCAN* ap_uavcan, uint8_t node_id, const MpptStreamCb &cb); | |||
|
|||
static float calculate_mah(float amps, float dt) { return (float) (amps * dt * 0.0000002778f); } |
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.
Needs a comment to say where the magic constant came from, and arguably should actually be a helper that is in the general battery backend (or a seperate static function that any of the backends could include as needed), since the analog monitor has the same code path and we should be trying to hold these to do identical calculations.
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.
Alright, I made it a static function in the backend header. Thought about virtual but it would make it harder to run the test class, although its currently causing errors for some reason it might just be best to scrap it.
I also made Analog use the new function.
Really nicely done. @peterbarker should probably decide if he's happy with the test code. |
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.
Love the fact that you included unit tests!! :) 🥇
Looking good! Two things:
If you need help with the squashing let me know? |
3b18e01
to
d47c1ef
Compare
@hendjoshsr71 Thank you for the suggestions. I've squashed the commits now let me know if its OK. |
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
just needs intel copyright removed |
d47c1ef
to
66c1e5b
Compare
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
This PR addresses issue #19452.
Also adds regression tests and accuracy tests to validate there isn't any loss of accuracy from removing the double casts.