State of Charge

Introduction

Determining the state of charge of a battery is an often underestimated task. This document seeks to provide a starting to point to such a task from an electrical first principles perspective.

What is state of charge? You know how your phone gives you a percentage of how charged it is? That’s a state of charge. The big question this document will introduce us to is how does your phone calculate that number? And consequently how we at WARG can use a similar, simplified, approach to get a value with the same meaning.

Related Documents

Background

Physics

Before we get to the calculations lets cover some relevant physical, mostly electrical, quantities:

  • Energy

    • the capacity to perform work, in this case electrical work

    • The integration of power with respect to time gives us energy

    • measured in joules

      • this is equal to a watt-second

  • Power

    • rate of energy

    • For electrical circuits power equals voltage times current

    • measured in watts for electronics

      • horsepower is more common for mechanisms

      • 1 W = 746 Hp

    • power stretches far beyond just electronics as a concept

      • power from electronic circuits is often dissipated as heat, noise, or mechanical power

  • Voltage

    • electric potential

    • Mathematically voltage is the negative gradient of electric potential energy per unit charge

    • measured in volts

  • Current

    • rate of flow of electric charge

    • measured in amperes

      • amps for short

    • Current is equivalent to the charge through a point per unit time

  • Charge

    • the unit of charge is the coulomb

      • one coulomb represents 6.242 x 10^18 electrons

    • property responsible for creating electric fields

  • Energy Density

    • given as watt hour per gram

    • this is used to describes how much chemical energy is stored within the weight of those chemicals (and their housing)

Batteries

Now for some battery specifications which are also introduced in LiPo Battery Safety and Procedure. These are also used as marketing terms and ratings which are often exaggerated by manufacturers. Metrics cited here however are all measurable in the lab and so for a given battery you can likely find ratings that users have measured. Please note batteries do degrade over use. Anyways here’s some metrics:

  • Discharge Curve:

    • A discharge curve describes voltage over time for a constant load current assuming you start at a fully charged battery

    • The charge curve is extremely similar just in reverse

    • The shape of the discharge curve varies significantly based on battery chemistry, load current, & temperature

    • Most load profiles are not a constant current and consequently this discharge curve will not be a valid model your batteries use case discharge

    • An example:

  • Capacity

    • this is generally given commercially as a unit of ampere-hour or milliampere-hour when we need a bigger number for marketing purposes (business people out here manipulating us engineers gg)

    • describes how much constant current the battery can provide for one hour while remaining within a given safe voltage range assuming you start at the full given safe voltage and end at the lowest safe voltage at a reasonable temperature

    • Note that this value does not describe energy capacity of the battery because power is a function of voltage AND current.

  • Chemistry

    • batteries are made of different chemistries.

    • batteries convert between chemical energy and electrical energy making them pretty swag

    • some chemistries are better than others for specific load profiles, there is not a best chemistry

    • some chemistries are safer than others

    • This affects the discharge curve and the safe voltage range of the battery significantly

  • C-Rating

    • The maximum current that the battery is rated to draw continuously without damaging itself is given by the C-rating value multiplied by the capacity value

    • This is semi-arbitrary since of course under high currents battery voltage sag can be significant and generally heavy loading accelerates battery degradation so where the safe region lies is arbitrarily defined by manufacturers based on their testing, but hey, you can do your own testing if you care!

  • Cell

    • an individual small unit of chemical things

    • cells are used to make battery packs

    • are small and designed to be arranged in custom configurations

    • has no protections and is not recommended for use by itself

  • Pack

    • a group of cells in an xSyP configuration where x and y are whole numbers if one is zero then the letter is often left out for simplicity

  • #S Cells in a pack

    • Series cells in a battery pack

  • #P Cells in a pack

    • parallel cells in a battery pack

  • Internal Resistance

    •  

  • Fully Discharged

    • A fully discharged battery cannot safely provide more power

      • safe in this case means causing permanent degradation of the batteries physical properties

      • consuming power beyond this safety threshold could lead to fire

    • Note that a battery that is fully discharged may (and in most cases will) have a non-zero output voltage and non-zero energy within

      • This is why a fully discharged battery still has enough power to catch itself on fire

    • For most chemistries the threshold for when a battery is fully discharged is defined by a threshold in voltage do not be fooled however, voltage is not analogous to state of charge

  • Fully Charged

    • A battery is fully charged when a battery cannot safely accept more power

      • safe in this case means causing permanent degradation of the batteries physical properties

      • consuming power beyond this safety threshold could lead to fire

    • For most chemistries the threshold for when a battery is fully charged is defined by a threshold in voltage do not be fooled however, voltage is not analogous to state of charge

  • State of Charge

    • the quantity of usable energy remaining within a battery generally normalized and given as a percentage for human readability

    • Note that the usable energy is always less than the same as total energy of battery

