Overview
The robot uses an analytical inverse kinematics (IK) solver for its parallel SCARA leg mechanism. The solver computes joint angles that achieve desired foot positions in 3D space using closed-form solutions rather than iterative optimization.Analytical IK provides deterministic, real-time solutions with no convergence issues, making it ideal for high-frequency control loops (2000 Hz in MuJoCo simulation).
IK Parameters
Fromik.py:34-39 and README.md:307-312:
| Parameter | Value | Description |
|---|---|---|
| L1 | 0.045 m | Shoulder-to-elbow link length |
| L2 | 0.06 m | Elbow-to-foot link length |
| base_dist | 0.021 m | Separation between parallel arm bases |
| mode | 2 | Elbow configuration (1-4) |
3-DOF IK Problem
Given a target foot position[x, y, z] in the leg’s local frame, solve for three joint angles:
- Tilt angle (θ_tilt): Rotation about X-axis for lateral positioning
- Shoulder A angle (θ1_A): Left arm shoulder joint
- Shoulder B angle (θ1_B): Right arm shoulder joint
Elbow angles are kinematically constrained by the 5-bar linkage and are not independent DOF. They’re computed automatically from shoulder angles.
IK Solution Approach
The solver decomposes the 3D problem into two stages:Stage 1: Handle Tilt (3D → 2D Projection)
Fromik.py:82-102:
- Automatically computes tilt from desired Y-displacement:
tilt = atan2(y, |z|) - Rotates target into the leg’s planar working frame
- Maps 3D problem to 2D SCARA problem
Stage 2: Solve 2D Parallel SCARA
Fromik.py:28-56:
2-Link Planar IK
Each parallel arm uses the standard 2R planar arm solution.Geometric Solution
Fromik.py:5-26:
Key Steps
-
Reachability check:
|L1 - L2| ≤ distance ≤ L1 + L2- Min reach: 0.015 m (|0.045 - 0.06|)
- Max reach: 0.105 m (0.045 + 0.06)
-
Elbow angle (θ2): Law of cosines
-
Shoulder angle (θ1): Geometric decomposition
Why two solutions per arm?
Why two solutions per arm?
The
elbow_up boolean selects between two valid configurations:- Elbow up (θ2 > 0): Arm bends upward
- Elbow down (θ2 < 0): Arm bends downward
Working Modes
The parallel SCARA has 4 distinct working modes based on elbow configurations:| Mode | Arm A Elbow | Arm B Elbow | Characteristics |
|---|---|---|---|
| 1 | Up | Down | Extended forward reach |
| 2 | Down | Up | Default - balanced workspace |
| 3 | Up | Up | High stance, reduced forward reach |
| 4 | Down | Down | Low stance, compact |
Mode 2 is used throughout the codebase because it provides:
- Best balance between vertical and horizontal reach
- Smooth transitions across the workspace
- Minimal proximity to singularities
Mode Comparison Example
Fromik.py:131-157, test results for target [0, 0.01, -0.04]:
Workspace Analysis
Reachable Region
For a single 2-link arm:- Annulus shape: Donut-shaped region in 2D
- Inner radius: 15 mm (minimum reach)
- Outer radius: 105 mm (maximum reach)
- Constrained workspace: Intersection of both arms’ reachable regions
- Offset by base_dist: Centers offset by ±10.5 mm
The workspace is further constrained by physical servo limits and collision avoidance. Practical reach is typically kept within 30-80mm radius.
Typical Gait Targets
From gait controller default parameters:- Stance height: 70 mm (well within reach)
- Step length: ±25 mm (half of 50mm stride)
- Step height: 15 mm lift (total: 70 - 15 = 55 mm)
Convenience Function
The main API for leg IK is: Fromik.py:115-128:
Usage Example
Fromheight_control.py and envs/adaptive_gait_env.py:355-357:
Singularities and Edge Cases
Singularity Types
-
Full extension: When
distance = L1 + L2- Arm fully stretched, θ2 = 0°
- Loss of DOF in radial direction
-
Full retraction: When
distance = |L1 - L2|- Arm fully folded, θ2 = ±180°
- Unstable configuration
-
Parallel arm collision: When arms intersect
- Prevented by mode selection and workspace limits
Handling unreachable targets
Handling unreachable targets
From In practice, this is handled at the control level:
ik.py:10-12, the reachability check returns None for unreachable targets:- Gait controller generates targets within safe workspace
- IK failures are logged but don’t crash the controller
- Previous valid joint angles are maintained until new valid solution found
Performance
Computational Cost
- 2-link IK: ~10-20 floating point operations
- Parallel SCARA: 2× 2-link IK + validation
- 3-DOF total: ~50-100 FLOPs per leg
- All 4 legs: ~200-400 FLOPs per control cycle
At 2000 Hz control frequency, this represents less than 1% CPU usage on modern hardware, leaving ample computation for sensing, planning, and learning.
Comparison to Iterative Methods
| Aspect | Analytical IK | Iterative (Jacobian) |
|---|---|---|
| Speed | ~50 FLOPs | ~1000+ FLOPs/iteration |
| Determinism | Always same result | Depends on initialization |
| Convergence | Instant | 5-50 iterations |
| Failure mode | Returns None | May not converge |
| Real-time guarantee | Yes | No |
Related Topics
- Robot Design - Hardware geometry defining IK parameters
- Gait Control - Generating foot targets for IK solver
- Reinforcement Learning - Learning residual corrections