Run It
Every instrument is mocked, so the example runs without hardware.
bash
git clone https://github.com/tofupilot/panelscd panelstofupilot run battery-hitesterThe procedure
procedure.yaml
name: Battery HiTesterversion: 1.0.0plugs: - key: meter name: Battery HiTester python: plugs.hitester:BatteryHiTestermain: - key: acir name: Measure through the cycle python: phases.battery_hitester:measure measurements: - key: acir name: AC internal resistance at rest unit: "mΩ" validators: - operator: ">=" expected_value: 8.0 - operator: "<=" expected_value: 12.0 ui: panel: panels/hitester.htmlThe panel
panels/hitester.html
<div class="inst"><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"/><defs><linearGradient id="lcd" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#c3cdb0"/><stop offset="1" stop-color="#a9b597"/></linearGradient></defs><text x="18" y="24" text-anchor="start" style="font: 700 7.5px system-ui, sans-serif; letter-spacing: .14em; fill: #3a4048">BATTERY HITESTER</text><text x="302" y="24" text-anchor="end" style="font: 600 7px ui-monospace, Menlo, monospace; letter-spacing: .04em; fill: #5a6068">AC 1 kHz</text><rect x="16" y="32" width="288" height="118" rx="6" fill="#4a5048"/><rect x="21" y="37" width="278" height="108" rx="3" fill="url(#lcd)"/><g class="lcd"><text x="32" y="52" text-anchor="start" style="font: 700 7px ui-monospace, Menlo, monospace; letter-spacing: .14em; fill: #1b2115">R</text><g class="d7" data-bind="ui.r0" transform="translate(52.0 46.0) skewX(-7)"><rect class="sa" x="2.9" y="0.0" width="12.6" height="4.1" rx="2.0"/><rect class="sd" x="2.9" y="29.9" width="12.6" height="4.1" rx="2.0"/><rect class="sg" x="2.9" y="15.0" width="12.6" height="4.1" rx="2.0"/><rect class="sf" x="0.0" y="2.9" width="4.1" height="13.3" rx="2.0"/><rect class="se" x="0.0" y="17.9" width="4.1" height="13.3" rx="2.0"/><rect class="sb" x="14.3" y="2.9" width="4.1" height="13.3" rx="2.0"/><rect class="sc" x="14.3" y="17.9" width="4.1" height="13.3" rx="2.0"/></g><g class="d7" data-bind="ui.r1" transform="translate(78.5 46.0) skewX(-7)"><rect class="sa" x="2.9" y="0.0" width="12.6" height="4.1" rx="2.0"/><rect class="sd" x="2.9" y="29.9" width="12.6" height="4.1" rx="2.0"/><rect class="sg" x="2.9" y="15.0" width="12.6" height="4.1" rx="2.0"/><rect class="sf" x="0.0" y="2.9" width="4.1" height="13.3" rx="2.0"/><rect class="se" x="0.0" y="17.9" width="4.1" height="13.3" rx="2.0"/><rect class="sb" x="14.3" y="2.9" width="4.1" height="13.3" rx="2.0"/><rect class="sc" x="14.3" y="17.9" width="4.1" height="13.3" rx="2.0"/></g><g class="d7" data-bind="ui.r2" transform="translate(105.0 46.0) skewX(-7)"><rect class="sa" x="2.9" y="0.0" width="12.6" height="4.1" rx="2.0"/><rect class="sd" x="2.9" y="29.9" width="12.6" height="4.1" rx="2.0"/><rect class="sg" x="2.9" y="15.0" width="12.6" height="4.1" rx="2.0"/><rect class="sf" x="0.0" y="2.9" width="4.1" height="13.3" rx="2.0"/><rect class="se" x="0.0" y="17.9" width="4.1" height="13.3" rx="2.0"/><rect class="sb" x="14.3" y="2.9" width="4.1" height="13.3" rx="2.0"/><rect class="sc" x="14.3" y="17.9" width="4.1" height="13.3" rx="2.0"/></g><g class="d7" data-bind="ui.r3" transform="translate(131.6 46.0) skewX(-7)"><rect class="sa" x="2.9" y="0.0" width="12.6" height="4.1" rx="2.0"/><rect class="sd" x="2.9" y="29.9" width="12.6" height="4.1" rx="2.0"/><rect class="sg" x="2.9" y="15.0" width="12.6" height="4.1" rx="2.0"/><rect class="sf" x="0.0" y="2.9" width="4.1" height="13.3" rx="2.0"/><rect class="se" x="0.0" y="17.9" width="4.1" height="13.3" rx="2.0"/><rect class="sb" x="14.3" y="2.9" width="4.1" height="13.3" rx="2.0"/><rect class="sc" x="14.3" y="17.9" width="4.1" height="13.3" rx="2.0"/></g><g class="dp on" transform="translate(71.7 46.0) skewX(-7)"><rect x="0" y="29.9" width="4.1" height="4.1" rx="1.4"/></g><text x="288" y="80" text-anchor="end" style="font: 700 15px system-ui, sans-serif; letter-spacing: .14em; fill: #1b2115">mΩ</text><text x="32" y="106" text-anchor="start" style="font: 700 7px ui-monospace, Menlo, monospace; letter-spacing: .14em; fill: #1b2115">V</text><g class="d7" data-bind="ui.v0" transform="translate(52.0 100.0) skewX(-7)"><rect class="sa" x="2.9" y="0.0" width="12.6" height="4.1" rx="2.0"/><rect class="sd" x="2.9" y="29.9" width="12.6" height="4.1" rx="2.0"/><rect class="sg" x="2.9" y="15.0" width="12.6" height="4.1" rx="2.0"/><rect class="sf" x="0.0" y="2.9" width="4.1" height="13.3" rx="2.0"/><rect class="se" x="0.0" y="17.9" width="4.1" height="13.3" rx="2.0"/><rect class="sb" x="14.3" y="2.9" width="4.1" height="13.3" rx="2.0"/><rect class="sc" x="14.3" y="17.9" width="4.1" height="13.3" rx="2.0"/></g><g class="d7" data-bind="ui.v1" transform="translate(78.5 100.0) skewX(-7)"><rect class="sa" x="2.9" y="0.0" width="12.6" height="4.1" rx="2.0"/><rect class="sd" x="2.9" y="29.9" width="12.6" height="4.1" rx="2.0"/><rect class="sg" x="2.9" y="15.0" width="12.6" height="4.1" rx="2.0"/><rect class="sf" x="0.0" y="2.9" width="4.1" height="13.3" rx="2.0"/><rect class="se" x="0.0" y="17.9" width="4.1" height="13.3" rx="2.0"/><rect class="sb" x="14.3" y="2.9" width="4.1" height="13.3" rx="2.0"/><rect class="sc" x="14.3" y="17.9" width="4.1" height="13.3" rx="2.0"/></g><g class="d7" data-bind="ui.v2" transform="translate(105.0 100.0) skewX(-7)"><rect class="sa" x="2.9" y="0.0" width="12.6" height="4.1" rx="2.0"/><rect class="sd" x="2.9" y="29.9" width="12.6" height="4.1" rx="2.0"/><rect class="sg" x="2.9" y="15.0" width="12.6" height="4.1" rx="2.0"/><rect class="sf" x="0.0" y="2.9" width="4.1" height="13.3" rx="2.0"/><rect class="se" x="0.0" y="17.9" width="4.1" height="13.3" rx="2.0"/><rect class="sb" x="14.3" y="2.9" width="4.1" height="13.3" rx="2.0"/><rect class="sc" x="14.3" y="17.9" width="4.1" height="13.3" rx="2.0"/></g><g class="d7" data-bind="ui.v3" transform="translate(131.6 100.0) skewX(-7)"><rect class="sa" x="2.9" y="0.0" width="12.6" height="4.1" rx="2.0"/><rect class="sd" x="2.9" y="29.9" width="12.6" height="4.1" rx="2.0"/><rect class="sg" x="2.9" y="15.0" width="12.6" height="4.1" rx="2.0"/><rect class="sf" x="0.0" y="2.9" width="4.1" height="13.3" rx="2.0"/><rect class="se" x="0.0" y="17.9" width="4.1" height="13.3" rx="2.0"/><rect class="sb" x="14.3" y="2.9" width="4.1" height="13.3" rx="2.0"/><rect class="sc" x="14.3" y="17.9" width="4.1" height="13.3" rx="2.0"/></g><g class="d7" data-bind="ui.v4" transform="translate(158.1 100.0) skewX(-7)"><rect class="sa" x="2.9" y="0.0" width="12.6" height="4.1" rx="2.0"/><rect class="sd" x="2.9" y="29.9" width="12.6" height="4.1" rx="2.0"/><rect class="sg" x="2.9" y="15.0" width="12.6" height="4.1" rx="2.0"/><rect class="sf" x="0.0" y="2.9" width="4.1" height="13.3" rx="2.0"/><rect class="se" x="0.0" y="17.9" width="4.1" height="13.3" rx="2.0"/><rect class="sb" x="14.3" y="2.9" width="4.1" height="13.3" rx="2.0"/><rect class="sc" x="14.3" y="17.9" width="4.1" height="13.3" rx="2.0"/></g><g class="d7" data-bind="ui.v5" transform="translate(184.6 100.0) skewX(-7)"><rect class="sa" x="2.9" y="0.0" width="12.6" height="4.1" rx="2.0"/><rect class="sd" x="2.9" y="29.9" width="12.6" height="4.1" rx="2.0"/><rect class="sg" x="2.9" y="15.0" width="12.6" height="4.1" rx="2.0"/><rect class="sf" x="0.0" y="2.9" width="4.1" height="13.3" rx="2.0"/><rect class="se" x="0.0" y="17.9" width="4.1" height="13.3" rx="2.0"/><rect class="sb" x="14.3" y="2.9" width="4.1" height="13.3" rx="2.0"/><rect class="sc" x="14.3" y="17.9" width="4.1" height="13.3" rx="2.0"/></g><g class="dp on" transform="translate(98.2 100.0) skewX(-7)"><rect x="0" y="29.9" width="4.1" height="4.1" rx="1.4"/></g><text x="288" y="134" text-anchor="end" style="font: 700 15px system-ui, sans-serif; letter-spacing: .14em; fill: #1b2115">V</text></g><g class="lamps" data-bind="ui.comp"><circle class="hi" cx="214" cy="176" r="6" stroke="#2a2e33"/><circle class="in" cx="246" cy="176" r="6" stroke="#2a2e33"/><circle class="lo" cx="278" cy="176" r="6" stroke="#2a2e33"/></g><text x="214" y="194" text-anchor="middle" style="font: 700 7px system-ui, sans-serif; letter-spacing: .1em; fill: #3a4048">HI</text><text x="246" y="194" text-anchor="middle" style="font: 700 7px system-ui, sans-serif; letter-spacing: .1em; fill: #3a4048">IN</text><text x="278" y="194" text-anchor="middle" style="font: 700 7px system-ui, sans-serif; letter-spacing: .1em; fill: #3a4048">LO</text><text x="18" y="180" text-anchor="start" style="font: 600 6.5px system-ui, sans-serif; letter-spacing: .14em; fill: #5a6068">COMP ON · RANGE 30 mΩ · 4-TERMINAL</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); } .lcd { --on: #1b2115; --off: #a4b08f; } .lamps circle { fill: #3a3f45; transition: fill .15s; } .lamps[data-value=HI] .hi { fill: #ff5a4f; } .lamps[data-value=IN] .in { fill: #38e07a; } .lamps[data-value=LO] .lo { fill: #ffb02e; }</style>The phase
phases/battery_hitester.py
"""Reads the AC internal resistance meter clipped to the pack through acycle. `ui.r*` and `ui.v*` drive its LCD digits and `ui.comp` its comparatorlamps against the 8.0-12.0 mΩ window. The run records the resistance at rest."""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)WINDOW_MOHM = (8.0, 12.0)def measure(ui, measurements, meter): rest = [] for _ in range(meter.length()): mohm, volts, step = meter.read() show(ui, "r", f"{mohm:5.3f}") show(ui, "v", f"{volts:7.4f}") ui.comp = "HI" if mohm > WINDOW_MOHM[1] else "LO" if mohm < WINDOW_MOHM[0] else "IN" if step == "REST": rest.append(mohm) time.sleep(0.1) measurements.acir = round(sum(rest) / len(rest), 3) time.sleep(1.5)The mocked instrument
plugs/hitester.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 BatteryHiTester(_Replay): """Mock AC internal resistance meter (1 kHz, 4-terminal). Replace it with your meter's driver.""" def read(self): """[AC internal resistance in mΩ, voltage in V, cycler step]""" s = self._next() return [s["acir_mohm"], s["voltage"], s["step"]]