Skip to content

Latest commit

Β 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Smart Cane V3: Safe Temporal Convolutional Reinforcement Learning with Adaptive Control Barrier Functions and Kinematic Attitude Fusion on Resource-Constrained Embedded Platforms

Python 3.10+ PyTorch 2.x TinyML INT8 Hardware RTOS Simulation License: MIT


πŸ‘₯ Authors & Affiliation

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


πŸ“Œ Abstract & Overview

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).

Smart Cane V3 Physical Prototype

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.


🌟 Key Technical Innovations

  1. 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.
  2. 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.
  3. 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.
  4. 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 (PROGMEM Flash: 9.16 KB).
  5. 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.
  6. 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).
  7. 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.
  8. 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.

πŸ“Š Benchmark & Quantitative Results

1. Navigation Policy Performance (120 Evaluation Episodes)

Metric Heuristic Rule-Based Vanilla DQN Double DQN (DDQN) SC-D3QN-PER V2 SC-V3 (Proposed)
Mean Cumulative Reward $-42.6 \pm 18.4$ $-11.8 \pm 9.22$ $+5.06 \pm 5.82$ $+184.2 \pm 2.95$ $\mathbf{+207.4 \pm 1.83}$
95% Confidence Interval $[-45.9, -39.3]$ $[-13.4, -10.2]$ $[+4.02, +6.10]$ $[+183.7, +184.7]$ $\mathbf{[+207.1, +207.7]}$
Collision Rate (%) 36.7% 21.7% 10.8% 0.0% 0.0%
Total Collisions 44 26 13 0 0
Reward Improvement vs V2 --- --- --- Baseline $\mathbf{+12.6%}$ ($p < 0.001$, $d=1.09$)
Execution Latency 52 $\mu$s 309 $\mu$s 215 $\mu$s 273 $\mu$s 1.78 ms (ATmega328P)
Cumulative Reward Comparison Collision Rate Ablation

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.

2. Clinical Fall Detection ROC Analysis (180 Controlled Trials)

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 $<$ 100 ms
Fall Kinematic Signatures Fall Detection ROC Curves

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.

3. Continuous UBM-Cane Calorie Estimation vs. Indirect Calorimetry

Ambulatory Regime Cadence Steps Actual Energy (kcal)$^\dagger$ Fixed Pedometer Piecewise Cadence Proposed UBM-Cane
Slow Walking ($<60$ spm) 45.0 spm 1,350 $42.1 \pm 2.3$ 54.0 ($+28.3%$) 40.5 ($-3.8%$) $\mathbf{42.1 \pm 0.4}$ ($\mathbf{+0.1%}$)
Normal Walking ($60\text{--}100$ spm) 80.0 spm 2,400 $98.3 \pm 3.8$ 96.0 ($-2.3%$) 96.0 ($-2.3%$) $\mathbf{98.5 \pm 0.6}$ ($\mathbf{+0.2%}$)
Brisk Walking ($>100$ spm) 110.0 spm 3,300 $176.8 \pm 6.2$ 132.0 ($-25.3%$) 181.5 ($+2.7%$) $\mathbf{177.0 \pm 1.1}$ ($\mathbf{+0.1%}$)
Mixed Ambulatory Transitions 72.7 spm 2,180 $91.2 \pm 4.1$ 87.2 ($-4.4%$) 82.0 ($-10.1%$) $\mathbf{87.1 \pm 0.8}$ ($\mathbf{-4.4%}$)
Mean Absolute Percentage Error (MAPE) --- --- --- 15.08% 4.72% $\mathbf{1.22%}$
Error Reduction vs. Fixed Pedometer --- --- --- Baseline 68.7% Reduction $\mathbf{91.9%}$ Reduction
Error Reduction vs. Piecewise Model --- --- --- --- Baseline $\mathbf{74.2%}$ Reduction

($^\dagger$ Ground truth measured via continuous breath-by-breath indirect calorimetry using Cosmed K5).


πŸ› οΈ Cyber-Physical Circuit & Hardware Architecture

Arduino Uno Schematic ESP32 IMU Schematic

Fig. 4: (Left) Arduino Uno obstacle avoidance and haptic PWM circuit schematic. (Right) ESP32-WROOM MPU-6050 I2C interface and cloud telemetry circuit.

Complete Hardware Pinout & Wiring Specification

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 ($d_L, d_C, d_R, a^*$)
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 ($>85$ dB at 1 m)
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

πŸ“ Repository Directory Structure

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

πŸš€ Quick Start Guide

1. Environment Setup

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 matplotlib

2. Run Comprehensive Master System Verification

Execute 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.py

Expected 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!
==================================================================

3. Evaluate the UBM-Cane Calorie Engine

python scripts/evaluate_calorie_model.py

4. Run INT8 TinyML Quantization & Concordance Test

python scripts/tinyml_quantizer.py

5. Run Navigation Policy Training & Benchmark Suite

python scripts/run_v3_benchmarks_fast.py

🌐 Wokwi Online Simulation

You 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.

πŸ“œ Citation

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}
}

πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for complete details.
Copyright (c) 2026 Runtime Slayers.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages