Skip to content
RHUDHRESHPublic

About

Remaining-range estimator for Indian electric cars and two-wheelers: physics, a learned residual correction, conformal intervals and a driver-facing app.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Range 2.0 — will your EV make it?

Remaining-range estimator for Indian electric cars and two-wheelers. It gives a driver one plain verdict and gives a researcher every input behind it.

Stack: Next.js 16 (App Router) · React 19 · TypeScript · Tailwind v4 · scikit-learn (model training)

Lineage: this is the current app for cars and two-wheelers. The earlier four-wheeler estimator is hera-range-estimator; the two-wheeler estimator is hera-scoot.

Physics traction (Fiori / VT-CPEM) + India-first HVAC + a residual gradient booster + split-conformal intervals, wrapped in an app that gives a driver a straight answer and gives a researcher every knob behind it.

Four surfaces, all first-class:

  • Drive — one plain-language verdict, a Google map with the route shaded by energy burn, a charging plan, a round-trip check, and a side-by-side comparison against other cars.
  • Simulate — steps the car along the real route in simulated time, integrating battery power as it goes. Change speed or climate mid-drive and the arrival projection moves with you; the trace chart shows the running divergence from the plan.
  • Lab — one-at-a-time sweeps, two-factor grids, tornado sensitivity, scenario diffing, the full derived-quantity catalogue, and CSV export.
  • Garage — every vehicle parameter is editable, with live steady-state feedback as you change it. Edited vehicles save to the browser and travel with the planning request.
  • Methods — how each stage works and where it stops being trustworthy.

Every result also carries a Why this number panel: a counterfactual waterfall from a benign reference drive down to the real answer, attributing kilometres to terrain, speed, heat, air-conditioning, payload, wind and the learned correction. The chain is sequential, so the bars sum exactly — there is no unexplained remainder.

Design decisions on the driver-facing side are grounded in the range-interface literature; the survey and the changes it produced are in docs/literature-review.md.

Quick start

npm install
npm run dev

Open http://localhost:3000. Try the three presets: a Delhi city run, the Mumbai–Pune ghat, and Delhi–Jaipur (which needs charging stops).

The trained model is committed in models/, so the app runs without Python. Python is needed only to retrain it; see The model.

Configuration

.env.local holds the Google Maps Platform keys:

NEXT_PUBLIC_GOOGLE_MAPS_API_KEY=...   # browser — Maps JavaScript API, necessarily public
GOOGLE_MAPS_API_KEY=...               # server — Routes, Places, Elevation

The browser key is exposed by design and should carry HTTP referrer restrictions. The server key is used only from route handlers and should ideally be a separate key restricted by IP.

APIs required on the Cloud project: Maps JavaScript API, Routes API, Places API (New), Maps Elevation API.

Everything degrades rather than breaking. If a Google API is disabled, over quota, or unauthorised, the app falls back to OSRM (routing), Nominatim (places) and Open-Meteo (elevation), and reports the downgrade in the "Where these numbers came from" panel instead of hiding it.

What changed from 1.0

The 1.0 engine assigned a single trip-mean speed to every route point. That made the inertia term identically zero and evaluated aerodynamic drag at ⟨v⟩ rather than over the real distribution — a systematic underestimate of roughly Var(v)/⟨v⟩², which on a mixed Delhi–Jaipur run measures 15% of the aero term. 2.0 builds a real per-segment speed profile from routing step durations.

Also new in the engine:

  • Altitude-dependent air density via the barometric formula. Mumbai–Pune sheds measurable drag as it climbs; 1.0 held density constant and missed it.
  • Wind projected onto the direction of travel, rather than fetched and ignored.
  • Per-segment energy accounting, which is what lets the map shade the route and the SOC curve integrate along it.
  • Soak decay — the hot-cabin pull-down penalty now fades with a time constant instead of taxing a four-hour drive for its whole length.
  • Force components are reported at the wheel, with battery traction energy kept separate.

Two-wheelers

Seventeen vehicles: eleven cars and six electric two-wheelers. Scooters are not modelled as small cars — three differences are structural:

  • No climate system. The entire HVAC branch is skipped, which is why two-wheelers are far less weather-sensitive than cars. On a small-pack car, air-conditioning can be a third of trip energy.
  • The rider is the payload. A car's kerb figure already carries about two people; a scooter's carries none, so a 75 kg rider on a 111 kg scooter is 40% of the moving mass.
  • The learned correction is switched off. The residual model was fitted on synthetic car cycles (1650-2150 kg, CdA 0.78-0.94). Extrapolating it to a 190 kg scooter produced corrections larger than the physics itself, so two-wheelers run on physics alone with a proportional interval and say so.

