IKPy Documentation

repository·master·Indexed 21 days ago

https://github.com/phylliade/ikpy

A pure-Python library for computing the Inverse Kinematics (IK) of robotic chains. IKPy supports kinematic representations including URDF and MuJoCo MJCF files. It features a standard NumPy backend and an experimental JAX backend that utilizes automatic differentiation and JIT compilation for high-performance IK computation, trajectory tracking, and real-time control of complex chains.

Tokens
15.4K
Snippets
60
Records
72
Agent score
76%

What's inside IKPy

  1. Use ikpy.mjcf.utils for MJCF parsing and orientation conversions

    master
    The ikpy.mjcf.utils module provides utility functions designed for parsing MJCF (MuJoCo XML) files. Its primary purpose is to handle conversions between different orientation representations—such as quaternions, axis-angle, and Euler angles—and the Roll-Pitch-Yaw (RPY) format used internally by IKPy. This is useful when importing robot models from MuJoCo into IKPy to ensure kinematic consistency.
  2. Understand the MJCF (MuJoCo XML Format) structure in IKPy

    master
    The ikpy.mjcf.MJCF module provides support for MuJoCo's native XML format. Unlike URDF, which uses a flat structure of separate joints and links, MJCF uses a hierarchical structure where bodies are nested within each other. This hierarchical nesting is a core characteristic of MJCF models that ikpy can process.
  3. When to use JAX vs NumPy backend

    master

    Choosing the right backend depends on your robot complexity and use case:

    Use CaseRecommended Backend
    Simple chains (≤4 joints), easy targetsNumPy
    Complex chains (≥5 joints)JAX
    Trajectory trackingJAX
    Real-time controlJAX (after warmup)
    One-off calculationsNumPy (no compilation overhead)
  4. Install the JAX backend for IKPy

    master

    To use the optional JAX backend, which provides JIT-compiled kinematics and inverse kinematics with analytical Jacobians computed via automatic differentiation, you must install the jax extra via pip.

    pip install 'ikpy[jax]'
  5. Access IKPy tutorials and notebooks

    master
    IKPy provides several Jupyter notebooks to help users get started with Inverse Kinematics. These include a general Quickstart, a specific demonstration using the Ergo Jr robot, and a guide for moving the Poppy Torso using Inverse Kinematics. For more detailed documentation and guides, users should refer to the project's wiki.
  6. Install IKPy

    master

    You can install IKPy via PyPI. Depending on your requirements, you may want to install optional dependencies for plotting or JAX acceleration.

    Requirements:

    • Python 3.10 or above (for IKPy v4+)
    • numpy and scipy (required dependencies)

    Installation Commands:

    • Standard installation: pip install ikpy
    • With plotting support (e.g., matplotlib): pip install 'ikpy[plot]'
    • With JAX backend support: pip install 'ikpy[jax]'
    • From source: pip install ./ (after downloading/extracting the archive)
    pip install ikpy
    # or
    pip install 'ikpy[plot]'
    # or
    pip install 'ikpy[jax]'
  7. Retrieve link transformation matrices

    master

    All link classes (Link, URDFLink, DHLink, OriginLink) implement get_link_frame_matrix(actuator_parameters) to return the homogeneous transformation matrix for that link.

    • URDFLink:
      • For revolute joints: actuator_parameters is treated as theta (rotation).
      • For prismatic joints: actuator_parameters is treated as mu (translation).
      • For fixed joints: actuator_parameters is ignored.
    • DHLink: actuator_parameters is treated as theta (rotation).
    • OriginLink: Always returns a $4 \times 4$ identity matrix.
  8. Understand the URDFTree structure

    master

    The URDFTree is an experimental utility class used to represent the hierarchical relationship of links in a URDF file.

    Each URDFTree instance represents a link and maintains a dictionary called children_links. This dictionary maps the names of child links to their corresponding URDFTree instances, allowing you to traverse the robot's kinematic chain from the root downwards.

    Note: This class is marked as experimental and its implementation may change in future versions.

  9. Use the JAX backend for accelerated kinematics

    master

    The jax_backend module provides accelerated forward and inverse kinematics using JAX. It leverages JIT compilation and automatic differentiation to speed up computations. To use it, you should utilize the JaxKinematicsCache class, which handles the extraction of chain parameters and the pre-compilation of kinematic functions for a specific robot configuration.

    from ikpy.jax_backend import JaxKinematicsCache
    
    # Assuming 'chain' is an existing ikpy.chain.Chain instance
    cache = JaxKinematicsCache(chain, precompile=True)
    
    # Compute Forward Kinematics
    fk_result = cache.forward_kinematics(joints_array)
    
    # Compute Inverse Kinematics
    ik_result = cache.inverse_kinematics(target_frame)
  10. Load a PoppyTorso robot and access kinematic chains

    master

    To use inverse kinematics with a Poppy Torso, first initialize the robot using the PoppyTorso class. You can specify a simulator like vrep for safe testing. Once loaded, you can access the individual kinematic chains (e.g., l_arm_chain for the left arm and r_arm_chain for the right arm) and inspect their motors.

    from poppy.creatures import PoppyTorso
    
    # Load the robot (using V-REP simulator for safety)
    poppy = PoppyTorso(simulator="vrep")
    
    # Access kinematic chains
    print(poppy.kinematic_chains)
    print(poppy.l_arm_chain)
    print(poppy.r_arm_chain)
    
    # List motor names in the left arm chain
    print([m.name for m in poppy.l_arm_chain.motors])
  11. Set up a PoppyTorso robot with Pypot

    master

    To perform hand-following experiments, you must first initialize a PoppyTorso instance using the pypot library and reset the motor positions.

    Note: This requires a functioning torso, either physical or in a simulator like V-REP.

    import time
    import numpy as np
    from pypot.creatures import PoppyTorso
    
    # Create the robot
    poppy = PoppyTorso()
    
    # Initialize all motor positions to 0
    for m in poppy.motors:
        m.goto_position(0, 2)
  12. Configure motor compliance for hand following

    master

    In a hand-following experiment where one arm follows the other, you must configure the compliance of the motors. For the follower to react to a moving target, the 'leader' arm (e.g., the left arm) should be compliant so it can be moved manually, while the 'follower' arm (e.g., the right arm) and the torso should be active (non-compliant) to maintain precise positioning.

    # Left arm is compliant (can be moved manually)
    for m in poppy.l_arm:
        m.compliant = True
    
    # Right arm is active (follows targets)
    for m in poppy.r_arm:
        m.compliant = False
    
    # The torso must remain stable
    for m in poppy.torso:
        m.compliant = False