Electronics

  • Power Module

    • A hobbyist term for a device that measure’s battery voltage and current and reports the data to a flight controller

  • Load Profile

    • A given electrical load on a battery or any other power supply is profiled by its voltage and current requirements with respect to time

    • While most loads are considered resistive in the sense that they dissipate electrical power into another form of power

  • Resistance

    • Resistors dissipate electrical power as thermal power

    • V = IR

      • Combining with P = IV we see P = V*I^2 where this is the power dissipated as heat

    • All conductors have some parasitic resistance

  • Capacitance

  • Inductance

  • Series

    •  

  • Parallel

    •  

Calculating SoC

Because a state of charge calculation is highly specific to the types of electrical loading and charging profiles as well as the battery chemistry this problem does not have a unilateral solution for every system with a battery. There are two general approaches to solving problems like this for a given system: modelling and testing. The best solution is a healthy combination of as much of both as possible.

There are a few things we can measured with respect to time from the the system that are relevant to the batteries state of charge:

  • Voltage

    • The voltage of the entire battery pack can be measured easily and is on WARG

    • The voltage of individual pack cells can be measured but on WARG often isnt

  • Current

    • The current of the entire battery pack output can be measured easily

  • Temperature

    • The temperature of a battery pack can be measured in various positions but on WARG it often isnt

    • temperature affect the chemical performance of the battery

  • Power Train Commands

    • Power train commands can be used to predict currents when a current sensor is not present or has an insufficient sample rate

    • i.e. If the flight controller command the motors to a higher throttle we can assume this corresponds to more current draw at a point in time

  • System Response

    • The response of the system to a given control input can be used to estimate battery parameters

    • i.e. a fully charged battery will cause more acceleration of the drone for a given throttle input as compared to a more discharged battery due to changes in internal resistance and voltage throughout the discharge curve.

Wikipedia introduces a few primitive methods using this aggregated data well via State of charge and I will break it down into modelling methods:

  • Chemical State

    • A model of a chemical reaction can be performed and integrated into the model of the load profile to calculate a state of charge

    • Data from the pack can be compared with the chemical model to guess the state of charge

  • Voltage Position

    • output voltage of a battery is affected by the output current and temperature in addition to the state of charge making this a noisy measurement

    • the raw voltage value can be used to approximate state of charge via a theoretical discharge curve

    • Because voltage can sag significantly due to internal resistance or spike due to inductance, raw voltage should be used with caution, especially for “threshold” based algorithms

  • Current Integration

    • integrated current measurements with respect to time is called coulomb counting and can be used to guess discharge state

    • error accumulates over time and a current sensor with a low sample rate can cause severe inaccuracies with this method of estimation

    • current may also experience lots of transients during flight

      • hovering consumes very little current

      • jerking upwards quickly consumes lots of current

  • Voltage & Current Combined

    • Using both values an algorithm can be formed that is more accurate than both

    • This boils down to taking the raw voltage vale and scaling it based on load current then using a curve to guess state of charge. Can also mix in coulomb counting.

    • generally for human (non-computer) SoC calculations (done during flight) a pilot will look at the coulomb count, current, and voltage at a given time to make a judgement calculation

  • Filtering

    • Generally Kalman filters

    • can be applied to improve accuracy due to the noise of sensors

Now for some commercial implementations which may be tangible/easy to use. Note that Mavlink has message structures for this data https://mavlink.io/en/messages/common.html#BATTERY_STATUS :

  • A guide for PX4 with some general information as well: https://docs.px4.io/main/en/config/battery.html

    • Solid open source guide

    • Solid open source codebase

    • Implemented approximation methods:

      • Raw Voltage

      • Voltage with load compensation

        • This does not require current sensing, it simply assumes thr current is higher when the controller is commanding more motor output power from the ESCs.

      • voltage with current integration

    • We do not use PX4 at WARG at the time of writing so of course we cannot out of box use these implementations

  • Gas Gauge ICs

    • Some integrated circuits have their own built in algorithms

  • Ardupilot

    • At the time of writing F23 and to my best knowledge Ardupilot does not feature a state of charge calculator?

      • Though it may support raw coulomb counting approach? This can be setup with some battery parameters through their interface

    • Ardupilot does support numerous power modules for relevant data acquisition

    • You have to use external code if you want to use that raw data to calculate a state of charge with a more complex and accurate algorithm

      • The reason cited for doing this is that SoC is complex, requires multiple accurate sensors, and based on numerous factors so they would rather just present the simplest form of the data to users and allow them to do their own analysis. This approach is extremely sensical for such a project.

    • Ardupilot is used at WARG extensively.

    • Source: https://github.com/ArduPilot/ardupilot/issues/1434 & https://github.com/ArduPilot/ardupilot/issues/12897

      • My source for this is a few Google searches so please correct me if I’m wrong.

Please note that people write PhDs on SoC algorithms. This is not a simple topic. However, getting a valid approximation that’s good enough for WARG purposes is absolutely achievable!