Skip to content
Tutorials Center
My learning

Topics

Lesson 37 of 46 ยท Robotics

Introduction to Robotics: Sensors, Actuators and Control

Learn how robots sense, plan and act: noisy sensors, the sense-plan-act loop, PID control simulated in Python and a differential-drive motion model.

Everything so far in this course happened inside a program: states, moves and scores were exact, and nothing ever went wrong between "decide" and "do". A robot removes that comfort. It has a body in the physical world, its sensors lie a little, its motors do not do exactly what you ask, and the world keeps changing while it thinks. Robotics is where the agent idea meets friction, noise and time.

This lesson gives you the vocabulary and three working models. You will see how a robot is built, why one sensor reading cannot be trusted, how a PID controller drives an error to zero, and how a differential-drive robot moves when you set its wheel speeds. The next two lessons build on this: kinematics for robot arms and path planning for getting from A to B. Everything runs live in Python, so the physics here is a simulation, but the equations are the real ones.

Anatomy of a robot

Strip away the casing and almost every robot has the same parts, which map neatly onto the PEAS description you already know.

  • Sensors measure the world and the robot itself. Proprioceptive sensors look inward: wheel encoders (count rotations), joint angle sensors, gyroscopes, battery monitors. Exteroceptive sensors look outward: cameras, ultrasonic and infrared range finders, lidar (laser range scanners), bump switches, GPS.
  • Actuators produce motion: electric motors (DC, stepper, servo), hydraulics, pneumatics, speakers and grippers.
  • A controller is the computer and software that turns sensor data into actuator commands. It can be a tiny microcontroller running a fast loop or a full computer running planning code.
  • A body (links, joints, wheels, chassis) and a power source tie it all together.

A useful measure of a robot's mechanical freedom is its degrees of freedom (DOF): the number of independent ways it can move. A robot arm with six rotating joints has six DOF. A car-like robot on a flat floor moves in a plane and can turn, so its pose has three numbers (x, y, heading) but it can only control two of them directly at any moment, which makes parking surprisingly hard.

graph LR
    W["World"] --> S["Sensors"]
    S --> C["Controller<br/>(software)"]
    C --> A["Actuators"]
    A --> B["Body moves"]
    B --> W

A robot is an agent in a loop: sensors read the world, software decides, actuators change it.

Sensors are noisy

A sensor never reports the truth, it reports a measurement of the truth with error. Two kinds of error matter most:

  • Random noise: each reading is a little different, scattered around the true value. It averages out.
  • Systematic error (bias): every reading is off in the same direction, for example a range finder that always reads 3 cm too long. Averaging does not remove it, only calibration does.

Real sensors also produce occasional outliers, such as an ultrasonic sensor that gets an echo from the wrong surface. The program below simulates a range sensor with Gaussian noise and a 5 percent chance of a wild reading, and compares the mean, the median and the error when several readings are combined.

Python A noisy range sensor and how to tame it

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

You should see that the mean (122.0 cm) is dragged away from 120 by the outliers, while the median (120.5 cm) shrugs them off. The standard deviation of 21.3 cm looks huge compared with the sensor's own noise of 4 cm, again because of the outliers. Combining more readings shrinks the error, from about 6.4 cm for a single reading to 0.4 cm for the median of 100. The price is time: 100 readings take 100 sensor cycles, and a moving robot has travelled while you waited. This trade-off between accuracy and delay returns in the filtering lesson, where noisy sensor streams are combined with a motion model in a principled way.

Averaging only helps against random error. If the sensor is biased, a million readings give you a very precise wrong answer.

Sense, plan, act

The oldest robot architecture is a three-step cycle, repeated many times per second:

  1. Sense: read the sensors and update the robot's picture of the world.
  2. Plan: choose what to do next, using any of the algorithms in this course (search, planning, logic, probability).
  3. Act: send commands to the actuators.

Real systems run several loops at different speeds. A motor controller might run at 1,000 times per second, an obstacle-avoidance layer at 50, and a route planner once every few seconds. The slow high-level planner picks a goal; the fast low-level controller does the exact tracking. Splitting the work this way is called a layered or hierarchical architecture, and it is why a robot can react to a sudden obstacle without waiting for a full re-plan.

The fast loops almost always use feedback control: compare what you wanted with what you measured and correct the difference. That brings us to the most widely used controller in engineering.

PID control

Suppose a robot must move to a position 1 m away. The error is the goal minus the measured position. A PID controller turns the error into a motor command as the sum of three terms:

  • P (proportional): push in proportion to the error right now. kp * error. A big error gives a big push.
  • I (integral): add up the error over time. ki * sum(error * dt). If a small error lingers, this term keeps growing until the error is gone.
  • D (derivative): react to how fast the error is changing. kd * (error change / dt). It acts as a brake: when the robot rushes toward the goal, the error shrinks quickly and the D term pushes back, reducing overshoot.

