An energy report for a robot can be lower than expected even when every exported power sample is present. The problem can occur when a job integrates each file separately and adds the results. Each file contains intervals between its own samples. The interval from the final sample of one file to the first sample of the next file is absent from both calculations. A report assembled from separate files needs a policy for that boundary.
This example uses four invented power readings. It measures neither a robot's consumption nor the accuracy of a physical power sensor. The fixture isolates how file boundaries affect a composite trapezoidal estimate. The timestamp is elapsed seconds and the signal is power in watts, so the resulting area is in watt-seconds, equivalent to joules.
Use the sample timestamps
The readings are 10 W at 0 s, 14 W at 1 s, 18 W at 3 s, and 22 W at 4 s. The trapezoidal estimate treats power between adjacent observations as changing linearly. For each interval, multiply its duration by the mean of its endpoint power readings. The three intervals last one, two, and one seconds. Their contributions are 12 J, 32 J, and 20 J. The running estimate at the four timestamps is 0 J, 12 J, 44 J, and 64 J.
import numpy as np
t = np.array([0., 1., 3., 4.])
power = np.array([10., 14., 18., 22.])
increments = np.diff(t) * (power[:-1] + power[1:]) / 2
energy = np.r_[0., np.cumsum(increments)]
assert energy.tolist() == [0., 12., 44., 64.]
assert np.trapezoid(power, t) == energy[-1]
This calculation was executed with NumPy 2.5.2. SciPy documents an equivalent cumulative calculation, cumulative_trapezoid(power, t, initial=0). Here initial=0 aligns the energy estimate with the first timestamp. Leaving that argument at its default returns one fewer result along the integration axis. The cumulative values describe energy since the first sample, so an application that resumes with an existing energy total must add that total separately.
See what a split removes
Suppose file A contains the first two readings and file B contains the last two. Running the same integration on file A gives 12 J. Running it on file B gives 20 J. Their sum is 32 J. The missing contribution runs from 1 s to 3 s and evaluates to 2 ? (14 + 18) / 2 = 32 J. The magnitude of the error depends on both the elapsed time and the two power readings at the split.
first = np.trapezoid(power[:2], t[:2])
second = np.trapezoid(power[2:], t[2:])
bridge = np.trapezoid(power[1:3], t[1:3])
assert (first, second, bridge) == (12., 20., 32.)
assert first + bridge + second == 64.
Using a constant one-second sample period in the full trace also gives a different answer. That assumption produces 12 J, 16 J, and 20 J, for a total of 48 J. It treats the two-second interval as one second. Use explicit timestamps when the acquisition or export process can produce irregular spacing. Convert timestamp units before integration and preserve enough precision to represent each actual interval.
Carry the previous sample and the cumulative total
For a continuous trace divided across storage files, retain the final accepted timestamp and power reading from the preceding chunk. Prepend that sample to the new samples used for the numerical calculation. The first new increment then covers the boundary. Add the cumulative energy through the retained sample to the new cumulative values. If the numerical result includes a row for the retained sample, discard that row from the new output to avoid recording it twice.
The retained state also needs enough identity to distinguish robot runs and power channels. A chunk for a different run or meter starts its own cumulative series. Chunk identifiers and the timestamp range provide a way to recognize a duplicate input during a retry. Save the accepted position and cumulative energy together so a resumed job can determine which intervals it has already counted. Otherwise, a retry could add the same boundary a second time.
Check whether a boundary should be integrated
A storage rollover inside a continuous recording can preserve a valid interval. A clock reset, a logger outage, or a run change can interrupt the measurement. Decide how much elapsed time the application can bridge and record any intervals it excludes. A recorded gap makes the coverage of the estimate visible to whoever compares energy totals later. Using the mean of the endpoints across an outage assumes a power trajectory that was never observed.
Check timestamp order before estimating energy. The SciPy trapezoid documentation specifies that the coordinates are used in their supplied order. A negative time difference can therefore subtract area. Investigate time resets and out-of-order records using the source timestamps and sequence data. For repeated readings at an overlapping file boundary, resolve the duplicate according to the export contract before carrying the final sample forward. Conflicting power readings at the same timestamp deserve an explicit result from ingestion.
An end-to-end test can run the same short trace as a single file, then split it at each eligible boundary. The result should agree at every emitted timestamp within the chosen numeric tolerance whenever the measurement remains continuous. Add an outage and check that the job records the gap and excludes the unsupported bridge. Together those cases verify both energy accumulation and the rules governing when an interval belongs in the estimate.
Sources checked November 28, 2026
SciPy, scipy.integrate.cumulative_trapezoid
https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.cumulative_trapezoid.html
SciPy, scipy.integrate.trapezoid
https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.trapezoid.html
Illustration. AI-generated concept showing a highlighted interval between two groups of power readings on a robot test-bench display.