Learning · Robot club · about 20 min
Readings with labels, and why bad data makes bad robots.
[1 mark]In this module, what is a sample?
[1 mark]Which of these produce a robot that does the wrong thing with total confidence?
Tick every answer that is true.
[1 mark]Why does drive_to end with wait(0.4) before a sample is recorded?
tof_grid() only works after a wait[1 mark]What does this program print?
data = [] data.append(([54, 52, 51], "open")) data.append(([16, 16, 16], "wall-ahead")) print(len(data), data[-1][1], data[0][0][1])
[1 mark]Who decides the label on a sample?
[1 mark]What does the label gap-left mean?
Visit the four spots in order, record the level rows at each with its label, and print recorded <label> each time.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
# maths: atan2, hypot, sin, cos, radians
import math
def wrapped(h):
return (h + 180) % 360 - 180
def go_to(x, y, speed=60):
# where am I?
px, py = position()
a = math.radians(wrapped(math.degrees(math.atan2(x - px, y - py)) - heading()))
# forward, sideways, rotation: -100 to 100 each, until the next command
drive(speed * math.cos(a), speed * math.sin(a), wrapped(0 - heading()) * 3)
def near(x, y, cm=4):
# where am I?
px, py = position()
return math.hypot(x - px, y - py) < cm
def drive_to(x, y):
while not near(x, y):
go_to(x, y)
# pause 0.1 s (the robot keeps doing what it was told)
wait(0.1)
# all motors off
stop()
# pause 0.4 s (the robot keeps doing what it was told)
wait(0.4)
drive_to(0, 10)
print('recorded', 'open')Plan your program here, then type it in and press Run.
data at the end. That text is your dataset; lesson 8.7 shows how to keep it.corner, recorded in a corner of the mat. What does the robot see there?