Accumulating angle from a gyro: use the real dt and read the effect of bias

Practise integrating a single-axis rotation rate using the real time intervals, compare the hold-start value with the trapezoid, and read the angle accumulated from bias, with worksheets, answers, images and diagrams.

Last updated:

Concept image of an angle-accumulation study desk with an IMU module, a microcontroller board, four blank cards, a dial gauge, a clock and a drone with its propellers removed
AI-generated conceptual mock-up; not a screenshot or a device model with confirmed support

Start the angle accumulation example · Back to the angle filtering and time chapter

Objectives and the baseline used

Practise converting a rotation rate into an angle change, using the real timestamp and being able to explain the assumptions used between points. Suitable for reading logs and checking the prediction step before IMU fusion. Use a PC calculator or paper; no board is needed. Read angles over time and IMU calibration first

The photorealistic image at the head of the chapter was generated with AI, using the IMU module, blank cards, dial and clock as conceptual media; it is not a certified angle-measuring device. All the numbers are fictitious and single-axis . There is no real angle to compare against, and no SciPy, firmware or IMU experiment was run.

Specify the initial value and how to compute between points

A rate in deg/s multiplied by a time in seconds gives an angle in degrees, e.g. 10 deg/s × 0.02 s = 0.2° . Accumulation gives the change in angle, while the reference angle needs theta0: in this exercise it is declared to start at 5° , and 5° was not derived from the first gyro point. Without an initial reference, only the relative change in angle under the model can be reported.

Define dt = (t_now − t_previous) / 1000 for timestamps in ms from the same clock/session, then choose a method:

  • Hold the start-of-interval value: delta_left = rate_previous × dt is a rectangle area; it uses a constant-rate model from the start of the interval until just before the next point
  • Trapezoid: delta_trap = (rate_previous + rate_now) × dt / 2 uses the average rate of the two ends, the area under a straight-line model between points

Both methods accumulate theta_now = theta_previous + delta and can give different results. Choosing a method is an assumption about the interval that was not measured at all, not evidence that the real motion is constant or linear. The trapezoid can be computed only once the end-of-interval data exists; it is not available before that sample arrives.

The SciPy cumulative_trapezoid documentation describes trapezoidal accumulation and passing x coordinates instead of a fixed spacing. This chapter computes by hand; if you use it with the API, pass time in seconds and separate theta0 from initial: the API documentation accepts initial as 0 or None; do not use initial = 5 to represent the starting angle. Add theta0 to the accumulated result afterwards, in the declared unit.

Accumulating four points with the real intervals

Given: the timestamps of every new sample are in the same clock/session with no reset; the intervals are deliberately unequal as in the table; it is not claimed that there are other samples between points; use degrees, seconds and deg/s; start theta0 = 5° for both methods.

Sample (ms) rate (deg/s)
0 0
10 10
30 20
70 10
Interval (ms) dt (s) delta start-of-interval (°) delta trapezoid (°)
0→10 0.01 0 0.05
10→30 0.02 0.2 0.3
30→70 0.04 0.8 0.6

Interval 10→30 ms: dt = 0.02 s the hold-start method gives 10 × 0.02 = 0.2° while the trapezoid gives (10 + 20) × 0.02 / 2 = 0.3° . Do not use dt = 0.01 s for every row just because the first two points are 10 ms apart.

Sample (ms) theta start-of-interval (°) theta trapezoid (°)
0 5 5
10 5 5.05
30 5.2 5.35
70 6 5.95

At 70 ms the accumulated change in angle is 1° or 0.95° depending on the method, not an angle starting from zero. If dt = 0.01 s were forced for all three intervals, the trapezoid theta would be 5.35° instead of 5.95° from the real intervals. The difference between the two methods does not say which is closer to the real angle, because the exercise does not declare a real angle or motion path.

Graphs of four rotation-rate points with the hold-start and straight-line models, a graph of accumulated angle for the two methods, and a diagram for checking time units and initial values

Matplotlib from fictitious numbers. The lines between rates show the chosen model, while the line joining theta should be read as the sequence of end-of-interval results, not a waveform or a measured real angle. Open the full-size angle accumulation and bias graph

A constant bias accumulates with elapsed time

A separate exercise: add a constant offset of +1 deg/s to every original rate, giving 1, 11, 21, 11 deg/s, keeping theta0 and the same trapezoid method. The accumulated result changes from the original set by offset × elapsed_time because every interval adds an area of 1 × dt.

At t = 10, 30, 70 ms the new trapezoid results are 5.06, 5.38, 6.02° , differing from the original set by +0.01, +0.03, +0.07° , respectively. These numbers show the effect of an offset declared in the model; they are not a bias measured from a chip or a value that should be set in practice. Subtracting the known offset exactly as in the exercise returns the original result, but with real data you must still check the provenance and the compensation status before subtracting.

Three-point averaging does not remove a constant bias just because the result looks smoother. A wrong initial value can also shift the whole set of angles. Separate bias, noise, units and axis direction before choosing a fix. Read IMU calibration and go on to Complementary Filter when you need to explain prediction and angle correction with another type of data.

Check the clock, missing data and the single-axis boundary

When dt ≤ 0, check duplicates, ordering, clock and resets before accumulating; do not invent a dt just to make the formula run. If the clock/session changes, split the segment and state a new initial reference that is either known or unknown. Read data age at the point of use

A long interval with known timestamps can still have its area computed under the model, but if data is missing and the rate in between is unknown, bridging with the end value does not recover the motion that was lost. Do not let an assumption become a confirmed result. If the operating policy does not allow bridging the interval, mark it unresolved and keep the raw data and interval boundaries separate from the intervals that can be verified.

After filtering the rate, check the time the result refers to and the time it is available; do not pair results that refer to different intervals without declaring how the times are matched. This exercise has no filtered input and no gaps, so it does not endorse a policy for those cases.

Single-axis scalar accumulation is not a three-dimensional attitude estimator. Directly integrating each body gyro axis and calling the result Euler roll/pitch/yaw does not work in every pose; a frame definition and a suitable orientation update are needed, following the limitations in the IMU fusion chapter . This set of numbers is not used to tune a controller or certify flight.

Practice steps and basic advice

  1. Read the angle accumulation set guide . Make a copy of the blank angle accumulation planning sheet and specify the axis, the clock/session unit and theta0 with its source
  2. Do the angle accumulation and bias exercise . Write the real dt and the area for each interval, separating the change in angle from the angle after adding the initial value.
  3. Add the offset as in the exercise, then check the difference against elapsed time before opening the angle accumulation answers . State the conclusions that still require a real reference.
  4. If you extend to hardware, keep the raw data, config, timestamps, reference and the compensation status following the real-board preparation guide . Matching the answer numbers does not replace an IMU measurement result.

Start by getting the units and time right before changing the calculation method. Keep full values before rounding, and do not conclude accuracy from a smooth graph. There are no new scores in the existing assessment form, and no new device results or flight-tuning values.

Numbers and references for the angle accumulation set · Hash list for the angle accumulation set · Back to the MCU overview

Used in courses

How to cite this page

Drone Institute, Rangsit University. (2026). Accumulating angle from a gyro: use the real dt and read the effect of bias. In UAS Technology Knowledge Hub (B.Tech.). https://rsu-uat.pk-research.work/en/kb/knowledge/microcontrollers/applied/integration/

Original from Drone-Hub: https://drone.pk-research.work/knowledge/microcontrollers/applied/integration/ · © PK-Research