Guide to AI and Data Courses · Lecture Notes

Chapter 23: Robotics and Robot Vision

Suppose we ask a warehouse robot to take a box from a shelf and put it on a bench. Saying where the tip of the arm should go is easy, but the motors are given joint angles, not a tip position. Wheels slip, sensors measure with noise, and the robot is not even sure where it is. Robotics is the course about these three problems: describing motion with geometry, reaching a goal with feedback, and estimating position from uncertain measurements. This note introduces the course and shows its three core ideas with small examples you can compute by hand.

Learning outcomes

Frames
Move a point from the robot frame to the world frame with a rotation and a translation; compute the forward kinematics of a two-joint arm.
Inverse kinematics
Find the joint angles of a two-joint arm, explain where the two solutions (elbow up and elbow down) come from, and recognize an unreachable target.
Feedback
Run a few steps of proportional and proportional-integral control by hand; show how a larger gain produces oscillation and then instability.
Localization
Compute the predict and update steps of a one-dimensional Kalman filter; say which step increases uncertainty and which decreases it.
Place of the course
State what separates robotics from computer vision, artificial intelligence, reinforcement learning and embedded AI.

23.1What question does the course ask?

How does a machine sense the physical world, know where it is and move?

Robotics studies how to design and control machines that sense and move in the physical world. The course combines perception, localization, planning and control under noisy measurements and real-time constraints; robot vision is the eye of this loop.

In ordinary software a program takes an input, produces an output and is done. A robot lives in a closed loop with its surroundings: it senses, estimates, plans, controls and acts; the action changes the world, and the changed world determines the next measurement. Every link of this loop is imperfect. A camera is sensitive to light, a lidar to reflective surfaces; wheels slip; there is a delay between a motor command and the motion that follows. Robotics teaches how a system built from imperfect links can still do its job.

So the course asks "what should the robot do?" and just as much "how will the robot know what is going on?" In an artificial intelligence course a plan is searched for among abstract states; in robotics the same plan is executed in a continuous space, in real time and with measurement error. However good the plan is, what keeps the robot on it is continuous feedback.

23.1.1Which tools does the course combine?

The course brings together three bodies of knowledge. Geometry and linear algebra (Linear Algebra) express the position of the robot and of objects with frames and transformation matrices. Control theory forces the robot to follow the desired motion. Probability and statistics (Probability and Statistics) account for the uncertainty in measurements and in motion. The three core sections below give one example of each: kinematics, control and localization. Path planning and robot vision are built on top of them in the course.

23.1.2At a glance

CriterionRobotics and Robot Vision
Approachsense-plan-act loop
Inputsensor measurements
Outputmotor commands, path
Success measuretask success, safety
Math loadhigh: transformations, control
Data needsphysical experiments and simulation

23.2A short history

YearMilestone
1961Unimate, the first industrial robot, starts work at a General Motors plant.
1966The Shakey project starts at SRI: the first mobile robot to sense and plan; A* is developed for it.
1986Brooks proposes the subsumption architecture: direct sense-act behaviors instead of planning.
1997The Sojourner rover explores the surface of Mars on the Mars Pathfinder mission.
2002The Roomba vacuum goes on sale; mobile robots enter homes.
2005Stanford's Stanley completes and wins the DARPA Grand Challenge desert race with no driver.

23.3Core concepts

The rest of the course is built on the concepts below. The following sections work through the most important ones with examples.

ConceptMeaning
Degrees of freedomThe number of axes along which a robot can move independently.
Coordinate frameWorld, robot, camera; transformation matrices between them.
Forward kinematicsFinding the end-effector position from joint angles.
Inverse kinematicsFinding the joint angles for a desired end-effector position.
PID controlFeedback that corrects error by proportional, integral and derivative terms.
LocalizationPosition from noisy measurements with Kalman and particle filters.
SLAMBuilding a map while locating yourself in it.
Path planningA*, RRT: a collision-free path to the goal.

23.4Frames and kinematics

In a robot the same point is written with different numbers in different frames: the world frame (the room), the robot frame (the robot body) and the camera frame. Moving between frames takes two things: a rotation and a translation. In the plane, if the robot frame sits at (tx, ty) in the world with heading θ, a point (x, y) in the robot frame lands in the world at:

Definition 23.1 (Frame transformation in the plane)

xw = tx + x cos θ − y sin θ, yw = ty + x sin θ + y cos θ. In matrix form: multiply by the rotation matrix R(θ) and add t.

Example 23.1: An object in front of the robot