The behavior of each term is easy to see in a simulation. The cart below has a mass of 1 kg, a little drag, and a constant 1 N push from a slope, so it constantly drifts back. The motor force is limited to plus or minus 10 N, as real motors always are.

Python P, PD, PI and PID controllers compared

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Read the table row by row, because it shows the whole story of PID tuning:

  • P alone rings: it overshoots by 0.437 m and keeps oscillating, because the cart has little drag to calm it. It also leaves a permanent error of about 0.165 m. The slope pushes back with 1 N, and with kp = 6 that is balanced only when the error is 1/6 m. This leftover is the steady-state error of proportional control.
  • PD removes the overshoot (0.000 m) by braking, but the steady-state error stays at +0.167 m, since the derivative term is zero when the cart is at rest.
  • PI cures the steady-state error in principle, but without damping the cart swings back and forth and never settles within 2 cm in 20 seconds.
  • PID combines the three roles: the integral term removes the offset, the derivative term damps the swing, and the cart settles at 5.40 s with a final error of 0.000 m.
  • Too much integral makes things worse again (0.732 m overshoot, 14.45 s to settle). The integral keeps accumulating while the cart is still far from the goal, which is called integral windup.

A common tuning recipe: start with only P, raise it until the response is quick but starts to oscillate; add D to damp the oscillation; add a small I last to remove any leftover error. Real controllers also clamp the integral term (anti-windup) and filter the derivative, because differentiating a noisy sensor amplifies the noise.

A differential-drive robot

The simplest wheeled robot, found in robot vacuums and many classroom robots, has two powered wheels on a common axle. There is no steering; you turn by driving the wheels at different speeds. Let v_left and v_right be the wheel speeds and L the distance between the wheels (the track).

  • Forward speed: v = (v_right + v_left) / 2
  • Turning rate: w = (v_right - v_left) / L (positive turns left)

If both wheels have the same speed the robot drives straight. If they are opposite, v = 0 and the robot spins on the spot. In all other cases it follows a circular arc of radius r = v / w. Over a short time dt the pose (x, y, heading) changes along that arc, which the code below computes exactly rather than with small straight steps.

Python Driving a differential-drive robot

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The first block checks the model: driving at 0.2 m/s for 2 s moves the robot 0.4 m, and the spin command turns it exactly 90 degrees. The second block is the important one. Estimating position by integrating wheel motion is called odometry or dead reckoning, and with an 8 percent random error in each wheel speed the estimate ends 0.161 m away from the ideal path after only 40 seconds. Because every step builds on the last, errors accumulate without bound. (The heading prints as 382 degrees because we never wrap angles back into the range 0 to 360; the robot has simply made a full turn and a bit.)

That is why serious robots never rely on odometry alone. They correct it with other sensors, which is exactly the job of localization with filters.

What this means for AI

Robots show why the textbook assumptions of earlier lessons are idealizations. The world is only partially observable (noisy sensors), actions are not deterministic (wheel slip), and the environment is dynamic. Classical robotics responds with layers: feedback controllers for the fast, local work, and the algorithms from this course for slow, global decisions. In the next lesson we look at how to compute where a robot arm's hand is, and how to find joint angles that put it somewhere useful.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Why is the median often a better estimate than the mean for a sensor that sometimes returns wild readings?

    A few extreme readings can drag the mean far from the truth, while the median depends only on the middle of the sorted values. Neither fixes a constant bias.
  2. 2. A proportional-only controller on a system with a constant disturbance usually leaves what?

    With only P, the controller needs a non-zero error to produce the force that balances the disturbance, so a permanent offset remains. The integral term is what removes it.
  3. 3. What is the main job of the derivative term in a PID controller?

    The derivative term reacts to the rate of change of the error and acts like a brake, which reduces overshoot and oscillation. It also amplifies noise, so it is usually filtered.
  4. 4. A differential-drive robot has its left wheel at 0.1 m/s and its right wheel at 0.3 m/s. What does it do?

    The forward speed is the average (0.2 m/s) and the turning rate (right minus left) is positive, which means a left turn. It moves along a circular arc.
  5. 5. Why does dead reckoning from wheel odometry become less reliable over time?

    Each pose estimate is built on the previous one, so small errors add up without bound unless an outside sensor corrects them.

Summary

  • A robot is an agent with sensors, actuators, a controller and a body; degrees of freedom count its independent motions.
  • Sensors give noisy measurements. Random noise averages out, bias does not, and outliers call for robust statistics such as the median.
  • The sense-plan-act loop is usually layered: fast feedback controllers below, slower planners above.
  • PID control combines proportional, integral and derivative terms: P reacts to the present error, I removes steady-state error, D damps overshoot. Too much I causes windup.
  • A differential-drive robot has forward speed (vr + vl) / 2 and turning rate (vr - vl) / L, and moves along circular arcs.
  • Odometry drifts, so real robots correct it with other sensors and filters.

Next: Forward and Inverse Kinematics.