Battery Level Smoothing

I have a saber with a full blade and two single neopixel “crystal chambers”.

One of those chambers I have permanently set to &style_charging in order to have a battery indicator.

The issues s you all know, is that an “off” main blade vs a “all white” main blade pulls power and therefore voltage down substantially… or said in reverse, an off main blade causes an overly optimistic view of battery life.

I wonder if its possible to keep track of total led intensity (in blade.h) where intensity is r+g+b per pixel and then averaged or whatnot to determine the load on the battery when battery_now() is called and bias it accordingly to produce a more realistic view of how long you have to kill the Sith Lords.

J

This is in fact the plan.
A few of the particulars in case someone decides to have a go at implementing this before I do:

  1. we would add a new API to SaberBase that would let each saberbase estimate the number of amps it’s using.
  2. For neopixel blades, this probably means adding up the “r”, the “g” and the “b” separately, then compute I_{red}(voltage) * R_{sum} + I_{green}(voltage) * G_{sum} + I_{blue}(voltage) * B_{sum} + I_{standby} * Leds Where the three “I” functions estimate the current based on the voltage. The reason to do it this way is because the red, green and blue LEDs draw different amounts of current at the same voltage.
  3. We would approximate the battery circuit as an ideal battery in series with an unknown resistor (R_{battery}). When we estimate the battery level, we would add I_{total} * R_{battery} to the estimate, before smoothing it.
  4. When we see a large change in I_{total} (basically, when turning the saber on or off.) we would keep track of the measured voltage before and after the current estimate changed. We should be able to use that to adjust R_{battery}. Basically, we would assume that the voltage of the ideal battery hasn’t changed much and do: V_{measuredBefore} + I_{totalBefore} * R_{battery} = V_{measuredNow} + I_{totalNow} * R_{battery} then solve for R_{battery}, which would give us: \frac{V_{measuredBefore} - V_{measuredNow}}{I_{totalNow} - I_{totalBefore}} = R_{battery}

If this all works out well, then the adjustment of R_{battery} will cancel out most inaccuracies in estimating the current. Finally, we’ll have the battery monitor return the voltage of the ideal battery, which shouldn’t change under load, and it should be the voltage of the battery when it’s not under load, which is what most people are used to seeing anyways.