-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Increase battery voltage resolution to 10mV #2668
Increase battery voltage resolution to 10mV #2668
Conversation
Nice work! Would be awesome to add battery profiles to this battery code overhaul like the ability of having separate low voltage alarms for LiPo and LiOn batteries with the ability to switch profiles via the OSD. |
Good idea. You should open a new issue for discussing the best way to do it. I also have one or two other ideas about the battery management. |
…places where vbat calculations needs to be divided by 10
@@ -588,7 +588,7 @@ void handleSmartPortTelemetry(void) | |||
vfasVoltage = vbat / batteryCellCount; | |||
else | |||
vfasVoltage = vbat; | |||
smartPortSendPackage(id, vfasVoltage * 10); // given in 0.1V, convert to 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.
I'm pretty sure the comment is wrong. If vfasVoltage = vbat
and vbat resolution is 100mV then vfasVoltage * 10
gives result in 10mV increments not in 1V increments.
@@ -739,7 +739,7 @@ void handleSmartPortTelemetry(void) | |||
//case FSSP_DATAID_A3 : | |||
case FSSP_DATAID_A4 : | |||
if (feature(FEATURE_VBAT)) | |||
smartPortSendPackage(id, vbat * 10 / batteryCellCount ); // given in 0.1V, convert to 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.
I'm pretty sure the comment is wrong. If vbat resolution is 100mV then vbat * 10 / batteryCellCount
gives the individual cell voltage in 10mV increments not in 1V increments.
…100mV resolution because modifying the viewer is not trivial
I tested this apart from the telemetry. Looks good to me.
|
@shellixyz is this ready for merge? |
@digitalentity Yes it is ready |
@shellixyz another thought. Maybe use voltage/current readings |
@digitalentity If it is an option for sure would make the code easier to read. Not sure about the practicality though. Can the OSD code manage formatting floats ? And we will still need to convert the floats to integer representation for communication purposes (telemetry, MSP). I will look into it. |
I'm a bit scared of floats for performance reasons. F3 and F4 only have hardware FPU for 32 bits, not for 64 (not sure about F7, I think it does but F3 and F4 is like 99% of the userbase right now). Doing an accidental promotion to double in a calculation is very easy to introduce and difficult to spot later. However, from a functional standpoint and code clarity float would probably be better. Is there an easy way either via compiler options or via runtime configuration to make sure we don't accidentally introduce operations that require soft-fp? I've taken a quick look to the ARM specific options in GCC but I can't find how to produce an error when the code requires FP via software. |
@fiam |
@digitalentity Compiling the development branch with these options is already producing a lot of warnings (153). |
I suggest merging this before considering the float conversion. |
@shellixyz agreed on float-point related warnings |
@digitalentity I intend to make another pull-request for improving the battery management even more. Adding mWh draw calculation (better than mAh), improving the way the battery capacity percentage is calculated and also the possibility to use the battery capacity as thresholds for the battery warnings. I am talking about this here because the changes also involve data that should be included in the new MSPV2 messages created by this PR and the mWh calculation also depends on the voltage resolution. So it would be better if this PR and the new one could be merged close in time to each other and that I could base the new PR on the changes made by this one. |
@shellixyz sure, no problem. BTW I'm ok with merging this right away. |
Nice. I have some polishing to do but I will be working on the new PR tomorrow and should be ready soon :) |
Battery voltage resolution of 100mV is not enough for me. This patch increases the voltage resolution to 10mV.
osd_main_voltage_decimals
MSP2_ANALOG
,MSP2_MISC
,MSP2_SET_MISC
,MSP2_VOLTAGE_METER_CONFIG
,MSP2_SET_VOLTAGE_METER_CONFIG
Matching configurator update: iNavFlight/inav-configurator#328