Road surface and traffic

Two additions make the road itself matter:

  • Surface roughness multiplies rolling resistance. Rolling dominates at low speed, so a broken surface costs far more in traffic than on an expressway — on a Delhi run, smooth-to-broken moves consumption 154 to 186 Wh/km.
  • Stop-start losses are modelled statistically, because ~1 km sampling cannot resolve individual braking events. Each stop sheds kinetic energy at a net battery cost of ½mv²·(1/η_drive − η_regen). Stop density is derived from each segment's own speed by default, so a jam gets many stops and an expressway almost none.

This is what finally makes regenerative braking quality matter. Swinging regen from weak to strong on the same route is worth 4.1% in free flow and 18.6% in gridlock — which is the physically correct shape, and something the earlier engine could not express at all.

The model

The residual model is a stacked tree ensemble — gradient boosting, a random forest, and extremely randomised trees, blended by weights fitted on out-of-fold predictions — trained on the Vehicle Energy Dataset (Oh, LeBlanc & Peng, IEEE T-ITS 2020, Apache-2.0): 1 Hz OBD-II logs from real personal EVs and PHEVs in Ann Arbor, including HV battery current, voltage and state of charge.

Reproduce it with:

python scripts/prepare_ved.py
python scripts/train_residual.py

Three decisions shape what it learns:

  • The target is the residual, not consumption. Consumption is what the force balance is for. The model only ever sees what the physics missed.
  • PHEVs count while their engine is off. Zero fuel rate and zero RPM means the car is electric, which multiplies usable data roughly tenfold over the three pure EVs.
  • Measured climate load is removed from the target. VED is a cold-climate dataset where the heater dominates. Leaving it in would train something that only works in Michigan.

Scored on the latest 20% of trips, chronologically split so no trip appears on both sides:

MAE, Wh/km
Predict the mean (baseline) 72.6
Physics alone 88.4
Single best model + physics 62.6
Ensemble + physics 60.8

The ensemble cuts physics-only error by 31.3%. Diversifying the blend, rather than letting the optimiser collapse onto its single best member, was worth a further 1.8 Wh/km on data neither had seen.

Conformal intervals hold up: the nominal 80% band covers 90% of held-out trips and the 90% band 92% — wider than strictly needed, which is the safe direction for a range estimate.

The domain gate, and why it matters more than the accuracy

VED covers -15 to 18 °C and trips of 3 to 15 km. India is 25-45 °C, and this app routinely plans hundreds of kilometres. That is not a gap a bigger model closes.

A tree model does not fail loudly outside its training range — it silently returns whatever its outermost leaf says. Asked about a 144 km Mumbai-Pune run at 29 °C it confidently added +64 Wh/km and produced a 238 km-wide interval. So the training domain is exported with the model and checked at inference. Outside it, the app falls back to physics alone with a proportional band and says so in plain language, naming the features that fell out of range.

That gate is what keeps every number trustworthy: outside the training domain the app runs on physics alone and says so. Indian driving data is the next unlock, not more trees.

What the exercise did establish is a first real validation of the physics engine: against measured battery energy it lands within 88 Wh/km, and roughly a third of that error is learnable structure rather than noise.

Roadmap

  • Indian driving data. The residual model is trained on real measured trips from Michigan. Indian trip logs switch it on for Indian roads; the domain gate already keeps every estimate inside what the data supports.
  • Measured vehicle coefficients. Replace estimated CdA, Crr, usable kWh and HVAC ratings (each carries a confidence tag in the Methods table) with measured values.
  • Calibrated intervals everywhere. Extend conformal calibration beyond the single global quantile, including outside the training domain.
  • Stop-start dynamics. Sample faster than one point per kilometre to capture braking cycles in city traffic.

Stack

Next.js 16 App Router (Turbopack), React 19, TypeScript, Tailwind v4. Charts are hand-rolled SVG on theme tokens — no chart library — so light, dark, and the map share one palette.

The engine is isomorphic. The residual model is 16 KB gzipped and ships to the browser as a bundled import, so lib/ contains no filesystem access and the same code runs on the server for /api/plan and in the browser for the simulator and the attribution waterfall. That is what makes the simulator interactive: a physics step costs microseconds, and the seventeen model runs behind "Why this number" happen locally in a few milliseconds rather than over the network.


Built by Rhudhresh R

About

Remaining-range estimator for Indian electric cars and two-wheelers: physics, a learned residual correction, conformal intervals and a driver-facing app.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages