Git Product home page Git Product logo

kinpy's Introduction

Build status PyPI version MIT License Downloads

Simple kinematics body toolkit.

Core features

  • Pure python library.
  • Support URDF, SDF and MJCF file.
  • Calculate FK, IK and jacobian.

joint_angle_editor

Installation

pip install kinpy

Getting started

Here is a program that reads urdf and generates a kinematic chain.

import kinpy as kp

chain = kp.build_chain_from_urdf(open("kuka_iiwa/model.urdf").read())
print(chain)
# lbr_iiwa_link_0_frame
# └──── lbr_iiwa_link_1_frame
#       └──── lbr_iiwa_link_2_frame
#             └──── lbr_iiwa_link_3_frame
#                   └──── lbr_iiwa_link_4_frame
#                         └──── lbr_iiwa_link_5_frame
#                               └──── lbr_iiwa_link_6_frame
#                                     └──── lbr_iiwa_link_7_frame

Displays the parameter names of joint angles included in the chain.

print(chain.get_joint_parameter_names())
# ['lbr_iiwa_joint_1', 'lbr_iiwa_joint_2', 'lbr_iiwa_joint_3', 'lbr_iiwa_joint_4', 'lbr_iiwa_joint_5', 'lbr_iiwa_joint_6', 'lbr_iiwa_joint_7']

Given joint angle values, calculate forward kinematics.

import math
th = {'lbr_iiwa_joint_2': math.pi / 4.0, 'lbr_iiwa_joint_4': math.pi / 2.0}
ret = chain.forward_kinematics(th)
# {'lbr_iiwa_link_0': Transform(rot=[1. 0. 0. 0.], pos=[0. 0. 0.]), 'lbr_iiwa_link_1': Transform(rot=[1. 0. 0. 0.], pos=[0.     0.     0.1575]), 'lbr_iiwa_link_2': Transform(rot=[-0.27059805  0.27059805  0.65328148  0.65328148], pos=[0.   0.   0.36]), 'lbr_iiwa_link_3': Transform(rot=[-9.23879533e-01  3.96044251e-14 -3.82683432e-01 -1.96942462e-12], pos=[ 1.44603337e-01 -6.78179735e-13  5.04603337e-01]), 'lbr_iiwa_link_4': Transform(rot=[-0.65328148 -0.65328148  0.27059805 -0.27059805], pos=[ 2.96984848e-01 -3.37579445e-13  6.56984848e-01]), 'lbr_iiwa_link_5': Transform(rot=[ 2.84114655e-12  3.82683432e-01 -1.87377891e-12 -9.23879533e-01], pos=[ 1.66523647e-01 -1.00338887e-12  7.87446049e-01]), 'lbr_iiwa_link_6': Transform(rot=[-0.27059805  0.27059805 -0.65328148 -0.65328148], pos=[ 1.41421356e-02 -7.25873884e-13  9.39827561e-01]), 'lbr_iiwa_link_7': Transform(rot=[ 9.23879533e-01  2.61060896e-12 -3.82683432e-01  4.81056861e-12], pos=[-4.31335137e-02 -1.01819561e-12  9.97103210e-01])}

You can get the position and orientation of each link.

If you want to use IK or Jacobian, you need to create a SerialChain. When creating a SerialChain, an end effector must be specified.

chain = kp.build_serial_chain_from_urdf(open("kuka_iiwa/model.urdf"), "lbr_iiwa_link_7")
th = [0.0, -math.pi / 4.0, 0.0, math.pi / 2.0, 0.0, math.pi / 4.0, 0.0]
ret = chain.forward_kinematics(th, end_only=True)
# chain.inverse_kinematics(ret)
# chain.jacobian(th)

Visualization

KUKA IIWA

kuka

Mujoco humanoid

humanoid

Mujoco ant

ant

Simple arm

simple_arm

Citing