The robot is at (2, 1) in the world with heading θ = 90°, so it faces along the world y axis. It sees an object exactly 1 m ahead: (x, y) = (1, 0) in the robot frame.

  1. Trigonometry. cos 90° = 0, sin 90° = 1.
  2. Transform. xw = 2 + 1·0 − 0·1 = 2; yw = 1 + 1·1 + 0·0 = 2.

The object is at (2, 2) in the world: the robot faces up, so its "front" points in the world y direction.

The frame transformation is also the basis for computing where the tip of an arm is. In a two-joint planar arm the first link has length L1, the second L2, and the joint angles are θ1 and θ2; the second angle is measured relative to the first link. Forward kinematics gives the tip from the angles:

Definition 23.2 (Forward kinematics of a two-joint arm)

x = L1 cos θ1 + L2 cos(θ1 + θ2), y = L1 sin θ1 + L2 sin(θ1 + θ2).

Example 23.2: Forward and inverse kinematics

Both links are 1 m: L1 = L2 = 1.

  1. Forward. For θ1 = 30°, θ2 = 60°: x = cos 30° + cos 90° = 0.866 + 0 = 0.866, y = sin 30° + sin 90° = 0.5 + 1 = 1.5. The tip is at (0.87, 1.5).
  2. Inverse: second angle. Let the target be (1, 1). From the law of cosines, cos θ2 = (x² + y² − L1² − L2²) / (2 L1 L2) = (1 + 1 − 1 − 1) / 2 = 0, so θ2 = ±90°.
  3. Inverse: first angle. θ1 = atan2(y, x) − atan2(L2 sin θ2, L1 + L2 cos θ2). For θ2 = +90°: 45° − atan2(1, 1) = 0°; for θ2 = −90°: 45° − atan2(−1, 1) = 45° + 45° = 90°.
  4. Check. (0°, 90°): x = 1 + cos 90° = 1, y = 0 + 1 = 1. (90°, −90°): x = cos 90° + cos 0° = 1, y = sin 90° + sin 0° = 1. Both reach the target.

Two different arm postures (elbow down and elbow up) reach the same tip position. In inverse kinematics there are usually several solutions; if the target lies outside the arm's workspace there are none: cos θ2 falls outside [−1, 1].

Common mistake

Solving inverse kinematics as if "the angles have a single answer". Two postures reach the target above, and which one to pick depends on obstacles, joint limits and the current posture. Also, an arm with L1 = L2 = 1 cannot reach (2.5, 0): the maximum reach is 2 m, and cos θ2 = (6.25 − 2)/2 = 2.125 > 1.

23.5Feedback control

A plan tells the robot where to go, but the measured position drifts from the plan. The job of control is to keep measuring this deviation, the error, and change the motor command accordingly. The most widely used controller is the PID: the command is proportional to the error itself (proportional), to the sum of past errors (integral) and to the change of the error (derivative).

Definition 23.3 (PID controller (discrete time))

The error is ek = r − xk and the command is uk = Kp ek + Ki Σ ej + Kd (ek − ek−1); r is the desired value. The proportional term shrinks the error at once, the integral term removes a lasting error, the derivative term smooths sudden changes.

Example 23.3: Three behaviors of proportional control

A simple model: at each step the position changes by the command, xk+1 = xk + uk. The desired position is r = 10, start x0 = 0, proportional term only (Ki = Kd = 0). At every step the error is multiplied by ek+1 = (1 − Kp) ek.

  1. Kp = 0.5. The factor is 0.5: the position goes 5, 7.5, 8.75, 9.375, …, approaching without overshoot.
  2. Kp = 1.5. The factor is −0.5: the position goes 15, 7.5, 11.25, 9.375, 10.31, …, settling while swinging on both sides of the goal.
  3. Kp = 2.5. The factor is −1.5: the position goes 25, −12.5, 43.75, −40.63, …; the swings grow and the system is unstable.

If the absolute value of the factor is below 1 the error shrinks; in this model Kp < 2 is the stability limit. A larger gain speeds things up, but past some point it destroys stability.

A real robot also faces a steady disturbance: a slope, friction or a load. Proportional control then cannot quite reach the goal, because to produce a command the error must stay above zero. The integral term removes this.

Example 23.4: A lasting error and the integral

The same model, but a disturbance of −1 is added to the position at every step: xk+1 = xk + uk − 1; r = 10.

  1. Proportional only, Kp = 0.5. The position goes 4, 6, 7, 7.5, … and stalls at 8: there 0.5·(10 − 8) = 1 exactly cancels the disturbance.
  2. Proportional + integral, Kp = 0.5, Ki = 0.1. Step 1: e = 10, sum 10, u = 5 + 1 = 6, x = 6 − 1 = 5. Step 2: e = 5, sum 15, u = 2.5 + 1.5 = 4, x = 8. Step 3: e = 2, sum 17, u = 1 + 1.7 = 2.7, x = 9.7. Step 4: x = 10.58.

