Odometry and drift · University · about 30 min
flow() and imu() in, a pose out, in about ten lines. Then check it against the truth.
[1 mark]One odometry update, with a deliberately long 1 s step so the numbers are easy. The robot starts at heading 0, reads (vx, vy) = (0, 20) and turns at 60 deg/s. What does this print?
import math DT = 1.0 x = y = h = 0.0 vx, vy, rate = 0.0, 20.0, 60.0 h_mid = h + 0.5 * rate * DT a = math.radians(h_mid) x += (vx * math.cos(a) + vy * math.sin(a)) * DT y += (-vx * math.sin(a) + vy * math.cos(a)) * DT h += rate * DT print(round(h_mid, 1), round(x, 2), round(y, 2), round(h, 1))
[1 mark]Why does the odometry update rotate flow() by the heading before adding it to x and y?
[1 mark]Why is rotating by the heading at the start of the step, rather than the midpoint heading, a problem worth fixing?
[1 mark]The loop step is 0.1 s and the robot turns at 60 deg/s. By how many degrees does the heading change within one step, which is the gap between turning first and moving first?
[1 mark]How do the fused heading imu()[0] and the integrated gyro rate differ?
[1 mark]In the task, why must the turn be made with drive() inside your loop rather than with turn_right(angle=90)?
Drive at least 90 cm with a corner in it, running your own odometry, and print my x: and my y: at the end. position() is not allowed anywhere in this task, not even to print. Turn with drive() inside your loop: a blocking turn_right(angle=90) runs the world without running your loop, so the turn never reaches your estimate.
from bugbot import * import math connect() DT = 0.1 x = y = h = 0.0
Plan your program here, then type it in and press Run.
odometry() after the same run. They should agree closely; if they do not, one of you has a bug.heading() for a run with three turns in it.