Noise and filtering · University · about 40 min
Sit 25 cm from a wall, steadily, on a depth sensor that is 3 cm noisy.
[1 mark]The gap controller runs for three ticks with no robot. What does it print?
TARGET, ALPHA = 25.0, 0.3
gap = 40.0
for raw in (37, 34, 31):
gap = ALPHA * raw + (1 - ALPHA) * gap
error = gap - TARGET
if abs(error) < 1.0:
cmd = 0
else:
cmd = max(-45, min(45, 2.2 * error))
print(round(gap, 2), round(cmd, 1))39.1 31.0 37.57 27.7 35.6 23.3
Tick 1: gap = 0.3 x 37 + 0.7 x 40 = 39.1, error 14.1, command 2.2 x 14.1 = 31.0. The filter lags the raw readings, so each command is a little larger than the raw gap would ask for.
[1 mark]With TARGET = 25, a dead band of 1 cm and gain 2.2, what drive command is sent when the filtered gap is 25.6 cm?
[1 mark]The plot of the gap shows a slow sine wave around 25 cm. What does the lesson say to change?
[1 mark]The robot settles at 27 cm and stays there. What is this, and where is the proper fix?
[1 mark]The chart holds 25 cm, but a ruler shows the robot is nearer the wall. What does the lesson say is happening?
[1 mark]Why is a 1 cm dead band not really a cost on this robot?
Settle 25 cm from the wall and stay there. The checker watches the last part of the run as well as the end, so hunting fails even if the final position is right.
from bugbot import * connect() TARGET = 25.0
The hint students can ask for: The wall's near face is 150 cm up the mat, so 25 cm from it is y = 125, which is 65 cm from where the robot starts. Filter the depth reading, control on the filtered value, and make sure the robot settles rather than hunting: the checker watches the last part of the run, not just the end.
from bugbot import *
connect()
TARGET = 25.0
ALPHA = 0.3
gap = distance()
for tick in range(450):
gap = ALPHA * distance() + (1 - ALPHA) * gap
plot("gap", gap)
error = gap - TARGET
speed = max(-45.0, min(45.0, 2.2 * error))
if abs(error) < 1.0:
stop()
else:
drive(speed, 0, 0)
wait(0.1)
stop()
print("settled at", round(gap, 1), "cm from the wall")
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.