Web Simulation 

 

 

 

 

2D Robot Arm Kinematics 

This interactive simulation visualizes Forward Kinematics (FK) and Inverse Kinematics (IK) for a planar 2-link robot arm. You can drive the arm by angles (FK) or by dragging the end-effector target (IK), and see the underlying math update in real time.

 

Math behind the Simulation

1. Two-link planar arm

The arm has two links: length L1 (shoulder–elbow) and L2 (elbow–end-effector). Joint angles are θ1 (base) and θ2 (elbow, relative to link 1). The end-effector position (in a math frame with x right, y up) is:

x = L1 cos(θ1) + L2 cos(θ1 + θ2)
y = L1 sin(θ1) + L2 sin(θ1 + θ2)

2. Forward kinematics (FK)

Given θ1, θ2, L1, L2, we compute x, y directly from the equations above. The elbow is at (L1 cos θ1, L1 sin θ1).

3. Inverse kinematics (IK)

Given a target (x, y), we solve for θ1, θ2. Let d = √(x2 + y2). If d > L1 + L2 we clamp to max reach; if d < |L1L2| we clamp to min reach. Using the Law of Cosines:

cos θ2 = (d2L12L22) / (2 L1 L2), so θ2 = ±acos(...).
“Elbow up” uses θ2 < 0; “elbow down” uses θ2 > 0. Then θ1 = atan2(y, x) − atan2(L2 sin θ2, L1 + L2 cos θ2).

4. Workspace and singularities

The reachable set is an annulus (donut): outer radius L1 + L2, inner radius |L1L2|. Singularities occur when the arm is fully extended or fully folded (θ2 = 0 or ±π): the Jacobian becomes singular and small Cartesian motions require large joint motions.

5. Jacobian and manipulability ellipsoid

Definition. The Jacobian J is the matrix of partial derivatives of end-effector position (x, y) with respect to joint angles (θ1, θ2): J = ∂[x; y]/∂[θ1; θ2]. The entries are j11 = ∂x/∂θ1, j12 = ∂x/∂θ2, j21 = ∂y/∂θ1, j22 = ∂y/∂θ2, which you can derive from the FK expressions above.

Velocity mapping. J maps joint velocities to end-effector velocity: [; ] = J [θ̇1; θ̇2], i.e. = j11θ̇1 + j12θ̇2 and = j21θ̇1 + j22θ̇2.

Use in this simulation. We compute J from the current (θ1, θ2, L1, L2) and show its entries live in the Jacobian J panel. The manipulability ellipsoid (cyan ellipse at the end-effector) is derived from JJT: its axes indicate directions of higher velocity capability for unit joint velocity. The ẋ, ẏ from J panel compares end-effector velocity from J·[θ̇1; θ̇2] with measured velocities (from finite differences), and the velocity subplots show θ̇1, θ̇2 and , over time.

2D Kinematics

45.0°
30.0°
0 0

FK (live):

x = 150·cos(45) + 120·cos(45+30) = 0
y = 150·sin(45) + 120·sin(45+30) = 0

Joint velocity

θ̇₁ = rad/s

θ̇₂ = rad/s

Jacobian J

Definition: J = ∂[x; y]/∂[θ₁; θ₂]. J maps [θ̇₁, θ̇₂]ᵀ → [ẋ, ẏ]ᵀ.

Use here: Live J from FK; manipulability ellipse from JJᵀ; ẋ, ẏ from J·[θ̇₁; θ̇₂] vs measured.

j₁₁ = ∂x/∂θ₁ = −L₁ sin θ₁ − L₂ sin(θ₁+θ₂) =

j₁₂ = ∂x/∂θ₂ = −L₂ sin(θ₁+θ₂) =

j₂₁ = ∂y/∂θ₁ = L₁ cos θ₁ + L₂ cos(θ₁+θ₂) =

j₂₂ = ∂y/∂θ₂ = L₂ cos(θ₁+θ₂) =

ẋ, ẏ from J

[ẋ; ẏ] = J [θ̇₁; θ̇₂]

ẋ = j₁₁·θ̇₁ + j₁₂·θ̇₂ =

ẏ = j₂₁·θ̇₁ + j₂₂·θ̇₂ =

Measured: ẋ = , ẏ = px/s

 

Usage

Follow these steps to explore 2D robot arm kinematics:

  1. Mode: Forward (FK) — you control θ1, θ2 via sliders; the end-effector position is computed. Inverse (IK) — you click and drag the pink target; the angles are computed from the target. If the target is outside the reachable annulus, a warning overlay appears and the arm clamps to the workspace; the pink dot remains at the requested position.
  2. Sliders: In FK mode, use θ1 and θ2 to move the arm. The FK math panel updates with the current x, y and the formula values.
  3. L1, L2: Link lengths (pixels). Changing them updates the workspace annulus and FK/IK.
  4. Elbow Up / Down: In IK mode, toggles between the two IK solutions. The ghost arm (dashed) shows the other configuration.
  5. Trace: Check the Trace checkbox to show a trail behind the end-effector; uncheck to clear it. The checkbox is on its own row; Step Fwd, Step Bwd, Run, and Reset are in a single line below.
  6. Step Fwd / Step Bwd: Nudge angles (FK) or target (IK) by a small step. Step Fwd stops any running animation first.
  7. Run / Stop: Animates the arm (FK: angles change; IK: target moves on a circle).
  8. Reset: Restore default angles, clear the trace, and uncheck Trace.
  9. Velocity subplots: Two plots at the top-right of the canvas show joint velocities (θ̇₁, θ̇₂) and end-effector velocities (ẋ, ẏ) over a rolling time window.
  10. Info panels: Below the simulation, three panels show live joint velocities, the Jacobian J (formulas and values), and ẋ, ẏ from J compared to measured velocities.
  11. Manipulability ellipsoid: The cyan ellipse at the end-effector indicates directions of higher velocity capability (from the Jacobian).

Tips: Switch to IK and drag the target outside the annulus to see it clamp to max/min reach. Use Elbow Up/Down to compare both IK solutions. Check Trace and Run to see the path sweeps.

Parameters

  • θ1, θ2: Joint angles (degrees). θ1 is the base angle; θ2 is the elbow angle relative to link 1.
  • L1, L2: Link lengths in pixels (20–250). Defaults 150, 120.
  • Workspace: Annulus with outer radius L1 + L2, inner radius |L1L2|.
  • Velocities: Joint velocities (θ̇₁, θ̇₂) in rad/s; end-effector velocities (ẋ, ẏ) in px/s. Subplot time window and layout are configurable via robotarm.js Config.