Odometry and drift · University · about 25 min
The odometry update, one step at a time, and what the step size costs you.
[1 mark]Speeds in cm/s are read every 0.1 s as the robot speeds up. This integrates them two ways. What does it print?
speeds = [0.0, 8.0, 14.0, 18.0, 20.0, 20.0]
DT = 0.1
euler = 0.0
trap = 0.0
for i in range(1, len(speeds)):
euler += speeds[i] * DT
trap += 0.5 * (speeds[i] + speeds[i - 1]) * DT
print("euler:", round(euler, 2))
print("trapezium:", round(trap, 2))euler: 8.0 trapezium: 7.0
Euler uses each new reading for the whole step: (8 + 14 + 18 + 20 + 20) × 0.1 = 8.0 cm. The trapezium rule averages each pair: (4 + 11 + 16 + 19 + 20) × 0.1 = 7.0 cm. While accelerating, Euler overestimates.
[1 mark]Which integration method takes the speed read at one instant and uses it as if it were the average over the whole step?
[1 mark]When do the trapezium rule and Euler integration give the same answer?
[1 mark]A loop multiplies by DT = 0.1, but its real period is 0.11 s. The robot drives at a steady 20 cm/s for 50 passes. By how many centimetres does the integral fall short of the true distance?
[1 mark]Why does assuming the loop period, rather than measuring it with clock(), cause an error that grows through the run?
[1 mark]A straight-line integral of flow() is close to the truth but not exact. Which of these are reasons the lesson gives?
Tick every answer that is true.
Drive at least 50 cm in a straight line, integrating flow() as you go, and print your own answer as my y: 54.3. It is marked against where the robot really ended up.
from bugbot import * connect() DT = 0.1 y = 0.0 forward(70)
The hint students can ask for: Drive straight and read flow() every tenth of a second. Each reading is a speed in cm/s, so it contributes speed times the length of the step. Add them up as you go.
from bugbot import *
connect()
DT = 0.1
y = 0.0
forward(70)
for i in range(40):
vx, vy = flow()
y += vy * DT
wait(DT)
stop()
print("my y:", round(y, 1))
print("truth", position())
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.