Skip to main content

C++ implementation with Python bindings of analytic forward and inverse kinematics for the Universal Robots.

Project description

UR Analytic IK

C++ implementation with Python bindings of analytic forward and inverse kinematics for the Universal Robots based on Alternative Inverse Kinematic Solution of the UR5 Robotic Arm.

This project is still very experimental, the API will likely still change.

The main advantages of using analytic IK:

  • extremely fast. FK calls from python take +- 4 µs, IK calls +- 18 µs.
  • finds all solutions at once, allowing you to select the most convenient one.
  • no need to provide initial guess, as opposed to numerical IK solutions.

Warning: this repo uses the default DH-parameters for the UR robots. But every robot is slightly different and is factory-calibrated to provide very accurate DH parameters, which are also used by the robot controlbox. From a few tests we have run, using the default DH-parameters typically results in 1-2mm differences in the FK for a given joint configuration. See here for details. If you need very high precision, you might want to use your robot's DH-parameters for FK/IK.

Installation

pre-built wheels are availabe on PyPI and can be installed with pip:

pip install ur_analytic_ik

To install from source, see the Developer section.

Usage

Afterwards, you should be able to issue the FK and IK functions like this:

import numpy as np
from ur_analytic_ik import ur5e

eef_pose = np.identity(4)
X = np.array([-1.0, 0.0, 0.0])
Y = np.array([0.0, 1.0, 0.0])
Z = np.array([0.0, 0.0, -1.0])
top_down_orientation = np.column_stack([X, Y, Z])
translation = np.array([-0.2, -0.2, 0.2])

eef_pose[:3, :3] = top_down_orientation
eef_pose[:3, 3] = translation

solutions = ur5e.inverse_kinematics(eef_pose)

More examples:

import numpy as np
from ur_analytic_ik import ur3e

joints = np.zeros(6)
eef_pose = np.identity(4)
eef_pose[2, 3] = 0.4
tcp_transform = np.identity(4)
tcp_transform[2, 3] = 0.1

ur3e.forward_kinematics(0, 0, 0, 0, 0, 0)
ur3e.forward_kinematics(*joints)
tcp_pose = ur3e.forward_kinematics_with_tcp(*joints, tcp_transform)

joint_solutions = ur3e.inverse_kinematics(eef_pose)
joint_solutions = ur3e.inverse_kinematics_closest(eef_pose, *joints)
joint_solutions = ur3e.inverse_kinematics_with_tcp(eef_pose, tcp_transform)
joint_solutions = ur3e.inverse_kinematics_closest_with_tcp(eef_pose, tcp_transform, *joints)

Development

This codebase uses nanobind to provide python bindings for the FK/IK functions.

building

python package building

This is the easiest option. It leverages scikit-build to create a python package and build the bindings. This flow is based on https://github.com/wjakob/nanobind_example

  • Create a conda environment for the project: conda env create -f environment.yaml
  • to create the python package, including the bindings: pip install . (this uses scikit-build to build the C++ from the top-level CMakelist.txt)
  • you can now import the library in python.

C++ building

if you want to build the C++ code without building the bindings or creating a python package:

  • make sure you have a C++ compiler available.
  • make sure you have the Eigen package available, if not run apt install libeigen3-dev.

Some linux users have eigen installed at /usr/include/eigen3 instead of /usr/include/Eigen. Symlink it:

sudo ln -sf /usr/include/eigen3/Eigen /usr/include/Eigen
sudo ln -sf /usr/include/eigen3/unsupported /usr/include/unsupported
  • run cmake -S . -B & cmake --build build from the src/ dir.
  • execute ./build/main

testing

run pytest -v .

Tests are also automatically executed in github for each commit.

Wheels are built automatically for all PRs, you can check them on test PyPI.

Releasing

  • bump the version in the pyproject.toml file. We use semantic versioning. Use pre-releases if you want to test changes.
  • create a new tag, corresponding to the version: git tag vX.Y.Z-...
  • push the tag git push --tag, this will already trigger a build of the wheels on test PyPI
  • once you have verified the wheels work and are built properly, create a new release with the same name as the semantic version for the tag on github. This will trigger an upload to PyPI.

Welcome Improvements

Python API

Adding an IK function that returns the closest solution and accepts a TCP transform.

Reducing the amount of separate IK functions, e.g. replacing:

