A wheeled robot has two knobs: its left and right wheel speeds. They set a forward speed and a turn rate, and the heading turns those into a path on the map. The robot can never slide sideways, yet it can still park 0.6 m to its left.
Pick a move and watch two wheel speeds become a path. Then we build, piece by piece, frames, rotations, rigid transforms, the no-slip rule and the wheel models behind it.
You need sine and cosine, what a vector is and a little Python. We build the matrices from zero.
Lesson 2 of 15 in our follow-along of Stanford AA 274A, Principles of Robot Autonomy I. Every idea is re-taught here in our own words and devices. Before: Lesson 1, the autonomy stack. Next: Lesson 3, motion planning.
Illustrative toy: wheel radius 5 cm, wheels 30 cm apart, the size of a small lab robot. Teal is the robot, its body axes and its trail. Warm bars are the wheel commands, in radians per second.
Chapter 0
Spin a robot and send the same command; watch it land somewhere new each time
Tell a small robot: drive forward 1 m. Where does it end up on the map? You cannot say yet. "Forward" is wherever the robot's nose points, and the nose turns with the robot.
The map has a fixed world frame: an origin on the floor, an x axis pointing east and a y axis pointing north. The robot carries its own body frame: the origin at its centre, x out of its nose, y out of its left side. When the robot turns, its body frame turns with it.
The warm arrow is the command: 1 m along the nose. The grey arrow is east on the map. Set the heading, then press Forward.
Illustrative toy on a 1 m grid. The robot always moves exactly 1 m along its nose.
Work the number. Facing 0°, forward 1 m moves the robot by (1.00, 0.00) on the map. Facing 90°, by (0.00, 1.00). Facing 40°, by (0.77, 0.64): that is cos 40° and sin 40°. The heading turns one body command into different world moves.
Three languages meet in every wheeled robot. This lesson builds the translators between them.
| Layer | Speaks | Example |
|---|---|---|
| Planner | world frame | "reach (4.2, 1.8) facing 90°" |
| Kinematics | body frame | forward speed v, turn rate ω |
| Motors | wheel speeds | left 10 rad/s, right 14 rad/s |
The symptom is a robot that drives off at the wrong angle when its start heading changes. To measure it, log the command and the world move at two headings. The fix is to rotate every body command by the heading, as Chapter 2 shows.
Chapter 1
Drag a dock and a robot, and read one point in two frames
A charging dock sits on the floor. From the map origin it is at (5, 3). From the robot it is "3 m ahead and 2 m to the left". Both are right. They describe one spot from two places.
A reference frame is an origin plus a set of axis directions. We write the frame as a small letter before the point. Wp (W-p) is point p in the world frame. Bp (B-p) is the same point in the body frame.
Start with the easy case: the robot has not turned, so its axes are parallel to the world's. Call the robot's position on the map OB (O-B), the origin of the body frame.
B-p equals W-p minus O-B.
Subtract the robot's position O-B from the point's map position W-p. The rest, B-p, is the point seen from the robot. Add O-B back to undo it.
Robot at O-B = (2, 1), dock at W-p = (5, 3). B-p = (5 − 2, 3 − 1) = (3, 2). Adding (2, 1) back gives (5, 3) again.
Drag the pink dock or the teal robot. Grey is the world frame; teal is the body frame.
Illustrative toy. Positions snap to 0.1 m. The body frame does not rotate here; Chapter 3 adds the turn.
The symptom is a target that drifts the wrong way when the robot moves. Ask what moved: the thing or the observer. If the robot drives 1 m east, the dock's world x stays and its body x drops by 1. To measure it, move only the robot in a test and check the sign. The fix is to name the frame in every variable, as in p_body and p_world.
Chapter 2
Turn a dial and watch two axis arrows fill the matrix
The subtraction works only while the frames are parallel. Once the robot turns, we must also turn vectors. A rotation matrix is a 2 by 2 table of numbers that turns any vector by an angle θ (theta), counter-clockwise.
Do not memorise it. Ask one question: where do the two axis arrows go? Every vector is a mix of the x arrow (1, 0) and the y arrow (0, 1). Turn both, and you have turned everything.
R of theta is the two by two matrix: cos theta, minus sine theta on top; sine theta, cos theta below.
To turn a vector (x, y) by theta, take x times the first column. Add y times the second column. The sum is the turned vector.
At theta = 90°, cos is 0 and sin is 1. Turn (2, 1): 2 × (0, 1) + 1 × (−1, 0) = (−1, 2). Mostly right became mostly up.
The two teal arrows are the columns of R. The pink arrow is the vector (2, 1), turned. Watch the arrows stay square and length 1.
Exact maths on a toy vector. Angles count counter-clockwise from the x axis.
Three facts make R a rotation. Together they define the set SO(2): all 2 by 2 rotations.
| Fact | What it means | Check at 30° |
|---|---|---|
| R⊤R = I | columns are square and length 1: no stretch | 0.866 × (−0.5) + 0.5 × 0.866 = 0 |
| det R = 1 | a turn, not a mirror | 0.866² + 0.5² = 1 |
| R−1 = R⊤ | undo a turn by flipping the matrix | the flip is R(−30°) |
The symptom is a robot that turns the wrong way. The minus sign sits in the wrong corner, so R turns clockwise. To measure it, turn (1, 0) by +90° and expect (0, 1). The fix is that one test in your code, as the Code Lab checks.
Chapter 3
Move a robot and watch one matrix carry a point from its body to the map
A robot that has turned and moved needs both steps. To take a point from the body frame to the map, first rotate it by the heading θ, then shift it by the robot's position. Call that position t = (tx, ty), the translation.
A matrix and a vector, applied in the right order, invite bugs. So we use a trick: write every point with a third number, always 1. These are homogeneous coordinates: (x, y) becomes (x, y, 1), and we mark it with a tilde, p̃. Now one 3 by 3 matrix does both steps. This matrix is a rigid-body transform. The set of all of them is SE(2).
W-p-tilde equals T times B-p-tilde. T holds R of theta in its top-left corner, t-x and t-y in its last column, and zero, zero, one along the bottom.
Multiply each row of T by the body point (x, y, 1). The 1 picks up t-x and t-y, so the shift rides along with the turn. The answer is the map point, still ending in 1.
The robot stands at t = (2, 1), facing theta = 90°. A point is 3 m ahead: B-p-tilde = (3, 0, 1). Row 1: 0 × 3 − 1 × 0 + 2 × 1 = 2. Row 2: 1 × 3 + 0 × 0 + 1 × 1 = 4. The point is at (2, 4): 3 m north of the robot.
The pink point is fixed in the robot's body frame. Turn the robot, slide the point along the nose, or drag the robot. The read-out does T's two rows.
Exact maths on a toy floor. The robot snaps to 0.5 m when you drag it.
The symptom is a point that lands in the wrong place. The usual cause is shift first, then rotate. To measure it, run the 90° test above and expect (2, 4). Shift-then-rotate gives R(90°) times (5, 1) = (−1, 5). The fix is to let T do both steps, never the two by hand.
Chapter 4
Bolt a camera on a robot and find where it looks on the map
Someone bolts a camera to the robot. You know the camera's pose on the robot and the robot's pose on the map. Where is the camera on the map? Write each pose as a transform, then multiply.
Name a transform by two frames. TWB (T-W-B) is the body frame B described in the world frame W. TBC (T-B-C) is the camera frame C described in the body frame B.
T-W-C equals T-W-B times T-B-C.
Write the chain so the inner letters touch: W-B, then B-C. The two B's cancel. The outer letters, W and C, name the answer.
Robot at (2, 1), facing 90°. Camera 1 m ahead, turned 90°: T-B-C is (1, 0, 90°). The product puts the camera at (2, 2), facing 180°. Swap the order and you get (0, 2), 2 m off.
Turn the robot and the camera mount. Then press Swap the order to see where the wrong product puts the camera.
Illustrative toy: the robot stays at (2, 1) and the camera sits 1 m ahead of its centre.
To go the other way, invert. A rigid transform has a cheap inverse: turn back with R⊤ (R-transpose) and shift by −R⊤t.
For the robot above, the dock at (5, 3) on the map sits at (2, −3) in the body. That is 2 m ahead and 3 m to the right.
The symptom is a sensor reading that lands metres off on the map. The usual cause is the order TBC · TWB. To measure it, check that the inner letters touch. The fix is names like T_world_body and T_body_cam, so a wrong chain reads wrong.
Chapter 5
Aim a velocity at a pendulum and see which directions the rule lets through
Lesson 1 named the pose ξ (xi) = (x, y, θ): the robot's configuration. Its rate of change, ξ̇ (xi-dot) = (ẋ, ẏ, θ̇), says how fast each number changes. A kinematic constraint is a rule that these must obey at every instant.
Most robot rules are linear in the velocities: each rate appears once, never squared. The course writes them in Pfaffian form. Call the table of rule numbers A(ξ); its numbers depend only on where the system is.
A-transpose of xi, times xi-dot, equals zero.
Multiply each row of A-transpose into the velocity xi-dot, entry by entry, and add. If the sum is zero, the velocity is square to that forbidden direction. The rule allows it.
A bead on a rod of length 5 m sits at (3, 4). Its rule row is (3, 4). Velocity (−4, 3): 3 × (−4) + 4 × 3 = 0, allowed. Velocity (3, 4): 9 + 16 = 25, forbidden.
Where does the row (3, 4) come from? The rod fixes the distance, so x² + y² − L² = 0 at all times, with L the rod length. Take the rate of change: 2xẋ + 2yẏ = 0. Divide by 2. The rule row is (x, y), which points along the rod.
Move the bead around its circle, then aim the velocity. The rule lets a velocity through only when it is square to the rod.
Exact maths on a toy: rod 5 m, speed 5 m/s. "Allowed" means the rule value is within 0.5 of zero, so the slider can land on it.
The symptom is a simulated pendulum whose rod slowly stretches. Each straight step along the tangent leaves the circle a little. To measure it, track x² + y² − L² over time. The fix is to put the bead back on the circle after each step.
Chapter 6
Push a robot sideways, then reach the same spot by a legal route
The pendulum and the rolling wheel both give a Pfaffian rule. They differ in one deep way. The pendulum's rule traps the bead on a circle. The wheel's rule forbids sliding, yet the robot can still reach every pose.
| Kind | What it means | Example | Poses you can reach |
|---|---|---|---|
| Holonomic | the rule integrates to a position rule h(ξ) = 0 | pendulum: x² + y² = L² | a circle: one dimension lost |
| Nonholonomic | the rule cannot be integrated to a position rule | rolling wheel: no sliding | every (x, y, θ) |
Now derive the wheel's rule. The robot rolls along its heading, (cos θ, sin θ). The axle points sideways, along (−sin θ, cos θ). No slip means zero velocity along the axle.
x-dot sine theta minus y-dot cos theta equals zero.
Take the robot's velocity, x-dot and y-dot. Measure how much of it points along the axle. That sideways part must be zero.
Facing 90° (north), sin 90° = 1 and cos 90° = 0, so the rule reads x-dot = 0. The robot may drive north and may turn, but may not slide east.
Why can we not integrate this rule? The forbidden direction turns with θ. Pivot, drive, pivot back: each leg is legal, and the sum is a sideways move. No fixed surface traps the robot.
Push the robot forward or sideways. With grip on, the wheels refuse the sideways push. Then press Sidestep to reach the spot by a legal route.
Illustrative toy. A push is 0.3 m/s for 1 s. Grip off stands for omni wheels, which can slide.
The symptom is a planned path with a sideways step the robot cannot drive. To measure it, compute x-dot sin θ minus y-dot cos θ along the path; a value far from zero is a slide. The fix is to plan with the motion model, as Lessons 3 to 5 do.
Chapter 7
Set a speed and a turn rate, and watch Euler steps chase the true arc
The no-slip rule says what the robot cannot do. The unicycle model says what it can do. It has two inputs: the forward speed v, in metres per second, and the turn rate ω (omega), in radians per second.
x-dot equals v cos theta, y-dot equals v sine theta, and theta-dot equals omega.
Point the speed v along the heading theta: cos theta of it goes to x, sine theta of it to y. The heading changes at omega.
v = 2 m/s, omega = 1 rad/s, facing theta = 0: x-dot = 2, y-dot = 0, theta-dot = 1. In the no-slip rule: 2 × 0 − 0 × 1 = 0. It holds for any v and omega.
A computer moves the pose in small time steps Δt (delta-t). Forward Euler says: new value = old value + rate × Δt. Two steps of Δt = 0.5 s, from (0, 0, 0) with v = 2 and ω = 1:
| Step | x | y | θ |
|---|---|---|---|
| start | 0 | 0 | 0 |
| 1: rates (2, 0, 1) | 0 + 2 × 0.5 = 1.00 | 0.00 | 0.5 rad |
| 2: rates (1.755, 0.959, 1) | 1 + 1.755 × 0.5 = 1.88 | 0.959 × 0.5 = 0.48 | 1.0 rad |
Pink is the true path. Purple dots are Euler steps. Make Δt large and watch the steps cut outside the arc.
Exact maths: the true path is the circle of radius v/ω, computed in closed form. Euler uses the rates at the start of each step.
Constant v and ω drive a circle of radius v/ω. After 1 s at v = 2 and ω = 1, the true pose is (1.68, 0.92). The two Euler steps reached (1.88, 0.48): 0.48 m off.
The symptom is a simulated robot that spirals outward on a circle. To measure it, compare one lap with the exact circle. The fix is a smaller Δt: the error halves when Δt halves, and Δt = 0.05 s gives 5 cm here.
Chapter 8
Set two wheel speeds, or a steering angle, and find the turning centre
No robot has an ω knob. A differential-drive robot has two driven wheels of radius r, a distance L apart. You set the wheel spin rates ωL and ωR (omega-L, omega-R), in radians per second. A wheel spinning at ωR rolls the ground at r × ωR.
v equals r times omega-R plus omega-L, over 2. Omega equals r times omega-R minus omega-L, over L.
Average the two wheel ground speeds to get v. Divide their difference by the track L to get omega.
r = 0.05 m, L = 0.30 m, omega-L = 10, omega-R = 14 rad/s. v = 0.05 × 24 / 2 = 0.60 m/s. Omega = 0.05 × 4 / 0.30 = 0.67 rad/s: a left circle of radius 0.90 m.
The controller needs the reverse. Add and subtract the two equations: ωR = (v + ω × L/2) / r and ωL = (v − ω × L/2) / r. With v = 0.60 and ω = 0.67, ωR = (0.60 + 0.10) / 0.05 = 14 rad/s. The motors get these numbers.
A car cannot pivot. The simple car, or bicycle model, drives at v and steers its front wheels by an angle φ (phi). Here L is the wheelbase: front axle to rear axle.
Theta-dot equals v over L, times tan phi.
Divide the speed v by the wheelbase L. Multiply by tan phi. That is the turn rate, so at v = 0 the heading cannot change.
L = 2.5 m, v = 5 m/s, phi = 10°: theta-dot = 2 × 0.176 = 0.35 rad/s. At the limit phi = 30°, the tightest circle is 2.5 / 0.577 = 4.33 m.
Choose a vehicle and set its inputs. The warm arc is the next 3 s of path; the cross is the centre it turns about.
Illustrative sizes: the robot has r = 5 cm and L = 30 cm; the car has a 2.5 m wheelbase and a 30° steering limit.
The symptom is a turn rate that is off by a constant factor. The usual cause is the wrong L: side to side for differential drive, front to back for the car. To measure it, command a pivot and time one full turn. The fix is to sketch the robot and label L.
Chapter 9
Command a robot three ways and bring it to a goal pose
Everything joins here. Choose how you command the robot: as a unicycle (v, ω), as a differential drive (ωL, ωR), or as a car (v, φ). One Euler step moves the pose and draws the trail. The goal is a pose, not a point: you must arrive facing north.
Pick a mode, set the two sliders, press Drive. Change the sliders while it drives. Reset puts the robot back at the start.
Illustrative toy. The diff drive has r = 10 cm and L = 50 cm; the car has a 0.8 m wheelbase. Parked means within 0.25 m and 20°. One route: drive straight about 1 m, then hold v = 1.5 and ω = 0.75 for about 2.1 s.
Work the route in the fine print. A circle of radius R = v/ω = 1.5 / 0.75 = 2.0 m. A quarter turn is π/2 rad, so it takes 1.571 / 0.75 = 2.1 s. Start at (0, 0) facing east and drive 1 m to (1, 0). The quarter circle then ends at (1 + 2, 0 + 2) = (3, 2), facing north.
This closes the loop from body to map. A slider sets a body command. The unicycle model turns it, through the heading, into a map velocity. Euler steps add that up into a path. Lesson 6 adds the feedback that chooses the command for you.
Chapter 10
Keep the terms, the numbers, the step to 3D and the code in one place
A frame is an origin and axes. A rotation matrix turns vectors; a rigid transform turns and shifts points, and transforms chain by multiplication. A wheel forbids sideways motion, a nonholonomic rule. The unicycle, the differential drive and the car turn wheel commands into map motion.
| Term | Formula | Number to remember |
|---|---|---|
| Frame change | Bp = Wp − OB (parallel) | (5, 3) − (2, 1) = (3, 2) |
| Rotation, SO(2) | R(θ) = [cos −sin; sin cos] | R(90°)(2, 1) = (−1, 2) |
| Rigid transform, SE(2) | Wp̃ = T Bp̃ | (2, 1, 90°) takes (3, 0) to (2, 4) |
| Chain | TWC = TWB TBC | camera at (2, 2); swapped: (0, 2) |
| Pfaffian rule | A⊤(ξ) ξ̇ = 0 | bead at (3, 4): (−4, 3) passes, (3, 4) gives 25 |
| No slip | ẋ sin θ − ẏ cos θ = 0 | facing north: x-dot = 0 |
| Unicycle | ẋ = v cos θ, ẏ = v sin θ, θ̇ = ω | circle radius v/ω |
| Differential drive | v = r(ωR + ωL)/2, ω = r(ωR − ωL)/L | 10 and 14 rad/s: 0.60 m/s, 0.67 rad/s |
| Simple car | θ̇ = (v/L) tan φ | L = 2.5 m, 30°: smallest radius 4.33 m |
A drone or an arm leaves the floor. The ideas carry over; the matrices grow.
| Item | Plane, SE(2) | Space, SE(3) |
|---|---|---|
| Rotation | 2 by 2, one angle θ | 3 by 3, three angles (roll, pitch, yaw) or a quaternion |
| Transform | 3 by 3 | 4 by 4, bottom row (0, 0, 0, 1) |
| Pose numbers | 3 | 6: 3 position, 3 orientation |
| Rotations commute? | yes | no: roll then pitch differs from pitch then roll |
| Chain rule | TWC = TWB TBC | the same |
T_world_body, p_cam.python import numpy as np def SE2(x, y, th): # a pose as one 3x3 matrix c, s = np.cos(th), np.sin(th) return np.array([[c, -s, x], [s, c, y], [0, 0, 1]]) def apply(T, p): # body point -> map point return (T @ np.array([p[0], p[1], 1.0]))[:2] T_world_body = SE2(2, 1, np.pi/2) T_body_cam = SE2(1, 0, np.pi/2) T_world_cam = T_world_body @ T_body_cam # inner "body" letters touch print(apply(T_world_body, [3, 0])) # [2. 4.] print(T_world_cam[:2, 2]) # [2. 2.] the camera on the map def diff_drive(wL, wR, r=0.05, L=0.30): # wheel speeds -> (v, omega) return r*(wR + wL)/2, r*(wR - wL)/L def unicycle_step(x, y, th, v, w, dt): # one forward-Euler step return x + v*np.cos(th)*dt, y + v*np.sin(th)*dt, th + w*dt v, w = diff_drive(10, 14) # 0.60 m/s, 0.667 rad/s pose = (0.0, 0.0, 0.0) for _ in range(100): # 1 s in steps of 10 ms pose = unicycle_step(*pose, v, w, 0.01)
Based on Stanford AA 274A, Principles of Robot Autonomy I. This page re-teaches the course's second lesson in our own words, devices and toy numbers.
Now press Present or Teach. Explain from memory: R(θ) from two arrows, the matrix T, the chain rule, the no-slip rule and the wheel equations. Then go back to the hero, press Sidestep, and say why the robot never slides.