The robot as a system · University · about 25 min
How often the loop runs, how late the answer arrives, and what both do to a controller.
[1 mark]This drive takes about a quarter of a second to get most of the way to a new speed. Which of the three times in the lesson is that?
[1 mark]The drive's time constant is about 0.25 s. Which loop rate does the lesson's rule of thumb favour?
[1 mark]Why can too much delay make a feedback loop unstable?
[1 mark]A loop oscillates because its information is late. Which of these are fixes from the lesson?
Tick every answer that is true.
[1 mark]A loop asks for wait(0.05), and each pass also spends 0.012 s in distance() and 0.018 s in scan(). What does this print?
work = 0.012 + 0.018
requested = 0.05
period = requested + work
print("period:", round(period, 3), "s")
print("rate:", round(1 / period, 1), "Hz")period: 0.08 s rate: 12.5 Hz
The pass costs 0.05 + 0.03 = 0.08 s, so the loop runs at 1 / 0.08 = 12.5 Hz, not the 20 Hz the wait suggests.
[1 mark]The heading-hold loop works out its error with wrapped(). With clockwise-positive heading, what does this print?
def wrapped(a):
return (a + 180) % 360 - 180
print(wrapped(0 - 350), wrapped(0 - 10), wrapped(190))10 -10 -170
A robot at heading 350 is 10 degrees anticlockwise of 0, so the error is +10 (turn clockwise), not -350. At heading 10 it is -10, and 190 wraps to -170.
Drive into the green zone, and from three seconds onwards stay within 8 degrees of heading 0. This robot pulls hard to one side, so the loop has to be doing real work all the way.
from bugbot import *
connect()
def wrapped(a):
return (a + 180) % 360 - 180
# drive, correcting as you go, and keep correcting once you are there
forward(70, distance=130)
stop()The hint students can ask for: This robot pulls to one side. Correct with the rotation term of drive(), in proportion to the heading error. A slower loop needs a gentler gain, or it will swing about.
from bugbot import *
connect()
def wrapped(a):
return (a + 180) % 360 - 180
while position()[1] < 130:
error = wrapped(0 - heading())
drive(70, 0, error * 3)
wait(0.1)
stop()
for i in range(12):
error = wrapped(0 - heading())
drive(0, 0, error * 3)
wait(0.1)
stop()
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.