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

AP_BatteryMonitor: remove use of double in mah calculation #19452

Closed
rmackay9 opened this issue Dec 7, 2021 · 3 comments
Closed

AP_BatteryMonitor: remove use of double in mah calculation #19452

rmackay9 opened this issue Dec 7, 2021 · 3 comments
Labels

Comments

@rmackay9
Copy link
Contributor

rmackay9 commented Dec 7, 2021

As pointed out by @WickedShell when reviewing PR #19404 we probably don't need to cast to double in lines like below in AP_BattMonitor_UAVCAN.cpp.

float mah = (float) ((double) _interim_state.current_amps * (double) dt * (double) 0.0000002778f);

We should remove the doubles and make sure the accuracy of the output is not reduced.

@shiv-tyagi
Copy link
Contributor

shiv-tyagi commented Dec 14, 2021

@rmackay9 I would like to work on this issue. But I have one question, if we simply do to divide _interim_state.current_amps * dt by 3600000 we should surely get more accurate results than multiplying by 0.0000002778f but we know that divisions are much costlier than multiplication. So should I compromise cost for accuracy?

@rmackay9
Copy link
Contributor Author

@shiv-tyagi I wouldn't expect any difference in accuracy but maybe I'm misunderstanding something. In general we should go for accuracy though. By the way, when it comes to testing it would be good to check various values to ensure the calculations are the same before and after the change.

@hendjoshsr71
Copy link
Member

Closing. Thanks! @arBalasquide

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

No branches or pull requests

3 participants