ur3e.inverse_kinematics_with_tcp(eef_pose)
# with
ur3e.inverse_kinematics(eef_pose, tcp=tcp_transform)

The same holds for functions ending with _closest().

Performance

Currently IK runs at about 10 μs / EEF pose on my laptop. However, before I implemented the filtering of the solutions, it was closer to 3 μs. Part of this is because I adapted the bindings in ur_analytic_ik_ext.cpp to return vectors with the solutions.

Code Quality

  • Adding more technical documentation.
  • ur_analytic_ik_ext.cpp should be made much more readable.
  • Reducing some duplication e.g. when defining the IK/FK functions and bindings for the different robots.

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

ur-analytic-ik-0.0.8.tar.gz (32.5 kB view details)

Uploaded Source

Built Distributions

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

ur_analytic_ik-0.0.8-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (26.2 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

ur_analytic_ik-0.0.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (26.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

ur_analytic_ik-0.0.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (26.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

ur_analytic_ik-0.0.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (26.2 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

ur_analytic_ik-0.0.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (26.2 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file ur-analytic-ik-0.0.8.tar.gz.

File metadata

  • Download URL: ur-analytic-ik-0.0.8.tar.gz
  • Upload date:
  • Size: 32.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ur-analytic-ik-0.0.8.tar.gz
Algorithm Hash digest
SHA256 16ccf34d7e92ab6109a987e963e12c78efd2f8d9f0b43ceb339f1de666a27df8
MD5 84a2014e8028ed3116501f059854475b
BLAKE2b-256 04787b08353837cf49a4789140bc7b0ef590ddca3300b23f08698d5934d6753d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ur-analytic-ik-0.0.8.tar.gz:

Publisher: wheels.yml on Victorlouisdg/ur-analytic-ik

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ur_analytic_ik-0.0.8-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ur_analytic_ik-0.0.8-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ddb950983b04f5ee37ffb3828b9c56ce57b9658c3e36dc50559a966391046293
MD5 319757f5d504bfbe5c1dc36d5f7ec859
BLAKE2b-256 aeb052dea8946be32e34c07c73b0893c1fe7ed478789872a338fafe2b0b7e44f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ur_analytic_ik-0.0.8-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on Victorlouisdg/ur-analytic-ik

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ur_analytic_ik-0.0.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ur_analytic_ik-0.0.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8b237aec2d54d192153326efe058972857265a1319414768fa2d197ea4712652
MD5 b1a2599da5f5aed5589387100b3b326d
BLAKE2b-256 c36a35c57a2a91ae13ebc3af8e2d284f5da1a4cb54d32c74c542ed2dd3a60c0f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ur_analytic_ik-0.0.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on Victorlouisdg/ur-analytic-ik

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ur_analytic_ik-0.0.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ur_analytic_ik-0.0.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b7a14f3cbd202c0bd1f7c2572f28497913cc0f6c2f313e808aa3620f63351c7f
MD5 d8a46930cc0d76e463d1e9782a52ee21
BLAKE2b-256 b1745afeca4abc32bcdf2c78c205a98dbf2951f78aff5a18616c9488fc4c0e73

See more details on using hashes here.

Provenance

The following attestation bundles were made for ur_analytic_ik-0.0.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on Victorlouisdg/ur-analytic-ik

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ur_analytic_ik-0.0.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ur_analytic_ik-0.0.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e84ba84c648e599ef64cdb945a347e73eade6bb448f7cdfcf734949c13c0a825
MD5 5a0edc2d923aa6a90b3b632d34527939
BLAKE2b-256 5a30e5c466b74e48e06c9c0491520cf3b4a3b0ab724576982f1088b7a990ea5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ur_analytic_ik-0.0.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on Victorlouisdg/ur-analytic-ik

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ur_analytic_ik-0.0.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ur_analytic_ik-0.0.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6037b2e3e27e035b89fc463185a2fecdae7c02ddd2990e31f34f6822fea6a9c0
MD5 31c78257e6fa9e12f015e9784d3428ab
BLAKE2b-256 976eeba8a225f8bce79ca3151f43a5493a4e71e7acec769d432f5568f281eb64

See more details on using hashes here.

Provenance

The following attestation bundles were made for ur_analytic_ik-0.0.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on Victorlouisdg/ur-analytic-ik

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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