@software{kinpy,
    author = {{Kenta-Tanaka et al.}},
    title = {kinpy},
    url = {https://github.com/neka-nat/kinpy},
    version = {0.0.3},
    date = {2019-10-11},
}

kinpy's People

Contributors

colormotor avatar itechbear avatar neka-nat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

kinpy's Issues

ERROR: Cannot uninstall 'PyYAML'.

python version : 3.8.8

I have a conda environment and when i tried pip install

it gives error for trying to uninstall PyYAML

Attempting uninstall: PyYAML
Found existing installation: PyYAML 5.3.1
ERROR: Cannot uninstall 'PyYAML'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

any reason for this? do i need different version of PyYAML?

Invalid access for fixed joints at the end of a Serial Chain during FK

Hi there,

There seems to be a small issue while using a chain which includes a fixed joint at the very end of the chain. During FK computation for the chain, computing the transform for the last joint raises an index error.

To reproduce the issue, please consider using the following robot.txt.

arm = kp.build_serial_chain_from_urdf(
    open("robot.txt").read(),
    root_link_name="base_link",
    end_link_name="ee_link",
)
fk_solution = arm.forward_kinematics(np.zeros(len(arm.get_joint_parameter_names())))

The issue occurs in the following function, with the cnt-indexed access on line 129. There is not entry in th for the last frame (a fixed joint):

kinpy/kinpy/chain.py

Lines 124 to 133 in c4e5af4

def forward_kinematics(self, th, world=transform.Transform(), end_only=True):
cnt = 0
link_transforms = {}
trans = world
for f in self._serial_frames:
trans = trans * f.get_transform(th[cnt])
link_transforms[f.link.name] = trans * f.link.offset
if f.joint.joint_type != "fixed":
cnt += 1
return link_transforms[self._serial_frames[-1].link.name] if end_only else link_transforms

Assuming my use of forwards_kinematics is correct, I have tried a small but very inelegant change. It seems to work, but I am concerned about the validity of the result:

            if f.joint.joint_type != "fixed":
                trans = trans * f.get_transform(th[cnt])
            else:
                trans = trans * f.get_transform(th[cnt - 1])

Here is a working example using kinpy to move the arm to the correct target positions:
wpNmvkMjEl

Issue with PyYAML dependancy

Hey, I'm trying to use your library to do calculations with a URDF file and I can't actually install it due to the PyYAML library failing during "getting requirements to build wheel" step which only seems to occur for PyYAML 5.4.1, and as far as I can tell kinpy somehow forces use of that version when installing it which causes it to fail (other versions of PyYAML install successfully.
I'm not super familiar with wheel files and pip so if there's an obvious solution apologies

Wrong transforms for ShadowHand

Hello, I am trying to use your tool with the Shadow Hand but it seems to compute wrong the transforms when I move the joints.
In the initial position where joints are at 0 it seems to work fine:
Isaac Gym_053
(I visualized the transforms for each rigid body)

But when I move the joints around it seems to compute the transforms wrong, e.g. when I move the little finger:
Isaac Gym_050
(The red circled transforms are the ones computed wrong)

Have you tried it with any dexterous hands before?

IK AttributeError: 'dict' object has no attribute 'matrix'

Hello,
Thanks for the tool!

However, I have problems to run the IK function.

I do the following:

from scipy.spatial.transform import Rotation as R
import kinpy as kp

r = R.from_matrix([[-1, 0, 0],
                   [0, 1, 0],
                   [0, 0, -1]])
pos = np.array([0.5 , 0., 0.])

target = kp.transform.Transform(rot = r.as_quat(), pos= pos )
ik_sol = kp.ik.inverse_kinematics(chain, pose = target)

where chain points to my urdf , which works since I manage to use the forward_kinematics function of kinpy.
The last line does not work, as I get the error "AttributeError: 'dict' object has no attribute 'matrix' ".

I tried going into the ik.py file and changing tf.matrix() to tf["tool0"].matrix() (where tool0 is the name of my end effector). Then I do not get any error but I get completely wrong solutions, with values more than 10000.

Could you help, please ?

Can kinpy compute the gradient of reward with respect to the model parameters?

  My research interest is robustness of RL algorithms to environment parameters. I want to modify currents RL algorithms to make them achieve good performance when they are tested in environments with unfamilar parameters. (For example, an agent is trained in Cartpole environment with 1m pole. I want it achieve good performance in Cartpole environment with 3m pole.)
  To achieve this goal, I want to get the relationship between model parameter values and RL algorithm's performance (reward). As a result, I want to get the gradient of reward with respect to the model parameters.
  Mujoco simulator has applied in my experiments. But Mujoco simulator is not implemented by pure python. So I cannot get the the gradient of reward with respect to the model parameters. After searching in github, I notice that your code has the function of calculating FK, IK and jacobian, which gives me some hopes. ^_^
 So my queation is:
 Can kinpy compute the gradient of reward with respect to the model parameters? If so, how should I use it to achieve this goal?

Prismatic joint support for Jacobians

Currently there's no support for prismatic joints when computing the Jacobian. The Jacobian code seems to be from pybotics: code link, which also doesn't handle prismatic joints. This is seen by computing the Jacobian on a robot with only prismatic joints (URDF below):

For any joint configuration, the Jacobian returned is the zero matrix, but it should be

                                           [[0., 0., 1.],
                                            [0., -1., 0.],
                                            [1., 0., 0.],
                                            [0., 0., 0.],
                                            [0., 0., 0.],
                                            [0., 0., 0.]]
<robot name="prismatic_robot"> 
<link name="link1" />
<link name="link2" />
<link name="link3" />
<link name="link4" />

<joint name="joint1" type="prismatic">
    <origin xyz="0.0 0.0 1.0"/>
    <axis xyz="0 0 1"/>
    <limit lower="-0.5" upper="0.5" effort="1" velocity="1"/>
    <parent link="link1"/>
    <child link="link2"/>
</joint>
<joint name="joint2" type="prismatic">
    <origin xyz="0.0 0.0 0.0" rpy="1.57079632679 0 0"/>
    <axis xyz="0 0 1"/>
    <limit lower="-0.5" upper="0.5" effort="1" velocity="1"/>
    <parent link="link2"/>
    <child link="link3"/>
</joint>
<joint name="joint3" type="prismatic">
    <origin xyz="0.0 0.0 0.0" rpy="0 1.57079632679 0"/>
    <axis xyz="0 0 1"/>
    <limit lower="-0.5" upper="0.5" effort="1" velocity="1"/>
    <parent link="link3"/>
    <child link="link4"/>
</joint>

</robot>

Can I use the DH not the urdf?

Thanks for the wonderful tool.
Can I use the DH not the urdf? Or are there any py file to convert the DH model to a simple URDF file?
Thanks

Possible adjustment of scipy requirement

Is it possible to lower down scipy requirement from 1.6.0 to 1.5.0 as python 3.6 does not support those latest scipy version? I believe the new features of scipy 1.6.0 do not impair kinpy function.

Cannot handle joint of "slide" type

I try to use build_chain_from_mjcf function to read 'roboschool/mujoco_assets/hopper.xml'.

But I got error information as follows:

File "/root/aliyun/mymirror/test.py", line 122, in test
chain_kp = kp.build_chain_from_mjcf(open(xml_path).read())
File "/root/anaconda3/envs/distralmirror37/lib/python3.7/site-packages/kinpy/mjcf.py", line 75, in build_chain_from_mjcf
_build_chain_recurse(root_frame, root_body)
File "/root/anaconda3/envs/distralmirror37/lib/python3.7/site-packages/kinpy/mjcf.py", line 42, in _build_chain_recurse
cur_frame, cur_base = add_composite_joint(root_frame, root_body.joint, base)
File "/root/anaconda3/envs/distralmirror37/lib/python3.7/site-packages/kinpy/mjcf.py", line 33, in add_composite_joint
joint=joint_to_joint(joints[0], base))]
File "/root/anaconda3/envs/distralmirror37/lib/python3.7/site-packages/kinpy/mjcf.py", line 27, in joint_to_joint
joint_type=JOINT_TYPE_MAP[joint.type],
KeyError: 'slide'

In "kinpy/mjcf.py", I notice that 'JOINT_TYPE_MAP' is defined as a dictionary {'hinge': 'revolute'} at the beginning of mjcf.py. So 'JOINT_TYPE_MAP' can only receive joint of 'hinge' type.

But in 'roboschool/mujoco_assets/hopper.xml' in following figure, there are some joints of "slide" type.
1652669456(1)

So how to process joint of "slide" type? Do you have any advice? Thanks for your help in advance ^_^ @neka-nat

Error: ModuleNotFoundError: No module named 'kinpy.urdf_parser_py' when importing kinpy

I've just installed kinpy with python setup.py build and python setup.py install. I can't use the package though, i'm getting the following error:

'''

import kinpy
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kinpy/init.py", line 1, in
from .urdf import *
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kinpy/urdf.py", line 1, in
from .urdf_parser_py.urdf import URDF, Mesh, Cylinder, Box, Sphere
ModuleNotFoundError: No module named 'kinpy.urdf_parser_py'
'''

How can this problem be fixed?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.