Lesson 18: Measure the room
A robot with a tape measure
- Builders use laser measures: a beam goes to the wall and back, and the device shows the distance.
- The robot's distance sensor works the same way. With two readings it can measure a whole room.
- You turn the readings into the room's length, width and floor area.
Words for this lesson
| Word | Meaning |
|---|---|
| length | how long the room is, from the bottom wall to the top wall |
| width | how wide the room is, from the left wall to the right wall |
| area | how much floor there is: length × width |
| m² | square metre: a square 1 m by 1 m |
| round | make a whole number: round(1319.6) is 1320 |
The sensor does not see the robot
| Part | mm |
|---|---|
| sensor reading (the gap in front) | 1320 |
| the robot itself | + 180 |
| room length | 1500 |
- The robot's back touches the wall, and the sensor is at its front. So the room is the gap plus the robot.
From mm² to m²
| Room | length × width | Area |
|---|---|---|
| 1600 × 1250 mm | 2 000 000 mm² | 2.0 m² |
| 1400 × 900 mm | 1 260 000 mm² | 1.26 m² |
- 1 m = 1000 mm, so 1 m² = 1000 × 1000 = 1 000 000 mm². Divide by 1 000 000 to get m².
from vexcode_vr import *
def main():
length = 1600
width = 1250
brain.print(length * width)
brain.new_line()
brain.print(length * width / 1000000)
vr_thread(main)
- The brain prints
2000000and then2.0.
Difficulty 3/5 · 200 coins + a small bonus on first completion today
A builder needs the size of a room. The robot stands with its back in the bottom-left corner, facing up. The distance sensor at its front measures to the top wall, and the robot itself is 180 mm long. Work out length = round(reading) + 180 and print Length: 1500 mm (with the real number). The rooms have different sizes.
Click Run to see the output here.
Difficulty 4/5 · 280 coins + a small bonus on first completion today
Now measure the width too: turn right 90° and read the sensor again (add 180 mm as before). Then work out the floor area in square metres: area = length * width / 1000000. Print Length: … mm, Width: … mm and Area: … m² on three lines.
Click Run to see the output here.