A deterministic 500 Hz haptic hand stabilizer on the Arduino UNO R4 WiFi (Renesas RA4M1)
Status disclosureEvery result on this page comes from Software-in-the-Loop (SIL) simulation. The simulation runs the unmodified firmware control code against a physics model and a model of a human operator. The firmware compiles for the Arduino UNO R4 WiFi but has never run on silicon: I don't own the board or the rail yet. The hardware data folders in the repository are empty on purpose. Nothing here is hardware data.
Core Idea & MotivationWhen your hand is tense or tired, precise work gets harder in a way you can feel. Your grip tightens and small tremors come through. Poise is a carriage on a linear rail that pushes back with programmable viscous drag. It gets heavier when your grip and tremor rise and lighter when you relax.
The name comes from the poise, the CGS unit of dynamic viscosity. Viscous drag is the only thing the device produces, and a steady hand is what it's for. The code keeps the working name SymbioGrip.
The research question is narrow and testable: does adapting damping to grip and tremor beat a well-chosen fixed damper? In simulation the answer is currently no. This page explains why, and why hardware is the only way to settle it.
How It Works- Mechanics: a carriage on a 180 mm MGN12 rail, belt-driven through 20-tooth GT2 pulleys by a 12 V, 4.4:1 brushed gearmotor.
- Position: a 600 PPR encoder on the idler pulley, decoded in hardware as 4× quadrature: 60, 000 counts per meter, or 16.67 µm per count.
- Grip: an FSR 402 in the handle, buffered by the RA4M1's internal op-amp and read by the 14-bit ADC.
- Drive: a TB6612FNG H-bridge at 20 kHz PWM, above human hearing, limited to 1.2 A.
- Task: steer a stylus through a 2.7 mm sinusoidal wire-loop corridor without touching the walls.
- Calm cue: a 0.1 Hz breathing pacer on the board's LED matrix (4 s in, 6 s out).
The firmware treats the RA4M1 as a set of linked peripherals rather than a polling loop. Peripherals decide when things are sampled and actuated. loop() only handles telemetry, commands and the LED pacer.
GPT0 overflow (500 Hz) --ELC--+--> GPT1: encoder count latched into GTCCRA (ELSR0 = event 93)
+--> ADC14: AN002 scan, 4x hardware average (ELSR8 = event 93)
ADC0_SCAN_END --NVIC priority 1--> control ISR -> HapticEngine::step()
+--> GPT3 GTCCRC (buffered, applied at next PWM trough)
+--> AIN1/AIN2/STBY via PCNTR3 (atomic set/reset)- GPT0 (pacer): 96, 000 counts at PCLKD = 48 MHz, which is exactly 2.000 ms per tick. One time base for everything.
- ELC (Event Link Controller): ELSR0 and ELSR8 are both set to event 93 (GPT0 overflow). One timer edge latches the encoder and starts the ADC, with no CPU involvement, so the sampling instant has no software jitter.
- GPT1 (quadrature decoder): 4× phase counting on P105/P104. GTUPSR = 0x6900 and GTDNSR = 0x9600 are checked by a
static_assertagainst the device-header bit positions. The GPT digital noise filter runs at PCLKD/64. - GPT3 (20 kHz PWM): symmetric triangle mode, GTPR = 1200, started in the same GTSTR write as GPT0. Since 96, 000 = 40 × 2, 400, every control tick lands on a PWM trough, so grip is sampled while the bridge isn't switching. GTIOC3B (P112) also hardware-captures wire-loop contact edges.
- OPAMP0 + ADC14: the op-amp is a unity-gain follower (A1/A2 to A3 = AN002). The ADC converts at 14 bits with 4× hardware averaging.
- NVIC: the control ISR runs at priority 1, above
millis()(8) and the LED matrix (12). - POEG: latches the PWM output LOW if a tick overruns, so a lost tick makes the motor go limp instead of misbehaving.
- WDT: a 10.92 ms timeout, refreshed only by the control ISR. It resets the MCU if the control path stops.
- Boot self-test: reads back every configured register and checks the internal reference, a DAC-to-ADC loopback and the op-amp. The motor driver's STBY pin stays LOW until all of it passes.
The static worst-case bound for the linked control ISR is 72.9 µs of a 250 µs budget, with no loops and no double-precision calls. The control law alone (HapticEngine::step()) is 33.6 µs. ADC conversion time and interrupt-disabled sections in core code can't be bounded statically, so the firmware reports them at runtime in its #STAT lines.
Serial1is the D0/D1 header. WiFiS3 talks to the ESP32-S3 overSerial2.- AGT0 is already taken by
millis(). - D7 has no external-interrupt line, so contacts are captured on GTIOC3B instead.
- The core sets OFS0 = 0xFFFFFFFF, so the IWDT can't be started. The firmware uses the register-started WDT.
- The DAC can't be routed internally to the ADC, so the self-test loopback goes through the shared pin.
It's the same C++ file (admittance.h) in the firmware, the simulation and the desktop bench.
- Velocity: backward difference of encoder counts, then a 2nd-order Butterworth low-pass at 25 Hz.
- Tremor: acceleration high-passed at 5 Hz, then its RMS over 0.25 s. It counts only above a 0.25 m/s² floor, which is 4σ above encoder quantization noise.
- Grip: inverse FSR divider model F = S·a/(1−a), 20 ms smoothing, normalized over 2.5–8 N.
- Damping: difficulty (0.72 × grip + 0.28 × tremor) mapped to 4.5–21.5 N·s/m, slew-limited, then passed through a critically damped 36 rad/s smoother.
- Drive: force F = −B·v, converted to current, then to voltage with back-EMF feed-forward, then to PWM duty. Below 4 mm/s the bridge coasts so the carriage doesn't buzz.
The motor is wired to a person's hand, so it must never inject energy. 19 automated checks pass, and the script exits with an error if any one fails:
- Filter coefficients match fresh scipy designs to within 4.4 × 10⁻¹⁰.
- The sampled-data passivity condition (generalized Colgate–Schenkel) holds over the whole damping range: 10.0 N·s/m required vs 15.25 available.
- Closed loop with a compliant simulated hand, true motor work is −1130 mJ (adaptive) and −1484 mJ (fixed). The device only absorbs energy.
- Deliberately unstable test: with back-EMF over-compensated 2.5×, the motor generates +64 mJ without the passivity controller and −11 mJ with it. The first version of this test failed (+35.5 mJ). I fixed it and documented the failure in the repo.
Ten matched simulation seeds per condition. A = motor off, B = fixed damping at 13 N·s/m, C = adaptive.
- Causal grip model (primary): movement time 3.61 / 5.04 / 4.55 s; lateral error SD 0.439 / 0.361 / 0.412 mm.
- Null grip (grip unrelated to the task): movement time 3.65 / 5.04 / 4.19 s; lateral error SD 0.498 / 0.354 / 0.461 mm.
- Dose-matched (B fixed at C's average, 8.22 N·s/m): movement time 3.61 / 4.56 / 4.55 s; lateral error SD 0.439 / 0.413 / 0.412 mm.
What this means:
- Damping trades speed for smoothness. A fixed damper cut longitudinal jerk by 1.66 m/s³ and lateral error by 0.090 mm, but added 1.5 s of movement time.
- Adaptive mode beats the fixed damper at 13 N·s/m on speed only because it applies less damping on average. Against a fixed damper set to that same average, the two are indistinguishable.
- A second round tested nine more controllers (dual-band tremor impedance, fractional dampers, virtual inertia). None beat the fixed-damper curve on accuracy. The protocol was pre-registered, and its SHA-256 hash was saved before the runs.
- Dual-band impedance lowered jerk by about 15% at equal speed. That is only significant under a statistical correction chosen after the data were seen, and the report labels it that way.
- I also found a real flaw: adaptive mode mistakes a firm resting grip for difficulty. With a steady 8 N grip it is about 1 s slower than the matched fixed damper.
Seeds are not participants: these p-values measure robustness to simulated noise, not effects in people. The simulated human is a model I designed, so it can't answer whether real grip tension carries task information. That is what the hardware is for.
[OPTIONAL: INSERT IMAGE from repo — telemetry/results/figures/fig2_controls.png — caption: "Adaptive minus fixed damping across all simulated conditions"]
Code & Repository StructureRepository: github.com/smtherer/SymbioGrip
firmware/src/ config.h, ra4m1_registers.h, admittance.h, src.ino, fabric_types.h
firmware/sim/ plant.h (4 kHz physics), operator_model.h, test_bench.cpp, hil_bridge.cpp,
innovation_engine.h, innovation_lab.cpp, arm_probe.cpp
telemetry/scripts/ run_pipeline.py, verify_control_theory.py, evaluator.py, plot_benchmarks.py,
hil_trackpad_bench.py, serial_logger.py, arm_cycle_budget.py
docs/ HardwareFabric.md, CONTROL_THEORY.md, CALIBRATION.md, InnovationResearch.mdTo reproduce every software result, run this (about 40 s; needs MSVC, g++ or clang++):
pip install -r requirements.txt
python telemetry/scripts/run_pipeline.pyThe desktop bench (hil_trackpad_bench.py) puts a real person in the loop using a mouse or pen. It is not hardware-in-the-loop, and its data are labelled that way.
- Bring-up: run the boot self-test and the motor-polarity test, read the
#STATtiming lines (overruns, max ISR time, max latency), and check encoder counts per mm against a ruler. - Confirm unverified silicon behavior: GPT1 capture on the ELC event, the triangle-PWM output polarity, POEG forcing the output LOW, the 14-bit average-of-4 ADC scale, and the WDT timeout.
- Plant identification: measure the motor constant, resistance, friction and reflected mass with step tests. Passivity needs Kt²/R ≥ 9.1 N·s/m; the datasheet estimate is 14.25. Then update
config.hand re-run the 19 checks. - Fix the known flaw: add grip-baseline tracking so a firm resting grip isn't read as difficulty, and pre-register the change before testing it.
- Human study: pre-registered before any data are collected; adaptive vs. dose-matched fixed damper; primary outcomes are wall contacts and lateral error; block-randomized and blinded; N ≥ 12 with informed consent (and parental consent for minors). All data will be published, including if the hypothesis fails.







Comments