Sensing · Robot club · about 15 min
position(), heading(), velocity(), and resetting them.
[1 mark]What do the two numbers in position() mean?
[1 mark]The robot starts at heading 0, runs turn_right(30, angle=45), then turn_left(30, angle=135). What does heading() say? Give a whole number of degrees.
[1 mark]What is velocity() especially useful for?
stop() the robot may still be sliding for a moment.[1 mark]Roughly what does the last line print?
forward(60, distance=20) turn_right(30, angle=90) reset_position() reset_heading() forward(60, distance=10) print(position())
[1 mark]Which sensors are inside the robot's 9-axis inertial sensor?
Tick every answer that is true.
[1 mark]What does this program print?
import math
x, y = 3, 4
print("from home:", math.sqrt(x*x + y*y), "cm")from home: 5.0 cm
Straight-line distance from home is the square root of x times x plus y times y. 9 plus 16 is 25, and its square root is 5.
[1 mark]After driving a square, the robot is not quite back where it started, and a few degrees off. What is the right way to think about that?
Get to the point 30 cm right and 30 cm forward of where you start, and print a line in the shape at (30.1, 29.8) facing 1.2 from position() and heading().
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() # drive forward at 60 for 30 cm, then stop forward(60, distance=30)
The hint students can ask for: Get to the point 30 cm right and 30 cm up from where you start (forward then right, or right then forward), and print your position and heading in the form at (30.1, 29.8) facing 1.2
from bugbot import *
connect()
forward(60, distance=30)
right(60, distance=30)
x, y = position()
print(f'at ({x}, {y}) facing {heading()}')
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.