Skip to content

Commit

Permalink
Merge branch 'master' into improve-urdf-loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Phylliade authored Mar 17, 2019
2 parents b79239d + 25c6fa8 commit e9756b5
Show file tree
Hide file tree
Showing 50 changed files with 287 additions and 169 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ notebooks/*/.ipynb_*
.sass-cache/
src/*.egg-info/
*.odg
.pytest_cache
*.egg-info
*.ipynb_checkpoints
.idea
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
install:
- pip install .
script: cd tests/ikpy && ./tests.sh
- pip install .[plot]
- pip install pytest
script: cd tests && ./tests.sh
cache: pip
dist: trusty
sudo: false
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
![demo](two_arms.png)

# Demo
A live demo of what IKpy can do : (click on the image below to see the video)
Live demos of what IKPy can do : (click on the image below to see the video)

[![](http://img.youtube.com/vi/H0ysr5qSbis/0.jpg)](https://www.youtube.com/watch?v=H0ysr5qSbis)
[![](http://img.youtube.com/vi/Jq0-DkEwwj4/0.jpg)](https://www.youtube.com/watch?v=Jq0-DkEwwj4)

Also, a presentation of IKPy : [Presentation](https://github.com/Phylliade/ikpy/blob/master/tutorials/ikpy/IKPy%20speech.pdf).
Also, a presentation of IKPy : [Presentation](https://github.com/Phylliade/ikpy/blob/master/tutorials/IKPy%20speech.pdf).

# Features
With IKPy, you can :
Expand All @@ -38,7 +39,7 @@ You have three options :
```bash
pip install ikpy
```
If you intend to plot your robot, you can install the plotting dependencies (mainly matplotlib) :
If you intend to plot your robot, you can install the plotting dependencies (mainly matplotlib) :
```bash
pip install 'ikpy[plot]'
```
Expand All @@ -56,7 +57,7 @@ You have three options :
NB : You must have the proper rights to execute this command
# Quickstart
Follow this IPython [notebook](https://github.com/Phylliade/ikpy/blob/master/tutorials/ikpy/Quickstart.ipynb).
Follow this IPython [notebook](https://github.com/Phylliade/ikpy/blob/master/tutorials/Quickstart.ipynb).
# Guides and Tutorials
Expand Down
10 changes: 7 additions & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __getattr__(cls, name):
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath("../src"))
import ikpy

# -- General configuration ------------------------------------------------

Expand All @@ -58,6 +59,7 @@ def __getattr__(cls, name):
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
'sphinx.ext.napoleon'
]

# Add any paths that contain templates here, relative to this directory.
Expand All @@ -76,17 +78,19 @@ def __getattr__(cls, name):

# General information about the project.
project = 'ikpy'
copyright = '2015, Pierre Manceron'
copyright = '2015-2018, Pierre Manceron'
author = 'Pierre Manceron'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '1.9.99-1'
version = ikpy.__version__
release = version
# version = '1.9.99-1'
# The full version, including alpha/beta/rc tags.
release = '1.9.99-1'
# release = '1.9.99-1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
5 changes: 0 additions & 5 deletions doc/modules.rst

This file was deleted.

File renamed without changes.
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

47 changes: 29 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
#!/usr/bin/env python
from setuptools import setup
from setuptools import setup, find_packages
import os

setup(name='ikpy',
version='2.2.3',
author="Pierre Manceron",
description="An inverse kinematics library aiming performance and modularity",
url="https://github.com/Phylliade/ikpy",
license="GNU GENERAL PUBLIC LICENSE Version 3",
packages=['ikpy'],
package_dir={'': 'src'},
setup_requires=['numpy'],
install_requires=['numpy', 'scipy', 'sympy', "matplotlib"],
# TODO: Move maptlotlib to extra_requires
classifiers=[
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering",
]
)

def get_version():
version = {}
with open(os.path.join(os.path.dirname(__file__), "src/ikpy/_version.py")) as fp:
exec(fp.read(), version)
return version["__version__"]


setup(
name='ikpy',
version=get_version(),
author="Pierre Manceron",
description="An inverse kinematics library aiming performance and modularity",
url="https://github.com/Phylliade/ikpy",
license="GNU GENERAL PUBLIC LICENSE Version 3",
packages=find_packages("src", exclude=("tests", "docs")),
package_dir={'': 'src'},
setup_requires=['numpy'],
install_requires=['numpy', 'scipy', 'sympy'],
extras_require={
'plot': ["matplotlib"],
},
classifiers=[
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering",
])
50 changes: 32 additions & 18 deletions src/ikpy/URDF_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding= utf8
"""
.. module:: URDF_utils
URDF_utils module
This module contains helper functions used to parse URDF.
"""

Expand All @@ -13,10 +14,15 @@


def find_next_joint(root, current_link, next_joint_name):
"""Find the next joint in the URDF tree
:param xml.etree.ElementTree current_link: The current URDF link
:param string next_joint_name: Optional : The name of the next joint
"""
Find the next joint in the URDF tree
Parameters
----------
current_link: xml.etree.ElementTree
The current URDF link
next_joint_name: str
Optional : The name of the next joint
"""
# Trouver le joint attaché
has_next = False
Expand Down Expand Up @@ -45,10 +51,15 @@ def find_next_joint(root, current_link, next_joint_name):


def find_next_link(root, current_joint, next_link_name):
"""Find the next link in the URDF tree
:param xml.etree.ElementTree current_joint: The current URDF joint
:param string next_link_name: Optional : The name of the next link
"""
Find the next link in the URDF tree
Parameters
----------
current_joint: xml.etree.ElementTree
The current URDF joint
next_link_name: str
Optional : The name of the next link
"""
has_next = False
next_link = None
Expand Down Expand Up @@ -83,14 +94,17 @@ def get_chain_from_joints(urdf_file, joints):


def get_urdf_parameters(urdf_file, base_elements=["base_link"], last_link_vector=None, base_element_type="link"):
"""Returns translated parameters from the given URDF file
:param urdf_file: The path of the URDF file
:type urdf_file: string
:param base_elements: List of the links beginning the chain
:type base_elements: list of strings
:param last_link_vector: Optional : The translation vector of the tip.
:type last_link_vector: numpy.array
"""
Returns translated parameters from the given URDF file
Parameters
----------
urdf_file: str
The path of the URDF file
base_elements: list of strings
List of the links beginning the chain
last_link_vector: numpy.array
Optional : The translation vector of the tip.
"""
tree = ET.parse(urdf_file)
root = tree.getroot()
Expand Down Expand Up @@ -180,7 +194,7 @@ def get_urdf_parameters(urdf_file, base_elements=["base_link"], last_link_vector


def _get_motor_parameters(json_file):
"""Returns a dictionnary with joints as keys, and a description (dict) of each joint as value"""
"""Returns a dictionary with joints as keys, and a description (dict) of each joint as value"""
with open(json_file) as motor_fd:
global_config = json.load(motor_fd)

Expand Down
1 change: 1 addition & 0 deletions src/ikpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import chain
from ._version import __version__
2 changes: 2 additions & 0 deletions src/ikpy/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__version__ = '2.2.3'

77 changes: 54 additions & 23 deletions src/ikpy/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@
.. module:: chain
This module implements the Chain class.
"""
import numpy as np

# IKPY imports
from . import URDF_utils
from . import inverse_kinematics as ik
import numpy as np
from . import link as link_lib


class Chain(object):
"""The base Chain class
:param list links: List of the links of the chain
:param list active_links_mask: A list of boolean indicating that whether or not the corresponding link is active
:param string name: The name of the Chain
Parameters
----------
links: list
List of the links of the chain
active_links_mask: list
A list of boolean indicating that whether or not the corresponding link is active
name: str
The name of the Chain
"""
def __init__(self, links, active_links_mask=None, name="chain", profile=''"", **kwargs):
self.name = name
Expand All @@ -37,14 +43,22 @@ def __init__(self, links, active_links_mask=None, name="chain", profile=''"", **
self.active_links_mask = np.array([True] * len(links))

def __repr__(self):
return("Kinematic chain name={} links={} active_links={}".format(self.name, self.links, self.active_links_mask))
return "Kinematic chain name={} links={} active_links={}".format(self.name, self.links, self.active_links_mask)

def forward_kinematics(self, joints, full_kinematics=False):
"""Returns the transformation matrix of the forward kinematics
:param list joints: The list of the positions of each joint. Note : Inactive joints must be in the list.
:param bool full_kinematics: Return the transorfmation matrixes of each joint
:returns: The transformation matrix
Parameters
----------
joints: list
The list of the positions of each joint. Note : Inactive joints must be in the list.
full_kinematics: bool
Return the transformation matrices of each joint
Returns
-------
frame_matrix:
The transformation matrix
"""
frame_matrix = np.eye(4)

Expand All @@ -71,9 +85,16 @@ def forward_kinematics(self, joints, full_kinematics=False):
def inverse_kinematics(self, target, initial_position=None, **kwargs):
"""Computes the inverse kinematic on the specified target
:param numpy.array target: The frame target of the inverse kinematic, in meters. It must be 4x4 transformation matrix
:param numpy.array initial_position: Optional : the initial position of each joint of the chain. Defaults to 0 for each joint
:returns: The list of the positions of each joint according to the target. Note : Inactive joints are in the list.
Parameters
----------
target: numpy.array
The frame target of the inverse kinematic, in meters. It must be 4x4 transformation matrix
initial_position: numpy.array
Optional : the initial position of each joint of the chain. Defaults to 0 for each joint
Returns
-------
The list of the positions of each joint according to the target. Note : Inactive joints are in the list.
"""
# Checks on input
target = np.array(target)
Expand All @@ -88,10 +109,16 @@ def inverse_kinematics(self, target, initial_position=None, **kwargs):
def plot(self, joints, ax, target=None, show=False):
"""Plots the Chain using Matplotlib
:param list joints: The list of the positions of each joint
:param matplotlib.axes.Axes ax: A matplotlib axes
:param numpy.array target: An optional target
:param bool show: Display the axe. Defaults to False
Parameters
----------
joints: list
The list of the positions of each joint
ax: matplotlib.axes.Axes
A matplotlib axes
target: numpy.array
An optional target
show: bool
Display the axe. Defaults to False
"""
from . import plot_utils

Expand All @@ -111,14 +138,18 @@ def plot(self, joints, ax, target=None, show=False):
def from_urdf_file(cls, urdf_file, base_elements=["base_link"], last_link_vector=None, base_element_type="link", active_links_mask=None, name="chain"):
"""Creates a chain from an URDF file
:param urdf_file: The path of the URDF file
:type urdf_file: string
:param base_elements: List of the links beginning the chain
:type base_elements: list of strings
:param last_link_vector: Optional : The translation vector of the tip.
:type last_link_vector: numpy.array
:param list active_links: The active links
:param string Name: The name of the Chain
Parameters
----------
urdf_file: str
The path of the URDF file
base_elements: list of strings
List of the links beginning the chain
last_link_vector: numpy.array
Optional : The translation vector of the tip.
active_links: list
The active links
name: str
The name of the Chain
"""
links = URDF_utils.get_urdf_parameters(urdf_file, base_elements=base_elements, last_link_vector=last_link_vector, base_element_type=base_element_type)
# Add an origin link at the beginning
Expand Down
12 changes: 8 additions & 4 deletions src/ikpy/geometry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ def from_transformation_matrix(transformation_matrix):
def to_transformation_matrix(translation, orientation_matrix=np.zeros((3, 3))):
"""Converts a tuple (translation_vector, orientation_matrix) to a transformation matrix
:param np.array translation: The translation of your frame presented as a 3D vector.
:param np.array orientation_matrix: Optional : The orientation of your frame, presented as a 3x3 matrix.
Parameters
----------
translation: numpy.array
The translation of your frame presented as a 3D vector.
orientation_matrix: numpy.array
Optional : The orientation of your frame, presented as a 3x3 matrix.
"""
matrix = np.eye(4)

Expand Down Expand Up @@ -133,8 +137,8 @@ def cartesian_to_homogeneous_vectors(cartesian_vector, matrix_type="numpy"):


def homogeneous_to_cartesian_vectors(homogeneous_vector):
"""Converts a cartesian vector to an homogenous vector"""
return homogeneous_vector[:-1]
"""Converts a cartesian vector to an homogenous vector"""
return homogeneous_vector[:-1]


def homogeneous_to_cartesian(homogeneous_matrix):
Expand Down
Loading

0 comments on commit e9756b5

Please sign in to comment.