Battery Cycler Channel

The front panel of a battery cycler channel: terminal voltage and current on a fluorescent display, the CC and CV mode, the direction, and the overcurrent trip.

STATIONCLI/PROCEDUREBattery Cycler Channel

Charge and discharge

PASS00:22.76Charge and discharge (1/1)Passed

Run It

Every instrument is mocked, so the example runs without hardware.

bash
git clone https://github.com/tofupilot/panelscd panelstofupilot run battery-cycler

The procedure

procedure.yaml
name: Battery Cycler Channelversion: 1.0.0plugs:  - key: cycler    name: Battery cycler    python: plugs.cycler:BatteryCyclermain:  - key: cycle    name: Charge and discharge    python: phases.battery_cycler:charge_and_discharge    measurements:      - key: cc_charge_current        name: Constant-current charge current        unit: "A"        validators:          - operator: ">="            expected_value: 49          - operator: "<="            expected_value: 51      - key: cv_voltage        name: Voltage held in CV        unit: "V"        validators:          - operator: ">="            expected_value: 54.5          - operator: "<="            expected_value: 54.7    ui:      panel: panels/cycler.html

The panel

panels/cycler.html
<div class="inst" data-bind="ui.ocp"><svg viewBox="0 0 320 210" role="img"><defs><linearGradient id="fp" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#e6e8eb"/><stop offset="1" stop-color="#c9cdd2"/></linearGradient><linearGradient id="win" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#000" stop-opacity=".55"/><stop offset=".14" stop-color="#000" stop-opacity="0"/></linearGradient></defs><rect x="1" y="1" width="318" height="208" rx="10" fill="url(#fp)" stroke="#9aa1a8" stroke-width="2"/><circle cx="12" cy="12" r="3.2" fill="#aeb4ba" stroke="#9aa1a8"/><circle cx="308" cy="12" r="3.2" fill="#aeb4ba" stroke="#9aa1a8"/><circle cx="12" cy="198" r="3.2" fill="#aeb4ba" stroke="#9aa1a8"/><circle cx="308" cy="198" r="3.2" fill="#aeb4ba" stroke="#9aa1a8"/><text x="18" y="24" text-anchor="start" style="font: 700 7.5px system-ui, sans-serif; letter-spacing: .14em; fill: #3a4048">BATTERY CYCLER</text><text x="302" y="24" text-anchor="end" style="font: 600 7px ui-monospace, Menlo, monospace; letter-spacing: .04em; fill: #5a6068">CH 1</text><rect x="16" y="32" width="288" height="152" rx="6" fill="#050807" stroke="#2f3533" stroke-width="2"/><rect x="16" y="32" width="288" height="152" rx="6" fill="url(#win)"/><g class="vfd"><g class="d7" data-bind="ui.v0" transform="translate(46.0 44.0) skewX(-7)"><rect class="sa" x="4.4" y="0.0" width="19.2" height="6.2" rx="3.1"/><rect class="sd" x="4.4" y="45.8" width="19.2" height="6.2" rx="3.1"/><rect class="sg" x="4.4" y="22.9" width="19.2" height="6.2" rx="3.1"/><rect class="sf" x="0.0" y="4.4" width="6.2" height="20.3" rx="3.1"/><rect class="se" x="0.0" y="27.3" width="6.2" height="20.3" rx="3.1"/><rect class="sb" x="21.8" y="4.4" width="6.2" height="20.3" rx="3.1"/><rect class="sc" x="21.8" y="27.3" width="6.2" height="20.3" rx="3.1"/></g><g class="d7" data-bind="ui.v1" transform="translate(86.6 44.0) skewX(-7)"><rect class="sa" x="4.4" y="0.0" width="19.2" height="6.2" rx="3.1"/><rect class="sd" x="4.4" y="45.8" width="19.2" height="6.2" rx="3.1"/><rect class="sg" x="4.4" y="22.9" width="19.2" height="6.2" rx="3.1"/><rect class="sf" x="0.0" y="4.4" width="6.2" height="20.3" rx="3.1"/><rect class="se" x="0.0" y="27.3" width="6.2" height="20.3" rx="3.1"/><rect class="sb" x="21.8" y="4.4" width="6.2" height="20.3" rx="3.1"/><rect class="sc" x="21.8" y="27.3" width="6.2" height="20.3" rx="3.1"/></g><g class="d7" data-bind="ui.v2" transform="translate(127.1 44.0) skewX(-7)"><rect class="sa" x="4.4" y="0.0" width="19.2" height="6.2" rx="3.1"/><rect class="sd" x="4.4" y="45.8" width="19.2" height="6.2" rx="3.1"/><rect class="sg" x="4.4" y="22.9" width="19.2" height="6.2" rx="3.1"/><rect class="sf" x="0.0" y="4.4" width="6.2" height="20.3" rx="3.1"/><rect class="se" x="0.0" y="27.3" width="6.2" height="20.3" rx="3.1"/><rect class="sb" x="21.8" y="4.4" width="6.2" height="20.3" rx="3.1"/><rect class="sc" x="21.8" y="27.3" width="6.2" height="20.3" rx="3.1"/></g><g class="d7" data-bind="ui.v3" transform="translate(167.7 44.0) skewX(-7)"><rect class="sa" x="4.4" y="0.0" width="19.2" height="6.2" rx="3.1"/><rect class="sd" x="4.4" y="45.8" width="19.2" height="6.2" rx="3.1"/><rect class="sg" x="4.4" y="22.9" width="19.2" height="6.2" rx="3.1"/><rect class="sf" x="0.0" y="4.4" width="6.2" height="20.3" rx="3.1"/><rect class="se" x="0.0" y="27.3" width="6.2" height="20.3" rx="3.1"/><rect class="sb" x="21.8" y="4.4" width="6.2" height="20.3" rx="3.1"/><rect class="sc" x="21.8" y="27.3" width="6.2" height="20.3" rx="3.1"/></g><g class="dp on" transform="translate(116.7 44.0) skewX(-7)"><rect x="0" y="45.8" width="6.2" height="6.2" rx="2.1"/></g><text x="290" y="94" text-anchor="end" style="font: 700 22px system-ui, sans-serif; letter-spacing: .14em; fill: #7ff5d6">V</text><g class="irow"><g class="d7" data-bind="ui.i0" transform="translate(46.0 108.0) skewX(-7)"><rect class="sa" x="4.4" y="0.0" width="19.2" height="6.2" rx="3.1"/><rect class="sd" x="4.4" y="45.8" width="19.2" height="6.2" rx="3.1"/><rect class="sg" x="4.4" y="22.9" width="19.2" height="6.2" rx="3.1"/><rect class="sf" x="0.0" y="4.4" width="6.2" height="20.3" rx="3.1"/><rect class="se" x="0.0" y="27.3" width="6.2" height="20.3" rx="3.1"/><rect class="sb" x="21.8" y="4.4" width="6.2" height="20.3" rx="3.1"/><rect class="sc" x="21.8" y="27.3" width="6.2" height="20.3" rx="3.1"/></g><g class="d7" data-bind="ui.i1" transform="translate(86.6 108.0) skewX(-7)"><rect class="sa" x="4.4" y="0.0" width="19.2" height="6.2" rx="3.1"/><rect class="sd" x="4.4" y="45.8" width="19.2" height="6.2" rx="3.1"/><rect class="sg" x="4.4" y="22.9" width="19.2" height="6.2" rx="3.1"/><rect class="sf" x="0.0" y="4.4" width="6.2" height="20.3" rx="3.1"/><rect class="se" x="0.0" y="27.3" width="6.2" height="20.3" rx="3.1"/><rect class="sb" x="21.8" y="4.4" width="6.2" height="20.3" rx="3.1"/><rect class="sc" x="21.8" y="27.3" width="6.2" height="20.3" rx="3.1"/></g><g class="d7" data-bind="ui.i2" transform="translate(127.1 108.0) skewX(-7)"><rect class="sa" x="4.4" y="0.0" width="19.2" height="6.2" rx="3.1"/><rect class="sd" x="4.4" y="45.8" width="19.2" height="6.2" rx="3.1"/><rect class="sg" x="4.4" y="22.9" width="19.2" height="6.2" rx="3.1"/><rect class="sf" x="0.0" y="4.4" width="6.2" height="20.3" rx="3.1"/><rect class="se" x="0.0" y="27.3" width="6.2" height="20.3" rx="3.1"/><rect class="sb" x="21.8" y="4.4" width="6.2" height="20.3" rx="3.1"/><rect class="sc" x="21.8" y="27.3" width="6.2" height="20.3" rx="3.1"/></g><g class="d7" data-bind="ui.i3" transform="translate(167.7 108.0) skewX(-7)"><rect class="sa" x="4.4" y="0.0" width="19.2" height="6.2" rx="3.1"/><rect class="sd" x="4.4" y="45.8" width="19.2" height="6.2" rx="3.1"/><rect class="sg" x="4.4" y="22.9" width="19.2" height="6.2" rx="3.1"/><rect class="sf" x="0.0" y="4.4" width="6.2" height="20.3" rx="3.1"/><rect class="se" x="0.0" y="27.3" width="6.2" height="20.3" rx="3.1"/><rect class="sb" x="21.8" y="4.4" width="6.2" height="20.3" rx="3.1"/><rect class="sc" x="21.8" y="27.3" width="6.2" height="20.3" rx="3.1"/></g><g class="dp on" transform="translate(157.3 108.0) skewX(-7)"><rect x="0" y="45.8" width="6.2" height="6.2" rx="2.1"/></g></g><text x="290" y="158" text-anchor="end" style="font: 700 22px system-ui, sans-serif; letter-spacing: .14em; fill: #7ff5d6">A</text><g class="ann" data-bind="ui.cc"><text x="34" y="176" text-anchor="start" style="font: 700 8px ui-monospace, Menlo, monospace; letter-spacing: .06em">CC</text></g><g class="ann" data-bind="ui.cv"><text x="76" y="176" text-anchor="start" style="font: 700 8px ui-monospace, Menlo, monospace; letter-spacing: .06em">CV</text></g><g class="ann" data-bind="ui.chg"><text x="118" y="176" text-anchor="start" style="font: 700 8px ui-monospace, Menlo, monospace; letter-spacing: .06em">CHG</text></g><g class="ann" data-bind="ui.dsg"><text x="166" y="176" text-anchor="start" style="font: 700 8px ui-monospace, Menlo, monospace; letter-spacing: .06em">DSG</text></g><g class="ocpann"><g class="ann" data-bind="ui.ocp"><text x="214" y="176" text-anchor="start" style="font: 700 8px ui-monospace, Menlo, monospace; letter-spacing: .06em">OCP</text></g></g><g class="ann" data-bind="ui.out"><text x="262" y="176" text-anchor="start" style="font: 700 8px ui-monospace, Menlo, monospace; letter-spacing: .06em">OUT</text></g></g><text x="18" y="200" text-anchor="start" style="font: 600 6.5px system-ui, sans-serif; letter-spacing: .14em; fill: #5a6068">0–60 V · ±100 A · 4-WIRE SENSE</text></svg></div><style>  .inst { width: min(560px, 100%); margin: 0 auto; }  .inst svg { display: block; width: 100%; height: auto; }  .inst text { font-family: system-ui, sans-serif; }  .dp rect { fill: var(--off); }  .dp.on rect, .dp[data-value=true] rect { fill: var(--on); }  .led circle { fill: #2a2f35; transition: fill .15s; }  .led[data-value=true] circle { fill: var(--led, #38e07a); }  .ann text { fill: var(--off); transition: fill .15s; }  .ann[data-value=true] text { fill: var(--on); }  .d7 rect { fill: var(--off); transition: fill .08s; }  .d7[data-value="0"] :is(.sa, .sb, .sc, .sd, .se, .sf) { fill: var(--on); }  .d7[data-value="1"] :is(.sb, .sc) { fill: var(--on); }  .d7[data-value="2"] :is(.sa, .sb, .sd, .se, .sg) { fill: var(--on); }  .d7[data-value="3"] :is(.sa, .sb, .sc, .sd, .sg) { fill: var(--on); }  .d7[data-value="4"] :is(.sb, .sc, .sf, .sg) { fill: var(--on); }  .d7[data-value="5"] :is(.sa, .sc, .sd, .sf, .sg) { fill: var(--on); }  .d7[data-value="6"] :is(.sa, .sc, .sd, .se, .sf, .sg) { fill: var(--on); }  .d7[data-value="7"] :is(.sa, .sb, .sc) { fill: var(--on); }  .d7[data-value="8"] :is(.sa, .sb, .sc, .sd, .se, .sf, .sg) { fill: var(--on); }  .d7[data-value="9"] :is(.sa, .sb, .sc, .sd, .sf, .sg) { fill: var(--on); }  .d7[data-value="-"] :is(.sg) { fill: var(--on); }  .d7[data-value="E"] :is(.sa, .sd, .se, .sf, .sg) { fill: var(--on); }  .d7[data-value="U"] :is(.sb, .sc, .sd, .se, .sf) { fill: var(--on); }  .d7[data-value="r"] :is(.se, .sg) { fill: var(--on); }  .vfd { --on: #7ff5d6; --off: #0f2620; }  .inst[data-value=true] .irow, .ocpann { --on: #ff6b6b; }</style>

