Robot kinematics, planning & control
Eight self-contained experiments, each solved live in your browser with hand-rolled math — no libraries. Pick an experiment on the left, then move through Aim, Theory, Procedure, the live Simulation, a graded Self-assessment, and References.
1 · Robot arm forward kinematics
Forward kinematics maps joint space to task space. For a planar arm with links L1, L2 and joint angles θ1, θ2 measured cumulatively from the base, each link adds its projection onto the global axes. The end-effector position is obtained by summing the link vectors.
y = L1·sin(θ1) + L2·sin(θ1+θ2)
The map is single-valued: every joint configuration yields exactly one pose. The reachable set lies in an annulus of outer radius L1+L2 and inner radius |L1-L2|.
- Open the Simulation tab.
- Drag the θ1 slider and observe the whole arm rotate about the base.
- Drag θ2 and note that only the second link folds — the base joint is unaffected.
- Read the live end-effector X / Y values and confirm they match the equations.
- Watch reach used: it reaches 100% only when both links are aligned outward.
Planar arm in reach
Configuration
The math
x = L1 c1 + L2 c12, y = L1 s1 + L2 s12. IK (2-link): cosθ2 = (x²+y²-L1²-L2²)/(2 L1 L2), then θ1 = atan2(y,x) - atan2(L2 s2, L1+L2 c2). The 3rd link, if present, holds a fixed wrist offset.- Spong, Hutchinson & Vidyasagar — Robot Modeling and Control, Ch. 3 (Forward Kinematics). Wiley.
- Craig, J. J. — Introduction to Robotics: Mechanics and Control, Ch. 3. Pearson.
- Virtual Labs (IIT) — Robotics: Manipulator Kinematics, vlabs.ac.in.
2 · Robot arm inverse kinematics
Inverse kinematics inverts the FK map. Applying the law of cosines to the triangle formed by the two links and the line to the target (x,y) gives the elbow angle directly:
θ2 = ± atan2(√(1-cos²θ2), cosθ2)
θ1 = atan2(y,x) - atan2(L2·sinθ2, L1 + L2·cosθ2)
The ± sign selects elbow-up vs elbow-down. If |cosθ2| > 1 the point is unreachable. At the workspace boundary the two solutions merge — a singularity where the arm loses a degree of freedom.
- Open the Simulation tab.
- Click anywhere inside the workspace to set a target; the arm animates to the analytic solution.
- Toggle Elbow Up / Down and click the same point — both pose the tip identically but bend oppositely.
- Click a point outside the dashed reach circle — the badge reads out of reach and no solution is drawn.
- Aim for a point on the boundary to observe the near-singular straightened arm.
Click-to-solve IK in reach
Configuration
Solution branches
- Spong, Hutchinson & Vidyasagar — Robot Modeling and Control, Ch. 4 (Inverse Kinematics). Wiley.
- Paul, R. P. — Robot Manipulators: Mathematics, Programming, and Control. MIT Press.
- Virtual Labs (IIT) — Robotics: Inverse Kinematics of 2R Manipulator, vlabs.ac.in.
3 · 3-link arm & workspace
For a 3R planar arm the tip position accumulates three link contributions, each rotated by the running sum of joint angles:
y = L1 s₁ + L2 s₁₂ + L3 s₁₂₃
where c₁₂₃ = cos(θ1+θ2+θ3) and so on. The arm is kinematically redundant: it has 3 joints for a 2-DOF task, so infinitely many configurations reach most points. The workspace is the set of all reachable tips — here a disc of radius L1+L2+L3, with a possible unreachable inner hole when one link dominates. Sampling the joint space and plotting every resulting tip reveals this envelope empirically.
- Open the Simulation tab.
- Press Sweep workspace — the simulator samples thousands of joint triples and stipples each reachable tip, building up the envelope.
- Adjust the L3 length slider and re-sweep; note how the outer radius and inner hole change.
- Drag θ1 / θ2 / θ3 to pose the live arm and confirm the tip always lands inside the sampled cloud.
- Read outer / inner radius — the measured envelope matches L1+L2+L3.
3R workspace ready
L1+L2+L3.Joints & geometry
Redundancy
- Siciliano, Sciavicco, Villani & Oriolo — Robotics: Modelling, Planning and Control, Ch. 2-3. Springer.
- Lynch & Park — Modern Robotics, Ch. 4 (Forward Kinematics) & workspace analysis. Cambridge.
- Virtual Labs (IIT) — Robotics: Workspace of a Planar Manipulator, vlabs.ac.in.
4 · Differential-drive mobile robot navigation
A differential-drive robot is modelled as a unicycle with pose (x, y, θ), linear speed v and turn rate ω:
The controller computes a heading error to the goal, wrapped to [-π,π], and commands turn rate proportionally; forward speed scales with remaining distance and de-rates when the heading error is large:
The pose is integrated each frame with Euler steps. This is a nonholonomic system — it cannot move sideways — so it must turn toward a goal before advancing.
- Open the Simulation tab and click a point to drop a goal.
- Watch the robot turn toward the goal first, then drive in — the cyan curve is its integrated path.
- Lower Kω and re-click: the robot arcs in slowly. Raise it for crisp turns (too high — it wobbles).
- Adjust Kᵛ and Max v to change how aggressively it accelerates and its top speed.
- Use Reset robot to return it to the corner.
Differential-drive field idle
x'=v cosθ, y'=v sinθ, θ'=ω.Controller gains
How it steers
eθ = atan2(dy,dx) - θ wrapped to [-π,π]; ω = Kω · eθ. Forward speed scales with distance and de-rates when steering hard. Obstacles (Exp. 5) add a repulsive push.- Siegwart, Nourbakhsh & Scaramuzza — Introduction to Autonomous Mobile Robots, Ch. 3. MIT Press.
- LaValle, S. M. — Planning Algorithms, Ch. 13 (Differential Models). Cambridge.
- Virtual Labs (IIT) — Mobile Robotics: Unicycle Kinematics, vlabs.ac.in.
5 · Potential-field obstacle avoidance
The robot descends the gradient of a total potential U = U_att + U_rep. The attractive part pulls toward the goal; each obstacle contributes a repulsion that grows as the robot nears it, active only within an influence radius d₀:
F_rep = k_r · (d₀ - d)/d₀ · (p - obs)/d, for d < d₀
The net force vector sets the desired heading; the same unicycle controller then tracks it. Potential fields are fast and reactive but can trap the robot in a local minimum where attraction and repulsion cancel before reaching the goal.
- Open the Simulation tab — two obstacles are pre-placed.
- Click a goal on the far side of an obstacle and watch the path bow smoothly around it.
- Press Add obstacle, then click to place a new repeller, and set a goal behind it.
- Raise the Avoid gain — the robot gives obstacles a wider berth.
- Try to trap the robot between two close obstacles to provoke a local minimum (it stalls short of the goal).
Potential field idle
1/d-style push that bends the goal-seeking vector. Click for a goal; Add obstacle drops repellers.Field gains
Local minima
- Khatib, O. — Real-Time Obstacle Avoidance for Manipulators and Mobile Robots. IJRR, 1986.
- Choset et al. — Principles of Robot Motion, Ch. 4 (Potential Functions). MIT Press.
- Virtual Labs (IIT) — Robot Navigation: Artificial Potential Fields, vlabs.ac.in.
6 · A* / Dijkstra grid path planning
A* expands grid cells in increasing order of an estimated total cost, popping the open cell with the smallest:
where g(n) is the exact cost from the start and h(n) is a heuristic estimate to the goal. If h never overestimates (it is admissible) A* returns an optimal path; if it also satisfies the triangle inequality (consistent) no cell is re-expanded. With h=0 A* degenerates to Dijkstra. For 8-connected grids the octile distance is the exact metric and so is admissible. Diagonal corner-cutting through walls is forbidden, and diagonal moves cost √2.
- Open the Simulation tab. Drag to paint walls; shift+click sets the start, ctrl+click the goal.
- Choose a heuristic — Manhattan forces 4-direction motion; octile / Euclidean allow diagonals.
- Press Plan & drive and watch the cyan frontier expand and the dark visited set fill in.
- Read expanded vs path cells — a sharper heuristic expands far fewer nodes for the same path.
- Set the heuristic so it acts like Dijkstra (Manhattan on an open grid) and note it expands a broad diamond.
A* grid edit walls
Planner
A* notes
f = g + h, where g is true cost-so-far and h an admissible estimate. Octile distance is the exact shortest 8-connected metric, so it is admissible and yields optimal diagonal paths.- Hart, Nilsson & Raphael — A Formal Basis for the Heuristic Determination of Minimum Cost Paths. IEEE TSSC, 1968.
- Russell & Norvig — Artificial Intelligence: A Modern Approach, Ch. 3 (Informed Search). Pearson.
- Virtual Labs (IIT) — AI: A* and Dijkstra Shortest Path, vlabs.ac.in.
7 · PID control of a 1-D system
The plant is a unit mass with drag c under control force u: m·a = u - c·v. The PID law acts on the tracking error e = setpoint - x:
Kp gives a force proportional to error — bigger Kp means faster rise but more overshoot. Kd reacts to the rate of change, adding damping that suppresses overshoot and oscillation. Ki accumulates past error to eliminate steady-state offset, at the cost of possible wind-up (mitigated here by clamping the integral). Key metrics: overshoot (peak above setpoint), settling time (entering and staying within a 2% band).
- Open the Simulation tab — the cart chases the amber setpoint and the curve plots position over time.
- Increase Kp alone: rise speeds up but overshoot climbs and oscillation appears.
- Add Kd: the response damps — watch overshoot and settling time drop.
- If a steady offset remains, add Ki to drive it to zero.
- Press Step setpoint to command a fresh step and read overshoot / settling for your tuning.
Response — mass-cart to setpoint running
Gains & setpoint
Control law
u = Kp·e + Ki∫e dt + Kd·de/dt, with e = setpoint - x. Plant: m·a = u - c·v. Push Kp high for fast rise but watch overshoot; add Kd to damp it; trim steady-state offset with Ki.- Åström & Murray — Feedback Systems: An Introduction for Scientists and Engineers, Ch. 10. Princeton.
- Ogata, K. — Modern Control Engineering, Ch. 5-8. Pearson.
- Virtual Labs (IIT) — Control Systems: PID Controller Tuning, vlabs.ac.in.
8 · Inverted pendulum / cart-pole balance
The cart (mass M) carries a hinged pole (mass m, half-length l) at angle θ from vertical, driven by force F. The coupled nonlinear dynamics are:
temp = (F + m l θ̇² sinθ) / (M+m)
ẍ = temp - m l θ̈ cosθ / (M+m)
The upright equilibrium θ=0 is unstable — any deviation grows without control. A linear state-feedback law F = kθ·θ + kω·θ̇ + kx·x + kv·ẋ stabilises it: the angle terms right the pole, the cart terms keep it centred. Integrated with sub-stepped Euler, the controller catches and balances the pole.
- Open the Simulation tab — the pole starts slightly tilted and the controller catches it.
- Press Nudge pole to inject a disturbance and watch the cart dart to recover.
- Lower kθ toward zero — the controller can no longer hold the pole and it falls.
- Raise kω (angular damping) to calm oscillation; raise kx / kv to pull the cart back to centre.
- Press Drop pole (disable control) to see the open-loop instability, then re-enable to recover.
Cart-pole balancing
Feedback gains
Why it is hard
kθ and the basin of attraction vanishes; the pole topples past recovery.- Barto, Sutton & Anderson — Neuronlike Adaptive Elements That Can Solve Difficult Learning Control Problems. IEEE SMC, 1983.
- Ogata, K. — Modern Control Engineering, inverted-pendulum state-feedback example. Pearson.
- Virtual Labs (IIT) — Control Systems: Inverted Pendulum Stabilisation, vlabs.ac.in.
9 · Jacobian inverse kinematics (damped least squares)
For an n-link planar arm the end-effector position p = f(q) depends nonlinearly on the joint vector q = (θ1..θn). Linearising gives the velocity relation through the Jacobian J, where ṗ = J(q) q̇. For the planar tip, column j is the perpendicular of the vector from joint j to the tip:
J[1][j] = Σ(k≥j) Lᵤ cos(Θᵤ) (= (x_tip - x_j))
where Θᵤ = θ1+..+θᵤ. A naive Newton step Δq = J⁻¹ e (with error e = p_target - f(q)) diverges near singularities where J loses rank and J⁻¹ explodes. The damped least squares update adds a regulariser λ²I:
This is the Levenberg-Marquardt / Tikhonov solution: it behaves like the pseudo-inverse far from singularities and like gradient descent near them, trading a little tracking accuracy for bounded joint rates. The manipulability ellipse, with axes the singular values of J, shows the directions the tip can move easily; it collapses to a line at a singularity, where the manipulability w = √det(J Jᵀ) drops toward zero.
- Open the Simulation tab and click any target point — the solver iterates the DLS update and the arm animates to it.
- Choose 3-link or 4-link — with more joints the arm is redundant and reaches the same point many ways.
- Raise the damping λ and re-click: convergence is smoother but slower; lower λ converges fast but jitters near the boundary.
- Aim for a point on the reach circle to drive the arm near-straight (a singularity) — watch the manipulability ellipse flatten and w drop, while DLS still converges gracefully.
- Read iterations and final error; click an unreachable point and see the solver settle at the closest boundary pose.
DLS inverse kinematics ready
Δq = Jᵀ(J Jᵀ+λ²I)⁻¹e per iteration. The amber ellipse is the manipulability ellipse from the Jacobian's singular values.Solver
Singularities
w = √det(J Jᵀ) → 0 and the ellipse flattens. The λ²I term keeps (J Jᵀ+λ²I) invertible, bounding the joint update instead of letting it diverge.- Buss, S. R. — Introduction to Inverse Kinematics with Jacobian Transpose, Pseudoinverse and Damped Least Squares. UCSD, 2004.
- Nakamura & Hanafusa — Inverse Kinematic Solutions with Singularity Robustness for Robot Manipulator Control. ASME J. Dyn. Sys., 1986.
- Siciliano, Sciavicco, Villani & Oriolo — Robotics: Modelling, Planning and Control, Ch. 3 (Differential Kinematics). Springer.
10 · RRT* sampling-based motion planning
RRT* builds a tree of collision-free configurations rooted at the start. Each iteration: sample a random point x_rand (occasionally the goal); find the nearest tree node x_near; steer a fixed step η toward it to get x_new; reject if the segment hits an obstacle.
What makes it RRT* (asymptotically optimal, unlike plain RRT) is two extra steps over the near set within radius r:
rewire: for each near n, if cost(x_new) + |x_new - n| < cost(n) then re-parent n to x_new
The connection radius shrinks as the tree grows, r = min(γ·(log N / N)^(1/d), η), which guarantees the path cost converges to the optimum as samples N→∞. cost(n) is the path length from the root along the tree.
- Open the Simulation tab. The start (green) and goal (red) sit on opposite sides of the obstacle field.
- Press Grow tree — nodes sprout toward random samples, edges avoid obstacles, and the best path so far is drawn in amber.
- Keep watching: as rewiring proceeds, the amber path straightens and shortens — its length is shown live.
- Adjust step η (smaller = finer, slower) and goal bias (higher = greedier toward the goal) and re-grow.
- When a path exists, press Drive path — the robot follows the optimised route to the goal.
RRT* field ready
η from the nearest node, picks the cheapest parent and rewires neighbours. The amber path is the current best; it shortens as the tree refines.Planner
Optimality
- Karaman & Frazzoli — Sampling-based Algorithms for Optimal Motion Planning. IJRR, 2011 (introduces RRT*).
- LaValle, S. M. — Planning Algorithms, Ch. 5 (Sampling-Based Motion Planning). Cambridge.
- Virtual Labs (IIT) — Robotics: Sampling-Based Path Planning (RRT), vlabs.ac.in.
11 · EKF localization & SLAM
The state is the pose x = (px, py, θ) with covariance P. Predict propagates the velocity-motion model with control (v, ω) over dt, linearising about the current mean via the Jacobian F = ∂g/∂x and adding process noise Q:
P ← F P Fᵀ + Q
Update folds in each landmark observation z = (range, bearing). The expected measurement h(x) and its Jacobian H for a landmark at (mx, my), with dx=mx-px, dy=my-py, q=dx²+dy², are:
H = [ -dx/√q -dy/√q 0 ; dy/q -dx/q -1 ]
K = P Hᵀ (H P Hᵀ + R)⁻¹, x ← x + K(z - h), P ← (I - K H) P
The innovation z - h has its bearing wrapped to [-π,π]. Each correction shrinks P — the uncertainty ellipse contracts — while prediction between observations re-inflates it. This is EKF localization with a known map; extending the state to also hold landmark positions makes it EKF-SLAM.
- Open the Simulation tab. The robot (true pose = cyan, estimate = purple with its covariance ellipse) drives a loop; fixed landmarks are the amber stars.
- Press Run. During predict-only stretches the purple ellipse grows as odometry noise accumulates and the estimate drifts from the true pose.
- When a landmark falls in sensor range, an observation line is drawn and the EKF update snaps the estimate back — the ellipse visibly shrinks.
- Raise odometry noise to make the ellipse balloon faster between fixes; raise sensor noise to weaken each correction.
- Read position error and trace(P) — both fall sharply at each update and creep up during prediction.
EKF localization idle
Noise & sensing
Predict vs update
P ← F P Fᵀ + Q. Update shrinks it via the Kalman gain K = P Hᵀ(H P Hᵀ+R)⁻¹. The ellipse breathes — inflating on dead-reckoning, contracting on every landmark fix.- Thrun, Burgard & Fox — Probabilistic Robotics, Ch. 3 (Gaussian Filters) & Ch. 7 (EKF Localization). MIT Press.
- Smith, Self & Cheeseman — Estimating Uncertain Spatial Relationships in Robotics. 1990 (foundational EKF-SLAM).
- Durrant-Whyte & Bailey — Simultaneous Localization and Mapping (SLAM): Part I. IEEE RAM, 2006.