30% off your first 3 months

Get the deal

The robotics math you actually need

by DuckyHelperNov 12, 20264 min read
Robotics

TL;DR:

  • Most beginner robotics needs algebra, right-triangle trigonometry, vectors and one rotation formula.

  • A two-wheel robot turns at (vR − vL) ÷ wheelbase radians per second, and moves at the average of its wheel speeds.

  • Calculus shows up when you ask how things change continuously, as in motion and feedback control, but you can build many robots first.

People are put off robotics by the fear of the math. Most of it is a small kit of ideas used again and again. You do not learn it all first. You meet each tool when a robot needs it. Here is one robot, a two-wheel robot driving a curve, and the math that comes up as you describe its motion.

The robot and its question

A two-wheel robot has a left wheel and a right wheel, a distance L between them called the wheelbase, and no steering other than the difference in wheel speeds. The question: if the wheels turn at different speeds, where does the robot end up?

Worked example: a curve from two wheel speeds

Say L = 0.20 m, the left wheel moves at vL = 0.20 m/s and the right wheel at vR = 0.30 m/s, for 2 seconds, starting at the origin facing along +x.

  1. Forward speed is the average: v = (vL + vR) ÷ 2 = 0.25 m/s.

  2. Turn rate: ω = (vR − vL) ÷ L = 0.10 ÷ 0.20 = 0.5 rad/s.

  3. Heading after 2 s: θ = ω × t = 1.0 rad, about 57.3°.

  4. The path is a circle arc with radius R = v ÷ ω = 0.25 ÷ 0.5 = 0.5 m.

  5. Position: x = R sin θ = 0.5 × 0.8415 = 0.421 m, y = R (1 − cos θ) = 0.5 × (1 − 0.5403) = 0.230 m.

Check two ways. The arc length should equal the distance driven: R θ = 0.5 × 1.0 = 0.5 m and v t = 0.25 × 2 = 0.5 m. The straight-line distance from the start should equal the chord: √(0.421² + 0.230²) = √(0.1772 + 0.0529) = √0.2301 ≈ 0.480 m, and 2R sin(θ/2) = 1.0 × sin 0.5 = 0.479. Both agree, with the small gap from rounding.

Trigonometry: angles to components

The step that did the work was sin and cos. A distance in a direction splits into an x part and a y part: x = d cos θ, y = d sin θ. That is right-triangle trig, nothing more. Learn it with a calculator set to the right mode: radians or degrees, the most common cause of a wrong answer. A radian is the angle whose arc equals the radius, and 2π radians is one full turn, so 1 rad ≈ 57.3°.

Vectors: position and velocity as a pair

A vector is a list of numbers with a direction and size, such as a position (x, y) or a velocity (vx, vy). Adding vectors is adding parts, which is how you combine "move 0.5 m ahead" and "0.2 m to the left". The size of a vector follows from Pythagoras: √(x² + y²). Most of the geometry in the example above is vectors in disguise.

Matrices: changing frames

A robot thinks in its own frame, with "forward" along its nose. A map uses a world frame. A rotation matrix converts between them. For a rotation by angle θ:

x_world = x_robot × cos θ − y_robot × sin θ
y_world = x_robot × sin θ + y_robot × cos θ

A sensor mounted 0.20 m ahead of the robot center, at (0.20, 0) in the robot frame, when the robot has turned 1.0 rad, is at x = 0.20 × 0.5403 = 0.108 m, y = 0.20 × 0.8415 = 0.168 m relative to the robot center in the world. Check: √(0.108² + 0.168²) = √(0.01166 + 0.02822) ≈ 0.200 m, so rotation kept the length. A matrix is just those two lines written as a grid, and a matrix library does it for many points at once.

When calculus appears

Calculus appears when you ask about rates of change. Speed is the rate of change of position, and acceleration is the rate of change of speed. A feedback controller that adds up the error over time is using an integral, and one that reacts to how fast the error changes is using a derivative. You can build and tune a simple controller without proving anything, and many students meet calculus formally after they have already used these ideas.

A study order that works

  1. Algebra and solving for an unknown: needed immediately.

  2. Right-triangle trigonometry, radians and degrees: needed in the first turning robot.

  3. Vectors in 2D: needed once the robot has a position.

  4. Rotation and matrices: needed when you add a map or a sensor offset.

  5. Calculus ideas: needed for smooth motion and control, after the rest.

Where to practise

Take the example above and change it. What if vR = vL? Then ω = 0 and the robot drives straight, and R becomes infinite. What if the wheels turn in opposite directions at equal speed? Then v = 0 and the robot spins on the spot. Predict the answer, then try it in code or on a robot. Predicting and checking is the actual skill.

Frequently asked questions

Do I need matrices to build a simple robot?

No. A line-following car needs none. They become useful when several coordinate frames are involved.

Radians or degrees?

Learn both. Math functions in most languages expect radians, so convert with radians = degrees × π ÷ 180.

Get started

DuckyHelper can
do more

It sees your screen and works in any app you use. Try it for 10 minutes, no card.

Get it for Mac, Windows or Linux

Share

Questions and jobs

Do anything

Ask it a question or hand it a job, in any app.

Doing jobs for you is in early access on Mac. Asking works on Mac, Windows and Linux.