Skip to main content

torchkin

License pypi PyPi Downloads Python pre-commit black PRs

A library for differentiable kinematics


Getting Started

Prerequisites

  • We strongly recommend you install torchkin in a venv or conda environment with Python 3.8-3.10.
  • torchkin requires torch installation. To install for your particular CPU/CUDA configuration, follow the instructions in the PyTorch website.

Installing

  • pypi

    pip install torchkin
    
  • From source

    The simplest way to install torchkin from source is by running the following

    git clone https://github.com/facebookresearch/theseus.git && cd theseus/torchkin
    pip install -e .
    

    If you are interested in contributing to torchkin, also install

    pip install -r ../requirements/dev.txt
    pre-commit install
    

    and follow the more detailed instructions in CONTRIBUTING.

Example

An inverse kinematics example is available in script.

import torch

import torchkin as kin

# We can load a robot model from a URDF file
dtype = torch.float64
device = "cuda"
robot = kin.Robot.from_urdf_file(YOUR_URDF_FILE, dtype=dtype, device=device)

# Print robot name, number of links and degrees of freedom
print(f"{robot.name} has {len(robot.get_links())} links and {robot.dof} degrees of freedom.\n")

# Print joint id and name
for id, name in enumerate(robot.joint_map):
    # A joint is not fixed if and only if id < robot.dof
    print(f"joint {id}: {name} is {'not fixed' if id < robot.dof else 'fixed'}")
print("\n")

# Print link id and name
for link in robot.get_links():
    print(f"link {link.id}: {link.name}")

# We can get differentiable forward kinematics functions for specific links
# by using `get_forward_kinematics_fns`. This function creates three differentiable
# functions for evaluating forward kinematics, body jacobian and spatial jacobian of
# the selected links, in that order. The return types of these functions are as
# follows:
#
# - fk: return a tuple of link poses in the order of link names
# - jfk_b: returns a tuple where the first is a list of link body jacobians, and the
#          second is a tuple of link poses---both are in the order of link names
# - jfk_s: same as jfk_b except returning the spatial jacobians
link_names = [LINK1, LINK2, LINK3]
fk, jfk_b, jfk_s = kin.get_forward_kinematics_fns(
    robot=robot, link_names=link_names)

batch_size = 10
# The joint states are in the order of the joint ids
joint_states = torch.rand(batch_size, robot.dof, dtype=dtype, device=device)

# Get link poses
link_poses = fk(joint_states)

# Get body jacobians and link poses
jacs_b, link_poses = jfk_b(joint_states) 

# Get spatial jacobians and link poses
jacs_s, link_poses = jfk_s(joint_states) 

Citing torchkin

If you use torchkin in your work, please cite the paper with the BibTeX below.

@article{pineda2022theseus,
  title   = {{Theseus: A Library for Differentiable Nonlinear Optimization}},
  author  = {Luis Pineda and Taosha Fan and Maurizio Monge and Shobha Venkataraman and Paloma Sodhi and Ricky TQ Chen and Joseph Ortiz and Daniel DeTone and Austin Wang and Stuart Anderson and Jing Dong and Brandon Amos and Mustafa Mukadam},
  journal = {Advances in Neural Information Processing Systems},
  year    = {2022}
}

License

torchkin is MIT licensed. See the LICENSE for details.

Additional Information

Metadata

Release files for torchkin 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for torchkin 0.1.1
File Size Uploaded
torchkin-0.1.1.tar.gz 12.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for torchkin 0.1.1
File Interpreter ABI Platform
torchkin-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 23.0 kB

Release files / torchkin-0.1.1.tar.gz

Download URL torchkin-0.1.1.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7827345ff787469a461aaf453bb33da968107886536fa4f2b00d1c0f006b6450
BLAKE2b-256 checksum
How to use checksums
b6b33c73baa7370e5230a348c9a4e545aee05b8ef2dc7a930bfafa90224b8597
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release files / torchkin-0.1.1-py3-none-any.whl

Download URL torchkin-0.1.1-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f05babc4c9b578754417fa28ad1f0f2520f4ad6c0215d0865be46ee457093f5
BLAKE2b-256 checksum
How to use checksums
ac28447bb1038a9c8d76ba7a63b15561e13d285262b326d978e1f967561ed574
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page