The phase

phases/battery_cycler.py
"""Charges and discharges the pack on the cycler. The panel shows thechannel's front: `ui.v*` and `ui.i*` drive its 7-segment digits, `ui.cc`,`ui.cv`, `ui.chg`, `ui.dsg` and `ui.ocp` its annunciators. The run recordsthe constant-current charge current and the voltage held in CV."""import timedef show(ui, prefix, text):    """One 7-segment glyph per character, decimal points left to the panel."""    for k, ch in enumerate(c for c in text if c != "."):        setattr(ui, f"{prefix}{k}", "_" if ch == " " else ch)def charge_and_discharge(ui, measurements, cycler):    cc, cv = [], []    for _ in range(cycler.length()):        s = cycler.read()        volts, amps = s["voltage"], s["current"]        show(ui, "v", f"{volts:5.2f}")        show(ui, "i", ("-" if amps < -0.05 else " ") + f"{min(abs(amps), 99.9):4.1f}")        ui.cc = s["step"] in ("CC", "DSG")        ui.cv = s["step"] == "CV"        ui.chg = amps > 0.05        ui.dsg = amps < -0.05        ui.ocp = amps < -85 or amps > 60        ui.out = abs(amps) > 0.05        if s["step"] == "CC":            cc.append(amps)        if s["step"] == "CV":            cv.append(volts)        time.sleep(0.1)    measurements.cc_charge_current = round(sum(cc) / len(cc), 2)    measurements.cv_voltage = round(sum(cv) / len(cv), 2)    time.sleep(1.5)

