Course 6.2Lesson 2 of 3
Not every machine is a robot. A robot has a mechanical structure or framework, electrical components such as sensors, microprocessors and actuators, and it is programmable. This lesson checks all three for real machines and programs a robot that stops before a wall.
Try the code and the simulations beside the lesson.
No. It has a frame, but nothing electrical, and no program. What about a remote-controlled toy car? It has a frame and motors. But it only does what the person holding the remote control tells it, moment by moment. Nobody can give it a program to follow. So it is not a robot either. To decide, we check three characteristics.
1. A mechanical structure or framework. The robot has a physical body: a frame, arms, joints, wheels, legs or propellers. The structure gives it a shape that suits its job. A welding arm has joints. A drone has a light frame and propellers.
2. Electrical components, such as sensors, microprocessors and actuators.
3. It is programmable. The robot is controlled by a program, and the program can be changed so that the robot does a different task. A factory arm can be reprogrammed to weld a new car body.
A machine needs all three to be a robot. Check each one in turn.
A robot vacuum must not crash into walls. Its proximity sensor measures the distance to the nearest object. The microprocessor compares the reading with a stored value. If the object is too close, it signals the motors to turn the robot.
The box marked pseudocode is Cambridge pseudocode. It is shown, not run. The Python box after it does the same job, and you can run it.
CONSTANT TooClose ← 15
WHILE TRUE DO
INPUT Distance
IF Distance < TooClose
THEN
OUTPUT "Turn"
ELSE
OUTPUT "Forward"
ENDIF
ENDWHILEHere INPUT Distance is a reading of the proximity sensor in centimetres, and each OUTPUT is a signal to the wheel motors.
The program uses a list of nine proximity readings in place of the sensor. It turns the robot when a reading is below and counts the turns.
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…
This lesson is free to read. Enroll free to keep your place and take the tests.