Sensing · Robot club · about 20 min
Why the robot wanders, and the first closed loop.
[1 mark]Which of these programs is closed loop?
[1 mark]Why does the robot slide sideways when it drives forward? Choose all that apply.
Tick every answer that is true.
[1 mark]After a 10 cm leg, position() says x is 2.5. What does the correcting program do?
x, y = position()
if x > 1:
left(40, distance=x)
elif x < -1:
right(40, distance=-x)left(40, distance=x) slides it back by that much.[1 mark]What does this program print?
error = 355
if error > 180:
error = error - 360
print(error)-5
A heading of 355 is really 5 degrees to the left of 0, so the error should be -5, not 355.
[1 mark]In drive(70, -x * 15, 0), x is 2. What is the sideways value? Give a whole number.
[1 mark]You change -x * 15 to -x * 40. What do you expect?
[1 mark]Why is it worth correcting the heading as well as x?
Drive about 64 cm and finish inside the small square, still facing 0 within 6 degrees. Correct as you go.
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() # drive forward at 70 for 64 cm, then stop forward(70, distance=64)
The hint students can ask for: This robot leaks sideways badly. Drive about 64 cm and finish inside the small square, still facing 0. Check position() and heading() as you go and correct with small strafes and turns.
from bugbot import *
connect()
for step in range(6):
forward(70, distance=10)
x, y = position()
if x > 1:
left(40, distance=x)
elif x < -1:
right(40, distance=-x)
err = heading()
if err > 180:
err -= 360
if abs(err) > 2:
turn_left(30, angle=err)
forward(40, distance=4)
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.