Lite / Engineering Complex Systems / Week 7
Energy budget from a power log
A delivery robot logged its power draw every second for a whole route. Will its 10 Wh battery last two routes? Code the integral and find out.
Why should I care?
Battery-powered systems live or die by their energy budget. The data arrive as a log, not a formula, so the integral is a few lines of code. Getting the units and the sample rate right is where real projects go wrong.
- Write a function that integrates a sampled power log with the trapezoid rule.
- Convert between joules, watt-hours and battery charge in mAh at a given voltage.
- Judge whether the logging rate was fast enough to capture spikes.
Safety: Work with logs and simulations only. Do not open or short battery packs to measure them.
Predict
A log reads 0, 10, 10, 0 W at 60 s intervals. What energy does the trapezoid rule give?
- 600 J
- 1200 J
- 1800 J
- 20 J
Guess first, then reveal
60 × (0/2 + 10 + 10 + 0/2) = 1200 J. The ends count half: the power ramps up over the first minute and down over the last.
Discover
Open the Code Lab. Write trapezoid(samples, h) that returns h × (sum − first/2 − last/2). Test it on [0, 10, 10, 0] with h = 60 (expect 1200). Then generate a power log, for example 20 + 15·sin(t) sampled every 0.5 s for 6 s, and compare with the exact 120.6 J. Halve the step and check the error ratio.
What the interactive shows (text version)
This lesson's activity is writing a short trapezoid-rule function in the Code Lab. The expected results: [0, 10, 10, 0] W at 60 s spacing gives 1200 J; 20 + 15·sin t over 6 s gives close to the exact 120.6 J, with the error falling by about four each time the step halves.
Understand
From samples to joules
With power samples p₀ … pₙ every h seconds: E ≈ h·(p₀/2 + p₁ + … + pₙ₋₁ + pₙ/2) joules. Ten lines of code, but test it on a case you can do by hand first (a constant power gives P × total time exactly).
Units that trip people up
1 Wh = 3600 J. Battery capacity in mAh is charge: a 2000 mAh cell at a nominal 3.7 V stores about 2 × 3.7 = 7.4 Wh. Divide energy by average power for run time: 10 Wh at an average 2.5 W lasts 4 h, ignoring the usable fraction and temperature effects.
Is the log fast enough?
A motor starting can draw several times its running power for a fraction of a second. If you sample once a second you may miss the spike or catch it by luck. Compare the integral at your rate with every second sample: a big change means the log is too coarse. Spikes also matter for peak current, even when their energy is small.
Explain it another way
Intuitive
A power log is a tally of how hard the battery is being worked, moment by moment. Adding up 'how hard × how long' gives how much it has been drained.
Technical
E = Σ ½(pᵢ + pᵢ₊₁)h. Margin: design for E_route × safety factor (often 1.2–1.5) plus reserve, below the usable battery energy.
Mathematical
If noise in each sample is independent with spread σ, the noise in the trapezoid total grows only like σ·h·√n, much less than n·σ·h: integration averages noise, the opposite of differentiation.
Applied
Drone flight controllers integrate measured current continuously to estimate remaining battery and trigger return-to-home before the reserve is used.
Worked example 1
A route uses 5400 J. How many Wh is that, and how many routes fit in a 10 Wh battery with 20% kept in reserve?
5400/3600 = 1.5 Wh. Usable: 8 Wh. 8/1.5 = 5.33, so 5 complete routes.
Common mix-ups
Battery mAh tells you the energy directly.
✓ Multiply by voltage: Wh = Ah × V.A slow log just gives a slightly blurred answer.
✓ It can miss short events completely, with large errors in energy and peak current.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Estimate one day's energy for a device you own (phone, laptop or a sensor) by guessing its power in each activity and the time spent. Build the log in a spreadsheet at one-hour steps, integrate it, and compare with its battery capacity.
Reflect
Why does integrating noisy samples give a steadier answer than differentiating them?
Write your answer on paper or in your own notes. Lite never stores what you write.