Making a Robot Think · Lesson 8 of 11
Simple control logic
Turning a reading into an action
Here is where it all comes together. A robot constantly turns sensor readings into actions using simple logic, usually if and else. Imagine an obstacle-avoiding car with a distance sensor. The rule: if something is closer than 20 cm, stop; otherwise, go.
Python
Run it. That tiny function is real robot logic. Change the 20 to make the car more or less cautious, and run it again.
Exercise
Exercise — check your understanding
Write a function action(temp) for a cooling-fan robot: return "on" if the temperature is above 30, otherwise return "off".
You’re reading for free. Sign in to keep your progress and earn a certificate when you finish.Sign in to keep my progress →