The answersDownload the PDF
Worksheet

2.1 Where am I?

Sensing · Robot club · about 15 min

BugBotLab
NameClassDate

What this lesson is about

position(), heading(), velocity(), and resetting them.

Questions 7 marks in all

  1. [1 mark]What do the two numbers in position() mean?

    1. Ax is centimetres to the right and y is centimetres forward, from where the program started
    2. Bx is the speed and y is the heading
    3. Cx is forward and y is to the right
    4. DThey count from the middle of the mat
  2. [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.

  3. [1 mark]What is velocity() especially useful for?

    1. AKnowing whether the robot has actually stopped
    2. BSetting how fast the robot drives
    3. CFinding how far away the wall is
    4. DResetting the position
  4. [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. A(0, 10)
    2. B(10, 20)
    3. C(0, 30)
    4. D(10, 0)
  5. [1 mark]Which sensors are inside the robot's 9-axis inertial sensor?

    Tick every answer that is true.

    1. AGyroscope
    2. BAccelerometer
    3. CMagnetometer
    4. DOptical-flow sensor
    5. ETime-of-flight sensor
  6. [1 mark]What does this program print?

    import math
    x, y = 3, 4
    print("from home:", math.sqrt(x*x + y*y), "cm")
  7. [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?

    1. AEvery move is a little off, and small errors add up
    2. BThe optical-flow sensor is broken
    3. Cposition() only works in straight lines
    4. DThe robot really is exactly home

The task: report from the corner

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)

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/2-1-where-am-i/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Print position() and velocity() every 0.5 s while driving.
  2. Drive a triangle and print how far from home you end up: x*x + y*y under a square root.
  3. Reset the heading after each turn of a square. Does the final error change?