The integral term adds the accumulated error to the command and removes the lasting error; the price is a short overshoot (the position passes 10). Tuning the proportional, integral and derivative gains (PID tuning) is a balance between speed, overshoot and stability.

Common mistake

Raising the gain without limit to make the robot "faster and more robust". The Kp = 2.5 case throws the robot away from the goal. In a real system delay and sensor noise push the stability limit even lower; gains are raised starting from small values.

23.6Localization under uncertainty

A robot cannot read its position directly; it knows only noisy measurements and its motion commands. The probabilistic approach keeps the position not as a single number but as a probability distribution. In the simplest case the distribution is Gaussian and is described by two numbers: the mean (the best estimate) and the variance (the uncertainty). The Kalman filter repeats two steps in turn.

Definition 23.4 (One-dimensional Kalman filter)

Predict (motion): if the robot moves by u, the mean becomes μ ← μ + u and the variance σ² ← σ² + q; motion noise q increases uncertainty. Update (measurement): for a measurement z with variance r the gain is K = σ² / (σ² + r); the mean becomes μ ← μ + K (z − μ) and the variance σ² ← (1 − K) σ².

Example 23.5: Position in a corridor

A robot moves along one axis of a corridor. Initial belief: mean μ = 10 m, variance σ² = 4. A lidar measures the position z = 12 m with measurement variance r = 1. Then the robot moves u = 2 m (motion variance q = 1) and a second measurement z = 14 arrives, again with r = 1.

  1. First update. K = 4 / (4 + 1) = 0.8; μ = 10 + 0.8 · (12 − 10) = 11.6; σ² = 0.2 · 4 = 0.8.
  2. Predict. μ = 11.6 + 2 = 13.6; σ² = 0.8 + 1 = 1.8. Uncertainty grew.
  3. Second update. K = 1.8 / 2.8 ≈ 0.643; μ = 13.6 + 0.643 · (14 − 13.6) ≈ 13.86; σ² = (1 − 0.643) · 1.8 ≈ 0.64.

Each update shrinks the uncertainty (4 → 0.8 → 0.64), each motion enlarges it (0.8 → 1.8). The gain decides how much to trust the measurement: in the first step the estimate was uncertain, so the measurement got weight 0.8. The result is a mean between the measurement and the prediction, closer to the more reliable of the two.

The Kalman filter is optimal for linear models and Gaussian noise. If the robot may be in several places (as in a symmetric corridor) a single-peaked Gaussian is not enough; the particle filter represents the position with many weighted samples. Particles that agree with a measurement gain weight, those that do not are dropped. When a robot in an unknown place must estimate its position while building the map, the problem is called SLAM; the course extends these ideas to mapping.

Common mistake

Trusting the measurement and dropping the prediction, or the reverse. If only measurements are used, their noise passes straight through; if only the motion model is used, uncertainty (σ² + q) grows step by step and the robot gets lost. The value of the Kalman filter is that it weights the two by their variances.

23.7How is the course taught?

23.7.1A typical workflow

Sensecamera, lidar,IMULocalizefilters,SLAMPlanpath andtrajectoryControlPID, motorcommandsActwheels,joints
Figure 23.1: A typical workflow in Robotics and Robot Vision

A warehouse robot scans its surroundings with lidar and a camera, estimates its position on the map with a particle filter, plans a path between shelves with A* and sets wheel speeds with PID. The loop runs tens of times a second; each pass, measurements correct the plan.

23.7.2Topics over the semester

  1. Position and orientation: rotation matrices, frames
  2. Forward kinematics and Denavit-Hartenberg notation
  3. Inverse kinematics and the Jacobian
  4. Robot dynamics: forces, torques, equations of motion
  5. Feedback control: PID and stability
  6. Trajectory generation and manipulator control
  7. Mobile robot kinematics and odometry
  8. Sensors: cameras, lidar, IMU, encoders
  9. Probabilistic state estimation: the Kalman filter
  10. Particle filters and Monte Carlo localization
  11. Mapping and SLAM
  12. Motion planning: A*, probabilistic roadmaps, RRT

This is a typical semester; the order and coverage vary between universities.

23.7.3Skills you will gain

  • writing ROS 2 nodes and topics
  • simulating robots in Gazebo
  • planning arm motion with MoveIt
  • tuning PID gains
  • sensor fusion with a Kalman filter
  • robot vision with OpenCV

