Skip to content
Tactiverge

School/□ Systems Engineer/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.

About 45 min · 3 goals · Checked by automated tests

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

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

Can't use the interactive? Read a description instead

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.

3.Checkpoint: guided practice

Check what you just discovered before going on. Hints appear after a wrong answer.

Practice 1 · a fresh version every time

A robot's power draw was logged every 10 s: 8, 15, 15, 4, 8, 10 W. Estimate the energy used over the log with the trapezoid rule, in joules.

J

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

Open BUILD 007: Design a Smart Greenhouse →

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

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.

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.

6.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 2

Convert 5400 J to watt-hours.

Wh

Practice 3

A 10 Wh battery powers a device averaging 2.5 W. Ideal run time, in hours?

h

Practice 4

Power samples 0, 10, 10, 0 W every 60 s. Trapezoid energy, in joules?

J

Practice 5

A log sampled once every 10 s shows a smooth 3 W, but the robot has a 15 W motor that starts for 0.5 s every 20 s. What is the main risk?

7.Predict

A log reads 0, 10, 10, 0 W at 60 s intervals. What energy does the trapezoid rule give?

Guess first. Being wrong here is how the surprise works.

8.Reflect

Concepts: Numerical integration and differentiation · Electrical power and energy budgets