Control · Robot club · about 25 min
Round a box and into a bay facing east, on the worst robot in the course.
[1 mark]In hold_line(0, 67), what does x = 0 mean?
[1 mark]In slide_right, which part of the drive is the speed?
drive((target_y - y) * 10, 70, wrapped(0 - heading()) * 4)
[1 mark]hold_heading(90) is running and the robot faces 60. What rotation does max(-60, min(60, error * 3)) ask for?
[1 mark]What does this program print?
def wrapped(h):
return (h + 180) % 360 - 180
target = 90
for heading in [350, 80, 120]:
error = wrapped(target - heading)
print(heading, max(-60, min(60, error * 3)))[1 mark]Put the parking program's main lines in order, after the functions have been defined.
Number the lines 1 to 4 to put them in the right order.
hold_line(0, 67)print("facing", round(heading(), 1))hold_heading(90)slide_right(67, 55)[1 mark]Why does hold_heading loop while abs(error) > 2 instead of until the error is exactly 0?
Reach the bay without touching the box and finish facing 90, within 6 degrees.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
def wrapped(h):
return (h + 180) % 360 - 180
def hold_line(target_x, until_y):
while position()[1] < until_y:
# where am I? (cm from where I started)
x, y = position()
# forward, sideways, rotation: -100 to 100 each, until the next command
drive(70, (target_x - x) * 10, wrapped(0 - heading()) * 4)
# pause 0.1 s (the robot keeps doing what it was told)
wait(0.1)
# all motors off
stop()
hold_line(0, 67)Plan your program here, then type it in and press Run.
go_to(x, y) that drives to any point using math.atan2 for the heading and the two-loop line holder, and park with two calls to it.