Control · Robot club · about 20 min
Sluggish, good, oscillating. Loop speed and driving speed.
[1 mark]With a gain of 1 on the curving robot, what happens?
[1 mark]With a gain of 40, the robot snakes. What is that called?
[1 mark]Rotation is capped at 100. With a gain of 40, above what heading error is the controller just bang-bang again? Give the number of degrees.
[1 mark]What does this program print?
errors = [5, 2, -1, -3, 1, 4, -2]
worst, flips, last = 0, 0, 0
for error in errors:
worst = max(worst, abs(error))
if error * last < 0:
flips += 1
last = error
print("worst", worst, "and", flips, "sign changes")worst 5 and 3 sign changes
A sign change is when this error and the last one have opposite signs, so they multiply to a negative. That happens at -1, 1 and -2. The biggest size is 5.
[1 mark]Why is a high gain with a slow loop the worst combination?
[1 mark]In a sweep of gains, where is the good gain?
[1 mark]A gain works well at speed 50. What might happen at speed 100?
The zone is narrower and you have six seconds. The starter's gain of 40 wobbles and wastes time, and its speed is too low. Tune both.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
def wrapped(h):
return (h + 180) % 360 - 180
while position()[1] < 72:
error = wrapped(0 - heading())
# forward, sideways, rotation: -100 to 100 each, until the next command
drive(60, 0, error * 40)
# pause 0.05 s (the robot keeps doing what it was told)
wait(0.05)
# all motors off
stop()The hint students can ask for: Same robot, but the zone is narrower and you have 6 seconds. The starter's gain is far too high: it wobbles and wastes time. Tune the gain and the speed.
from bugbot import *
connect()
def wrapped(h):
return (h + 180) % 360 - 180
while position()[1] < 72:
error = wrapped(heading())
drive(100, 0, -error * 4)
wait(0.05)
stop()
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.