AI services#
Since 2.1.0, OpenCarMind EdgeOS runs three small AI models as services: the battery estimator, the battery anomaly detector and the network guard. They are soft real-time jobs. A late result is worth less, never dangerous. The battery page and the network guard page explain each model. This page covers how they share the chip.
OpenCarMind EdgeOS runs its small AI models as services. Since 2.1.0 there are three: the battery estimator, which gives the cell’s state of charge (SoC) and state of health (SoH, now with the partial-charge regressor), the battery anomaly detector, and a network guard for Bluetooth and Wi-Fi. The Health app shows all three in plain words. Each of its pages opens with one status card: a colour, an icon and a word (Good, Learning, Check soon, Act now), a headline such as “Battery is wearing out”, what it means and what to do. The header counts the issues (“All good”, “1 thing to check”), a new issue raises the banner with Open Health, and the Health icon on Home gets an amber or red dot. The scores and counters stay below the card for experts. All services share one worker task at FreeRTOS priority 1, below the screen, the R.E.V learner, the model and the OBD poll, so any of those can preempt a service at any instruction. The worker is admitted by the same response-time analysis as the models. On build 13757fd the board admitted it on core 1 with a worst-case response of 2.00 ms against a 1,000 ms deadline, and the battery estimator’s self-test took 570 µs of its 2 ms budget.
A service reads copies of its inputs and writes its results without a lock, so it cannot hold up the jobs above it. No service acts on power, and none cuts the car link during a drive. When the model misses deadlines, the AI services are the first thing the board slows. On 13757fd the boot health check rated the board good at 68.9 s and released Wi-Fi with 130,623 B of internal RAM free. The estimates themselves, the new ladder rung and the pairing rules are built and being checked on the board now.
Model |
What it does |
Cost per step |
Status |
|---|---|---|---|
Battery charge (SoC): extended Kalman filter on a one-RC cell model |
counts the charge and corrects it with the voltage, once a second |
111 flops and 1 exp, 324 B |
on the board with placeholder parameters. Self-test checked on 13757fd, estimates being checked |
Battery health (SoH): counted capacity and resistance trend |
capacity between two charge anchors, and a DC resistance flag |
a few ops, inside the charge estimator |
on the board, being checked |
Battery health: partial-charge regressor |
SoH from the shape of a deep charge, with no full count |
8 multiply-adds and 16 ops, 100 B |
in the firmware since 2.1.0 (C matches the Mac to 1.3e-7). Needs 10 deep charges of this cell to learn its reference, so not yet seen working on the board |
Battery anomaly detector |
an alarm when 60 s windows stop looking normal for this cell. The Health card names the feature with the largest error in plain words, for example “warms up more than usual” |
under 400 ops a window, 920 B |
in the firmware since 2.1.0 (1.05e-6 against the Mac). Admitted on the board, in its 24 h warm-up |
Network intrusion detector: rotation detector |
scores each 5 s of Bluetooth and Wi-Fi traffic for address-rotation floods |
about 60 integer ops, 552 B per head |
in the firmware since 2.1.0 as the network guard (bit-exact against the Mac). Admitted on the board, in its 2 h shadow |
Pairing rules R1, R2 and R6 |
adapter fingerprint, no silent re-pair, clock jump guard (Pairing safety) |
one compare per link or clock sync, 48 B in NVS |
on the board, being checked |
Residual MLP, 3-state EKF, neural ECM, KalmanNet-lite, pure MLP, general IDS learners |
learned replacements or corrections |
tested, not shipped (see the last dropdown) |
Why the services meet their deadlines and cannot deadlock#
The AI services are soft real-time jobs. A late result is worth less, never dangerous, so a miss is counted and fed to the ladder, never fatal.
Each service is one table entry with a period T, a relative deadline D ≤ T, a CPU budget C and four hooks (main/ai_svc.c, rules in main/ai_svc_core.c). Inside the worker, a release table picks the due service with the shortest deadline first (deadline-monotonic order), and a step runs to its end. One worker instead of one task per service saves a stack and a scheduler slot per service. The cost is that one service can wait for one step of another, and the admission covers that. The worker is analysed as one job:
and its response Rw comes from the same response-time analysis as the models[5], with every measured job above it on that core. If Rw ≤ Dw, every service is released at most once inside any window of length Rw, so the sum of the budgets bounds all the work the worker can face, waiting for another service included. On 13757fd that gave R 2.00 ms on core 1, a margin of 998 ms. Admission runs when the boot health verdict is formed, about 65 s after a start, once the scheduler monitor has measured the other jobs, on the core with the lower measured load first. A service whose self-test takes longer than its budget is refused on its own. If both cores refuse the worker, the board runs without AI services and the Board page says why. In safe mode they stay off.
Overruns do not pile up. A step that runs past its budget may finish, and that service’s next release is skipped. A worker that comes back late runs only the newest release and counts the older ones as skipped. No job ever waits in a queue behind another, so overload cannot build a backlog. make -C tests/host ai simulates the release table under overload (a step 3.5 periods long, budget overruns, a blocked worker) and checks that no service ever has more than one job outstanding, and that the ladder sheds in the order AI services, screen, learner, model, and comes back in reverse.
The worker cannot deadlock either. A deadlock needs a cycle of tasks, each holding something the next one waits for. A service step takes no mutex, waits on no queue, does no I/O and allocates nothing. Its input is a copy of the latest sample in a single-writer seqlock: the reader retries a torn copy at most four times, then keeps the last good one, and never waits. Its result goes out the same way, and the screen reads it without a lock. Rows for storage go into a single-producer, single-consumer ring that drops and counts when full. The board task drains it, since it already owns NVS and the file writes. The only lock on a step’s path is the scheduler monitor’s spinlock, held for a few field copies and never nested. So the worker never holds one resource while it waits for another, and the cycle cannot form through it.
On the Board page, the AI SERVICES card shows each service’s period, deadline, budget, runs, misses, skips and worst response.
Models tested and not shipped#
Model |
What it tried |
Result on the Mac |
Why it is not shipped |
|---|---|---|---|
Residual MLP, phase 2 (10 → 12 tanh → 1, 375 multiply-add equivalents, 984 B) |
learn the EKF’s remaining SoC error |
RMSE 0.49 % middle and 0.21 % late life against the EKF’s 0.53 and 0.33 %, but a worst error of 6.49 % on the forward test against 3.96 %, and NASA 12.1 % against 12.9 % |
better in some places, worse in others. The gate was to beat the EKF everywhere |
Residual MLP, phase 3 (11 → 12 tanh → 1, trained with 120 simulated cells of random OCV shape, capacity, resistance and offset, with a confidence gate) |
make the correction hold on other cells |
the gate switched it off, or it raised the worst error |
it did not pass |
EKF with a third state for the current offset |
cancel a current-sensor offset |
under +0.01C offset, RMSE 5.3 % down to 0.27 to 0.79 %. On clean data the early-life worst error rose from 4.0 % to 7.5 % |
kept for boards whose measured offset is above about 0.003C (0.2 mA on 65 mAh), not the default |
UKF with one or two RC pairs[22] |
a better nonlinear filter |
the same RMSE as the EKF, a higher worst error (5.8 % against 2.5 % in middle life), 360 against 90 multiply-add equivalents |
linearisation was not the limit |
Neural ECM |
a network in place of the cell’s voltage map |
62 % RMSE on the NASA cells |
it learned one cell’s voltage map |
Pure MLP |
SoC straight from V, I and T |
32 % on the NASA cells, worst 10.8 % early in life, and no recovery from a wrong start |
no physics to fall back on |
KalmanNet-lite, a small KalmanNet[23] |
a learned Kalman gain |
worse than the EKF everywhere, for example 3.51 % RMSE early in life against 0.45 %, after a short training run |
it lost on every test |
SoH: GBDT and an 8-unit MLP |
other SoH regressors |
1.96 % and 20 % MAPE in forward cross-validation, against 0.83 % for ridge |
ridge was better and smaller |
Battery anomaly: z-score and online Gaussian as alarms |
simple baselines |
0.245 and 0.126 false alarms per hour on normal data, against a target of 0.05 |
ageing moved them. They only log |
IDS: z-score on all six features, diagonal Gaussian, Mahalanobis, online k-means, Half-Space Trees[24], a tiny autoencoder |
learn normal traffic, block anything unusual |
0.10 to 0.16 false blocks per hour on stable data (the autoencoder 0.009). After a move from a quiet place to a busy one, stuck blocking 33 to 100 % of the time |
they learned the crowd’s size, and the guard against poisoning froze them in the new place |
IDS: paired-adapter signal strength as a clone detector |
spot a second transmitter on the paired address |
0 / 60 clones found at z = 6 |
the public data has no fixed transmitter, so it could not answer. Clones stay with rule R1 |
The two studies came out opposite ways. For the intrusion detector, the general learners failed and a baseline built for one pattern, address rotation, passed. For the battery anomaly detector, the simple baselines failed on ageing drift and the autoencoder passed.