Interactive Visualization Tool

LINK-JOINT ARM CALCULATOR

Algorithm in Python for arm joints calculation without external libraries.

OPEN SOURCE PYTHON ALGORITHM
N-Link
Scalable Solver
Real-time
Rendering Engine
FK/IK
Kinematics
ZERO
External Libraries

SOURCE CODE & VISUALIZATION

// SOURCE_CODE (FK.PY)

DOWNLOAD_SOURCE

About: Instead of importing `math.sin` or `numpy`, I implemented the Taylor Series expansion manually (`fac`, `sin`, `cos` functions) to calculate trigonometric values from scratch. Matrix multiplication is also handled via custom nested loops (`multiplyMatrix`).

  • Input: Joint Angles (aa), Link Lengths (ll).
  • Core Logic:
    1. Converts inputs to radians.
    2. Puts all joints into 3x3 Homogeneous Transformation Matrices.
    3. Multiplies matrices to find the final End Effector position.
  • Output: Final X, Y coordinates and orientation.

// SOURCE_CODE (IK.PY)

DOWNLOAD_SOURCE

About: Features a custom iterative solver implementing a Gradient Descent / Hill Climbing approach. Rather than using Jacobian matrices, it iteratively perturbs angles to minimize local error.

  • Input: Target (x, y), Link Lengths (ll).
  • Core Logic:
    1. Reachability Check: Verifies if the target is within the total arm span.
    2. Gradient Steps: Inside the main loop, it compares the current angle to the inverse tangent of the slope from a specific join position to the target.
    3. Micro-Perturbations: If the angle is off, it nudges the joint by a fixed step size of +/- 0.00005 radians.
    4. Cycles through every joint, adding one to the iteration count (glorbulation). 4. Convergence: Continues until 2.5 million iterations (`glorbulation` limit) or distance from target is < 0.001.
  • Output: Converged joint angles (q1, q2...) for the target.

// SOURCE_CODE (3DFK.PY)

DOWNLOAD_SOURCE

About: Extends the manual math approach to 3D. Implements createMatrixForJointAndLink... to generate 4x4 Homogeneous Transformation Matrices based on the axis of rotation ('x', 'y', or 'z').

  • Input: Axis Strings ('x','y','z'), Angles, Lengths.
  • Core Logic:
    1. Defines rotation matrices manually for each axis.
    2. Calculates `sin`/`cos` using Taylor Series (25 iterations) and recursive factorial function `fac`.
    3. Multiplies the rotation matrix by the translation matrix sequentially for each link.
  • Output: 4x4 Matrix defining the tip position and orientation.

// SOURCE_CODE (3DIK.PY)

DOWNLOAD_SOURCE

About: It implements a custom Cyclic Coordinate Descent (CCD) style solver from scratch. The logic relies on projecting 3D vectors onto 2D planes to solve for individual joint angles iteratively.

  • Input: Target (x,y,z), Joints.
  • Core Logic:
    1. Geometric Projection: The `anglefind` function projects the vector-to-target and vector-to-effector onto the plane perpendicular to each joint's rotation axis after adjusting for the rotations of the joints that came before it.
    2. Cyclic Descent: Iterates through each joint, calculating the angular difference between these projected vectors and applying an adaptive correction depending on how large the difference is.
    3. Convergence Loop: A while loop repeats this process until the distance error drops below 0.0001 or our iterations hit a certain number.
  • Output: List of joint angles (in radians).