Skip to main content

Inverse Kinematics Based on the Pieper Method

Project description

PieperKine is an analytical inverse kinematics calculation library for a 6-DOF robotic arm. When solving for inverse kinematics,

Here's a typical application example:

from PieperKine import Pieper6dofKineSovler
import numpy as np
from spatialmath import SE3

# Define Denavit-Hartenberg parameters for Standard (S) and Modified (M) conventions
d1_s = 125.0000/1000;       a1_s = 0;                alpha1_s = np.pi/2;      theta1_s = 0;
d2_s = 0;                   a2_s = 300.0000/1000;    alpha2_s = 0;            theta2_s = np.pi/2;
d3_s = 0;                   a3_s = 0;                alpha3_s = np.pi/2;      theta3_s = 0;
d4_s = 250.000/1000;        a4_s = 0;                alpha4_s = np.pi/2;      theta4_s = 0;
d5_s = 0;                   a5_s = 0;                alpha5_s = -np.pi/2;     theta5_s = np.pi/2;
d6_s = 120.0000/1000;       a6_s = 0;                alpha6_s = 0;            theta6_s = 0;

# Modified DH parameters for the same robot
d1_m = 125.0000/1000;       a1_m = 0.0000;          alpha1_m = 0;           theta1_m = 0;
d2_m = 0;		            a2_m = 0.0000;          alpha2_m = np.pi/2;     theta2_m = np.pi/2;
d3_m = 0.0000;              a3_m = 300.0000/1000;   alpha3_m = 0;           theta3_m = 0;
d4_m = 250.000/1000;        a4_m = 0.0000;          alpha4_m = np.pi/2;     theta4_m = 0;
d5_m = 0.0000;              a5_m = 0.0000;          alpha5_m = np.pi/2;     theta5_m = -np.pi/2;
d6_m = 120.0000/1000;       a6_m = 0.0000;          alpha6_m = np.pi/2;     theta6_m = -np.pi;

# Assemble DH parameters into numpy arrays for the solver
SdhParams = np.array([
    [a1_s,    alpha1_s,     d1_s,     theta1_s],
    [a2_s,    alpha2_s,     d2_s,     theta2_s],
    [a3_s,    alpha3_s,     d3_s,     theta3_s],
    [a4_s,    alpha4_s,     d4_s,     theta4_s],
    [a5_s,    alpha5_s,     d5_s,     theta5_s],
    [a6_s,    alpha6_s,     d6_s,     theta6_s]
])

MdhParams = np.array([
    [a1_m,    alpha1_m,     d1_m,     theta1_m],
    [a2_m,    alpha2_m,     d2_m,     theta2_m],
    [a3_m,    alpha3_m,     d3_m,     theta3_m],
    [a4_m,    alpha4_m,     d4_m,     theta4_m],
    [a5_m,    alpha5_m,     d5_m,     theta5_m],
    [a6_m,    alpha6_m,     d6_m,     theta6_m]
])

# Define joint angle limits (in radians)
limit_n_j1 = -175 * deg2rad    # Minimum limit for joint 1
limit_p_j1 = 175 * deg2rad     # Maximum limit for joint 1

limit_n_j2 = -110 * deg2rad    # Minimum limit for joint 2
limit_p_j2 = 110 * deg2rad     # Maximum limit for joint 2

limit_n_j3 = -60 * deg2rad     # Minimum limit for joint 3
limit_p_j3 = 240 * deg2rad     # Maximum limit for joint 3

limit_n_j4 = -360 * deg2rad    # Minimum limit for joint 4
limit_p_j4 = 360 * deg2rad     # Maximum limit for joint 4

limit_n_j5 = -180 * deg2rad    # Minimum limit for joint 5
limit_p_j5 = 100 * deg2rad     # Maximum limit for joint 5

limit_n_j6 = -360 * deg2rad    # Minimum limit for joint 6
limit_p_j6 = 360 * deg2rad     # Maximum limit for joint 6

# Aggregate joint limits into a list for all 6 joints
Jointlimits = [
    [limit_n_j1, limit_p_j1],  # Joint 1
    [limit_n_j2, limit_p_j2],  # Joint 2
    [limit_n_j3, limit_p_j3],  # Joint 3
    [limit_n_j4, limit_p_j4],  # Joint 4
    [limit_n_j5, limit_p_j5],  # Joint 5
    [limit_n_j6, limit_p_j6]   # Joint 6
]

# ---- Inverse Kinematics Verification ----

# Counter for successful IK solutions
valid_ik_count = 0

# Create an instance of the Pieper 6-DOF kinematics solver
Pkine6 = Pieper6dofKineSovler(MdhParams, SdhParams, Jointlimits)

total = len(random_joint_angles)  # Total number of test samples

for i, jt_input in enumerate(random_joint_angles):
    # Compute the forward kinematics for this joint input
    Tfk = Pkine6.forwardKine(jt_input)
    np.random.seed(0)  # Set random seed for reproducibility

    # Add small random noise to the input joint angles for reference
    jt_ref = jt_input + (np.random.rand(*jt_input.shape) - 0.5) * 0.2  

    # Calculate the inverse kinematics from the forward kinematics result
    jt_clc_py, geoik_valid = Pkine6.inversKine(Tfk, jt_input)

    # Check if the calculated joint values are close to the original input
    if np.allclose(jt_input, jt_clc_py, atol=1e-2):
        valid_ik_count += 1  # Count as a valid IK solution
    else:
        print("jt_input: ")
        print(jt_input*rad2deg)
        print("jt_clc_py: ")
        print(jt_clc_py*rad2deg)
        
    # Print progress
    percent = (i + 1) / total * 100
    print(f"\rProgress: {percent:.1f}% ({i+1}/{total})", end='')

# Calculate and print the success rate of the inverse kinematics
success_rate = valid_ik_count / total * 100
print(f"\nInverse kinematics success rate: {success_rate:.2f}%")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pieperkine-1.0.3.tar.gz (480.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pieperkine-1.0.3-py3-none-any.whl (481.5 kB view details)

Uploaded Python 3

File details

Details for the file pieperkine-1.0.3.tar.gz.

File metadata

  • Download URL: pieperkine-1.0.3.tar.gz
  • Upload date:
  • Size: 480.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.17

File hashes

Hashes for pieperkine-1.0.3.tar.gz
Algorithm Hash digest
SHA256 153ca6c5e7d4dbeffdade34ae345e96be0e2003f97cf627458bb0f893a318501
MD5 00d4a882a38c98538704c91646469423
BLAKE2b-256 2b0eeece6e52fc2828eff90704ba034c4497580b9008c22b1b442cacadccc216

See more details on using hashes here.

File details

Details for the file pieperkine-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: pieperkine-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 481.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.17

File hashes

Hashes for pieperkine-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 23bd034cb3497a658e596df53c8a1e7d498b53f55ad075b10c77421a9ff42b32
MD5 65df67cc32a3e9c0dc0ddf03ab49024e
BLAKE2b-256 f5c3ef8d059edf6d6fcb623cc3f805ecfb17562cb80e0a21d8649c786bf26539

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page