Learning, and the capstone · University · about 35 min
Least squares in plain Python, and a robot that drives by the model it fitted to itself.
[1 mark]What does this least squares fit of speed against command print?
data = [(20, 3.1), (40, 7.4), (60, 11.2), (80, 15.3), (100, 19.0)] n = len(data) sx = sum(c for c, v in data) sv = sum(v for c, v in data) sxx = sum(c * c for c, v in data) sxv = sum(c * v for c, v in data) slope = (n * sxv - sx * sv) / (n * sxx - sx * sx) intercept = (sv - slope * sx) / n print(round(slope, 4), round(intercept, 3))
[1 mark]A fit gives v = 0.2 c - 0.8. How many seconds should the robot drive at command 60 to cover 80 cm open loop? Give 2 decimal places.
[1 mark]Speeds are read 0.2 s after each command change. Why is that worse than random noise?
[1 mark]What does taking (forward - backward) / 2 at each command achieve?
[1 mark]A straight line is fitted to commands from 5 to 100, including the region below 15 where the drive does not move. What is the sensible response?
[1 mark]A proportional heading correction asks for 8 percent turn during the sweep, and the robot slowly turns anyway. Why?
[1 mark]Driving for D / v open loop lands close to D despite the 0.25 s lag. Why?
Sweep the command, fit speed against command by least squares, print slope: and intercept:, then use the fit to drive 80 cm open loop and stop there.
from bugbot import * connect() DT = 0.1 COMMANDS = [20, 30, 40, 50, 60, 70, 80, 90, 100] TARGET = 80.0
Plan your program here, then type it in and press Run.