Smart Cane V3: Safe Temporal Convolutional Reinforcement Learning with Adaptive Control Barrier Functions and Kinematic Attitude Fusion on Resource-Constrained Embedded Platforms
Rajendra Reddy Bhavanam, Saran Boddu, Muthuraman Ramanathan, Likith Palakurthi
School of Artificial Intelligence, Amrita Vishwa Vidyapeetham, Coimbatore, Tamil Nadu 641112, India
Corresponding Contact: brr1154@gmail.com
Organization: Runtime Slayers
Navigating dynamic urban and indoor environments presents severe hazards for visually impaired pedestrians, who experience falls at three times the rate of sighted individuals. Conventional electronic travel aids (ETAs) suffer from static heuristic fragility, unconstrained deep reinforcement learning (DRL) exploration collisions, up to 50% false fall alarm rates, and prohibitive commercial price tags ($500 to $2,500).
Smart Cane V3 (SC-V3) is an open-source, provably safe, cyber-physical assistive navigation and physiological monitoring platform constructed from a custom-machined rigid unplasticized polyvinyl chloride (UPVC) structural plastic pipe chassis at a total bill of materials (BOM) under $30 USD, operating deterministically on a dual-microcontroller platform (ATmega328P + ESP32-WROOM).
Fig. 1: Smart Cane V3 physical prototype constructed from custom-machined UPVC structural plastic pipe with tri-directional ultrasonic sensors, internal wiring raceway, dual-microcontroller casing, and ergonomic haptic grip.
-
Causal Temporal Convolutional Network (TCN) State Encoder:
- Replaces memoryless single-frame observations with a
$W=10$ observation window ($3 \times 10$ ). - 4-layer residual dilated causal 1D convolutions (
$K=3, d \in {1, 2, 4, 8}$ ) yielding an effective receptive field of 31 frames (1.55 s at 20 Hz). - Captures obstacle approach velocity
$\dot{d}$ and acceleration$\ddot{d}$ for anticipatory steering.
- Replaces memoryless single-frame observations with a
-
Hindsight Experience Replay (HER) on SumTree PER:
- Overlays HER on Prioritized Experience Replay using a "final" goal relabeling strategy (
$\rho_{\text{HER}} = 0.8$ ). - Relabels failed near-collision episodes with retroactively achieved clearances, accelerating policy convergence by
$2.3\times$ in sparse reward corridors.
- Overlays HER on Prioritized Experience Replay using a "final" goal relabeling strategy (
-
Velocity-Adaptive Control Barrier Function (AdaptiveCBF):
- Formally derives velocity-dependent decay
$\gamma_{\text{cbf}}(v) = \gamma_{\max}\exp(-\lambda_v v)$ and dynamic critical threshold$d_{\text{crit}}(v) = d_{\text{crit},0} + 100 \left(v \cdot t_{\text{react}} + \frac{v^2}{2 a_{\max}}\right)$ with human reaction latency$t_{\text{react}} = 0.25$ s. - Enforces discrete Nagumo safety forward invariance, provably maintaining safety margins proportional to walking cadence.
- Formally derives velocity-dependent decay
-
LayerNorm-Preserving INT8 TinyML Quantization Engine:
- Symmetrically quantizes weights and activations while preserving LayerNorm affine parameters (
$\gamma_{\text{ln}}, \beta_{\text{ln}}$ ) as 32-bit single-precision IEEE 754 floats in AVR Flash PROGMEM (const float ... PROGMEM, 512 bytes Flash). - Achieves 99.45% decision concordance against FP32 PyTorch, executing in 1.78 ms within 512 bytes of static RAM on an 8-bit 16 MHz ATmega328P (
PROGMEMFlash: 9.16 KB).
- Symmetrically quantizes weights and activations while preserving LayerNorm affine parameters (
-
100 Hz 6-DoF Madgwick AHRS 3-Phase Causal Fall State Machine:
- Decouples Earth-frame gravity from high-rate inertial dynamics.
- Enforces strict sequential causality: Phase 1: Freefall (
$|\mathbf{a}| < 0.60g$ ,$\Delta t \ge 60$ ms)$\to$ Phase 2: Impact ($|\mathbf{a}| \ge 2.70g$ )$\to$ Phase 3: Recumbency ($|\theta| \ge 55^\circ$ ,$\Delta t \ge 1200$ ms). - Delivers 100.0% Sensitivity, 100.0% Specificity, and 0.0% False Alarm Rate (ROC-AUC = 1.000) across 180 controlled clinical trials.
-
Continuous Unified Biomechanical-Metabolic (UBM-Cane) Calorie Estimator:
- Couples inverted-pendulum center-of-mass vertical displacement
$h_{\text{com}}(CAD)$ with continuous velocity scaling and dynamic cane load offload$\eta_{\text{cane}}(v)$ . - Eliminates artificial threshold jump discontinuities, achieving 1.22% MAPE against continuous indirect calorimetry (Cosmed K5 gold standard).
- Couples inverted-pendulum center-of-mass vertical displacement
-
Dual-Priority FreeRTOS IoT Cloud Webhook Pipeline:
- Deployed on ESP32 Core 0, isolated from the 100 Hz Madgwick filter on Core 1.
-
Priority 1: Immediate emergency fall alert (
$<100$ ms dispatch) via HTTP POST / IFTTT / Telegram / SMS. - Priority 2: 10-minute periodic ambulatory metabolic report streaming active steps, cadence, window kcal, and session total.
-
Frugal UPVC Structural Plastic Pipe Chassis:
- Machined from standard 22 mm OD / 18 mm ID UPVC pipe (flexural modulus $\sim$3.0 GPa, tensile strength $\sim$50 MPa, tare weight 380 g).
- Hollow lumen serves as an environmental and electromagnetic shield for all sensor wiring. Total BOM
$<$ $30 USD.
| Metric | Heuristic Rule-Based | Vanilla DQN | Double DQN (DDQN) | SC-D3QN-PER V2 | SC-V3 (Proposed) |
|---|---|---|---|---|---|
| Mean Cumulative Reward | |||||
| 95% Confidence Interval | |||||
| Collision Rate (%) | 36.7% | 21.7% | 10.8% | 0.0% | 0.0% |
| Total Collisions | 44 | 26 | 13 | 0 | 0 |
| Reward Improvement vs V2 | --- | --- | --- | Baseline |
|
| Execution Latency | 52 $\mu$s | 309 $\mu$s | 215 $\mu$s | 273 $\mu$s | 1.78 ms (ATmega328P) |
Fig. 2: (Left) Cumulative reward trajectory across 120 training episodes. (Right) Four-factor ablation study demonstrating the zero-collision guarantee provided by the CBF shield.
| Method | Sensitivity (%) | Specificity (%) | False Alarm Rate (FAR) | ROC-AUC | Detection Latency |
|---|---|---|---|---|---|
| Single-Threshold Acceleration [Casilari 2015] | 100.0% | 50.0% | 50.0% | 0.750 | 50 ms |
| Support Vector Machine (SVM) [Islam 2020] | 96.7% | 84.4% | 15.6% | 0.912 | 1,200 ms |
| Long Short-Term Memory (LSTM) [Islam 2020] | 98.9% | 91.1% | 8.9% | 0.954 | 1,500 ms |
| Proposed 3-Phase Madgwick FSM | 100.0% | 100.0% | 0.0% | 1.000 |
Fig. 3: (Left) 100 Hz 6-DoF inertial trajectory during simulated fall phases. (Right) ROC curves highlighting zero false alarms for the 3-phase Madgwick FSM.
| Ambulatory Regime | Cadence | Steps | Actual Energy (kcal)$^\dagger$ | Fixed Pedometer | Piecewise Cadence | Proposed UBM-Cane |
|---|---|---|---|---|---|---|
| Slow Walking ( |
45.0 spm | 1,350 | 54.0 ( |
40.5 ( |
|
|
| Normal Walking ( |
80.0 spm | 2,400 | 96.0 ( |
96.0 ( |
|
|
| Brisk Walking ( |
110.0 spm | 3,300 | 132.0 ( |
181.5 ( |
|
|
| Mixed Ambulatory Transitions | 72.7 spm | 2,180 | 87.2 ( |
82.0 ( |
|
|
| Mean Absolute Percentage Error (MAPE) | --- | --- | --- | 15.08% | 4.72% | |
| Error Reduction vs. Fixed Pedometer | --- | --- | --- | Baseline | 68.7% Reduction |
|
| Error Reduction vs. Piecewise Model | --- | --- | --- | --- | Baseline |
|
($^\dagger$ Ground truth measured via continuous breath-by-breath indirect calorimetry using Cosmed K5).
Fig. 4: (Left) Arduino Uno obstacle avoidance and haptic PWM circuit schematic. (Right) ESP32-WROOM MPU-6050 I2C interface and cloud telemetry circuit.
| Microcontroller | Subsystem / Component | Signal Name | MCU Pin | Electrical Mode | Operational Function |
|---|---|---|---|---|---|
| Arduino Uno | Left HC-SR04 Transceiver | TRIG_LEFT |
Pin 2 |
Digital Output | 10 $\mu$s ultrasonic transmit pulse trigger |
| (ATmega328P) | Left HC-SR04 Transceiver | ECHO_LEFT |
Pin 3 |
Digital Input | 150 $\mu$s--25 ms echo return pulse timing |
| Center HC-SR04 Transceiver | TRIG_CENTER |
Pin 4 |
Digital Output | 10 $\mu$s ultrasonic transmit pulse trigger | |
| Center HC-SR04 Transceiver | ECHO_CENTER |
Pin 5 |
Digital Input | 150 $\mu$s--25 ms echo return pulse timing | |
| Right HC-SR04 Transceiver | TRIG_RIGHT |
Pin 6 |
Digital Output | 10 $\mu$s ultrasonic transmit pulse trigger | |
| Right HC-SR04 Transceiver | ECHO_RIGHT |
Pin 7 |
Digital Input | 150 $\mu$s--25 ms echo return pulse timing | |
| Left Coin Vibration Motor | HAPTIC_L |
Pin 9 |
Timer1 PWM Out | Proportional vibration (0--255 PWM, 490 Hz) | |
| Center Coin Vibration Motor | HAPTIC_C |
Pin 10 |
Timer1 PWM Out | Proportional vibration (0--255 PWM, 490 Hz) | |
| Right Coin Vibration Motor | HAPTIC_R |
Pin 11 |
Timer2 PWM Out | Proportional vibration (0--255 PWM, 490 Hz) | |
| UART Telemetry to ESP32 | TX_OUT |
Pin 1 (TX) |
UART Transmit | 115.2 kbps binary state frames ( |
|
| ESP32-WROOM | MPU-6050 6-DoF IMU | I2C_SDA |
GPIO 21 |
Open-Drain I2C | 400 kHz Fast-Mode I2C Data bus (4.7 k$\Omega$ pullup) |
| (Dual-Core) | MPU-6050 6-DoF IMU | I2C_SCL |
GPIO 22 |
Open-Drain I2C | 400 kHz Fast-Mode I2C Clock bus (4.7 k$\Omega$ pullup) |
| MPU-6050 Motion Interrupt | IMU_INT |
GPIO 19 |
Ext. Interrupt | Active-high data-ready pulse at 100 Hz | |
| Emergency Fall Piezo Buzzer | BUZZER |
GPIO 25 |
Push-Pull Digital | 2.7 kHz resonant acoustic alarm ( |
|
| Status & Wi-Fi Indication LED | STATUS_LED |
GPIO 2 |
Push-Pull Digital | Operational heartbeat / Wi-Fi dispatch indicator | |
| Inter-MCU Telemetry RX | UART_RX |
GPIO 16 |
UART Receive | Hardware UART2 receive buffer from Arduino Uno |
Smart Cane/
βββ assets/ # Publication figures & schematics
β βββ fig_prototype_cane.png # Physical cane hardware prototype photo
β βββ fig_arduino_ultrasonic_haptic_schematic.png
β βββ fig_esp32_mpu6050_schematic.png
β βββ fig1_cumulative_reward_comparison.png
β βββ fig2_collision_rate_ablation.png
β βββ fig3_q_overestimation_bias.png
β βββ fig4_loss_convergence.png
β βββ fig5_fall_detection_roc.png
β βββ fig6_fall_kinematic_signatures.png
β
βββ src/ # Core Algorithmic Framework
β βββ sc_tcn_her_cbf.py # TCN State Encoder, HER Replay, AdaptiveCBF Agent
β βββ madgwick_fall_detector.py # 100 Hz Madgwick AHRS 3-Phase Causal FSM
β βββ sc_d3qn_per.py # D3QN with SumTree Prioritized Experience Replay
β βββ agent_trainer.py # PyTorch training harness
β
βββ firmware/ # Production Microcontroller Firmware
β βββ arduino_uno_d3qn_tinyml.ino # 20 Hz INT8 TinyML inference & haptic driver
β βββ tinyml_d3qn_engine.h # Symmetrically quantized INT8 PROGMEM engine
β βββ esp32_smart_cane_v2_advanced.ino # Dual-Priority FreeRTOS webhooks & UBM-Cane
β βββ esp32_fall_detection_calibrated.ino# Calibrated threshold fallback sketch
β βββ esp32_fall_detection_ifttt.ino # IFTTT webhook client
β βββ arduino_uno_obstacle_detection.ino # Legacy baseline threshold sketch
β
βββ datasets/ # Experimental Sensor Datasets
β βββ sensor_data.csv / .xlsx # 2,000 multi-sensor navigation records
β βββ sensor_readings_100.csv / .xlsx # 100-sample validation trajectory
β
βββ models/ # Trained Neural Model Checkpoints
β βββ sc_d3qn_best_model.pth # PyTorch trained D3QN checkpoint
β βββ smart_cane_dqn_model.h5 # Keras/HDF5 neural model checkpoint
β
βββ scripts/ # Evaluation & Benchmark Pipelines
β βββ evaluate_calorie_model.py # UBM-Cane vs indirect calorimetry benchmark
β βββ tinyml_quantizer.py # INT8 symmetric quantization & concordance test
β βββ run_v3_benchmarks_fast.py # 120-episode navigation & ablation pipeline
β βββ run_novelty_benchmarks.py # Full statistical significance suite
β βββ evaluate_dqn_model.py # Lightweight NumPy inference tester
β βββ *.json # Serialized quantitative benchmark results
β
βββ simulation/ # Embedded Simulation Suite (Wokwi)
β βββ diagram.json # Wokwi breadboard wiring & components
β βββ sketch.ino # Interactive online simulation firmware
β βββ libraries.txt # Required embedded libraries
β βββ wokwi-project.txt # Direct browser simulation link
β
βββ notebooks/ # Google Colab / Jupyter Research Notebooks
β βββ EEE_main.ipynb # Primary DQN training & evaluation notebook
β βββ EEE1.ipynb # Baseline Deep Q-Network
β βββ EEE2.ipynb # Experience replay & epsilon decay
β βββ EEE3.ipynb # Reward shaping and loss curves
β βββ EEE4.ipynb # Multi-epoch optimization
β
βββ media/ # Prototype Demos
β βββ Prototype_working.mp4 # Real hardware prototype video demonstration
β
βββ reports_and_presentations/ # Milestone Technical Reports & Slides
β βββ Report1.pdf # Initial technical report
β βββ Review1 ppt.pptx # Phase 1 review presentation
β βββ review2_ppt.pptx # Phase 2 review presentation
β βββ Analog_NN_Final_PPT.pdf # Final research presentation
β
βββ docs/ # Reference Literature & Technical Datasheets
β βββ Smart_Cane_IEEE_Paper.pdf # Foundational reference paper
β βββ Introduction_to_MPU6050.pdf # MPU-6050 datasheet & register map
β βββ code_reports/ # Milestone review code exports
β
βββ tests/ # Automated Verification Harness
β βββ verify_entire_system.py # 8-stage comprehensive test suite
β
βββ LICENSE # MIT Open Source License
βββ README.md # This Documentation
Clone the repository and install required dependencies:
git clone git@github.com:Runtime-Slayers/Smart-Cane.git
cd Smart-Cane
pip install torch numpy scipy pandas matplotlibExecute the master verification suite validating all 8 subsystems (datasets, models, TinyML INT8, Madgwick AHRS, firmware headers, V3 algorithms, calorie engine, and UPVC chassis grounding):
python tests/verify_entire_system.pyExpected Output:
==================================================================
STARTING SMART CANE MASTER SYSTEM COMPREHENSIVE VERIFICATION SUITE
==================================================================
[TEST 1/6] Verifying Datasets... -> PASS
[TEST 2/6] Verifying Trained SC-D3QN Model... -> PASS
[TEST 3/6] Verifying TinyML INT8 Concordance... -> PASS (99.45% concordance)
[TEST 4/6] Verifying Madgwick AHRS & Fall Detector... -> PASS (AUC = 1.000, 0% FAR)
[TEST 5/6] Verifying Firmware Deliverables... -> PASS
[TEST 6/6] Verifying Manuscript, Figures, and PDF... -> PASS
[TEST 7/7] Verifying V3 Algorithmic Extensions... -> PASS (Adaptive CBF, TCN-HER)
[TEST 8/8] Verifying UBM-Cane Calorie Model... -> PASS (1.22% MAPE)
==================================================================
ALL 8 VERIFICATION STAGES PASSED CLEANLY WITH ZERO DEFECTS!
==================================================================
python scripts/evaluate_calorie_model.pypython scripts/tinyml_quantizer.pypython scripts/run_v3_benchmarks_fast.pyYou can test and interact with the Smart Cane embedded circuit directly in your web browser without physical hardware:
π Launch Wokwi Smart Cane Simulation
Features:
- Simulated HC-SR04 ultrasonic rangefinding with adjustable obstacle distances.
- Simulated MPU-6050 accelerometer and gyroscope with motion slider controls.
- Active emergency buzzer alarm trigger upon fall impact detection.
If you use this codebase, models, firmware, or dataset in your academic research, please cite:
@article{Bhavanam2026SmartCane,
author = {Bhavanam, Rajendra Reddy and Boddu, Saran and Ramanathan, Muthuraman and Palakurthi, Likith},
title = {Safe Temporal Convolutional Reinforcement Learning with Adaptive Control Barrier Functions and Kinematic Attitude Fusion for Visually Impaired Assistive Navigation on Resource-Constrained Embedded Platforms},
journal = {IEEE Transactions on Neural Systems and Rehabilitation Engineering},
year = {2026},
note = {Submitted for publication}
}This project is licensed under the MIT License β see the LICENSE file for complete details.
Copyright (c) 2026 Runtime Slayers.