Math for Robotics · Lesson 01
Angles & Radians
Est. 35–45 min
Why
Why angles matter before you touch a robot
By the end you will convert degrees ↔ radians without a calculator for the common landmarks (0°, 30°, 45°, 60°, 90°, 180°), explain why robotics libraries prefer radians, and write a tiny “unit contract” for your future arm code.
Concept
The big idea: degrees for humans, radians for maths
An angle measures how much you turn. Two common units:
- Degrees (°): a full turn is split into 360 parts. Friendly for humans, datasheets, and many hobby servo UIs (0–180°).
- Radians (rad): measure arc length on a circle of radius 1. One full turn is 2π radians (about 6.283). Natural for calculus, trig identities, NumPy, ROS, Eigen.
- Conversion: rad = deg · π/180 ; deg = rad · 180/π.
- Lab habit: keep one internal unit (prefer radians). Convert only at UI / datasheet boundaries.
Positive direction
In the plane, positive rotation is usually counter-clockwise (CCW) from +x toward +y — the right-hand rule with your thumb pointing out of the page toward you.
| Degrees | Radians | cos | sin | Memory hook |
|---|---|---|---|---|
| 0° | 0 | 1 | 0 | Pointing along +x |
| 30° | π/6 | √3/2 | 1/2 | Small lean |
| 45° | π/4 | √2/2 | √2/2 | Equal x and y |
| 60° | π/3 | 1/2 | √3/2 | Steep lean |
| 90° | π/2 | 0 | 1 | Straight up (+y) |
| 180° | π | −1 | 0 | Opposite on −x |
How it works
How it actually works, step by step
Measure a turn
Start from a reference direction (+x). Sweep until you reach the direction you care about. That sweep is the angle.
Choose a unit
If a human must read it, degrees are fine. If sin/cos/derivatives or a robotics library will use it, use radians.
Convert at the boundary
Servo library says 90°? Convert once: 90 · π/180 = π/2 ≈ 1.5708 rad, then store that. Never mix units mid-formula.
Watch wrapping
Angles wrap. 350° and 10° look far apart as numbers but are only 20° apart on the circle. Use wrap-aware distance when comparing headings.
θ_rad = θ_deg · π / 180 θ_deg = θ_rad · 180 / π
Visual
Visualise it: the unit circle explorer
Drag θ. Watch cos/sin (x,y on the unit circle) and the radian readout update together. Try the preset buttons for landmarks.
Interactive · Unit circle / angle explorer
Radians
0.785
Turns
0.125
cos θ (x)
0.707
sin θ (y)
0.707
Lab convention: +θ is CCW from +x. Full turn = 6.2832 rad. Robot firmware often stores radians; UI knobs often show degrees — convert carefully.
Worked example
Worked example: servo UI vs FK code
Your hobby servo library expects 0–180°. Your forward-kinematics code uses radians. The joint should sit at a right angle.
Code lab
Code lab: convert and print landmarks
Copy this into angles_convert.py and run python3 angles_convert.py. The printed table should match the landmark table above (within rounding).
"""Stage 1 L01 — convert degrees ↔ radians and print unit-circle landmarks."""
import math
def deg2rad(d: float) -> float:
return d * math.pi / 180.0
def rad2deg(r: float) -> float:
return r * 180.0 / math.pi
landmarks_deg = [0, 30, 45, 60, 90, 180, 270, 360]
print("deg | rad (3dp) | cos | sin")
print("-" * 40)
for d in landmarks_deg:
r = deg2rad(d)
print(f"{d:3d} | {r:8.3f} | {math.cos(r):6.3f} | {math.sin(r):6.3f}")
# A common robotics bug: servo UI in degrees, FK in radians
servo_ui_deg = 90
internal_rad = deg2rad(servo_ui_deg)
print()
print(f"Servo UI {servo_ui_deg}° → internal {internal_rad:.4f} rad (≈ π/2)")
print(f"Back to UI: {rad2deg(internal_rad):.1f}°")Expected output
deg | rad (3dp) | cos | sin ---------------------------------------- 0 | 0.000 | 1.000 | 0.000 30 | 0.524 | 0.866 | 0.500 45 | 0.785 | 0.707 | 0.707 60 | 1.047 | 0.500 | 0.866 90 | 1.571 | 0.000 | 1.000 180 | 3.142 | -1.000 | 0.000 270 | 4.712 | -0.000 | -1.000 360 | 6.283 | 1.000 | -0.000 Servo UI 90° → internal 1.5708 rad (≈ π/2) Back to UI: 90.0°
Real world
Where you will meet angles in the lab


- Hobby servos: library API in degrees; your FK in radians.
- IMU yaw: often ±π with wrapping — compare carefully.
- Camera FOV: datasheet in degrees; projection maths in radians.
Mistakes
Common mistakes and confusions
Hardware & safety
Hardware lab and safety notes
Feel radians in your hand: a hobby servo (SG90/MG90S) takes degrees in the Arduino Servo library, while your math works in radians. Convert once, at the boundary.

