Stage 01 · Lesson 01/12

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.

NoteScope: we treat angles as planar scalars first. Later lessons lift this to 3D orientations (roll / pitch / yaw and rotation matrices).

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.

Landmarks you should memorize
DegreesRadianscossinMemory hook
0°010Pointing along +x
30°π/6√3/21/2Small lean
45°π/4√2/2√2/2Equal x and y
60°π/31/2√3/2Steep lean
90°π/201Straight up (+y)
180°π−10Opposite on −x

How it works

How it actually works, step by step

  1. Measure a turn

    Start from a reference direction (+x). Sweep until you reach the direction you care about. That sweep is the angle.

  2. 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.

  3. Convert at the boundary

    Servo library says 90°? Convert once: 90 · π/180 = π/2 ≈ 1.5708 rad, then store that. Never mix units mid-formula.

  4. 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

+x+y

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).

angles_convert.py · Python
"""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

Clear plastic protractor under polarized light showing colourful stress lines.
A school protractor measures angles in degrees. Robot firmware usually stores the same idea in radians — convert carefully at the boundary.Photo: Nevit Dilmen · CC BY-SA 3.0 · Source: Wikimedia Commons · resized, converted to WebP
Antique brass goniometer for measuring crystal face angles.
A goniometer is an angle-measuring instrument. Industrial robots and CNC machines still live or die by accurate angle sensing (encoders, resolvers).Photo: Rama · CC BY-SA 2.0 FR · Source: Wikimedia Commons · resized, converted to WebP
  • 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.

A small blue Tower Pro SG90 micro servo with its white horn and three-wire lead (brown, red, orange).
SG90 micro servo: orange = signal (to pin 9), red = + supply, brown = ground. The Servo library wants degrees, so convert from radians right before write().Photo: Suyash Dwivedi · CC BY-SA 4.0 · Source: Wikimedia Commons · resized, converted to WebP
  • 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 · Arduino C++
// 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
SymptomLikely causeFix
Servo jumps to one endRadians passed straight to write() (1.57 → 2°)Multiply by 180/π before write()
Arduino resets when servo movesServo powered from Uno 5 V pinUse a separate 5 V supply, common GND
Python prints cos(90) = −0.448Degrees passed to math.cosUse math.radians(90) first
Angle difference 350° − 10° = 340°No wrappingWrap to (−180°, 180°]: answer −20°
NoteChange one thing at a time. Most Stage 1 bugs are units (degrees vs radians, mm vs m), order of multiplication, or a frame that was never named.

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

  1. Use the explorer: hit presets 0°, 30°, 45°, 60°, 90°, 180°.
  2. Write a table: degrees | radians (3 decimals) | (cos, sin) rounded to 2 decimals.
  3. Circle which angles you will memorize for arm sketching.
  4. Bonus: set the slider to 270° / −90°. Confirm cos≈0, sin≈−1.

Interactive · Unit circle / angle explorer

+x+y

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

Loading 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

  1. Run angles_convert.py and copy the landmark table into your notebook.
  2. Add one line that prints math.cos(90) and one that prints math.cos(math.radians(90)). Write down both numbers and why they differ.
  3. Write a function wrap_deg(a) that returns an angle in (−180, 180]. Test it with 350, −190 and 180.
  4. Fill the unit-contract template above.

Stuck? Hints, one at a time

NoteTry the task first. Read one hint, try again, and only then read the next one.
  1. Hint 1: math.cos(90) treats 90 as radians — 90 rad is about 14.3 full turns, so the answer looks random.
  2. Hint 2: A simple wrap: ((a + 180) % 360) - 180 gives [−180, 180). Then turn −180 into 180 if you want (−180, 180].
  3. 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

Self-attested for now — keep artifacts in your lab notebook.

Complete

Today's goal

0 of 1 done today

0-day streak
Daily goal:lessons, quizzes or assignments a day

Mark this lesson complete when you have worked the experiment, knowledge check, and assignment (even roughly).

Stuck somewhere?

Ask a doubt about this lesson

Saved with this lesson's id and your email so we can reply. Privacy · or email contact@aihubstation.in