23.7.4Try it yourself

The Try It: A Robot Arm Picks Up a Part slide in the presentation lets you solve a typical problem of this course yourself: The tip of a two-joint arm on an assembly line must reach a part on the table, but motors take joint angles, not tip positions. Click a target: inverse kinematics computes the angles and the arm turns there.

23.8Are you ready for this course?

23.8.1Prerequisites

CourseWhy it is needed
Linear Algebracoordinate transforms, kinematics
Physics (mechanics)force, torque, velocity and acceleration: the language of robot dynamics
Microprocessorsreading sensors, driving motors and real-time software
Programming with Cembedded control software is mostly written in C/C++

23.8.2Ask yourself

For every "no", the right-hand column shows where to start. If you can say "yes" to most of them, you are ready.

QuestionIf not, start with
Can you move a 2D point into another frame with a rotation matrix?Linear Algebra
Can you explain velocity, acceleration and torque with an example?Mechanics from physics: Newton's laws and rotational motion
Can you explain what the mean and variance of a Gaussian tell you?Probability and Statistics
Can you write a class in C++ or Python and process sensor data in a loop?An intro C course, then a short introduction to classes in Python

23.9Neighboring courses

Reinforcement LearningFuzzy LogicMulti-Agent SystemsLinear AlgebraComputer VisionEmbedded AIRobotics
subfieldbuilds onshares methodsapplication
Figure 23.2: Neighbors of Robotics and Robot Vision and the kind of relation

23.9.1Where it overlaps

RelationCourseShared ground
builds onThis course builds on Linear Algebracoordinate transforms, kinematics
shares methodsShares methods with Reinforcement Learningcontrol, learning motor skills
shares methodsShares methods with Fuzzy Logic and Fuzzy Systemsfuzzy controllers
shares methodsShares methods with Multi-Agent Systemsswarm robotics, coordination
shares methodsShares methods with Computer Visionrobot vision, SLAM
shares methodsShares methods with Embedded AIreal-time on-device inference

23.9.2Where it differs

  • Computer Vision: Computer vision understands what is in a scene; robot vision turns the image into position and motion decisions.
  • Artificial Intelligence: AI plans over abstract states; robotics carries out the plan in a continuous, noisy, physical world.
  • Reinforcement Learning: Reinforcement learning learns control by trial and error; robotics mostly designs it from models and control theory.
  • Embedded AI: Embedded AI fits the model onto a small device; robotics ties that device into a loop with sensors and motors.

23.10In practice

23.10.1Applications

AreaWhat is done
Industrial armsWelding, painting, assembly lines.
Warehouse robotsMoving shelves and picking orders.
Autonomous vehiclesPerception, localization and planning.
Surgical robotsMaking the surgeon's motion more precise.
Planetary explorationMars rovers that drive autonomously, far from any operator.
Home robotsRobot vacuums and lawn mowers.

23.10.2Risks and ethics

RiskExplanation
Collisions with peopleRobot arms exert large forces; speed and force limits, emergency stops and safety zones are part of collaborative robot design.
Sensor failure and spoofingA dirty lidar, a camera blind spot or a spoofed GPS signal can lead a robot confidently to the wrong place.
Liability in autonomous crashesIn crashes such as the 2018 Uber test vehicle that killed a pedestrian in Arizona, blame is split between maker, operator and driver.
Surveillance and weaponsCamera-equipped mobile robots and drones open private spaces to monitoring; autonomous weapons are a separate international debate.

These issues are discussed in depth in Explainable AI and AI Ethics.

23.10.3Tools and datasets

Tools: ROS 2, Gazebo, MoveIt, OpenCV, Point Cloud Library, Webots.

Well-known datasets: KITTI, TUM RGB-D, EuRoC MAV, nuScenes, YCB object set.

In robotics most experiments run first in simulation; moving to a real robot brings friction, noise and latency.

23.11Common misconceptions

Common mistake

Robotics is only mechanics and electronics.

Today's hard problems are mostly in software: perception, localization and planning.

Common mistake

A good plan gets the robot to the goal.

Wheels slip and sensors are noisy; a plan holds only with continuous feedback.

Common mistake

What works in simulation works in reality.

The sim-to-real gap is a research topic of its own in robotics.

Common mistake

Robot vision is the same as computer vision.

Robot vision stresses depth, pose and real time; its output is a motion.