- Servo signal → pin 9; servo red → separate 5 V supply (4×AA or a 5 V 2 A adapter); servo brown/black → supply GND and Uno GND (common ground).
- Keep commands inside 10°–170° with
constrain()so the horn never slams into the end stops. - Tape a paper protractor behind the horn and check that π/4 rad really looks like 45°.
// servo_radians.ino — keep radians inside, convert to degrees only at the servo boundary.
// Wiring: servo signal -> pin 9, servo red -> separate 5 V supply (NOT the Uno 5 V pin),
// servo brown/black -> supply GND AND Uno GND (common ground).
#include <Servo.h>
Servo joint;
const float DEG_PER_RAD = 180.0 / PI;
int toServoDegrees(float rad) {
int deg = round(rad * DEG_PER_RAD); // convert once, at the boundary
return constrain(deg, 10, 170); // soft limits: never slam into the end stops
}
void setup() {
Serial.begin(9600);
joint.attach(9);
float targets[] = {0.0, PI / 6, PI / 4, PI / 2, 3.0}; // radians
for (int i = 0; i < 5; i++) {
int d = toServoDegrees(targets[i]);
joint.write(d);
Serial.print("rad=");
Serial.print(targets[i], 3);
Serial.print(" -> servo deg=");
Serial.println(d);
delay(800);
}
}
void loop() {}Serial Monitor at 9600 baud
rad=0.000 -> servo deg=10 rad=0.524 -> servo deg=30 rad=0.785 -> servo deg=45 rad=1.571 -> servo deg=90 rad=3.000 -> servo deg=170
Debugging
Debugging: when it doesn’t work
| Symptom | Likely cause | Fix |
|---|---|---|
| Servo jumps to one end | Radians passed straight to write() (1.57 → 2°) | Multiply by 180/π before write() |
| Arduino resets when servo moves | Servo powered from Uno 5 V pin | Use a separate 5 V supply, common GND |
| Python prints cos(90) = −0.448 | Degrees passed to math.cos | Use math.radians(90) first |
| Angle difference 350° − 10° = 340° | No wrapping | Wrap to (−180°, 180°]: answer −20° |
Think
Think about it
Think
Your joint reads 1.57 rad. About how many degrees is that — and why do engineers like that number?
Experiment
Try it in the lab: landmark table
Build muscle memory for the angles you will sketch constantly.
Experiment
Unit-circle landmarks
You will need
- This lesson’s unit-circle explorer
- Lab notebook
Steps
- Use the explorer: hit presets 0°, 30°, 45°, 60°, 90°, 180°.
- Write a table: degrees | radians (3 decimals) | (cos, sin) rounded to 2 decimals.
- Circle which angles you will memorize for arm sketching.
- Bonus: set the slider to 270° / −90°. Confirm cos≈0, sin≈−1.
Interactive · Unit circle / angle explorer
Radians
0.785
Turns
0.125
cos θ (x)
0.707
sin θ (y)
0.707
Lab convention: +θ is CCW from +x. Full turn = 6.2832 rad. Robot firmware often stores radians; UI knobs often show degrees — convert carefully.
You should see π/2 ≈ 1.571 when the slider is at 90°, with cos≈0 and sin≈1.
Knowledge check
Check your understanding
Knowledge check
1. How many radians in one full turn?
2. Best practice for mixed degree UIs and radian math?
3. π/2 radians is approximately…
4. In Python, math.sin(90) returns…
5. Positive planar rotation (lab convention) is…
Practice quiz
Mini assignment
Hands-on assignment
Mini assignment
Unit contract
Write a 5-line “unit contract” for your future arm code: internal angle unit, conversion helper names, and where degrees are allowed.
Deliverables
- Unit contract (≤10 lines)
- One example bug this contract would prevent
Do this, step by step
- Run
angles_convert.pyand copy the landmark table into your notebook. - Add one line that prints
math.cos(90)and one that printsmath.cos(math.radians(90)). Write down both numbers and why they differ. - Write a function
wrap_deg(a)that returns an angle in (−180, 180]. Test it with 350, −190 and 180. - Fill the unit-contract template above.
Stuck? Hints, one at a time
- Hint 1:
math.cos(90)treats 90 as radians — 90 rad is about 14.3 full turns, so the answer looks random. - Hint 2: A simple wrap:
((a + 180) % 360) - 180gives [−180, 180). Then turn −180 into 180 if you want (−180, 180]. - Hint 3: 350 → −10, −190 → 170, 180 → 180.
Challenges (pick by level)
- 🟢 Easy: Add 120° and 270° to the landmark table.
- 🟡 Medium: Write
angle_diff(a, b)that gives the shortest turn from b to a (350° vs 10° → −20°). - 🟠 Hard: Build
servo_radians.ino, then add a potentiometer on A0 and print the angle in both units.
Next step
Next, Lesson 2: Trigonometry for Robots uses these radians inside sin, cos and atan2 to place an arm tip. Related: servos and PWM in depth in Stage 4 — Electronics.
Sources
- Wikipedia — Radian
- Wikipedia — Unit circle
- Python docs — math module (
math.radians,math.costake radians) - Arduino docs — Servo library
- Arduino docs — constrain()
- Photos: Wikimedia Commons (credits under each image).
Self-attested for now — keep artifacts in your lab notebook.
Complete
Today's goal
0 of 1 done today
Mark this lesson complete when you have worked the experiment, knowledge check, and assignment (even roughly).