Robotics From First Principles
Sense, think, act: actuators, frames, transforms, kinematics, motion and knowing where you are
Eight chapters that build a robot from the loop outwards. Start with sense, think, act and the motors that do the acting, learn to describe positions in frames and move between them with rotations and transforms, place a robot hand with forward and inverse kinematics, plan smooth motion, and finish by fusing uncertain measurements so the robot knows where it is.
Compiled and written by the Tactiverge team with AI assistance, from Tactiverge School lessons that were themselves written with AI assistance.
1. Sense, think, act
Every robot, from a robot vacuum to a Mars rover, runs the same loop: read its sensors, decide what to do, drive its actuators, and go round again many times a second. This chapter takes the loop apart. What makes a machine automatic rather than intelligent, what sensors can and cannot tell you, what actuators do, and why the loop rate sets a hard time budget for everything inside it.
Figure 1.1. 50 Hz means 20 ms per pass (described in words)
A 20 ms time bar for a 50 Hz loop split into sense 4 ms, think 6 ms and act 2 ms, with 8 ms spare. An arrow returns to the start: then round again, forever. Used 12 of 20 ms.
Explanation
1.1 Automatic or intelligent?
A music box plays the same tune perfectly every time. A robot vacuum never cleans your room the same way twice. Which one is smarter?
Automatic machines repeat
A music box, a toaster with a timer, or a wind-up toy does the same steps in the same order, whatever is happening around it. That is automatic. It can be precise and useful, but if the world changes, it carries on regardless.
Intelligent machines respond
An intelligent machine senses something about the world, decides what to do using rules, and acts. A robot vacuum feels a bump and turns. A night light measures darkness and switches on. Change the world and its behaviour changes too.
Smart is a spectrum
Engineers rarely mean 'thinks like a person'. They mean 'does the right thing in more situations'. A light that turns on at 7 pm is automatic. One that turns on when it gets dark is a little intelligent. One that also learns when you usually come home is more intelligent still.
Common mix-ups
Intelligent machines think like people.
✓ In engineering, an intelligent machine senses, follows rules and acts sensibly in changing situations. It doesn't need feelings or understanding.A better sensor makes a machine smarter.
✓ Sensors only measure. The intelligence is in the rules that turn measurements into actions.
1.2 Sense, think, act
A robot vacuum bumps a chair leg, backs off and turns. In that half second it did three different jobs. What were they?
Sense
Measure something about the world: a distance, a temperature, a colour, whether a button is pressed. A machine can only react to what it can measure.
Think
Compare the measurement with what you want and choose an action. At this level the thinking is usually a rule: if the wall is closer than 20 cm, stop. Rules can be simple and still produce clever-looking behaviour.
Act
Change something in the world: spin a motor, open a valve, sound a buzzer, light an LED. The parts that do this are called actuators.
Then do it again
Acting changes the world, so the next measurement is different. The loop goes round and round, often hundreds of times a second. That repetition is what lets a robot notice surprises and correct itself.
Common mix-ups
A robot senses once, makes a plan and follows it.
✓ Reliable robots sense again and again while they act, so they can react to changes.Only motors count as actuators.
✓ Anything that changes the world on the machine's command counts: valves, heaters, lights, speakers.
1.3 Sensors: how machines feel the world
Bats find moths in the dark by shouting and listening. Which robot sensor copies them?
A sensor turns the world into a number
A sensor measures something physical and reports it as a reading the controller can use: a distance in cm, a temperature in °C, pressed or not pressed. Without sensors, a machine is blind and deaf.
A sensor zoo
- Distance: ultrasonic (sound echoes) or infrared (light).
- Touch: bump switches, pressure pads.
- Light: light sensors, cameras.
- Temperature: thermometers.
- Movement: wheel encoders count turns; accelerometers feel tilt and shaking.
On/off or a number
Some sensors give just two answers (digital: pressed or not). Others give a whole range (analogue: 0 to 100 cm). A bump switch only tells you that you hit something; a distance sensor tells you how close it is before you hit it.
Common mix-ups
A camera is the best sensor for everything.
✓ Cameras are powerful but need lots of processing and struggle in the dark. Often a simple sensor does the job better.An ultrasonic sensor's echo time is the time to reach the object.
✓ It's the time there and back, so halve it.
1.4 Actuators: how machines change the world
A robot hand must hold an egg and a steel bolt. Same motor, same fingers. How can it crush one and drop the other?
Actuators make things happen
An actuator is a part that the controller switches or drives to change the world. Common ones:
- DC motor: spins continuously (wheels, fans).
- Servo: turns to a chosen angle (joints, steering).
- Solenoid: pushes or pulls a short distance (locks, valves).
- Heaters, lights, buzzers.
Joints are degrees of freedom
Each motor-driven joint gives a robot one way to move, called a degree of freedom. A gripper finger with a knuckle and a middle joint has two. More joints mean more possible poses, and more motors to control.
Actuators need feedback
A motor alone doesn't know how far it turned or how hard it's pushing. Pair it with a sensor (an encoder for angle, a pad for touch) and the controller can stop at the right place or the right squeeze.
Common mix-ups
Only motors are actuators.
✓ Heaters, lights, valves, locks and speakers are actuators too: anything the controller uses to change the world.A stronger actuator is always better.
✓ Too much force or speed can damage things. The right actuator, well controlled, beats the biggest.
Examples to try
Worked solutions are in the interactive chapter online.
Automatic or intelligent?: example 1
Is a microwave that runs for exactly 2 minutes automatic or intelligent? What would make it intelligent?
Sense, think, act: example 1
Split a smart greenhouse fan into sense, think and act.
Sensors: how machines feel the world: example 1
A robot must stop before touching a wall and also know if it has been bumped from behind. Choose sensors.
Actuators: how machines change the world: example 1
Choose an actuator for: (a) the wheels of a robot car, (b) a robot's elbow joint, (c) an automatic door lock.
Interactive figures, in words
Figure 1.2 from “Sense, think, act”
This robot's 'think' step is one rule. Slide the sensor reading towards the wall and watch the decision change. Each time you move the slider, you are doing one more turn of the loop.
The rule tester can be replaced by this description: the rule is 'IF distance < 20 cm THEN stop ELSE drive forward'. At 35 cm the condition is false so the robot drives; at 15 cm it is true so it stops; at exactly 20 cm, 20 < 20 is false, so it still drives.
Figure 1.3 from “Sensors: how machines feel the world”
Sort each part into Sense, Think or Act. Read the explanation after each choice, especially for any you got wrong.
The sorting activity can be replaced by this list. Sense: ultrasonic distance sensor, bump switch, thermometer, wheel encoder. Think: microcontroller. Act: DC motor, buzzer, servo motor, heater.
Laboratory (online)
These run in a browser on the full site. Simulations are simplified educational models.
- BUILD: Planetary rover, level 1 (BUILD level)
Name every sensor and actuator on the rover and say which part of the loop each one belongs to.
Open online - Nexus: Virtual Autonomous Rover (Nexus project)
Trace one pass of the rover's loop from a sensor reading to a wheel command.
Open online
Practice questions
Questions only. Each one is answered in its Lite lesson online, where it is checked on our server.
1. Which of these machines is intelligent rather than just automatic?
- A clock that chimes every hour
- A garden sprinkler that runs from 6:00 to 6:20 every morning
- A sprinkler that waters only when a soil sensor reads dry
- A conveyor belt that always runs at the same speed
Check it in “Automatic or intelligent?”
2. 'If the soil is drier than 30%, open the water valve.' Which stage is this sentence?
- Sense
- Think
- Act
Check it in “Sense, think, act”
3. A robot runs its sense–think–act loop 50 times every second. How many times does it run the loop in 3 seconds?
Answer:
Check it in “Sense, think, act”
4. A greenhouse needs to know when the soil is dry. Which sensor fits?
- Light sensor
- Soil moisture sensor
- Wheel encoder
Check it in “Sensors: how machines feel the world”
5. Is a speaker a sensor or an actuator?
- Sensor
- Actuator
Check it in “Sensors: how machines feel the world”
6. Which actuator is best for pointing a camera at a chosen angle and holding it there?
- DC motor
- Servo
- Buzzer
Check it in “Actuators: how machines change the world”
7. A robot arm has a shoulder, an elbow and a wrist, each turned by its own motor. How many degrees of freedom does it have?
Answer:
Check it in “Actuators: how machines change the world”
Engineering applications
Robot vacuums
A robot vacuum senses bumps, cliffs and dirt, decides whether to turn, reverse or keep cleaning, and drives two wheels and a brush. Its whole behaviour is that loop repeated many times a second.
Missed deadlines
If the think step sometimes takes longer than the loop period, commands arrive late and the robot reacts to an old world. Engineers measure the worst case, not the average, and leave spare time in every pass.
Summary
- A robot repeats sense, think, act; the faster and more regular the loop, the more responsive it is.
- Sensors turn the world into numbers; actuators turn numbers back into motion, light, sound or heat.
- The loop rate sets a time budget: at 50 Hz every pass, including the worst one, must fit in 20 ms.
Glossary
- Sense–think–act loop
- Most robots run a repeating cycle: read sensors, decide what to do, command actuators, then repeat, usually at a fixed rate.
- IMU (inertial measurement unit)
- An IMU combines an accelerometer, which measures acceleration including gravity, and a gyroscope, which measures angular velocity; some add a magnetometer.
- Encoder counts and resolution
- A rotary encoder reports rotation as a count of ticks. Its resolution is the number of counts per revolution (CPR), often four times the pulses per revolution with quadrature decoding.
- Degrees of freedom
- The degrees of freedom of a mechanism are the number of independent ways it can move. A rigid body free in space has 6: three translations and three rotations.
Project: A loop on paper
Design the sense–think–act loop for a robot that follows a line on the floor. List its sensors and actuators, write the rule it applies each pass in plain words, choose a loop rate and give a time budget for each stage with some spare.
Deliverables
- A block diagram of the loop
- The rule applied each pass
- A time budget that fits the loop period with a stated margin
References
- Roland Siegwart et al. (2011). Introduction to Autonomous Mobile Robots, 2nd edition. MIT Press.
- Peter Corke (2017). Robotics, Vision and Control: Fundamental Algorithms in MATLAB, 2nd edition. Springer.
2. Actuators and drives
A DC motor spins fast and weakly, a servo holds an angle, and a stepper moves in exact clicks. Choosing between them is choosing what you need to control: speed, position or count. Small motors almost never drive a joint directly; a gearbox trades their speed for turning force. And because a microcontroller pin can supply only a trickle of current, every real motor needs a driver in between.
Figure 2.1. Trade speed for torque (described in words)
A motor producing 0.05 N·m at 6000 rpm drives a 30:1 gearbox. Ideally the joint gets 0.05 × 30 = 1.5 N·m at 200 rpm; with 80% efficiency it gets 1.2 N·m.
Explanation
2.1 DC motors, servos and steppers
A fan, a robot's elbow and a 3D printer's nozzle all move with motors. Why do they use three different kinds?
DC motor: speed from voltage
A DC motor spins when current flows: more voltage, more speed; reverse the voltage, reverse direction. It is cheap, fast and powerful for its size, which is why fans, drills and wheels use it. But it does not know its position. To control position it needs a sensor such as an encoder and a feedback loop.
Servo: an angle on command
A hobby servo packs a small DC motor, a gearbox, a position sensor and a control circuit into one box. You send it a pulse that means an angle (next lesson), and its built-in feedback turns to that angle and holds it. Great for robot joints, steering and flaps; most hobby servos only cover about 180°.
Stepper: counted steps
A stepper motor moves in fixed steps each time its coils are switched in order. A common type has 200 steps per revolution: 360° ÷ 200 = 1.8° per step. Count steps and you know the angle without a sensor, as long as it never skips (too much load or acceleration makes it skip silently). Printers and CNC machines use steppers.
Common mix-ups
A servo is a special kind of motor that spins.
✓ A hobby servo is a motor plus gears plus a position sensor plus control electronics, built to reach and hold angles.Steppers always know where they are.
✓ They know how many steps they were told to take. If they skip, nothing tells them.
2.2 Talking to a servo in milliseconds
A servo has just one signal wire. How do you tell it 'turn to 135°' with a single wire that is only ever on or off?
A pulse every 20 ms
A hobby servo expects a pulse about every 20 ms (50 times a second). The width of each pulse carries the command. A common mapping is 1.0 ms → 0°, 1.5 ms → 90°, 2.0 ms → 180°. The voltage of the pulse is just 'high'; the information is in the time.
A straight-line mapping
Between the ends, angle and pulse width are linked by a straight line: angle = (pulse − 1.0 ms) × 180° per ms, and pulse = 1.0 ms + angle ÷ 180° × 1 ms. So each 0.1 ms is worth 18°. In Python:
def pulse_ms(angle):
return 1.0 + angle / 180Duty cycle of a servo signal
The duty cycle is the fraction of each period spent high. A 1.5 ms pulse every 20 ms is 1.5 ÷ 20 = 7.5%. The whole servo range lives between 5% and 10% duty. Microcontrollers make this signal with a timer-driven PWM peripheral, which you meet in week 25.
Common mix-ups
A servo's angle is set by the voltage on its signal wire.
✓ It is set by the pulse width. The signal is always either high or low.All servos use exactly 1–2 ms.
✓ That is a common convention; real models vary, so check the datasheet and test the ends carefully.
2.3 Choosing an actuator, and why pins need help
Your microcontroller pin can light an LED. Can it run a 6 W motor on its own?
Power, voltage, current
Electrical power is P = V × I. Rearranged, I = P ÷ V. A 12 V, 18 W pump draws 1.5 A; a 5 V, 1.5 W fan draws 0.3 A. Small motors often draw several times their running current for a moment when starting or stalled, so drivers and supplies need extra headroom.
Pins command, drivers deliver
A pin can safely supply only milliamps. Motors need amps, and they make electrical noise and voltage spikes. So the pin sends a small logic signal to a driver (a transistor or a motor-driver chip), which switches a separate supply through the motor. A diode or the driver's built-in protection catches the spike when the motor is switched off. Servos and stepper drivers follow the same idea.
A fair comparison
List what the task needs (angle or speed? holding force? cost? power?) and score each actuator against it, as in the trade-offs lab. Write down the must-haves first: a vent that must hold 45° in wind rules out a plain DC motor without a sensor, however cheap it is.
Common mix-ups
If a motor is small, a pin can power it.
✓ Even small motors draw hundreds of milliamps and spike when switched. Always use a driver.The cheapest actuator is the best choice.
✓ Must-haves come first. A cheap actuator that cannot hold an angle fails the task.
Examples to try
Worked solutions are in the interactive chapter online.
DC motors, servos and steppers: example 1
A 200-step stepper drives a dial. How many steps turn it through 54°?
Talking to a servo in milliseconds: example 1
What pulse width sets 45°, and what duty cycle is that at 50 Hz?
Choosing an actuator, and why pins need help: example 1
A 12 V greenhouse fan is rated 3 W. Its current, and how long can it run on a 12 V, 7 Ah battery?
Interactive figures, in words
Figure 2.2 from “Talking to a servo in milliseconds”
Set the PWM frequency to 50 Hz. Find the duty cycles that give a high time of 1.0 ms, 1.5 ms and 2.0 ms per period. (Ignore the motor readout here: a servo listens to pulse width, not average voltage.)
The PWM visualiser shows a square wave whose high time is the duty cycle times the period. At 50 Hz the period is 20 ms, so 5% duty gives a 1.0 ms pulse, 7.5% gives 1.5 ms and 10% gives 2.0 ms: the pulse widths a hobby servo reads as 0°, 90° and 180° in the common mapping.
Laboratory (online)
These run in a browser on the full site. Simulations are simplified educational models.
- Simulation OS: One robot joint (Simulation OS experiment)
Lower the torque limit until the joint can no longer reach its target in time, and note the limit.
Open online - Robotics Workbench (Studio)
Choose an actuator for a gripper finger and justify the choice in one sentence.
Open online
Practice questions
Questions only. Each one is answered in its Lite lesson online, where it is checked on our server.
1. Which actuator suits a desk fan best?
- A DC motor
- A hobby servo
- A stepper motor
Check it in “DC motors, servos and steppers”
2. A stepper with 48 steps per revolution must turn 90°. How many full steps is that?
Answer: steps
Check it in “DC motors, servos and steppers”
3. A stepper-driven printer head is pushed too hard and skips 10 steps. What does the firmware believe?
- It notices and corrects
- It still thinks the head is where it counted, so every later move is offset
- The motor stops forever
Check it in “DC motors, servos and steppers”
4. A hobby servo is told 1.0 ms means 0° and 2.0 ms means 180°, in a straight line between. How long a pulse sets it to 0°, in milliseconds?
Answer: ms
Check it in “Talking to a servo in milliseconds”
5. A servo signal has a 20 ms period and a 1.8 ms pulse. What is the duty cycle, in percent?
Answer: %
Check it in “Talking to a servo in milliseconds”
6. A 9 V DC motor uses 1.5 W when running. How much current does it draw, in amps?
Answer: A
Check it in “Choosing an actuator, and why pins need help”
7. Why does a motor connect through a driver with its own supply?
- Drivers make motors quieter
- Pins supply only milliamps, and motors need amps and produce voltage spikes
- Microcontrollers cannot make 0 and 1
Check it in “Choosing an actuator, and why pins need help”
Engineering applications
3D printers
Printers use stepper motors because counting steps gives position without a sensor. If a nozzle snags and steps are skipped, the printer does not know, and every later layer is shifted: the classic layer-shift fault.
Robot arms
Arm joints usually pair a fast motor with a high-ratio gearbox and an encoder. The gearbox multiplies torque, the encoder closes the loop on position, and the motor driver supplies the current the logic cannot.
Summary
- DC motors suit speed, servos suit angle, steppers suit counted steps.
- A gearbox multiplies torque by its ratio and divides speed by it, minus losses.
- A servo reads its target angle from the width of a repeating pulse.
- Motors draw far more current than a logic pin can give, so a driver switches the real power.
Glossary
- Hobby servo motor
- A hobby servo is a motor, gearbox, position sensor and controller in one case. It moves to an angle set by the width of a pulse repeated about every 20 ms.
- Stepper motor step angle
- A stepper motor turns in fixed increments called steps. A common motor has a 1.8° step, which is 200 full steps per revolution; microstepping divides each step further.
- Stall torque and no-load speed
- For a DC motor, stall torque is the torque at zero speed and no-load speed is the speed with zero torque; between them torque falls roughly linearly as speed rises.
- Gear ratio
- A gear ratio is the driven gear's teeth divided by the driver's teeth. It divides speed and, ignoring losses, multiplies torque by the same factor.
- PWM average voltage
- Pulse-width modulation switches a signal fully on and off quickly; the fraction of time it is on, the duty cycle, sets the average voltage delivered.
Project: Pick the motor
A camera turret must turn 180° in one second and hold its angle against a light wind. Compare a DC motor with an encoder, a hobby servo and a stepper for the job. Estimate the torque needed, choose a gear ratio if one is required, and explain how the motor will be driven.
Deliverables
- A comparison table of the three actuators
- A torque estimate and gear ratio
- A sketch of the driver between microcontroller and motor
References
- Kevin M. Lynch and Frank C. Park (2017). Modern Robotics: Mechanics, Planning, and Control. Cambridge University Press.
- Mark W. Spong et al. (2006). Robot Modeling and Control. Wiley.
3. Vectors and frames
A position is an arrow from somewhere. Change the somewhere and the same point gets a new address. Robots juggle frames constantly: the world frame on the map, the body frame on the chassis, a frame on every joint. This chapter adds and measures arrows, finds directions with atan2, and converts a point seen by the robot into a point on the map, which is how a robot knows where an obstacle really is.
Figure 3.1. One point, two addresses (described in words)
A robot at (2, 1) on a map, facing 90° (straight up the y axis). A point 1 m ahead in its body frame is at (2, 2) in the world, and a point 1 m to its left is at (1, 1).
Explanation
3.1 Vectors: arrows you can add
A drone flies 3 m east, then 4 m north. It is 5 m from where it started, not 7. Where did the other 2 m go?
Size and direction, written as components
A vector is a quantity with a size and a direction, such as a displacement, a velocity or a force. In 2D we write it as two components, v = (vx, vy): how far along x, then how far along y, measured in some coordinate frame. The same arrow drawn anywhere on the page is the same vector; only its components matter.
Adding: tip to tail, or part by part
To add a and b, draw b starting where a ends; the sum runs from the start of a to the end of b. Algebraically that is just a + b = (ax + bx, ay + by). Subtraction works the same way: a − b is the arrow from the tip of b to the tip of a. Scaling by a number k multiplies both parts: k·a = (k·ax, k·ay).
Magnitude: Pythagoras in disguise
The components form the two short sides of a right-angled triangle, so the length (magnitude) is |v| = √(vx² + vy²). Lengths do not add like components: |a + b| ≤ |a| + |b|, with equality only when a and b point the same way. That is the drone's missing 2 m: 3 east + 4 north is (3, 4), length 5.
Common mix-ups
The length of a + b is |a| + |b|.
✓ Only when a and b point the same way. In general |a + b| is smaller, and you must add components first.Moving an arrow to a different place on the page makes it a different vector.
✓ A vector is just its components. Position on the page doesn't matter; that is what lets you draw tip to tail.
3.2 Which way is it pointing? Direction with atan2
Your calculator says tan⁻¹(−1 ÷ −1) = 45°. But (−1, −1) points down and to the left. Who is wrong?
Two ways to write the same arrow
Components: (x, y). Polar form: length r and direction θ, measured anticlockwise from +x. To go from polar to components: x = r cos θ, y = r sin θ. To go back: r = √(x² + y²) and θ from the inverse tangent, carefully.
Why tan⁻¹(y/x) lies
tan θ = y/x, but dividing throws away the signs: (1, 1) and (−1, −1) both give y/x = 1. So tan⁻¹ can only answer between −90° and 90°: it is right for vectors pointing rightwards (x > 0) and exactly 180° out for vectors pointing leftwards. At x = 0 it divides by zero.
atan2: the angle that knows its quadrant
atan2(y, x) takes the two parts separately, checks their signs and returns an angle in (−180°, 180°]. Add 360° to negative answers if you want 0–360°. It is in every language: Python's math.atan2, JavaScript's Math.atan2, C's atan2. Note the order: y first. Robot code uses it to turn components back into headings and joint angles.
Common mix-ups
tan⁻¹(y/x) always gives a vector's direction.
✓ Only when x > 0. Use atan2(y, x), which checks both signs.atan2 takes (x, y) like a coordinate.
✓ It takes (y, x): the y component first. Swapping them gives the angle measured from the y axis instead.
3.3 One point, many addresses: coordinate frames
The gripper's camera says the cup is 10 cm ahead. The base says it is 52 cm to the right. They are both correct. How?
A frame is an origin plus axes
A coordinate frame is a chosen origin and a pair of perpendicular unit axes (x and y in 2D). A point's coordinates are its distances along those axes from that origin. Change the origin or turn the axes and the numbers change, even though the point hasn't moved.
Every part gets a frame
Robots typically use a world frame fixed to the room, a base frame on the robot, a frame on each link (x along the link) and a tool frame at the gripper tip. Sensors have frames too: a camera measures in a camera frame. We label points with the frame they're in, for example p_base or p_camera, and never mix them.
Translating between frames
If frame B's origin sits at t in frame A and B's axes are not rotated, then p_A = p_B + t. If B is also rotated, the axes no longer line up and we must rotate first: p_A = R·p_B + t. Rotations need matrices (week 13); the full move between frames is a transform (week 14). For now: always ask 'in which frame is this number?'.
Common mix-ups
A point has one true set of coordinates.
✓ Coordinates belong to a frame. The point is real; its numbers depend on the frame you measure from.Changing frames is always just adding an offset.
✓ Only when the axes are parallel. Rotated frames also mix x and y, which needs a rotation.
3.4 Body frame, world frame: how a vehicle sees the world
A pilot says 'traffic at two o'clock'. Air traffic control says 'traffic north-east of you'. Same aircraft. Why two languages?
Two frames, two jobs
The world frame is fixed: for an aircraft or rover, east (x) and north (y) on a flat map; for a spacecraft, axes pointing at chosen distant stars, because space has no 'north'. The body frame moves with the vehicle: x out of the nose, y out of the left side (and z up in 3D). Engines push along body axes; maps and waypoints are given in world axes.
Heading links them
Heading is the compass direction of the nose, in degrees clockwise from north. Maths angles go anticlockwise from +x (east). So the nose's maths angle is ψ = 90° − heading. A heading of 0° (north) is ψ = 90°; heading 90° (east) is ψ = 0°. Mixing the two conventions is a classic navigation bug.
What changes when you turn
Turn the vehicle and every body-frame coordinate of the outside world changes, while world-frame coordinates stay put. That is why a pilot's 'two o'clock' needs updating after every turn, while air traffic control's 'north-east' does not. Converting a world point into the body frame means: subtract the vehicle's position, then rotate by −ψ.
Common mix-ups
Heading and the mathematical angle are the same number.
✓ Heading is clockwise from north; the maths angle is anticlockwise from east. ψ = 90° − heading.The body frame is just the world frame moved to the vehicle.
✓ It is moved AND rotated with the nose. That rotation is why turning changes every body-frame number.
Examples to try
Worked solutions are in the interactive chapter online.
Vectors: arrows you can add: example 1
A rover drives a = (5, −2) m, then b = (−1, 6) m. Where does it end up, and how far is that from the start?
Which way is it pointing? Direction with atan2: example 1
Give the direction of (4, −9) in degrees from 0 to 360.
Which way is it pointing? Direction with atan2: example 2
A 2.5 m link points at 200°. Where is its tip?
One point, many addresses: coordinate frames: example 1
A camera is mounted 0.1 m forward and 0.05 m up from a gripper's origin, not rotated. It sees a cup at (0.25, −0.05) m in its own frame. Where is the cup in the gripper frame?
Body frame, world frame: how a vehicle sees the world: example 1
A simulated drone is at (0, 0) heading 180° (south). A waypoint is at (4, 0) km (east). Where is it in the body frame?
Interactive figures, in words
Figure 3.2 from “Vectors: arrows you can add”
In 'Add tip to tail', set a = (3, 1) and b = (1, 2.5). Check the green sum against your prediction. Now make b point exactly opposite to a. What happens to a + b? Then find a b for which |a + b| = |a| + |b|.
The vector playground draws vector a in blue from the origin, vector b in orange starting at the tip of a, and their sum in dashed green from the origin to the tip of b. The readout lists every component, the sum and its length, and the same information is in the text above.
Figure 3.3 from “Body frame, world frame: how a vehicle sees the world”
Start with the aircraft. Choose ALPHA and read its body-frame position. Now change only the heading, in steps of 45°. Which numbers in the readout change, and which stay the same? Switch to the spacecraft: what replaces 'north'?
The diagram shows a top-down map with a vehicle icon, its forward (blue) and left (green) body axes, and a diamond-shaped waypoint joined to it by a dashed line. The readout gives the waypoint's world coordinates, distance and bearing, plus its body-frame forward and left distances. Turning the vehicle changes only the body-frame numbers.
Laboratory (online)
These run in a browser on the full site. Simulations are simplified educational models.
- Equation Lab: Vectors (Equation Lab exploration)
Add two displacement vectors and check the length of the result with Pythagoras.
Open online - BUILD: Planetary rover, level 2 (BUILD level)
Convert an obstacle seen 2 m ahead of the rover into map coordinates for two different headings.
Open online
Practice questions
Questions only. Each one is answered in its Lite lesson online, where it is checked on our server.
1. a = (2, −3) and b = (−5, 4). What is the x component of a + b?
Answer:
Check it in “Vectors: arrows you can add”
2. What is the magnitude of the vector (6, 8)?
Answer:
Check it in “Vectors: arrows you can add”
3. atan2(3, −4) is closest to which angle?
- −36.9°
- 36.9°
- 143.1°
- 216.9°
Check it in “Which way is it pointing? Direction with atan2”
4. For which vector does tan⁻¹(y/x) give the correct direction?
- (−2, 5)
- (3, −1)
- (−1, −1)
- (0, 4)
Check it in “Which way is it pointing? Direction with atan2”
5. Frame B's origin is at (3, −1) in frame A, with the same axis directions. A point is at (2, 4) in B. What is its x coordinate in A?
Answer:
Check it in “One point, many addresses: coordinate frames”
6. In a simulation, an aircraft is at (−4, 0) km with its nose pointing 135° anticlockwise from the world +x axis. A waypoint is at (4, −2) km. In the aircraft's body frame (x forward, y to the left), what is the waypoint's forward (x) coordinate, in km? (2 decimal places; negative means behind)
Answer: km
Check it in “Body frame, world frame: how a vehicle sees the world”
7. A rover heads north (ψ = 90°) from (0, 0). A rock is at (−3, 5) m. How far to the LEFT of the rover is it, in metres? (Body frame: y is left.)
Answer: m
Check it in “Body frame, world frame: how a vehicle sees the world”
Engineering applications
Mapping obstacles
A lidar reports each obstacle as a distance and angle from the robot. To put it on a shared map, the robot rotates it by its own heading and adds its own position: a body-to-world conversion, many thousands of times a second.
Why atan2
The angle of an arrow from tan alone is ambiguous: (1, 1) and (−1, −1) give the same ratio. atan2 looks at both signs and returns the right quadrant, which is why navigation code uses it everywhere.
Summary
- A vector has components; add vectors by adding components, and find length with Pythagoras.
- atan2(y, x) gives the direction of an arrow in the correct quadrant, unlike tan alone.
- The same point has different coordinates in different frames.
- Body to world: rotate by the robot's heading, then add the robot's position.
Glossary
- Vector addition
- Vectors are added component by component: the x parts add, the y parts add, and the result is the single vector with the same effect as both.
- Vector magnitude and direction
- A 2D vector can be written as components (x, y) or as a magnitude and a direction angle; cosine and sine convert between the two.
- Coordinate frame
- A coordinate frame is an origin plus a set of axes used to describe positions and directions. Robots use several: world, base, each joint, sensors and the tool.
- Pythagoras' theorem
- In a right-angled triangle, the square of the hypotenuse equals the sum of the squares of the other two sides.
- Dot product
- The dot product of two vectors multiplies matching components and adds them; it also equals the product of their lengths and the cosine of the angle between them.
Project: From sensor to map
A robot at a known position and heading sees three obstacles, each given as a distance and bearing relative to its nose. Convert all three into world coordinates by hand and in code, then repeat after the robot turns 90°. Plot both sets and explain why the world positions did not change.
Deliverables
- Hand calculations for one obstacle
- A short program converting all three
- A plot and a one-paragraph explanation
References
- Kevin M. Lynch and Frank C. Park (2017). Modern Robotics: Mechanics, Planning, and Control. Cambridge University Press.
- John J. Craig (2005). Introduction to Robotics: Mechanics and Control, 3rd edition. Pearson Prentice Hall.
- Roland Siegwart et al. (2011). Introduction to Autonomous Mobile Robots, 2nd edition. MIT Press.
4. Rotations and transforms
A matrix is a machine that moves vectors. The rotation matrix turns any arrow by an angle without stretching it, and a homogeneous transform packs a rotation and a shift into one matrix so that chains of frames become chains of multiplications. Order matters: rotate then shift is not shift then rotate. With transforms you can walk from the world to a gripper and back again.
Figure 4.1. Rotate, then shift (described in words)
The vector (2, 0) rotated by 30° becomes (1.732, 1); shifting that by (1, 0.5) gives (2.732, 1.5). One homogeneous transform performs both steps at once.
Explanation
4.1 A matrix is a machine that moves vectors
Four numbers in a box can rotate, stretch, shear or flip an entire plane at once. How do they know where everything goes?
The recipe
For M = [a b; c d] and v = (x, y): M·v = (a·x + b·y, c·x + d·y). Each output component is one row of M dotted with v. A 2×2 matrix takes a 2D vector to another 2D vector.
Columns are where the axes land
M·(1, 0) = (a, c), the first column. M·(0, 1) = (b, d), the second column. Any vector (x, y) = x·(1, 0) + y·(0, 1), so M·v = x·(column 1) + y·(column 2). To design a matrix, decide where (1, 0) and (0, 1) should go and write those as columns. Grid lines stay straight, parallel and evenly spaced: that's what 'linear' means.
The determinant
det M = ad − bc is the factor by which areas change. det = 1: areas kept (rotations). det = 2: doubled. Negative: the plane is flipped over (a mirror image). det = 0: the plane is squashed onto a line or a point, information is lost, and the matrix cannot be undone.
Common mix-ups
The rows of a matrix tell you where the axes go.
✓ The columns do: column 1 is where (1, 0) lands, column 2 where (0, 1) lands.A negative determinant means the matrix shrinks things.
✓ The size of det is the area factor; the minus sign means a flip (mirror image).
4.2 The rotation matrix, built from scratch
Every robot, game engine and spacecraft turns things with the same four entries: cos, −sin, sin, cos. Where does that minus sign come from?
Using R(θ)
To rotate a point about the origin by θ (anticlockwise positive): x′ = x cos θ − y sin θ, y′ = x sin θ + y cos θ. For a clockwise rotation, use a negative θ: cos stays the same, sin changes sign. To rotate about some other pivot, shift the pivot to the origin, rotate, then shift back.
What makes it a rotation
Its columns are unit length and perpendicular to each other, so lengths and angles are kept (it is 'orthogonal'), and det = 1, so it doesn't mirror. A matrix with orthonormal columns but det = −1 is a reflection, not a rotation.
Same matrix, two stories
R(θ)·p can mean 'turn the point p by θ' or 'p is given in a frame turned by θ; here it is in the outer frame'. Both are the same calculation. Robotics uses the second story constantly: a link frame rotated by θ1 turns the link's own coordinates into the base frame's.
Derivation: Deriving R(θ)
A matrix is fixed by where it sends (1, 0) and (0, 1): those images are its columns.
Rotating (1, 0) by θ lands on the unit circle at angle θ: (cos θ, sin θ). That's column 1.
(0, 1) starts at 90°, so after rotating it is at θ + 90°: (cos(θ + 90°), sin(θ + 90°)) = (−sin θ, cos θ). That's column 2, and the source of the minus sign.
So R(θ) = [cos θ −sin θ; sin θ cos θ], and R(θ)·(x, y) = (x cos θ − y sin θ, x sin θ + y cos θ).
Check lengths: (x cos θ − y sin θ)² + (x sin θ + y cos θ)² = x²(cos² + sin²) + y²(sin² + cos²) + (cross terms that cancel) = x² + y². Lengths are kept.
Check area: det R = cos θ · cos θ − (−sin θ) · sin θ = cos²θ + sin²θ = 1. No stretching, no flipping.
Common mix-ups
The minus sign in R(θ) goes on the bottom-left entry.
✓ It goes top-right: column 2 is where (0, 1) lands, (−sin θ, cos θ). Rebuild it from a sketch if unsure.A rotation matrix rotates about any point you like.
✓ It rotates about the origin. For another pivot, translate, rotate, translate back (or use a homogeneous transform).
4.3 Homogeneous transforms: rotate and shift in one matrix
A 2×2 matrix can't move the origin. Add a row of 0, 0, 1 and suddenly it can. What is that extra 1 doing?
The 3×3 transform
T = [cos θ −sin θ tx; sin θ cos θ ty; 0 0 1] describes a frame turned by θ with its origin at (tx, ty) in its parent. Top-left 2×2: the rotation. Right column: where the frame's origin is. Bottom row: always 0, 0, 1. Points go in as (x, y, 1).
Reading T_parent←child
We label transforms by what they convert: T_WA turns coordinates in frame A into coordinates in the world W. So p_W = T_WA · p_A. Its columns even tell a story: column 1 is A's x axis seen in W, column 2 is A's y axis, column 3 is A's origin in W.
Points and directions
Points (positions) carry a 1: they get rotated and shifted. Directions (velocities, forces, axes) carry a 0: they get rotated only, because moving a frame doesn't change which way an arrow points. Keeping that last coordinate right is a common source of bugs in robot code.
Derivation: Why the extra row of 0, 0, 1 works
A rigid move is p′ = R·p + t: rotate, then add a translation. The '+ t' is not a matrix multiplication, so a 2×2 matrix can't do it.
Trick: write points with an extra coordinate fixed at 1: p = (x, y, 1).
Build T = [R t; 0 0 1] = [cos θ −sin θ tx; sin θ cos θ ty; 0 0 1].
Multiply: row 1 gives x cos θ − y sin θ + tx·1, row 2 gives x sin θ + y cos θ + ty·1, row 3 gives 0 + 0 + 1 = 1. That is exactly R·p + t, with the 1 still in place.
The 1 picks up the translation column. (A direction vector, which shouldn't be shifted, is written with a 0 instead, and correctly ignores t.)
Common mix-ups
You can translate first and rotate after, it makes no difference.
✓ T = [R t] means rotate the local point, then add t. Shifting first would rotate the shift too.The bottom row 0 0 1 is decoration.
✓ It keeps the final 1 in place so that transforms can be multiplied together and chained.
4.4 Chains of frames, and the way back
A camera on a wrist on an elbow on a shoulder sees a bolt. To grab it, the robot must know where the bolt is in the room. How many matrices is that?
Chaining: labels like dominoes
T_WB = T_WA · T_AB: the A's in the middle 'cancel'. For a longer chain, T_W←tool = T_W←base · T_base←1 · T_1←2 · T_2←tool. Multiply left to right in the order of the chain; the point goes in on the right. In 2D, the angles of a chain simply add, and the translations combine through the rotations.
Inverting a rigid transform
To go the other way (W → A), use T_AW = T_WA⁻¹. For a rigid transform no general inverse is needed: T⁻¹ = [Rᵀ −Rᵀt; 0 0 1]. Rotate back by −θ, and the new translation is the old one, rotated back and negated. Check: T⁻¹·T = I.
Up and down the tree
To get a camera's measurement into the gripper frame you might go up from camera to world and back down to gripper: T_gripper←camera = T_W←gripper⁻¹ · T_W←camera. Every arrow you traverse backwards needs an inverse. Writing the subscripts carefully is the whole skill.
Common mix-ups
The inverse of a transform just negates the angle and the translation.
✓ The angle negates, but the new translation is −Rᵀt: the old shift, rotated back, then negated.Transforms can be multiplied in any order as long as all of them are included.
✓ Only the order that chains the frame labels gives the right answer.
Examples to try
Worked solutions are in the interactive chapter online.
A matrix is a machine that moves vectors: example 1
Find [2 −1; 1 3]·(4, −2).
The rotation matrix, built from scratch: example 1
Rotate (3, 4) by 90° clockwise.
Homogeneous transforms: rotate and shift in one matrix: example 1
Write T for a frame rotated 30° with origin (1, 2), and find the point (2, 0) in the parent.
Chains of frames, and the way back: example 1
T_WA has θ = 90°, t = (2, 1). Find T_AW and use it to express the world point (2, 3) in A.
Interactive figures, in words
Figure 4.2 from “A matrix is a machine that moves vectors”
Try each preset and describe it in words. Then choose Custom and build: (a) a matrix that triples heights only, (b) one that swaps x and y, (c) one that squashes the plane onto a line. For each, watch where the orange (1, 0) and green (0, 1) arrows land, and the determinant.
The matrix grid shows the plane before (fine grid) and after (blue grid) applying the matrix. An orange arrow shows where (1, 0) lands, a green arrow where (0, 1) lands, and a purple patch shows the transformed unit square. A test point (1.5, 1) and its image P′ are joined by a dashed arrow. The readout lists the matrix, both columns, P′ and the determinant.
Figure 4.3 from “Homogeneous transforms: rotate and shift in one matrix”
Set frame B's rotation and shift to 0, so only frame A matters. Put A at 90°, shift (2, 1), and p at (1, 0). Check the world position against your prediction, and read T_WA. Which entries hold the rotation? Which hold the shift?
The frame-chain viewer draws the world axes in black, frame A in blue and frame B in orange (solid arrow for x, dashed for y), with point p as a lime dot. The readout shows p in B, in A and in the world, and prints the 3×3 matrices T_WA, T_AB and their product T_WB.
Laboratory (online)
These run in a browser on the full site. Simulations are simplified educational models.
- Equation Lab: Matrices (Equation Lab exploration)
Apply a 30° rotation matrix to the unit square and confirm that every side keeps its length.
Open online - Playground: Robotic kinematics (Playground lab)
Chain two frames and predict where a point ends up before checking it.
Open online
Practice questions
Questions only. Each one is answered in its Lite lesson online, where it is checked on our server.
1. [3 1; 0 2]·(2, 5): what is the first component?
Answer:
Check it in “A matrix is a machine that moves vectors”
2. Which matrix sends (1, 0) to (0, 2) and (0, 1) to (−1, 0)?
- [0 −1; 2 0]
- [0 2; −1 0]
- [0 −1; 0 2]
- [2 0; 0 −1]
Check it in “A matrix is a machine that moves vectors”
3. Which matrix is R(90°)?
- [0 1; −1 0]
- [0 −1; 1 0]
- [1 0; 0 1]
- [−1 0; 0 −1]
Check it in “The rotation matrix, built from scratch”
4. The point (5, 12) is rotated by 73°. What is its distance from the origin afterwards?
Answer:
Check it in “The rotation matrix, built from scratch”
5. Frame rotated 0° with origin (4, −1). Point (2, 3) in that frame. What is its parent x coordinate?
Answer:
Check it in “Homogeneous transforms: rotate and shift in one matrix”
6. Which is T_W←tool for the chain world → base → link → tool?
- T_W←base · T_base←link · T_link←tool
- T_link←tool · T_base←link · T_W←base
- T_W←base + T_base←link + T_link←tool
- T_W←base⁻¹ · T_link←tool
Check it in “Chains of frames, and the way back”
7. T has θ = 0° and t = (3, −2). What is the x translation of T⁻¹?
Answer:
Check it in “Chains of frames, and the way back”
Engineering applications
Robot software frameworks
Robot software keeps a tree of frames, map to robot to arm to camera to gripper, each joined by a transform. Asking where the camera sees a cup in map coordinates is a walk along that tree, multiplying transforms.
Games and graphics
Every object in a video game is drawn by multiplying its points by a chain of transforms: model to world, world to camera, camera to screen. The same mathematics places a robot hand.
Summary
- Multiplying a matrix by a vector moves the vector; the columns show where the axes go.
- A rotation matrix turns vectors by an angle and keeps their lengths.
- A homogeneous transform combines a rotation and a translation in one 3 × 3 matrix.
- Chains of transforms multiply in order; the inverse walks the chain backwards.
Glossary
- 2D rotation matrix
- A 2D rotation by angle θ anticlockwise maps (x, y) to (x cos θ − y sin θ, x sin θ + y cos θ), written as a 2×2 matrix.
- Matrix multiplication
- Multiplying matrices combines rows of the first with columns of the second: each entry of the result is a dot product of a row and a column.
- Coordinate frame
- A coordinate frame is an origin plus a set of axes used to describe positions and directions. Robots use several: world, base, each joint, sensors and the tool.
Project: A frame tree
Model a desk lamp with a base, two arms and a head as a chain of four frames. Choose angles and lengths, write each homogeneous transform, multiply them to find where the bulb is, and invert the chain to express a point on the desk in the bulb's frame.
Deliverables
- A labelled sketch of the four frames
- Each transform written out
- The bulb position and the inverted point, checked in code
References
- Kevin M. Lynch and Frank C. Park (2017). Modern Robotics: Mechanics, Planning, and Control. Cambridge University Press.
- John J. Craig (2005). Introduction to Robotics: Mechanics and Control, 3rd edition. Pearson Prentice Hall.
- Mark W. Spong et al. (2006). Robot Modeling and Control. Wiley.
5. Forward kinematics
Give an arm its joint angles and forward kinematics tells you where the hand is. For a two-link planar arm it is two lines of trigonometry: the elbow sits at the end of the first link, the hand at the end of the second, with the angles adding up along the way. Sweep every allowed angle and the hand traces out the workspace: every place the arm can reach, and the holes it cannot.
Figure 5.1. Where is the hand? (described in words)
A two-link arm with links 1 m and 0.8 m at θ1 = 30° and θ2 = 45°. The elbow is at (0.866, 0.5) and the hand at (1.073, 1.273). A dashed arc marks the outer reach of 1.8 m; the inner limit is 0.2 m.
Explanation
5.1 Forward kinematics: where is the hand?
A robot knows only its two joint angles. From those two numbers alone, it must know where its hand is to the millimetre. How?
Two vectors, tip to tail
Link 1 points at θ1: its vector is L1(cos θ1, sin θ1). Link 2 starts at the elbow and points at θ1 + θ2, because θ2 is measured from link 1. Add them:
x = L1 cos θ1 + L2 cos(θ1 + θ2)
y = L1 sin θ1 + L2 sin(θ1 + θ2)
Relative angles add up
Each joint's encoder measures its angle relative to the previous link. The absolute direction of any link is the sum of the joint angles before it. Forgetting to add θ1 to θ2 is the most common FK error, and it gives positions that look plausible but are wrong.
Two numbers in, one position out
FK always has exactly one answer: given the angles, the hand is in one place. A two-joint planar arm has two degrees of freedom, enough to place the hand anywhere in its ring-shaped workspace but not to choose the hand's orientation too. That needs a third joint.
Common mix-ups
Link 2 points at θ2.
✓ Link 2 points at θ1 + θ2, because θ2 is measured from link 1.The hand's distance from the shoulder is always L1 + L2.
✓ Only when the arm is straight (θ2 = 0). Bending the elbow brings the hand closer.
5.2 Forward kinematics as a chain of transforms
Add a third joint, a fourth, a seventh. The trigonometry gets ugly fast. What stays simple?
One block per joint
Each joint contributes A(θᵢ, Lᵢ) = Rot(θᵢ)·Trans(Lᵢ): turn by the joint angle, then move along the new x axis by the link length. The hand's pose in the base frame is the product T_base←hand = A₁·A₂·…·Aₙ. The last column gives the position; the top-left block gives the orientation.
Same answer, more information
For two links, multiplying out reproduces x = L1 cos θ1 + L2 cos(θ1 + θ2) exactly (see the derivation). But the matrix also hands you the orientation of the hand, θ1 + θ2, and the position of every intermediate joint along the way: just stop the product early.
Why engineers prefer chains
The chain is systematic: the same block, repeated. It works unchanged for any number of joints, and in 3D (with 4×4 matrices) for real industrial arms. Conventions such as Denavit–Hartenberg parameters are a standard recipe for writing each block. Computers multiply the matrices; humans just have to get the chain right.
Derivation: Two-link FK from transforms
Joint i rotates by θᵢ: Rot(θ) = [cos θ −sin θ 0; sin θ cos θ 0; 0 0 1]. Link i slides along its own x axis: Trans(L) = [1 0 L; 0 1 0; 0 0 1].
One joint-plus-link block: A(θ, L) = Rot(θ)·Trans(L) = [cos θ −sin θ L cos θ; sin θ cos θ L sin θ; 0 0 1].
The hand frame is T = A(θ1, L1)·A(θ2, L2). Its rotation block is R(θ1)R(θ2) = R(θ1 + θ2).
Its translation column is R(θ1)·(L2 cos θ2, L2 sin θ2) + (L1 cos θ1, L1 sin θ1).
Using the angle-addition formulas, R(θ1)·(L2 cos θ2, L2 sin θ2) = L2(cos(θ1 + θ2), sin(θ1 + θ2)). So the hand is at (L1 cos θ1 + L2 cos(θ1+θ2), L1 sin θ1 + L2 sin(θ1+θ2)): the familiar formula.
A third link just multiplies one more block: T = A(θ1, L1)·A(θ2, L2)·A(θ3, L3), with orientation θ1 + θ2 + θ3.
Common mix-ups
Matrix FK and trigonometric FK can give different answers.
✓ They're the same mathematics: multiplying the matrices out gives exactly the trig formula.The chain only gives the hand position.
✓ It also gives the hand's orientation and every intermediate joint frame.
5.3 Mapping the workspace: everywhere the hand can go
A two-link arm with 5 cm and 3 cm fingers can never touch a point 1 cm from its knuckle. Why is there a hole in the middle?
A ring
With joints that turn all the way round, the tip's distance from the shoulder can be anything from |L1 − L2| (elbow fully folded) to L1 + L2 (arm straight). Every direction is possible, so the workspace is a ring (annulus). A target is reachable exactly when |L1 − L2| ≤ √(x² + y²) ≤ L1 + L2.
Choosing link lengths
Equal links (L1 = L2) close the hole: the tip can reach the shoulder itself. Very unequal links leave a big hole. The outer radius sets the reach; the inner radius sets how close to the base the arm can work. Designers pick lengths so the task's points sit comfortably inside the ring, away from both edges (where the arm is nearly straight or nearly folded and moves poorly).
Real joints have limits
Real joints can't turn 360°: cables, hard stops and the arm hitting itself limit them. Joint limits carve slices out of the ring, so some points become reachable only with the elbow one way, or not at all. That's why the full design check in the Gripper Build tests real target points, not just the ring.
Common mix-ups
A two-link arm can reach every point within L1 + L2 of its base.
✓ Not the points closer than |L1 − L2|: there is a hole unless the links are equal.The workspace only depends on the total length.
✓ The split between L1 and L2 sets the hole's size, and joint limits cut out more.
Examples to try
Worked solutions are in the interactive chapter online.
Forward kinematics: where is the hand?: example 1
L1 = 0.4 m, L2 = 0.3 m, θ1 = 30°, θ2 = 60°. Find the hand position.
Forward kinematics as a chain of transforms: example 1
Use the block form to find the elbow position (the end of link 1) for θ1 = 60°, L1 = 0.5 m.
Mapping the workspace: everywhere the hand can go: example 1
L1 = 0.4 m, L2 = 0.25 m. Is (0.5, 0.45) m reachable?
Interactive figures, in words
Figure 5.2 from “Forward kinematics: where is the hand?”
In 'Forward' mode with L1 = 0.5 m, L2 = 0.35 m: predict the hand position for (θ1, θ2) = (0°, 90°), (90°, 0°) and (45°, −45°) on paper, then set each pose and check. Where must θ2 be to reach the furthest point of the ring? The nearest?
The two-link diagram draws the arm in blue from the shoulder at the centre, with a lime dot at the hand, over a purple ring showing every reachable point. In Forward mode the readout substitutes the chosen angles into both FK equations and gives the hand's x and y in metres.
Laboratory (online)
These run in a browser on the full site. Simulations are simplified educational models.
- Simulation OS: Two-link robot arm reach (Simulation OS experiment)
Set three pairs of joint angles, predict the gripper position by hand, then check each in the model.
Open online - Nexus: Virtual Robotic Arm (Nexus project)
Map the arm's workspace and mark one point it can never reach.
Open online
Practice questions
Questions only. Each one is answered in its Lite lesson online, where it is checked on our server.
1. L1 = 0.6 m, L2 = 0.4 m, θ1 = 0°, θ2 = 90°. What is the hand's y position, in metres?
Answer: m
Check it in “Forward kinematics: where is the hand?”
2. θ1 = 120° and θ2 = −30°. Which way does link 2 point?
- −30°
- 90°
- 150°
- 120°
Check it in “Forward kinematics: where is the hand?”
3. With θ2 = 0°, an arm of L1 = 0.5 m and L2 = 0.3 m reaches how far from the shoulder, in metres?
Answer: m
Check it in “Forward kinematics: where is the hand?”
4. Why is each block Rot(θ)·Trans(L) and not Trans(L)·Rot(θ)?
- It makes no difference
- The link extends along the joint's new direction, so the turn must come first
- Translations must always be on the left
- So that the determinant is 1
Check it in “Forward kinematics as a chain of transforms”
5. L1 = 0.45 m and L2 = 0.3 m. What is the inner radius of the workspace ring, in metres?
Answer: m
Check it in “Mapping the workspace: everywhere the hand can go”
6. Why do many arms use roughly equal link lengths?
- It's cheaper to buy identical parts
- It closes the hole: the tip can reach right back to the base
- It doubles the reach
- It removes all singularities
Check it in “Mapping the workspace: everywhere the hand can go”
7. An elbow can only bend between 0° and 150°. What happens to the workspace?
- Nothing
- Points needing a tighter fold than 150° become unreachable, and only one elbow pose is available
- It gets bigger
- The arm can no longer reach full stretch
Check it in “Mapping the workspace: everywhere the hand can go”
Engineering applications
Pick and place cells
Before a factory installs a robot arm, engineers check that every pick and drop point lies inside its workspace with margin. A part placed just outside the reach is a part the robot can never collect.
Digital checks
Animation rigs, excavators and surgical robots all compute forward kinematics continuously, to display the tool's position and to stop the tool before it reaches somewhere it must not go.
Summary
- Forward kinematics maps joint angles to the hand position.
- For two links: x = L1 cos θ1 + L2 cos(θ1 + θ2), y = L1 sin θ1 + L2 sin(θ1 + θ2).
- The same answer comes from multiplying one transform per joint.
- The workspace of two links is a ring between |L1 − L2| and L1 + L2, cut down by joint limits.
Glossary
- Forward kinematics (two-link arm)
- Forward kinematics computes where the end-effector is from the joint angles and link lengths.
- Workspace and reach
- A robot's workspace is the set of all positions its end-effector can reach. For a two-link planar arm it is a ring between radii |L1 − L2| and L1 + L2.
- End-effector
- The end-effector is the device at the end of a robot arm that interacts with the world: a gripper, suction cup, welding torch, camera or pen.
- Degrees of freedom
- The degrees of freedom of a mechanism are the number of independent ways it can move. A rigid body free in space has 6: three translations and three rotations.
- Sine, cosine and tangent
- In a right-angled triangle, sine is opposite over hypotenuse, cosine is adjacent over hypotenuse and tangent is opposite over adjacent, each a function of the angle.
Project: Workspace map
Write a program that sweeps both joints of a two-link arm through their limits in 5° steps and plots every hand position. Choose link lengths and joint limits for a real task, such as reaching the four corners of an A4 sheet, and show whether the arm can do it.
Deliverables
- The sweep program
- A plot of the reachable points with the task targets marked
- A verdict on whether the arm suits the task
References
- Kevin M. Lynch and Frank C. Park (2017). Modern Robotics: Mechanics, Planning, and Control. Cambridge University Press.
- John J. Craig (2005). Introduction to Robotics: Mechanics and Control, 3rd edition. Pearson Prentice Hall.
6. Inverse kinematics
Usually you know where the hand should go and need the joint angles. That is inverse kinematics, and it is harder: the law of cosines gives the elbow angle, but there are often two answers, elbow up and elbow down, and sometimes none at all. Near the edge of the workspace and when the arm is fully stretched, tiny moves of the hand demand huge moves of the joints. Those are singularities.
Figure 6.1. Two ways to reach one point (described in words)
A two-link arm with 1 m links reaching the target (1.2, 0.6). The law of cosines gives cos θ2 = -0.1, so θ2 = ±95.7°. Elbow down: θ1 = -21.3°, θ2 = 95.7°. Elbow up (dashed): θ1 = 74.4°, θ2 = -95.7°.
Explanation
6.1 Inverse kinematics: from a target to joint angles
Forward kinematics always has one answer. Ask the question backwards, 'which angles put the hand HERE?', and you may get two answers, or none. Why?
The elbow first
Only the distance to the target decides how much the elbow must bend; direction doesn't matter. Compute d² = x² + y², then cos θ2 = (d² − L1² − L2²)/(2L1L2). If |cos θ2| > 1 the target is unreachable. Otherwise there are two elbow angles, +θ2 and −θ2 (one if θ2 = 0 or 180°).
Then the shoulder
With θ2 chosen, θ1 = atan2(y, x) − atan2(L2 sin θ2, L1 + L2 cos θ2). The first term points the shoulder straight at the target; the second rotates it back by the angle the bent elbow adds. Use atan2 for both: targets behind or below the base are common.
Trust, but verify
IK formulas are easy to get subtly wrong (a sign, the order of atan2's arguments, degrees vs radians). The fix is cheap: run FK on your answer. If the hand lands on the target, the IK is right. Every robot library's tests do exactly this, as do this lesson's practice generators.
Derivation: Two-link IK with the law of cosines
Shoulder at the origin, target at (x, y), distance d = √(x² + y²). The shoulder, elbow and hand form a triangle with sides L1, L2 and d.
The interior angle at the elbow is 180° − |θ2| (θ2 measures how far link 2 turns away from straight).
Law of cosines: d² = L1² + L2² − 2·L1·L2·cos(180° − θ2) = L1² + L2² + 2·L1·L2·cos θ2.
So cos θ2 = (x² + y² − L1² − L2²) / (2·L1·L2), and θ2 = ±cos⁻¹(that). Plus is elbow down, minus is elbow up (this course's convention).
If the right-hand side is above 1 or below −1, no angle exists: the target is outside the ring.
Shoulder: aim at the target, then correct for the bend: θ1 = atan2(y, x) − atan2(L2 sin θ2, L1 + L2 cos θ2). The correction flips sign with θ2, giving the two matching shoulder angles.
Always check: put (θ1, θ2) back through FK. You should land on (x, y).
Common mix-ups
IK always has exactly one answer, like FK.
✓ A two-link arm usually has two (elbow up and down), one at the ring's edges, and none outside it.θ1 is just atan2(y, x).
✓ That points the shoulder at the target; you must subtract the extra angle the bent elbow adds.
6.2 Elbow up or elbow down? Choosing between solutions
Two sets of joint angles put the hand on the same bolt. One of them smashes the elbow into a shelf. How does a robot choose?
Mirror images
The two solutions share |θ2| and are reflections of each other across the line from shoulder to target. With this course's convention elbow up has θ2 < 0, elbow down θ2 > 0. At the edges of the ring (θ2 = 0 or ±180°) they coincide; in the middle of the ring they differ the most.
How to choose
Common rules: (1) reject any solution outside joint limits or that collides with something; (2) among the rest, pick the one closest to the current joint angles, so the move is short and predictable; (3) keep the same branch throughout a task. Many industrial arms fix the branch in the program ('elbow up' configuration) for exactly this reason.
Don't flip mid-move
If a controller re-solves IK at every step of a straight-line hand move and naively picks 'the first solution', it can jump from one branch to the other. The hand target barely changes, but the elbow swings through a huge arc in one step. That's a sudden, fast, dangerous motion, and a classic bug to test for.
Common mix-ups
Elbow up and elbow down are equally good, so it doesn't matter which you pick.
✓ Obstacles, joint limits and continuity with the current pose usually make one clearly better.Re-solving IK every step is always safe.
✓ Only if you keep the same branch; switching branches mid-move causes sudden large joint motions.
6.3 Unreachable targets, joint limits and singularities
Near full stretch, a tiny hand movement can need a huge, fast joint movement. Why do robots go 'weak' at the edge of their reach?
Outside the ring
If d > L1 + L2 (beyond reach) or d < |L1 − L2| (inside the hole), IK has no solution. A good solver says so and reports the gap: d − (L1 + L2) or |L1 − L2| − d. A common safe fallback is to reach the nearest reachable point along the same direction, and flag the shortfall rather than hide it.
Singularities
When θ2 = 0° (straight) or ±180° (folded), the two links are in line. Then both joints can only swing the hand sideways around the shoulder; moving along the arm's line needs no joint motion at first order. The arm's Jacobian determinant, L1·L2·sin θ2, is zero there. Near a singularity, small hand moves along that line demand very large, fast joint moves.
From joint error to hand error
Encoders are never perfect. A shoulder error Δθ1 swings the whole arm, moving the hand by about d·Δθ1 (radians), where d is the shoulder-to-hand distance. A stretched-out arm amplifies errors most. A 0.5° error at d = 0.8 m is 0.8 × 0.00873 ≈ 7 mm: enough to miss a small hole.
Common mix-ups
A robot is strongest and most precise at full stretch.
✓ Full stretch is a singularity: it loses a direction of motion and amplifies joint errors the most.Unreachable targets only happen beyond full stretch.
✓ Unless L1 = L2, there's also a hole near the base that the arm can't fold into.
Examples to try
Worked solutions are in the interactive chapter online.
Inverse kinematics: from a target to joint angles: example 1
L1 = 5 cm, L2 = 3 cm, target (6, 2) cm. Find both solutions.
Elbow up or elbow down? Choosing between solutions: example 1
The arm is at (θ1, θ2) = (40°, −70°). The two IK solutions for the next target are (45°, −75°) and (−5°, 75°). Which should it use?
Unreachable targets, joint limits and singularities: example 1
L1 = 40 cm, L2 = 25 cm. A target is at (50, 45) cm. Reachable? If not, by how much is it out?
Interactive figures, in words
Figure 6.2 from “Inverse kinematics: from a target to joint angles”
In 'Inverse' mode, drag the target around with the sliders. Watch the readout's cos θ2 value. What happens to it as the target approaches the outer edge? The inner edge? Just outside? Note the grey dashed arm: when do the two solutions look most different?
In Inverse mode a crosshair marks the target; the arm is drawn reaching it with the chosen elbow, and the other solution is shown as a grey dashed arm. The readout gives d, cos θ2, both joint-angle pairs and an FK check, or says the target is unreachable and by how much.
Laboratory (online)
These run in a browser on the full site. Simulations are simplified educational models.
- Simulation OS: Two-link arm reach (Simulation OS experiment)
Solve both IK solutions for a target, drive the arm to each and measure the tip error.
Open online - BUILD: Robotic gripper, level 2 (BUILD level)
Find the joint angles that put the fingertip on a target and check them with forward kinematics.
Open online
Practice questions
Questions only. Each one is answered in its Lite lesson online, where it is checked on our server.
1. L1 = 0.5 m, L2 = 0.5 m, target (0.5, 0.5) m. What is cos θ2? (2 decimal places)
Answer:
Check it in “Inverse kinematics: from a target to joint angles”
2. You compute cos θ2 = 1.18. What does it mean?
- θ2 ≈ 10°
- The target is beyond full stretch: no solution
- Use the elbow-up solution
- Round it to 1
Check it in “Inverse kinematics: from a target to joint angles”
3. What is the most reliable quick check of an IK answer?
- Check θ1 is positive
- Run forward kinematics on the angles and compare with the target
- Check θ2 is less than 180°
- Ask whether the angles look reasonable
Check it in “Inverse kinematics: from a target to joint angles”
4. What do the elbow-up and elbow-down solutions for the same target always share?
- The same θ1
- The same |θ2|
- The same elbow position
- Nothing
Check it in “Elbow up or elbow down? Choosing between solutions”
5. Which rule best avoids sudden elbow swings during a long move?
- Always pick the solution with positive θ1
- Pick the valid solution closest to the current joint angles, and keep the same branch
- Pick at random each step
- Always pick elbow down
Check it in “Elbow up or elbow down? Choosing between solutions”
6. For a two-link arm, at which elbow angles is it singular?
- θ2 = 90° and −90°
- θ2 = 0° and ±180°
- θ1 = 0°
- Whenever the hand is on the x axis
Check it in “Unreachable targets, joint limits and singularities”
7. A target is 3 cm beyond reach. What should a well-designed IK function do?
- Crash
- Return NaN and let the motors try
- Report 'unreachable' with the 3 cm gap, and optionally the nearest reachable pose
- Silently reach the nearest point and report success
Check it in “Unreachable targets, joint limits and singularities”
Engineering applications
Avoiding the table
When an arm works just above a table, the elbow-down solution may drive the elbow through the surface. Controllers pick the solution that keeps clear of obstacles and stays far from joint limits.
Graceful failure
If a target is out of reach, the cosine of the elbow angle comes out bigger than 1 and there is no solution. Good code detects that and moves to the nearest reachable point instead of crashing.
Summary
- Inverse kinematics finds joint angles for a desired hand position.
- For two links the law of cosines gives cos θ2; its two signs are elbow up and elbow down.
- If |cos θ2| > 1 the target is out of reach; check before taking the inverse cosine.
- Always verify an IK answer by running forward kinematics on it.
Glossary
- Inverse kinematics
- Inverse kinematics finds joint angles that place the end-effector at a desired position. There may be several solutions, one, or none.
- Forward kinematics (two-link arm)
- Forward kinematics computes where the end-effector is from the joint angles and link lengths.
- Workspace and reach
- A robot's workspace is the set of all positions its end-effector can reach. For a two-link planar arm it is a ring between radii |L1 − L2| and L1 + L2.
Project: A safe IK function
Write a function that returns both inverse-kinematics solutions for a two-link arm, reports clearly when a target is unreachable, and checks every answer with forward kinematics. Test it on targets inside, on the edge of and outside the workspace.
Deliverables
- The function with a docstring
- At least six test cases including edge and unreachable targets
- A note on which solution you would choose and why
References
- Kevin M. Lynch and Frank C. Park (2017). Modern Robotics: Mechanics, Planning, and Control. Cambridge University Press.
- John J. Craig (2005). Introduction to Robotics: Mechanics and Control, 3rd edition. Pearson Prentice Hall.
- Mark W. Spong et al. (2006). Robot Modeling and Control. Wiley.
7. Motion and trajectories
Knowing the start and the goal is not enough: a robot must get there without jerking, overshooting or tipping its payload. A trapezoidal profile ramps speed up, cruises, then ramps down, so the area under the speed graph equals the distance. For an arm, every joint follows its own profile, timed so they all finish together; and moving in joint space is not the same as moving in a straight line.
Figure 7.1. Speed up, cruise, slow down (described in words)
A trapezoidal velocity profile for a 1 m move with top speed 0.5 m/s and acceleration 1 m/s²: a 0.5 s ramp up, 1.5 s at constant speed and a 0.5 s ramp down, 2.5 s in total. The shaded area equals the 1 m distance.
Explanation
7.1 Motion profiles: getting there smoothly
The fastest way from A to B is 'full speed, then stop'. Why does no real lift, robot or train move like that?
Linear interpolation
The simplest trajectory: x(t) = x0 + (x1 − x0)·(t/T) for 0 ≤ t ≤ T. Constant speed |x1 − x0|/T the whole way. It's perfect for planning where to be in the middle of a move, but at t = 0 and t = T the speed jumps instantly, which would need infinite acceleration.
The trapezoid
Accelerate at the limit a until reaching the speed limit v, cruise, then decelerate at a to stop exactly at the target. The speed-time graph is a trapezoid; its area is the distance. Position during the first ramp is ½at²; during the cruise, v²/(2a) + v(t − ta); during the final ramp, D − ½a(T − t)².
Triangles and beyond
Short moves never reach v: the trapezoid collapses to a triangle. And the trapezoid still has instant jumps in acceleration (jerk), felt as a small jolt; lifts and precision machines use S-curves that also limit jerk, at the cost of a little more time. The Elevator Build's planner shows that next step.
Derivation: Duration of a trapezoidal move
Ramp up from rest at acceleration a to speed v: time ta = v/a, distance ½·a·ta² = v²/(2a).
Ramp down is the mirror image: another v/a seconds and v²/(2a) metres.
Cruise covers the rest, D − v²/a, at speed v, taking (D − v²/a)/v = D/v − v/a seconds. This needs D ≥ v²/a.
Total: T = 2·(v/a) + D/v − v/a = D/v + v/a. The extra v/a, compared with D/v, is the price of smoothness.
If D < v²/a there's no room to cruise: the profile is a triangle with peak speed √(D·a) and duration 2√(D/a).
Common mix-ups
Raising the speed limit always makes the move faster by the same proportion.
✓ T = D/v + v/a: for short moves the ramps dominate, and a higher v can barely help (or the move is a triangle anyway).A trapezoidal profile is perfectly smooth.
✓ Its speed is continuous, but its acceleration jumps; S-curves smooth that too.
7.2 Joint-space trajectories: moving every joint together
A robot's shoulder must turn 90° and its elbow only 10°. If both run flat out, one finishes long before the other. Is that a problem?
Interpolate each joint
For a move from θ_start to θ_end over time T, each joint follows θᵢ(t) = θᵢ,start + (θᵢ,end − θᵢ,start)·s(t), where s(t) runs from 0 to 1. With s = t/T it's linear interpolation; with s from a trapezoid (normalised by D) every joint ramps smoothly, at once. All joints share one s(t), so they start and finish together.
The slowest joint sets the pace
Each joint has its own speed limit. With linear interpolation, joint i needs speed |Δθᵢ|/T ≤ vᵢ,max, so T ≥ max(|Δθᵢ|/vᵢ,max). Choose the largest of these times and slow the other joints to match. That's 'synchronised' motion: it looks deliberate and keeps the hand's path predictable.
Joint space vs task space
Joint-space moves are cheap and safe (no IK mid-move, no singular surprises), but the hand curves. Task-space moves interpolate the hand position in a straight line and solve IK at each step: needed for welding a seam or inserting a peg, but they can drive the arm into a singularity or a joint limit halfway. Controllers offer both.
Common mix-ups
Moving every joint in a straight line moves the hand in a straight line.
✓ FK is nonlinear; a straight line in joint space is usually a curve for the hand.Each joint should move at its own top speed.
✓ Synchronised moves slow the faster joints so all finish together; otherwise the path is unpredictable.
7.3 Modelling rotating parts: x = L cos θ, y = L sin θ
A windscreen wiper, a crane jib and a robot's first link all trace the same shape. Which equation draws all three?
A link is a scaled unit circle
A link of length L at angle θ (from +x, anticlockwise) has its tip at x = L cos θ, y = L sin θ. It's the unit-circle point (cos θ, sin θ) stretched by L. If the pivot is not at the origin but at (px, py), add that offset: x = px + L cos θ, y = py + L sin θ.
Going back: angle from position
Given a tip position (x, y) relative to the pivot, the joint angle is θ = atan2(y, x) and the length is √(x² + y²). This is the seed of inverse kinematics: working backwards from where the tip is (or should be) to the angle that puts it there. atan2, not tan⁻¹, because joints swing through every quadrant.
How fast does the tip move?
If the joint turns at angular speed ω (rad/s), the tip moves along its circle at v = L·ω. Long links make fast tips: a 2 m crane jib turning at 0.5 rad/s moves its tip at 1 m/s. The tip's velocity points along the circle, perpendicular to the link: (−L ω sin θ, L ω cos θ).
Common mix-ups
x = L sin θ and y = L cos θ.
✓ With θ measured from the x axis, x uses cosine and y uses sine. (Swap them only if θ is measured from the y axis.)Every point on a rotating link moves at the same speed.
✓ Speed is L·ω: points further from the pivot move faster.
Examples to try
Worked solutions are in the interactive chapter online.
Motion profiles: getting there smoothly: example 1
D = 5.5 rad, a = 0.5 rad/s², v = 0.5 rad/s. Where is the joint at t = 6 s?
Joint-space trajectories: moving every joint together: example 1
A joint goes from 20° to 80° linearly over 3 s. Where is it at t = 1.2 s?
Modelling rotating parts: x = L cos θ, y = L sin θ: example 1
A crane jib 12 m long, pivoted 3 m above the ground, is raised to 40°. How high is its tip?
Interactive figures, in words
Figure 7.2 from “Motion profiles: getting there smoothly”
Start with D = 2 m, v = 1 m/s, a = 1 m/s² and check the 3 s prediction. Then shrink D until the trapezoid becomes a triangle: at what distance does that happen? Finally raise a: what happens to the trapezoid's duration as a gets very large?
The profile comparer plots position against time (top) and speed against time (bottom) for a constant-velocity move (dashed orange: speed jumps instantly) and a trapezoidal move (solid blue: speed ramps up, cruises, ramps down). The readout gives both durations, the ramp and cruise times, and both positions at the chosen time.
Laboratory (online)
These run in a browser on the full site. Simulations are simplified educational models.
- Simulation OS: Joint-space vs straight-line motion (Simulation OS experiment)
Move the arm between two points both ways and measure how far the joint-space path strays from the straight line.
Open online - BUILD: Elevator, level 2 (BUILD level)
Plan the lift's motion profile so the cabin reaches the next floor smoothly in a set time.
Open online
Practice questions
Questions only. Each one is answered in its Lite lesson online, where it is checked on our server.
1. A slider moves at constant speed from x = 10 cm to x = 50 cm in 4 s. Where is it at t = 1 s, in cm?
Answer: cm
Check it in “Motion profiles: getting there smoothly”
2. A joint follows a trapezoidal profile over 2.5 rad: it accelerates at 2 rad/s² up to 1 rad/s, cruises, then decelerates at 2 rad/s² to stop. How far has it moved at t = 1.1 s, in radians? (3 decimal places)
Answer: rad
Check it in “Motion profiles: getting there smoothly”
3. With v = 2 m/s and a = 1 m/s², which move is too short to reach full speed?
- D = 6 m
- D = 4.5 m
- D = 3 m
- D = 8 m
Check it in “Motion profiles: getting there smoothly”
4. Why don't robot controllers use pure constant-velocity moves between points?
- They're slower
- They demand an instant speed change at start and stop: infinite acceleration and huge jolts
- They can't reach the target
- They use more electricity in cruise
Check it in “Motion profiles: getting there smoothly”
5. Joint 1 moves 120° with a limit of 60°/s; joint 2 moves 45° with a limit of 30°/s. For a synchronised linear move, what is the shortest duration, in seconds?
Answer: s
Check it in “Joint-space trajectories: moving every joint together”
6. A welding robot must follow a straight seam. Which trajectory type is needed?
- Joint-space linear interpolation
- Task-space (straight hand path) with IK at each step
- Either: they give the same path
- Constant velocity in joint space
Check it in “Joint-space trajectories: moving every joint together”
7. A 0.6 m link turns at 2 rad/s. How fast does its tip move, in m/s?
Answer: m/s
Check it in “Modelling rotating parts: x = L cos θ, y = L sin θ”
Engineering applications
Lifts
A lift cabin follows a smoothed profile so passengers never feel a sudden lurch. Limiting acceleration, and how quickly acceleration changes, matters as much for comfort as the top speed.
Carrying liquids
A robot carrying a cup of coffee limits acceleration so the liquid does not slosh over the rim. The trip takes slightly longer, and nobody gets wet.
Summary
- Linear interpolation moves from start to goal at constant speed, with jerky starts and stops.
- A trapezoidal profile ramps up, cruises and ramps down; distance is the area under the speed graph.
- Short moves never reach top speed and become triangular profiles.
- Synchronising joints means timing every joint's profile to finish together.
Glossary
- Equations of uniform acceleration
- When acceleration is constant, displacement, initial velocity, final velocity, acceleration and time are linked by four short equations.
- Linear interpolation
- Linear interpolation estimates a value between two known points by assuming a straight line between them.
- Radians and degrees
- A radian is the angle at which the arc length equals the radius. A full turn is 2π radians, which is 360 degrees.
Project: A gentle delivery
A robot must carry a tray 3 m across a room in under 8 seconds without exceeding an acceleration of 0.5 m/s². Design a trapezoidal profile that meets both limits, plot speed and position against time, and show the distance under the speed graph is 3 m.
Deliverables
- The profile parameters with working
- Plots of speed and position against time
- A check that every limit is met
References
- Kevin M. Lynch and Frank C. Park (2017). Modern Robotics: Mechanics, Planning, and Control. Cambridge University Press.
- Mark W. Spong et al. (2006). Robot Modeling and Control. Wiley.
8. Where am I? Drift, uncertainty and fusion
Counting wheel turns tells a robot how far it has gone, until a wheel slips. Dead reckoning drifts, and the error only grows. A beacon or camera fix is noisy but does not drift. The answer is to keep a belief with an uncertainty attached, predict it forward with the motion model, and correct it with each measurement, weighting each source by how much it can be trusted. That is the predict–update cycle.
Figure 8.1. Two uncertain guesses, one better one (described in words)
Three bell curves: odometry says 4 m with σ 0.4 m, a beacon says 4.6 m with σ 0.3 m. Fusing them with gain K = 0.64 gives 4.384 m with σ 0.24 m, a narrower curve than either source.
Explanation
8.1 Accurate, precise, both or neither
Five readings that agree to the millimetre can all be 3 cm wrong. How would you ever know?
Two different questions
Accuracy: is the average reading close to the true value? Precision: do repeated readings agree with each other? They are independent. A bathroom scale that always reads 2 kg heavy is precise and inaccurate; a cheap thermometer whose readings jump around a correct average is accurate on average and imprecise.
Bias moves, noise spreads
A systematic error (bias) shifts every reading the same way: a zero offset, a mis-set gain, a sensor warmed by its own electronics. A random error scatters readings unpredictably: electrical noise, vibration, quantisation. Bias damages accuracy; noise damages precision.
You need the truth to see bias
You can measure precision from the readings alone: just look at their spread. Accuracy needs a reference: a known weight, a measured distance, a calibrated instrument. Without one, a biased sensor looks perfectly healthy. This is why calibration rigs exist.
Common mix-ups
Precise readings must be accurate.
✓ A tight group can sit far from the truth. Only a reference reveals bias.Averaging fixes every kind of error.
✓ Averaging shrinks random error. Bias survives any amount of averaging.
8.2 Dead reckoning and why it drifts
Count every wheel turn perfectly and you still end up metres from where you think you are. Where does the error come from, and how fast does it grow?
Integration accumulates
Dead reckoning adds up measured steps: x[k] = x[k−1] + d[k]·cos θ[k], y[k] = y[k−1] + d[k]·sin θ[k]. Any error in d or θ is added in and never removed. The estimate's uncertainty can only grow until an absolute measurement arrives.
Three growth laws
A scale bias (wheels over-reading by fraction s) gives along-track error s·d: linear in distance. A constant heading error θ₀ gives cross-track error d·sin θ₀: also linear. A heading drift rate b (gyro bias) makes the heading error grow with time, so cross-track error grows like ½·v·b·t². Independent random step errors grow only like √n.
Living with drift
The cure is not a perfect wheel but an occasional absolute fix: a landmark, a sun sensor, an orbital image. A drift model tells you the spacing: if heading drift adds 1 m of error every 100 m and the corridor allows 2 m, fix at least every 200 m, with margin.
Common mix-ups
Better wheel encoders fix dead reckoning.
✓ Encoders count turns; slip and heading drift are errors in what the turns mean. Only absolute references remove accumulated error.All odometry error grows like √n.
✓ Random error does. Biases grow linearly or faster, and they dominate long drives.
8.3 The predict–update cycle
Drive a metre: your uncertainty grows. See a landmark: it shrinks. Repeat forever. That rhythm is the whole idea of a filter.
Predict
Push the estimate through the model: x⁻ = x + u (here, the commanded move) and P⁻ = P + Q. Q is the variance the model adds each step: wheel slip, gusts, anything unmodelled. Prediction always increases uncertainty.
Update
When a measurement z with variance R arrives, compute the innovation z − x⁻, the gain K = P⁻/(P⁻ + R), then x = x⁻ + K(z − x⁻) and P = (1 − K)P⁻. This is the conjugate normal update from week 13 with the prediction as prior.
Checking a filter honestly
In simulation you know the truth, so measure RMSE of x − x_true. Also check consistency: about 95% of errors should fall within ±2√P. If the truth often leaves the band, the filter is overconfident (Q or R too small); if it never comes close to the edge, it is too cautious.
Common mix-ups
A low RMSE proves the filter is right.
✓ It must also be consistent: its own σ should match its actual errors, or downstream decisions will be over- or under-cautious.The update step can increase uncertainty.
✓ For a correct linear-Gaussian model P = (1 − K)P⁻ is always smaller than P⁻. A surprising measurement moves x a lot, but P still shrinks.
8.4 Navigation uncertainty ellipses and budgets
'Within 5 km' is not one number. Along the track you may know 4 km; across it, 1.5 km; and the two errors may be linked. Draw that and you get an ellipse.
Covariance to ellipse
Position error [eₓ, e_y] has covariance Σ = [[σₓ², ρσₓσ_y], [ρσₓσ_y, σ_y²]]. Contours of equal probability are ellipses whose axes are Σ's eigenvectors and whose 1σ semi-axes are √(eigenvalues). With ρ = 0 they line up with x and y; correlation tilts them.
Choosing the probability
For a 2-D Gaussian, the probability inside the ellipse scaled by k is p = 1 − e^(−k²/2), so k = √(−2 ln(1 − p)): k = 1 → 39%, 2 → 86%, 2.45 → 95%, 3.03 → 99%. Always state which ellipse you mean: '3σ' and '99%' are different in 2-D.
Budgets and zones
A navigation budget combines contributions (in each axis, by RSS if independent) into Σ. The design check: the p-ellipse must fit inside the safe zone with margin. If it does not, either shrink the uncertainty (more fixes, better sensors) or choose a bigger, safer zone.
Common mix-ups
2σ means 95% in any number of dimensions.
✓ Only in 1-D. In 2-D, 2σ holds about 86%; 95% needs about 2.45σ.A small σ in one direction means the position is well known.
✓ The ellipse is only as useful as its longest axis allows; and correlation can make the worst direction diagonal.
Examples to try
Worked solutions are in the interactive chapter online.
Accurate, precise, both or neither: example 1
A 100.0 g reference mass is weighed five times: 101.9, 102.1, 102.0, 101.8, 102.2 g. Describe accuracy and precision.
Dead reckoning and why it drifts: example 1
Wheels over-read by 3%. Distance 100 m. Along-track error?
The predict–update cycle: example 1
x = 0, P = 1 m². Drive u = 1 m with Q = 0.25 m². Fix z = 1.6 m with R = 0.5 m². Predict and update.
Navigation uncertainty ellipses and budgets: example 1
σₓ = 4 km, σ_y = 1.5 km, independent. Will the 95% ellipse fit a zone 20 km long by 10 km wide?
Interactive figures, in words
Figure 8.2 from “Dead reckoning and why it drifts”
Start with only 3% slip bias and no heading drift: double the steps and check the error doubles. Now set slip to 0 and heading drift to 0.1° per step: double the steps and watch the error roughly quadruple. Finally use noise only, and compare how slowly random error grows.
The drift rover draws the straight true track and the dead-reckoned track; the readout states the final error and the bias-only predictions for along-track and cross-track error.
Figure 8.3 from “The predict–update cycle”
Step predict → update ten times in clear skies and watch the band settle to a steady width. Reset, switch on dust, and step again: note how wide the band gets during the gaps. Check after each update that the green truth line stays inside the ±2σ band most of the time.
The Kalman stepper plots truth, landmark fixes and the estimate with a ±2σ band over 20 steps. Each button press updates a text readout with the estimate, σ, truth, error and gain.
Laboratory (online)
These run in a browser on the full site. Simulations are simplified educational models.
- Simulation OS: Two-sensor fusion (Simulation OS experiment)
Fuse drifting odometry with a camera that drops out and compare the fused error with each sensor alone.
Open online - Playground: Sensor fusion (Playground lab)
Change one sensor's noise and predict which way the fused estimate moves before you look.
Open online - BUILD: Planetary rover, level 3 (BUILD level)
Decide which sensor to trust on sand and which on firm ground, and justify each choice.
Open online
Practice questions
Questions only. Each one is answered in its Lite lesson online, where it is checked on our server.
1. Readings: 49.1, 50.8, 48.7, 51.5, 49.9 for a true value of 50. Which describes them?
- Accurate and precise
- Accurate on average, not very precise
- Precise but biased
- Neither
Check it in “Accurate, precise, both or neither”
2. A 20.0 cm gauge block measures 20.6, 20.4, 20.5, 20.5 cm. What is the bias, in cm?
Answer: cm
Check it in “Accurate, precise, both or neither”
3. Odometry over-reads distance by 4% because of slip. After 250 m, what is the along-track error, in metres?
Answer: m
Check it in “Dead reckoning and why it drifts”
4. With a constant gyro DRIFT RATE (heading error growing steadily), doubling the drive time at constant speed makes the cross-track error…
- About 4× larger
- 2× larger
- √2× larger
- Unchanged
Check it in “Dead reckoning and why it drifts”
5. After predicting, a 1-D Kalman filter's variance is P = 1 m². The camera measurement variance is R = 2 m². What is the Kalman gain K?
Answer:
Check it in “The predict–update cycle”
6. In simulation, the true position leaves the filter's ±2σ band on 40% of steps. The most likely problem is…
- Q and/or R are set too small: the filter is overconfident
- Q and R are too large
- The filter is working perfectly
- The truth is wrong
Check it in “The predict–update cycle”
7. A landing-position error budget has four independent 1σ contributions: entry navigation 2 km, atmosphere 4 km, aerodynamics 5 km and timing 1.5 km. What is the combined 1σ error (root-sum-square), in km?
Answer: km
Check it in “Navigation uncertainty ellipses and budgets”
Engineering applications
Phones and cars
Phone maps blend satellite fixes, motion sensors and wheel or step counts. In a tunnel the satellite fixes vanish and the estimate coasts on motion sensors, with its uncertainty growing until the next good fix.
Mars rovers
Rovers cannot ask Earth where they are in real time. They combine wheel odometry, inertial sensors and visual matching of the terrain, and stop to re-localise when slip makes odometry untrustworthy.
Summary
- Dead reckoning integrates motion, so small errors accumulate and the position drifts.
- Keep an estimate together with its uncertainty, not a bare number.
- Predict with the motion model (uncertainty grows), then update with a measurement (uncertainty shrinks).
- The gain weights each source by its trust: K = P / (P + R) for a single quantity.
Glossary
- Odometry
- Odometry estimates a robot's position and heading by adding up how far its wheels have turned since a known start.
- Encoder counts and resolution
- A rotary encoder reports rotation as a count of ticks. Its resolution is the number of counts per revolution (CPR), often four times the pulses per revolution with quadrature decoding.
- IMU (inertial measurement unit)
- An IMU combines an accelerometer, which measures acceleration including gravity, and a gyroscope, which measures angular velocity; some add a magnetometer.
- Random and systematic error
- Random errors scatter readings unpredictably above and below the true value; systematic errors shift every reading the same way.
- Standard deviation
- Standard deviation measures how spread out values are around their mean: the square root of the average squared distance from the mean.
Project: A one-dimensional localiser
Simulate a robot driving along a corridor with noisy wheel odometry and a beacon that gives a noisy position every few seconds. Implement the predict–update cycle for position alone, plot the estimate and its uncertainty band against the truth, and report how the error compares with odometry alone.
Deliverables
- The simulation and filter code with fixed random seeds
- A plot of truth, odometry and fused estimate with its band
- Error statistics for both methods and an honest limitation
References
- Sebastian Thrun et al. (2005). Probabilistic Robotics. MIT Press.
- R. E. Kalman (1960). "A New Approach to Linear Filtering and Prediction Problems". Journal of Basic Engineering 82(1), 35–45.
- Roland Siegwart et al. (2011). Introduction to Autonomous Mobile Robots, 2nd edition. MIT Press.
Known limitations
- Not yet tested by a person using a screen reader; only automated structure checks have run.
- Some interactive lesson diagrams need a pointer or keyboard and a recent browser; their text alternatives carry the same idea without the interaction.
- Mathematics is written as plain text (for example x^2 and sqrt(x)), like the School lessons, not typeset notation.