23.12Summary

  • A robot works in a sense-estimate-plan-control-act loop; every link of the loop is noisy and delayed.
  • A frame transformation moves a point from the robot frame to the world frame; forward kinematics gives the tip from joint angles, and inverse kinematics usually gives several solutions (or none).
  • Feedback control keeps measuring the error and correcting the command; a larger gain speeds things up but past a limit causes oscillation and instability.
  • Proportional control leaves a lasting error under a steady disturbance; the integral term removes it and brings a short overshoot.
  • The Kalman filter keeps position as a mean and a variance: motion increases uncertainty, a measurement decreases it; the particle filter and SLAM carry the same idea to multi-peaked and mapping problems.

23.13Test Yourself

  1. The robot frame is at (3, 2) in the world with heading θ = 0°. Where in the world is the point (2, 1) of the robot frame?

    Answer

    cos 0° = 1, sin 0° = 0: xw = 3 + 2 = 5, yw = 2 + 1 = 3. The heading does not change, so only the translation applies: (5, 3).

  2. For an arm with L1 = L2 = 1, θ1 = 90° and θ2 = −90°, where is the tip? Is the target (2.5, 0) reachable?

    Answer

    x = cos 90° + cos 0° = 1, y = sin 90° + sin 0° = 1: the tip is at (1, 1). For (2.5, 0), cos θ2 = (6.25 − 2)/2 = 2.125 > 1; there is no solution, the point is beyond the maximum reach of 2 m.

  3. Proportional control only, xk+1 = xk + uk, r = 10, x0 = 0, Kp = 1.2. What is the position after the first two steps? Is the control stable?

    Answer

    Step 1: e = 10, u = 12, x = 12. Step 2: e = −2, u = −2.4, x = 9.6. The error factor is 1 − 1.2 = −0.2, with absolute value below 1: it approaches the goal while oscillating and is stable.

  4. From its wheel encoders a robot reads that the left wheel moved 0.9 m and the right wheel 1.1 m; the distance between the wheels is 0.4 m. What are the heading change and the mean advance? If the robot was at (0, 0) with θ = 0, what is the approximate new position?

    Answer

    Δθ = (1.1 − 0.9)/0.4 = 0.5 rad; Δs = (0.9 + 1.1)/2 = 1.0 m. Using the mean heading (θ + Δθ/2 = 0.25 rad): x ≈ 1.0 · cos 0.25 ≈ 0.97, y ≈ 1.0 · sin 0.25 ≈ 0.25; the new heading is 0.5 rad.

  5. Prior belief: mean 0, variance 9. Measurement 4 with measurement variance 3. What are the mean and variance after the Kalman update? Why is the result closer to the measurement?

    Answer

    K = 9/(9 + 3) = 0.75; μ = 0 + 0.75 · 4 = 3; σ² = 0.25 · 9 = 2.25. The measurement variance (3) is smaller than the prior variance (9), so the measurement is more reliable; the gain is above 0.5 and pulls the mean toward the measurement. The new variance is smaller than both.

  6. A team proposes tracking position with the motion model alone (no measurements), adding variance q = 0.5 at every step. What is the position variance after 20 steps? Why is this a problem?

    Answer

    If the initial variance is 0, σ² = 20 · 0.5 = 10. Uncertainty grows linearly with the number of steps and with no measurement nothing pulls it back; the drift (odometry drift) accumulates. That is why the motion model is corrected with measurements from a lidar or a camera.

23.14After this course

Robotics brings vision, learning and control together in one physical system. From here you can move to learning motion with reinforcement learning, to multi-agent systems with robot swarms, or to on-device inference with embedded AI.

Related careers: Robotics software engineer, Control engineer, Perception engineer, Autonomous driving engineer, Mechatronics engineer.

23.15Further reading

  • K. M. Lynch and F. C. Park, Modern Robotics (2017): a modern textbook that treats frames, forward and inverse kinematics and control in one consistent language.
  • S. Thrun, W. Burgard and D. Fox, Probabilistic Robotics (2005): the standard reference for the Kalman filter, the particle filter and SLAM.
  • R. Siegwart, I. Nourbakhsh and D. Scaramuzza, Introduction to Autonomous Mobile Robots (2nd ed., 2011): mobile robot kinematics, perception and localization.

23.16References

  1. Siegwart, Nourbakhsh and Scaramuzza, Introduction to Autonomous Mobile Robots, 2nd ed., MIT Press, 2011.
  2. Thrun, Burgard and Fox, Probabilistic Robotics, MIT Press, 2005.
  3. Lynch and Park, Modern Robotics: Mechanics, Planning, and Control, Cambridge University Press, 2017.
  4. Corke, Robotics, Vision and Control, 2nd ed., Springer, 2017.

Related pages: Slides · Slides (PDF) · Course page