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

Improve battery monitoring #2705

Conversation

shellixyz
Copy link
Collaborator

@shellixyz shellixyz commented Jan 30, 2018

This PR includes the increased battery voltage resolution changes (#2668)

Changes summary:

  • Calculates and exports power draw in 0.01W unit.
  • Calculates and exports mWh drawn.
  • New settings for battery capacity and capacity based thresholds with chosable unit (mAh or mWh): battery_capacity, battery_capacity_unit, battery_warning_capacity, battery_critical_capacity.
  • Battery settings are available through OSD menu.
  • Battery capacity based beeper warnings.
  • Behaves exactly as before if battery capacity settings are 0 (by default).
  • Calculates and exports remaining battery capacity.
  • New improved battery remaining percentage calculation based on battery capacity if available.
  • New OSD elements: mWh drawn, remaining battery capacity, remaining battery percentage based on capacity if available, Wh/Km calculated efficiency
  • Improved OSD elements: battery gauge based on battery capacity if available, more resolution for the power indicator element.
  • Battery energy drawn in OSD stats can be displayed in mAh or Wh (osd_stats_energy_unit setting).
  • Simplified battery task.
  • Battery capacity is only used when the plugged battery was full the moment it was plugged in otherwise the battery voltage is used. Remaining battery capacity element on OSD will display NF if the battery was not full when plugged in. It displays NA if battery capacity has not been specified (battery_capacity = 0).
  • New/updated MSPv2 messages to read/set the new battery settings.

I tested these changes the best I could. I could not test the Wh/Km efficiency because I have no aircraft for the moment with video/OSD and it needs to get GPS speed.

OSD fonts update with new icons: iNavFlight/inav-configurator#333

@shellixyz
Copy link
Collaborator Author

I also merged #2684 in so it is not needed if you merge this.

@shellixyz
Copy link
Collaborator Author

shellixyz commented Jan 31, 2018

I will do some cleaning in the batteryConfig structure. I was thinking grouping the capacity/voltage items. And also moving the multiwiiCurrentMeterOutput item where it belongs. Where should it be best placed ? telemetryConfig maybe ? or systemConfig ?

// FIXME this doesn't belong in here since it's a concern of MSP, not of the battery code.
uint8_t multiwiiCurrentMeterOutput;     // if set to 1 output the amperage in milliamp steps instead of 0.01A steps via msp

@digitalentity
Copy link
Member

I'm not sure we need multiwiiCurrentMeterOutput at all. It's a legacy thing and I believe it should go at some point.

@digitalentity digitalentity added this to the 1.9 milestone Jan 31, 2018
@digitalentity
Copy link
Member

@shellixyz looks like merging of MANUAL mode created a merge conflict here

@shellixyz
Copy link
Collaborator Author

@digitalentity Can I remove multiwiiCurrentMeterOutput now ? It will probably break outdated communication libraries made to work with the old Multiwii protocol but it shouldn't be a big issue.

}
if (telemetryConfig()->smartportFuelPercent)
smartPortSendPackage(id, calculateBatteryPercentage()); // Show remaining battery % if smartport_fuel_percent=ON and battery_capacity set
else
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this instead so it doesn't set a telemetry fuel sensor if a current sensor doesn't exist:

else if (feature(FEATURE_CURRENT_METER))

@digitalentity
Copy link
Member

@shellixyz yes, please remove the multiwiiCurrentMeterOutput

@@ -399,6 +399,13 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
}
break;

case MSP2_INAV_VOLTAGE_METER_CONFIG:
Copy link
Member

Choose a reason for hiding this comment

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

Do we need a special MSPv2 message for voltmeter config? Same settings are available via MSP2_INAV_BATTERY_CONFIG.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed we do not. I added it with the PR increasing the voltage resolution but now it is redundant I will remove it.

@shellixyz
Copy link
Collaborator Author

I tested again the best I could the last changes. Including I-bus telemetry values this time.

I don't plan on making more changes. If it is good for you it is good for me to merge.

@digitalentity
Copy link
Member

Ack. Will review today

@shellixyz
Copy link
Collaborator Author

A couple of new mods in the end even though I said I would not. Should be good this time.

@digitalentity digitalentity merged commit f00194c into iNavFlight:development Feb 2, 2018
giacomo892 pushed a commit to giacomo892/inav that referenced this pull request Feb 2, 2018
* increase battery voltage resolution to 10mV
* increase battery voltage resolution to 10mV: update VBATT_HYSTERESIS
* increase battery voltage resolution to 10mV: fix telemetry and other places where vbat calculations needs to be divided by 10
* increase battery voltage resolution to 10mV: revert blackbox data to 100mV resolution because modifying the viewer is not trivial
* increase battery voltage resolution to 10mV: change new MSPv2 frame type names to follow convention

* smartport telemetry: remove wrong and now irrelevant comments

* Improve battery monitoring
* improve battery monitoring: fix/simplify the batteryAdcToVoltage function
* improve battery monitoring: Add OSD voltage decimals setting to OSD MISC menu
* improve battery monitoring: clean the batteryConfig struct
* improve battery monitoring: increase batteryConfig PG group version to 1
* improve battery monitoring: change capacity settings type from uin16_t to uint32_t (65Wh is not very large, it is about 6Ah for a 3S Li-Po)
* improve battery monitoring: rename capacity settings
* improve battery monitoring: improve OSD code
* improve battery monitoring: simplified taskUpdateBattery
* improve battery monitoring: use unfiltered vbat to decide if the battery is full
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.

3 participants