Skip to main content
Robotics & Embodied AI

⏱ About 10 min10 XP

If This, Then That

You already know how to think like a robot! Here is a rule you probably follow every day: if it is raining outside, then grab an umbrella. If your stomach is growling, then it is time for a snack. If the light turns red, then stop. These are called if-then rules. They are one of the most important tools a robot uses to make decisions. Today we are going to learn exactly how if-then rules work inside a robot's brain.

How If-Then Rules Work

An if-then rule has two parts. The IF part describes a condition — something the robot checks. Is the door open? Is something blocking the path? Is the battery running low? The THEN part describes the action — what the robot does when the condition is true. Turn right. Stop moving. Beep and return to the charging station. Every time a robot's brain reads an if-then rule, it checks: is the condition true right now? If yes, it does the action. If no, it skips the action and moves on. Robots can have dozens or even hundreds of if-then rules running at the same time, checking conditions over and over, many times per second.

The Big Idea

An if-then rule tells a robot: IF a certain condition is true, THEN do this action. These rules are how robots react to the world around them and make decisions.

Let us meet Zippy, a little cleaning robot. Zippy rolls around a classroom picking up paper scraps. Here are some of Zippy's if-then rules: IF the path ahead is clear, THEN keep rolling forward. IF something is directly in front of Zippy, THEN stop and turn right. IF the paper-scrap bin is full, THEN beep three times and stop. IF the battery level drops below 10%, THEN return to the charging dock. Notice how each rule is connected to a sensor. Zippy checks what the sensors say, then applies the matching if-then rule. Without sensors, there would be nothing to put in the IF part — the robot would have no idea what was happening around it.

Match each IF condition to the correct THEN action for Zippy the cleaning robot.

Terms

IF path ahead is clear
IF something is directly in front
IF paper bin is full
IF battery drops below 10%

Definitions

THEN stop and turn right
THEN beep three times and stop
THEN keep rolling forward
THEN return to the charging dock

Drag terms onto their definitions, or click a term then click a definition to match.

If-then rules can also be chained together. After one rule fires, its action might trigger another rule. For example: IF Zippy bumps into a wall, THEN turn right 45 degrees. IF after turning, the path is still blocked, THEN turn right another 45 degrees. IF the path is finally clear, THEN move forward. By chaining rules together, robots can handle situations that are more complicated — like finding a way through a maze or around a pile of furniture. This is how robots can seem to 'think' even though they are really just checking conditions and following rules.

You Use If-Then Rules Every Day

Think about your morning routine. IF you are still sleepy when the alarm rings, THEN hit snooze. IF breakfast is ready, THEN eat. IF you are running late, THEN skip the snack. You are already an expert at if-then thinking!

Complete the if-then rule sentence below.

An if-then rule has two parts: the (what the robot checks) and the action (what the robot does).

What are the two parts of an if-then rule?

Zippy's rule says: IF battery drops below 10%, THEN return to charging dock. Zippy's battery is at 8%. What will Zippy do?

Design a Robot With If-Then Rules

  1. You are going to design a pretend robot helper using if-then rules!
  2. Pick a simple helper robot. Ideas: a dog-feeding robot, a bedroom-tidying robot, or a homework-reminder robot.
  3. Write at least four if-then rules for your robot. Use this format for each one:
  4. IF (describe the condition your robot checks)
  5. THEN (describe what the robot does)
  6. Think about: what sensors would your robot need to check those conditions?
  7. Draw your robot and label the sensors it would need.
  8. Share your rules with someone. Ask them: can they think of a situation your rules would not cover? If so, add a new rule to handle it!