This project extends a navigation app and onboard computer for electric vehicles with functionality to estimate driving range along a given route. Range depends strongly on speed, so consumption and travel time vary between routes. We use consumption data for the Tesla Roadster together with GPS-derived speed data, but the methods generalize to other vehicles and routes.
Task:
Model energy consumption as a function of speed using the fitted relation
with coefficients
Implement consumption(v) that works with scalars and NumPy arrays, and plot
How I did it:
Implemented the formula in roadster.py and added a plotting routine in script_part1a.py.
Solution:
Function in roadster.py; plots in script_part1a.py.
Task:
Load route data (speed_anna.npz, speed_elsa.npz) and plot speed vs. distance. Interpolate a continuous speed profile using velocity(x, route).
How I did it:
Used roadster.load_route to read data and scatter-plot raw samples. Then evaluated velocity densely to plot the interpolated curve.
Solution:
Functions in roadster.py; plots in script_part1b.py.
Note:
velocity uses PCHIP interpolation, which passes through all data points and ensures monotone, smooth behavior between them.
Task:
Estimate travel time along a route by integrating
Implement time_to_destination(x, route, n) using the trapezoidal rule.
How I did it:
Coded a manual trapezoidal integration (no NumPy/SciPy integrators) and tested convergence by increasing (n) until results stabilized to the nearest minute.
Solution:
Function in roadster.py.
Task:
Estimate total energy usage along a route by integrating
Implement total_consumption(x, route, n).
How I did it:
Combined consumption with interpolated speeds from velocity, then applied trapezoidal integration over the route length.
Solution:
Function in roadster.py.
Task:
Given
Newton’s method: define
then iterate
Implementation notes
-
Use
time_to_destination(x, route, n)for$T(x)$ andvelocity(x, route)for$v(x)$ . -
Initial guess:
where
- Clamp iterates to
$[0,L]$ and stop when
with a hard cap on iterations.
- Accuracy depends on the trapezoidal resolution
$n$ insidetime_to_destinationand the Newton stopping tolerance.
Solution:
Function distance(T, route) in roadster.py.
Task. Given battery charge C (Wh), find the range x km along a route.
Total energy up to distance x is:
We solve for x such that
then update
Solution:
Function reach(C, route) in roadster.py.
Task:
Simulate travel along a route where speed depends on both position and time of day, based on historical traffic data. The aim is to estimate arrival time given a start time, and generate route files that can be used as input for earlier functions (e.g. reach from Part 3b).
How I did it:
Used the provided function route_nyc(t, x) in route_nyc.py, which returns the expected speed (km/h) at time t [hours of day] and position x [km] along a 60 km route.
Task:
Update the plotting script to show simulated trips along the NYC route with different start times. Each trip is represented by a curve from start time
How I did it:
Modified script_part4b.py to simulate and plot two runs:
- Start at 04:00
- Start at 09:30
The curves illustrate how traffic conditions at different times of day affect travel along the route.
Solution:
Code updates in script_part4b.py.