The mocked instrument

plugs/cycler.py
"""Mock instrument replaying a simulated 13S NMC, 50 Ah pack through a CC-CVcharge, a rest and a 75 A discharge."""import mathCELL_OFFSETS = [-0.42, 0.18, 0.05, -0.12, 0.5, -0.3, 0.1, 0.32, -0.05, -0.5, 0.24, 0.0, -0.2]SENSORS = [("CELL 1", -1.5), ("CELL 4", 0.0), ("CELL 7", 1.2), ("BUSBAR", 4.6),           ("CELL 10", -0.8), ("CELL 13", 0.4), ("INLET", -2.0), ("OUTLET", 0.9)]STEPS = [("CC", 0, 18), ("CV", 18, 28), ("REST", 28, 33), ("DSG", 33, 53), ("REST", 53, 60)]CYCLE_S, DT = 60, 0.3def _lerp(a, b, x):    return a + (b - a) * min(1.0, max(0.0, x))def _ease(x):    return 0.5 - 0.5 * math.cos(math.pi * min(1.0, max(0.0, x)))def _wob(t, k):    return math.sin(t * k) * 0.5 + math.sin(t * k * 2.3) * 0.25def pack_state(t):    """The simulated 13S NMC, 50 Ah pack at cycle time t (s): CC 50 A to    54.6 V, CV to 2.5 A, rest, 75 A discharge with a current spike, rest."""    bleed = False    if t < 18:        x = t / 18        soc, i = _lerp(20, 78, x), 50 + _wob(t, 3) * 0.4        v, temp, delta = 46.2 + 8.4 * x ** 1.6, _lerp(24, 31, x), _lerp(8, 14, x)    elif t < 28:        x = (t - 18) / 10        soc, i = _lerp(78, 99, _ease(x)), 2.5 + 47.5 * math.exp(-3.2 * x)        v, temp = 54.6, _lerp(31, 33, x)        delta = _lerp(14, 26, _ease(x * 1.4)) - _lerp(0, 8, (x - 0.6) / 0.4)        bleed = True    elif t < 33:        x = (t - 28) / 5        soc, i, v = 99, 0.0, _lerp(54.6, 54.0, _ease(x))        temp, delta, bleed = _lerp(33, 30, x), _lerp(18, 10, x), x < 0.6    elif t < 53:        x = (t - 33) / 20        spike = -17 * math.sin(math.pi * (t - 38) / 2.5) if 38 < t < 40.5 else 0.0        soc, i = _lerp(99, 22, x), -75 + spike + _wob(t, 2.7) * 0.6        v = 53.4 - 5.2 * x - 1.6 * x ** 6 + spike * 0.03        temp, delta = _lerp(30, 50, x ** 0.9), _lerp(10, 58, x ** 2.2)    else:        x = (t - 53) / 7        soc, i, v = 22, 0.0, _lerp(46.6, 47.4, _ease(x))        temp, delta = _lerp(50, 47, x), _lerp(58, 44, x)    step = next((name for name, a, b in STEPS if a <= t < b), "REST")    temps = [temp + o * (0.4 + (temp - 24) / 30) + _wob(t + k, 1.1) * 0.15 for k, (_, o) in enumerate(SENSORS)]    cells = [v / 13 + o * delta / 1000 for o in CELL_OFFSETS]    balancing = [bleed and o > 0.15 for o in CELL_OFFSETS]    acir = 9.6 * (1 - 0.006 * (temp - 25)) + 0.02 * math.sin(t * 2.3)    return {"step": step, "soc": soc, "voltage": v, "current": i, "temperatures": temps,            "cells": cells, "balancing": balancing, "acir_mohm": acir}class _Replay:    def __init__(self):        self.t = 0.0    def length(self):        return int(CYCLE_S / DT)    def _next(self):        state = pack_state(self.t)        self.t += DT        return stateclass BatteryCycler(_Replay):    """Mock battery cycler channel. Replace it with your cycler's driver."""    def read(self):        """The channel and the pack it reads: step, SOC %, V, A (charge        positive), cell voltages and balancing from the BMS."""        return self._next()

Run your first test in minutes