diff --git a/text/001x-battery_improvements.md b/text/001x-battery_improvements.md new file mode 100644 index 0000000..4a2651b --- /dev/null +++ b/text/001x-battery_improvements.md @@ -0,0 +1,291 @@ + * Start date: 2022-03-26 + * Contributors: Hamish Willee , ... + * Related issues: + - [16-cell support #1747](https://github.com/mavlink/mavlink/pull/1747) + - [common: added voltage and current multipliers to BATTERY_STATUS #233](https://github.com/ArduPilot/mavlink/pull/233) + - [Add MAV_BATTERY_CHARGE_STATE_CHARGING #1068](https://github.com/mavlink/mavlink/pull/1068) + - dronecan / DSDL : [WIP smart battery messages](https://github.com/dronecan/DSDL/pull/7) + - [DS-013 Pixhawk Smart Battery Standard](https://docs.google.com/document/d/1xYBhhgjND_RS2W3Hq0Seyc-R661ge3zonk9DTIyHclc/edit) v0.4.0 + - [Common: rename SMART_BATTERY_INFO to BATTERY_INFO and add SOH](https://github.com/mavlink/mavlink/pull/2070) + + +# Summary + +This RFC proposes: +- a new `BATTERY_STATUS_V2` message that has a single cumulative voltage value rather than individual cell voltage arrays. +- a new (optional) `BATTERY_VOLTAGES` message that can be scaled to as many cells as needed, and which reports them as faults. + + +# Motivation + +The motivation is to: +- reduce the memory required for battery reporting ([anecdotal evidence](https://github.com/ArduPilot/mavlink/pull/233#issuecomment-976197179) indicates cases with 15% of bandwidth on a default RF channel). +- Provide a cleaner message and design for both implementers and consumers. +- Align with DroneCan battery messages to ease transport and data conversion across different transports. + +The [BATTERY_STATUS](https://mavlink.io/en/messages/common.html#BATTERY_STATUS) has two arrays that can be used to report individual cell voltages (up to 14), or a single cumulative voltage, and which cannot be truncated. +The vast majority of consumers are only interested in the total battery voltage, and either sum the battery cells or get the cumulative voltage. +By separating the cell voltage reporting into a separate message the new battery status can be much smaller, and the cell voltages need only be sent if the consumer is actually interested. + +# Detailed Design + +There are three parts to the design: +1. A more efficient status message +2. A scalable battery voltage message. +3. Mechanisms that allow the new messages to seamlessly coexist with the old one along with eventual deprecation of the older message. + +## BATTERY_STATUS_V2 + +The proposed message is: + +```xml + + Battery dynamic information. + This should be streamed (nominally at 1Hz). + Static/invariant battery information is sent in BATTERY_INFO. + Note that smart batteries should set the MAV_BATTERY_STATUS_FLAGS_CAPACITY_RELATIVE_TO_FULL bit to indicate that supplied capacity values are relative to a battery that is known to be full. + Power monitors would not set this bit, indicating that capacity_consumed is relative to drone power-on, and that other values are estimated based on the assumption that the battery was full on power-on. + + Battery ID + Temperature of the whole battery pack (not internal electronics). INT16_MAX field not provided. + Battery voltage (total). NaN: field not provided. + Battery current (through all cells/loads). Positive value when discharging and negative if charging. NaN: field not provided. + Consumed charge. NaN: field not provided. This is either the consumption since power-on or since the battery was full, depending on the value of MAV_BATTERY_STATUS_FLAGS_CAPACITY_RELATIVE_TO_FULL. + Remaining charge (until empty). UINT32_MAX: field not provided. Note: If MAV_BATTERY_STATUS_FLAGS_CAPACITY_RELATIVE_TO_FULL is unset, this value is based on the assumption the battery was full when the system was powered. + Remaining battery energy. Values: [0-100], UINT8_MAX: field not provided. + Fault, health, readiness, and other status indications. + +``` + +`MAV_BATTERY_STATUS_FLAGS` is a new enum that includes faults, charge state, and battery mode: + +```xml + + Battery status flags for fault, health and state indication. + + + The battery is not ready to use (fly). + Set if the battery has faults or other conditions that make it unsafe to fly with. + Note: It will be the logical OR of other status bits (chosen by the manufacturer/integrator). + + + + + Battery is charging. + + + + + Battery is cell balancing (during charging). + Not ready to use (MAV_BATTERY_STATUS_FLAGS_NOT_READY_TO_USE may be set). + + + + + Battery cells are not balanced. + Not ready to use. + + + + + Battery is auto discharging (towards storage level). + Not ready to use (MAV_BATTERY_STATUS_FLAGS_NOT_READY_TO_USE would be set). + + + + + Battery requires service (not safe to fly). + This is set at vendor discretion. + It is likely to be set for most faults, and may also be set according to a maintenance schedule (such as age, or number of recharge cycles, etc.). + + + + + Battery is faulty and cannot be repaired (not safe to fly). + This is set at vendor discretion. + The battery should be disposed of safely. + + + + + Automatic battery protection monitoring is enabled. + When enabled, the system will monitor for certain kinds of faults, such as cells being over-voltage. + If a fault is triggered then and protections are enabled then a safety fault (MAV_BATTERY_STATUS_FLAGS_FAULT_PROTECTION_SYSTEM) will be set and power from the battery will be stopped. + Note that battery protection monitoring should only be enabled when the vehicle is landed. Once the vehicle is armed, or starts moving, the protections should be disabled to prevent false positives from disabling the output. + + + + + The battery fault protection system had detected a fault and cut all power from the battery. + This will only trigger if MAV_BATTERY_STATUS_FLAGS_PROTECTIONS_ENABLED is set. + Other faults like MAV_BATTERY_STATUS_FLAGS_FAULT_OVER_VOLT may also be set, indicating the cause of the protection fault. + + + + One or more cells are above their maximum voltage rating. + + + + One or more cells are below their minimum voltage rating. + A battery that had deep-discharged might be irrepairably damaged, and set both MAV_BATTERY_STATUS_FLAGS_FAULT_UNDER_VOLT and MAV_BATTERY_STATUS_FLAGS_BAD_BATTERY. + + + + Over-temperature fault. + + + Under-temperature fault. + + + Over-current fault. + + + + Short circuit event detected. + The battery may or may not be safe to use (check other flags). + + + + Voltage not compatible with power rail voltage (batteries on same power rail should have similar voltage). + + + Battery firmware is not compatible with current autopilot firmware. + + + Battery is not compatible due to cell configuration (e.g. 5s1p when vehicle requires 6s). + + + + Battery capacity_consumed and capacity_remaining values are relative to a full battery (they sum to the total capacity of the battery). + This flag would be set for a smart battery that can accurately determine its remaining charge across vehicle reboots and discharge/recharge cycles. + If unset the capacity_consumed indicates the consumption since vehicle power-on, as measured using a power monitor. The capacity_remaining, if provided, indicates the estimated remaining capacity on the assumption that the battery was full on vehicle boot. + If unset a GCS is recommended to advise that users fully charge the battery on power on. + + + + Reserved (not used). If set, this will indicate that an additional status field exists for higher status values. + + +``` + +The message is heavily based on [BATTERY_STATUS](https://mavlink.io/en/messages/common.html#BATTERY_STATUS) but: +- removes the cell voltage arrays: `voltages` and `voltages_ext` +- adds `voltage`, the total cell voltage. This is a float to allow batteries with more than 65V and also very small voltage changes. +- `current_consumed` has changed to capacity_consumed, and from an `int32_t` to a `float` in A. + This future proofs from 32767 mAh limit and allows very large and very small values. +- removes `energy_consumed`, which essentially duplicates `capacity_consumed` for most purposes, and `capacity_consumed` in mAh is nearly ubiquitous. +- adds `capacity_remaining`(Ah) as a `float`. + - This allows a GCS to more accurately determine available current and remaining time than inferring from the `capacity_consumed` and `percent_remaining`. + - This will be reliable for smart batteries. + - A flag has been added to indicate whether this is calculated from an assumed or known-full battery. + A GCS can use this to prompt that batteries be fully charged for power modules. +- Note that with capacity consumed and remaining, you have the full capacity and you could calculate the percentage remaining. + However percentage remaining is supplied anyway, as the other values are optional, and this is actually the one value that most users really want. +- change `current` from a `int16_t` (cA) to a `float` (A). Maximum size was previously 327.67A, which is not large enough to be future proof. New value gives full range and both very small and very high values. +- removes `time_remaining`. + ```xml + Remaining battery time (estimated), UINT32_MAX: Remaining battery time estimate not provided. + ``` + - This is an estimated "convenience" value which can be calculated as well or better by a GCS, in particular on multi-battery systems (from original charge, `capacity_consumed` and looking at the rate of `current` over some time period). + - Better to be lightweight. +- `percent_remaining` changed from int8 to uint8 (and max value set to invalid value). + This is consistent with other MAVLink percentage fields. +- removes `battery_function` and `type` (chemistry) as these are present in `BATTERY_INFO` and are invariant. + ```xml + Function of the battery + Type (chemistry) of the battery + ``` + - A GCS that needs invariant information should read `BATTERY_INFO` on startup + - A vehicle that allows battery swapping must stream `BATTERY_INFO` (at low rate) to ensure that battery changes are notifie (and ideally also emit it on battery change). +- New `battery_status` (`MAV_BATTERY_STATUS_FLAGS`) replaces [`fault_bitmask`](https://mavlink.io/en/messages/common.html#MAV_BATTERY_FAULT), [`charge_state`](https://mavlink.io/en/messages/common.html#MAV_BATTERY_CHARGE_STATE) and [`mode`](https://mavlink.io/en/messages/common.html#MAV_BATTERY_MODE) + ```xml + State for extent of discharge, provided by autopilot for warning or external reactions + Battery mode. Default (0) is that battery mode reporting is not supported or battery is in normal-use mode. + Fault/health/ready-to-use indications. + ``` + - The state is almost all inferred from the battery remaining. Traditionally the GCS sets appropriate levels for warning - the battery has a less accurate view on appropriate warning levels for a particular system, making this redundant. The exception is charging status. + - The mode and fault are reasonable, but make more sense as general status indication. + - The status loses some faults which make no sense (e.g. `MAV_BATTERY_FAULT_SPIKES`) or which can now be inferred (like deep discharge). + + +#### Questions + +- Do we need all the other fields? +- Are there any other fields missing? +- Should we have `MAV_BATTERY_FAULT` for critical level "just before deep discharge"? The battery can know this, and it might prevent over discharge. + ```xml + + Battery is at critically low level. Undamaged, but not ready to use. + + ``` +- `MAV_BATTERY_STATUS_FLAGS` + - Should this include `MAV_BATTERY_STATUS_FLAGS_IN_USE` (connected, drawing significant power to fly). Not clear when you would need this or how you would use it. Or precisely what would count as "in use". + +## Battery Cell Voltages + +The proposed battery message is: + +```xml + + Battery cell voltages. + This message is provided primarily for cell fault debugging. + For batteries with more than 126 cells the message should be sent multiple times, iterating the index value. + It should be streamed at very low rate (less than once a minute) or streamed only on request. + Battery ID + Cell index (0 by default). This can be iterated for batteries with more than 12 cells. + Battery voltage of up to 126 cells at current index. Cells above the valid cell count for this battery should be set to 0. + +``` + +Cell voltages can be used to verify that poorly performing batteries have failing cells, and to providing early warning of longer term battery degradation. +It is useful to have long term trace information in logs, but not necessary for this to be at particularly high rate. +Therefore the message provides all information about the battery voltages, but is expected to be sent at low rate, or on request. + +As designed, the message will not be zero-byte truncated (field re-ordering means that the array is last). +The message might be modified to make: +- `voltages` an extension field. For a 4S battery this would save 12 bytes per message but lose checking. If we do this we might as well mandate "no extension". +- `id` and `index` into `uint16_t`. For a 4S battery this would save 10 bytes per message,and retain mavlink checking on field. It would cost 2 additional bytes on every new message. + + +#### Alternatives + +An alternative is just to send fault information. +This assumes that the smart battery is capable of providing the long term trend analysis that can be obtained from logs using the above message. + +```xml + + Battery cell fault information. + Battery ID + Cell index (0 by default). This is iterated for every 64 cells, allowing very large cell fault information. + Fault/health indications. + +``` + +## BATTERY_INFO + +[BATTERY_INFO](https://mavlink.io/en/messages/common.html#BATTERY_INFO) is WIP in common. This has been renamed from `SMART_BATTERY_INFO` as there were no known implementations. + +Add note that it must be streamed at a low rate in order to allow detection of battery change, and should also be sent when the battery changes. + + + +## Migration/Discovery + +`BATTERY_STATUS` consumes significant bandwidth: sending `BATTERY_STATUS_V2` at the same time would just increase the problem. + +The proposal here is that GCS should support both messages for the forseeable future. +Flight stacks should manage their own migration after relevant ground stations have been updated. + + +# Alternatives + +TBD + +# Unresolved Questions + +TBD + +# References + +* ? +