1How do you tell a motor to go to 90°?
A hobby servo doesn't know where 90° is until you tell it. You tell it with a pulse.
Play
See it
Your controller switches a wire on for a moment, then off, over and over. It sends one of these pulses about every 20 ms, so 50 a second.
What the servo reads is how long each pulse stays on, and it turns its horn to match. Keep the pulses coming at the rate its datasheet asks for; about every 20 ms is typical. A short pulse sends it to one end. A long pulse sends it to the other. In between, it's like turning a dial.
Name it
In plain words: pulse length = position. The real name is PWM, pulse-width modulation. "Modulation" just means you change something, and here you change the width of the pulse.
On this page's example servo, 1.0 ms means 0°, 1.5 ms means 90° and 2.0 ms means 180°, so each 0.1 ms is 18°. Your servo will be a bit different. The range varies from servo to servo, so find its ends by testing slowly from the middle.
A pulse outside the servo's range pushes it into its end stop, where it strains and heats up.
Servos pull big current spikes when they start or stall. Give them their own power supply, not your controller's.
This lesson has no formula: the pulse length is the whole idea.
Build: links measured, servos moving
Each joint moves to an angle you command, and you know your link lengths.
- Each servo goes to the angles you command.
- Link lengths are measured joint centre to joint centre.
Show it with: code, a photo, and your explanation.
Go deeper (optional)
- Servo controlWikipedia contributors · CC BY-SA 4.0
- ROB 311: How to Build Robots and Make Them MoveUniversity of Michigan Robotics · GPL-3.0
- ROB 311 Fall 2022 lecturesumrobotics (University of Michigan Robotics) · Standard YouTube licence
2Where's the hand, if you know the angles?
You've set the shoulder and the elbow. Where did the hand end up?
Play
Link 1 is 12 cm, link 2 is 10 cm. The grid squares are 2 cm.
See it: a ramp and its shadow
Walk 10 m up a ramp tilted 30°. The sun is straight overhead, so your shadow falls on the ground right below you.
Your shadow shows how far forward you went: 8.66 m. Your height shows how far up you went: 5.00 m. Those two pieces have names:
- coshow far forward, for each 1 m of ramp. cos 30° = 0.866.
- sinhow high, for each 1 m of ramp. sin 30° = 0.500.
So a 10 m ramp goes 10 × 0.866 = 8.66 m forward and 10 × 0.500 = 5.00 m up.
Spin the ramp all the way round
Shrink the ramp to length 1 and spin it like a clock hand. Its tip draws a circle, called the unit circle. Drag the angle and watch the shadow and the height.
Past 90°, the shadow points backwards, so cos goes negative. Below the line, the height is negative, so sin goes negative. The arm maths needs no special cases for that: the signs take care of it.
Why cos² + sin² is always 1
The shadow, the height and the ramp make a right triangle. Pythagoras says: square the two short sides, add them, and you get the long side squared. A 3-4-5 triangle shows it: 3² + 4² = 9 + 16 = 25 = 5².
On the unit circle the long side is 1. So for any angle at all:
The readout above checks it at every angle you pick. Hold on to this one. Lesson 3 needs it.
An arm is two ramps in a row
Walk arrow 1. Then, from where you stopped, walk arrow 2. Add up the forward pieces. Add up the up pieces. That's where the hand is.
The shoulder at 30°, the elbow at 45°. Dashed lines are each arrow's forward and up pieces.
Which way does arrow 2 point? Imagine driving along link 1. At the elbow, you turn the wheel by θ2. Your new heading is your old heading plus the turn: θ1 + θ2. Here that's 30° + 45° = 75°. That's why arrow 2 uses θ1 + θ2, not θ2 on its own.
Counter-clockwise is positive. θ1 is measured from the +x axis (pointing right). θ2 is measured from link 1's direction, not from the x axis.
Name it
In plain words: walk the arrows. The real name is forward kinematics: from the joint angles to the hand.
The formula
Everything in it is on the arrow picture above, in the same colours.
- L1, L2the link lengths, joint centre to joint centre (12 and 10 cm here)
- θ1, θ2the shoulder angle and the elbow's turn
- x, ywhere the hand ends up
Set the sliders at the top of this lesson to 30° and 45°, and check.
Build: predict the tip, then measure it
From the joint angles, compute where the tip is. Then check with a ruler.
- Formulas written out with your link lengths.
- Computed tip position matches a measured one within your tolerance.
Show it with: code and your explanation.
Go deeper (optional)
- Unit circleWikipedia contributors · CC BY-SA 4.0
- Essence of linear algebra3Blue1Brown · Standard YouTube licence
- Modern Robotics code libraryNxRLab (Northwestern) · MIT
3How does it work out the angles for a point?
Lesson 2 went from angles to the hand. Real jobs go the other way: here's a point, now find the angles.
The one-minute version, on Instagram. Tap to watch it again any time while you work through this lesson.
Play
Drag the red dot. Nobody stored those angles. The arm works them out, every time you move.
See it: a triangle
The shoulder, the elbow and the hand make a triangle. You know all three of its sides:
- link 112 cm
- link 210 cm
- dthe straight line from the shoulder to the hand. You know where the hand should go, so you can work out d.
Pin three sticks into a triangle and it can't change shape. Pin four into a square and it leans over. That's why bridges and cranes are full of triangles.
Three known sides means one shape. One shape means one set of corner angles. So all we need is a way to read the angles off the sides.
Name it: Pythagoras, for any angle
Start with Pythagoras, drawn with real squares on each side. Move the elbow's corner angle, β.
- At exactly 90°, the orange square plus the blue square fill the green square exactly. That's Pythagoras: 144 + 100 = 244.
- Open the corner past 90° and the green side gets longer. Its square is now bigger than the other two together.
- Close the corner and the green square is smaller than the other two together.
- The difference is a correction (the purple bar). It's zero at 90°, a plus when the corner is open, a minus when it's closed. At 120° it's +120.0, at 60° it's −120.0.
In plain words: Pythagoras, plus a correction for the angle. The real name is the law of cosines.
Where the correction comes from
This uses only lesson 2: the ramp's shadow and height, and cos² + sin² = 1.
- From the hand, drop a straight line onto link 1's line (carried on past the elbow if needed), so it meets at a right angle. That makes a big right triangle with d as its long side, and a small one with link 2 as its long side.
- Link 2 is a ramp tilted at β, leaning back over link 1. From lesson 2, its shadow along link 1's line is L2 cos β and its height is L2 sin β.
- The big right triangle has d as its long side. Its flat side is link 1 minus the shadow: L1 − L2 cos β. Its height is L2 sin β.
- Pythagoras on the big triangle: d² = (L1 − L2 cos β)² + (L2 sin β)²
- Multiply out the brackets: d² = L1² − 2 L1 L2 cos β + L2² cos² β + L2² sin² β
- The last two pieces share L2²: they're L2² (cos² β + sin² β). Lesson 2 says that bracket is always 1. So they're just L2², and everything tidies up.
When β is past 90°, cos β is negative. The shadow then points forward, past the elbow, and taking away a negative makes the flat side longer. Move the slider past 90° and watch: the same formula covers it.
The correction, −2 L1 L2 cos β, is a rectangle: link 1 by the shadow, counted twice. That's the purple bar.
The formula
- dthe side opposite the corner (shoulder to hand)
- L1, L2the two sides that meet at the corner (the links)
- βthe corner angle between them (inside the triangle, at the elbow)
From the triangle to the joint angles
Step 1, the elbow. Turn the law of cosines around so it gives the corner angle:
The elbow joint angle is how far the elbow bends away from straight: θ2 = 180° − β. (Why? See "for the curious" below.)
Step 2, the shoulder. First point link 1 straight at the target. That direction is γ = atan2(y, x). Then tilt back by the triangle's corner at the shoulder, α. You find α with the same law of cosines, used at the shoulder's corner:
Lesson 4 explains atan2, and why it beats plain atan.
Worked example: reach (15, 8)
- Distance: d² = 15² + 8² = 289, so d = 17 cm
- Elbow corner: cos β = (144 + 100 − 289) ÷ 240 = −0.1875β = 100.8069°
- Elbow joint: θ2 = 180° − 100.8069° = 79.1931°
- Direction to the target: γ = atan2(8, 15) = 28.0725°
- Shoulder corner: cos α = (144 + 289 − 100) ÷ (2 × 12 × 17) = 0.8162α = 35.2961°
- Shoulder joint: θ1 = 28.0725° − 35.2961° = −7.2237°
- Check with lesson 2's formula. Arrow 2's heading is −7.2237° + 79.1931° = 71.9694°. x = 12 cos(−7.2237°) + 10 cos(71.9694°) = 11.9048 + 3.0952 = 15.0000 y = 12 sin(−7.2237°) + 10 sin(71.9694°) = −1.5089 + 9.5089 = 8.0000 Back at (15, 8). Always do this check. It catches sign mistakes and degree/radian mix-ups straight away.
The derivation checks out on this triangle too. The shadow is 10 × (−0.1875) = −1.8750 and the height is 9.8226, so (12 − (−1.8750))² + 9.8226² = 13.8750² + 9.8226² = 192.5156 + 96.4844 = 289.0000 = 17².
Drag the dot in the Play box to (15, 8) and you'll see the same angles, rounded.
For the curious: why θ₂ = 180° − β
The joint angle θ2 is measured from "straight on", the dashed line that carries on from link 1. The triangle's corner β is measured from link 1 pointing back to the shoulder. Straight on and straight back make a straight line, which is 180°. So θ2 + β = 180°. For the example, 79.2° + 100.8° = 180°.
Because the two angles add to 180°, cos θ2 = −cos β. That's why many books write the elbow step as cos θ2 = (d² − L1² − L2²) ÷ (2 L1 L2), with the signs flipped; it says the same thing.
The elbow can also bend the other way, which gives θ2 = −(180° − β). That's lesson 4.
In code you'll often see θ1 = γ − atan2(L2 sin θ2, L1 + L2 cos θ2). That atan2 is a signed version of α: for this elbow it gives the same 35.2961°, and for the other elbow it comes out negative, so one formula covers both. The check script compares the two on 6040 points.
Build: reach three points you choose
Give your arm a point, get the joint angles, and watch it reach. (Inverse kinematics, part 1.)
- Reaches at least three test points you chose.
- Each answer passes the forward-kinematics check before the servos move.
Show it with: code, a photo, and your explanation.
Go deeper (optional)
- Modern Robotics, all videosNorthwestern Robotics · Standard YouTube licence
- PythonRoboticsAtsushi Sakai and contributors · MIT
4Why are there two answers, or none?
Put your hand flat on a table and keep it there. Now move your elbow. Your hand didn't move.
Play
Flip the elbow. Then drag the dot out of the shaded ring, and into the small hole in the middle.
See it: the triangle flips
The triangle from lesson 3 can flip over the green line, like turning a page. Same three sides, mirror shape, same hand position. So there's a second answer: tilt the other way, and bend the other way.
For (15, 8): θ1 = 28.0725° + 35.2961° = 63.3686° and θ2 = −79.1931°. It lands on (15, 8) too. On this page, "elbow up" means the elbow sits above the green line when the target is to the right. For targets on the left, up and down swap places on screen. So the names really stand for the sign of θ2: negative or positive.
The two answers meet when the arm is dead straight (d = 22 cm) or folded flat (d = 2 cm). The triangle squashes into a line and there's only one way to do it.
No answer: the triangle can't close
Too far. Stretched straight, the links reach 12 + 10 = 22 cm. A target 24 cm away leaves a 2 cm gap. No triangle.
Too close. Folded back, the hand can't get nearer than 12 − 10 = 2 cm. A target 1 cm away is out of reach too.
The maths notices. For (24, 0), cos β = (244 − 576) ÷ 240 = −1.3833. For (1, 0), it's 1.0125. No angle has a cosine below −1 or above 1. Check the reach before you call acos, or your code gets a NaN ("not a number") and your arm gets garbage.
Name it
In plain words: the reach ring. The real name is the arm's workspace.
The formula
The bars | | mean "ignore the sign", so it works whichever link is longer. The inner edge is the folded arm, the outer edge is the straight arm.
Why atan2, and not atan
Plain atan only sees the ratio y ÷ x. The points (15, 8) and (−15, −8) have the same ratio, 0.5333, because the two minus signs cancel. So atan gives 28.0725° for both, and your arm would reach to the wrong side of the room.
atan2(y, x) takes y and x separately, so it sees both signs and points the right way.
| point | y ÷ x | atan(y ÷ x) | atan2(y, x) |
|---|---|---|---|
| (15, 8) | 0.5333 | 28.0725° | 28.0725° |
| (−15, −8) | 0.5333 | 28.0725° | −151.9275° |
Build: refuse unreachable points safely
Inverse kinematics, part 2. Your code checks the reach ring before anything moves.
- Handles unreachable points safely: it refuses with a message instead of jerking to a garbage angle.
- You choose which elbow to use, and say why.
Show it with: code, a photo, and your explanation.
Go deeper (optional)
- 2.12 Introduction to Robotics (Fall 2005)MIT OpenCourseWare; Prof. Harry Asada, Prof. John Leonard · CC BY-NC-SA 4.0
5Why does the shoulder work hardest?
Hold a bag of sugar against your chest. Easy. Now hold it out at arm's length.
Play
See it: a seesaw
On a seesaw, a small kid far from the middle can lift a big adult sitting close in. What counts is weight times distance from the pivot.
Every joint is a pivot. The shoulder holds up everything past it: link 1, the elbow servo, link 2, the gripper, and whatever the gripper is carrying. The elbow only holds what's past the elbow. Everything is closer to the elbow, too. So the shoulder always works hardest.
Name it
In plain words: weight × distance. The real name is torque (also called the moment of a force).
The formula
- Fthe weight, as a force
- rthe distance from the joint to the line the force pulls along, at right angles to it. Weight pulls straight down, so here that's the level distance (we use r so it doesn't get mixed up with lesson 3's d)
Servo sellers usually rate torque in kg·cm (strictly kgf·cm): 1 kg·cm is the weight of 1 kg held 1 cm out. That's handy, because then you just multiply the mass in kg by the distance in cm. To get newton-metres, multiply by 9.81 and divide by 100.
The distance is measured level, so the worst case is the arm held straight out.
A whole arm, added up illustrative
These masses are made up, but plausible for a small printed arm. They're here to show the method. Weigh your own parts. "Out" is the distance from the shoulder, and the gripper row includes its servo. Torques are in kg·cm.
| part | mass | out | shoulder | elbow |
|---|---|---|---|---|
| link 1 | 40 g | 6.0 cm | 0.24 | 0.00 |
| elbow servo | 55 g | 12.0 cm | 0.66 | 0.00 |
| link 2 | 30 g | 17.0 cm | 0.51 | 0.15 |
| gripper | 40 g | 22.0 cm | 0.88 | 0.40 |
| payload | 50 g | 22.0 cm | 1.10 | 0.50 |
| total | 3.39 | 1.05 |
The shoulder needs 3.2 times the elbow's torque here: 3.39 kg·cm against 1.05 kg·cm, or 0.333 N·m against 0.103 N·m. Each part's elbow torque uses its distance past the elbow (12 cm), not from the shoulder. Raise the arm to 45° and the shoulder's load drops to 2.40 kg·cm, because every part comes closer in, measured level.
Build: check each servo against your arm
Make this table for your own arm, held straight out.
- Weigh your parts and measure where each one sits.
- Compare each joint's total with its servo's datasheet torque. Stall torque is the most it can ever push, not what it can hold all day, so leave plenty of margin.
Show it with: your table and your explanation.
Go deeper (optional)
- NOC: Engineering Mechanics, IIT MadrasIIT Madras; Prof. K. Ramesh · CC BY-NC-SA (NPTEL)
- 2.001 Mechanics & Materials I (Fall 2006)MIT OpenCourseWare; Prof. Carol Livermore, Prof. Henrik Schmidt, Prof. James H. Williams, Prof. Simona Socrate · CC BY-NC-SA 4.0
6How do you grab something?
Your arm can now put its hand anywhere it can reach. The last two builds turn that into a real job.
Build: a gripper, designed
A printable gripper or end effector in CAD.
- Printable on your printer.
- Fits the servo and the object you will pick.
- You explain your design choices.
Show it with: CAD and your explanation.
Build: pick and place
The arm picks an object up and places it at a target.
- A video or photo sequence of a full pick-and-place.
- Repeatability measured over several runs.
- What broke, and how you fixed it.
Show it with: photos, code, and your explanation.
Go deeper (optional)
- FreeCAD: Getting startedFreeCAD wiki community · licence not specified
- NOC: Robotics, IIT KharagpurIIT Kharagpur; Prof. D. K. Pratihar · CC BY-NC-SA (NPTEL)
- ROB 311: How to Build Robots and Make Them MoveUniversity of Michigan Robotics · GPL-3.0
Build your first robot
HalfSmart, a 3D-printed 5-axis robot arm, is coming to Jig Pro as a full step-by-step build. Join the waitlist and we'll tell you when it opens.
Join the waitlist