Consica Labs

Consica Labs
Chapter 9

Robot Logic

Developing simple logic checks and conditions

Definition

Robot logic is the set of conditional statements (if-then-else) that guide a robot's decisions based on sensor values. Key concepts include Voltage Signal, Microcontroller, Actuator.

Think of Robot Logic as:

Nervous reflexes
Muscular control
Sensory mapping
Chassis frame

Just as your brain receives sensory feedback from your skin and signals muscles to react, Robot Logic manages feedback loops.

Real-Life Example

Just as humans rely on physical organs and reflexes, Robot Logic operates through specific electrical and mechanical rules:

  1. 1 Identify the physical parameter (like light, touch, or distance).
  2. 2 Convert this into a voltage change on the controller pin.
  3. 3 Execute motor actions to adjust the robot's physical position.

Key Highlights:

  • Physical detection
  • Electrical mapping
  • Mechanical feedback

Interactive Diagram

Launch the interactive diagram to see this in action.

Open Interactive Diagram

The interactive diagram for this chapter demonstrates Robot Logic. It shows a flowchart showing a robots decision-making process: if-then-else logic with sensor input.

What to explore:

  • change sensor values; watch the decision flow change through the flowchart; see the robot action change
  • robots make decisions using logical conditions — if a sensor detects something, then the robot performs a specific action

Introduction

A robot's controller runs its program, but what makes that program intelligent? The answer is logic — the decision-making rules that transform sensor data into meaningful actions. Robot Logic is the art of telling the robot what to do in every possible situation it might encounter.

Robot programs use conditional statements (if-then-else), loops (repeat actions), and logical operators (AND, OR, NOT) to create complex behaviors from simple rules. For example: IF the touch sensor is pressed AND the front distance sensor shows less than 10 cm, THEN stop the motors. These logical building blocks combine to create robots that can navigate mazes, follow paths, and respond to their environment.

In this chapter, you will learn how programmers design Robot Logic, from simple state machines to complex decision trees. You will see how Boolean logic, comparison operators, and control flow statements give robots the ability to make choices and adapt to changing conditions.

How It Works

The foundation of Robot Logic is the Boolean expression — a statement that is either true or false. Examples include distance < 20 cm, button_pressed == true, or light_level > 500. The controller evaluates these expressions using sensor readings and compares them to programmed thresholds. Based on whether the expression is true or false, the robot chooses different actions.

Conditional statements (if-then-else) allow the robot to execute different code depending on sensor readings. The basic structure is: if (condition) { do something } else { do something else }. For example: if (battery_voltage < 7.0) { go_to_charger(); } else { continue_exploring(); }. The robot constantly evaluates conditions and responds accordingly.

Household Object Analogy

Think of Robot Logic like a choose-your-own-adventure book. At each step, you read a situation and make a choice. If you open the door (condition), turn to page 42. If you walk away, turn to page 18. The robot does the same thing, using sensor data as the situation and program logic as the choices.

Deeper Dive

A state machine is a robot programming pattern where the robot can be in one of several states, and transitions between states are triggered by events or conditions. For example, a robot might have states: SEARCHING, APPROACHING, GRABBING, and RETURNING. The robot stays in SEARCHING until it detects an object, then transitions to APPROACHING. State machines make complex behaviors easier to design and debug.

Boolean logic uses operators like AND, OR, and NOT to combine conditions. AND requires ALL conditions to be true: if (front_sensor < 20 AND touch_pressed) means both must be true. OR requires ANY condition to be true. NOT inverts a condition: if NOT (bump_detected) is true only when no bump is detected. Programmers use these operators to create sophisticated decision criteria.

Comparison operators include: == (equal to), != (not equal to), < (less than), > (greater than), <= (less than or equal), and >= (greater than or equal). These allow the robot to check exact values, ranges, and thresholds. For example, only activate the gripper if distance is exactly 5 cm, not if it is 4 or 6 cm.

Key Insight

Robot Logic can be surprisingly simple. The famous Braitenberg vehicles from the 1980s showed that robots with just two sensors and two motors, connected by a few simple logical rules, could exhibit life-like behaviors like approaching light sources, avoiding obstacles, and even appearing to have emotions.

Advanced

Fuzzy logic is an alternative to Boolean logic that deals with degrees of truth rather than absolute true/false values. Instead of checking if a sensor reading is above or below a threshold, fuzzy logic uses ranges like very_close, somewhat_close, and far. This allows smoother behavior — the robot gradually slows down as it approaches an obstacle instead of slamming on the brakes at a fixed distance.

Decision trees are hierarchical structures where each node represents a condition, and branches represent the outcomes. The robot starts at the top of the tree and follows branches based on sensor readings until it reaches a leaf that tells it what action to take. Decision trees are easy to understand and modify, making them popular for robot navigation and object classification.

Behavior-based robotics decomposes complex tasks into simple, parallel behaviors. Each behavior is a simple rule (like avoid_obstacles, follow_light, or seek_charger) that runs continuously. A coordinator or priority system decides which behavior controls the robot at any moment. This approach, pioneered by Rodney Brooks in the 1980s, allows robots to react quickly without needing a central world model.

Vocabulary Table

Term Definition
Robot LogicThe primary technological concept explaining how components interact within the context of How Robots Work.
Voltage SignalAn electrical signal representing data values based on pressure or intensity.
MicrocontrollerA tiny computer chip designed to process inputs and steer physical circuits.
ActuatorA physical mechanical device (like a motor) that creates movement.

Fun Facts

The first robot programmed with Boolean logic was Shakey the Robot, developed at Stanford Research Institute in the late 1960s. Shakey could navigate rooms, push objects, and follow simple commands using logical reasoning.

A typical robot program might evaluate millions of Boolean expressions per second. Each sensor reading triggers comparisons, logical operations, and decisions.

The simplest Robot Logic can be implemented with just a few transistors and resistors — no programmable chip needed. These are called BEAM robots (Biology, Electronics, Aesthetics, Mechanics).

Some Robot Logic is implemented entirely in hardware using logic gates, making it extremely fast and reliable. These are called finite state machines implemented in hardware.

The Mars rover Opportunity operated for over 14 years using a radiation-hardened computer running at just 20 MHz — slower than a 1990s desktop computer.

Common Misconceptions

Misconception: Robot Logic means the robot is intelligent.

Truth: Robot Logic is just a set of programmed rules. The robot does not understand what it is doing — it simply follows instructions. True artificial intelligence that can learn and reason is far more complex.

Misconception: More logic always makes a better robot.

Truth: Complex logic can be harder to debug and may contain hidden bugs. Often the simplest solution that works is the best. Engineers follow the KISS principle: Keep It Simple, Stupid.

Misconception: A robot makes decisions like a human.

Truth: Humans use intuition, emotion, experience, and context to make decisions. Robots use rigid logical rules based on sensor numbers. A robot cannot decide to be helpful or creative — it only does what its program tells it.

Misconception: Robot Logic never makes mistakes.

Truth: Robot Logic is only as good as the programmer who wrote it and the sensors that provide data. Faulty sensors, edge cases the programmer did not consider, and hardware failures can all cause robots to behave incorrectly.

Knowledge Check

1. What is the primary role of Robot Logic?

Answer: To capture or process physical feedback

2. What does PWM stand for in motor speed control?

Answer: Pulse Width Modulation

3. Which unit converts physical attributes into electrical values?

Answer: A sensor