GithubHelp home page GithubHelp logo

auctus-team / pycapacity Goto Github PK

View Code? Open in Web Editor NEW
26.0 3.0 2.0 35.98 MB

An efficient task-space capacity calculation package for robotics and biomechanics

Home Page: https://auctus-team.github.io/pycapacity/

License: MIT License

Python 91.19% TeX 8.81%
biomechanics linear-algebra polytope robotics pip-package real-time

pycapacity's Introduction

An efficient task-space capacity calculation package for robotics and biomechanics

๐Ÿ“ข New version of the pycapacity package is out - version v2.1! - see full changelog

๐Ÿ“ข pycpacity JOSS paper accepted ๐ŸŽ‰ The full review available here and the ๐Ÿ“„ paper here

About

PyPI package Tests Docs status

What is pycapacity?

Python package pycapacity provides a set of tools for evaluating task space physical ability metrics for humans and robots, based on polytopes and ellipsoids. The aim of pycapacity is to provide a set of efficient tools for their evaluation in an easy to use framework that can be easily integrated with standard robotics and biomechanics libraries. The package implements several state of the art algorithms for polytope evaluation that bring many of the polytope metrics to the few milliseconds evaluation time, making it possible to use them in online and interactive applications.

The package can be easily interfaced with standard libraries for robotic manipulator rigid body simulation such as robotic-toolbox or pinocchio, as well as human musculoskeletal model biomechanics softwares opensim and biorbd. The package can also be used with the Robot Operating System (ROS).

The package additionally implements a set of visualization tools for polytopes and ellipsoids based on the Python package matplotlib intended for fast prototyping and quick and interactive visualization.

See full API documentation and docs.

Robotic manipulator capacity metrics

For the robotic manipulators the package integrates several velocity, force and acceleration capacity calculation functions based on ellipsoids:

  • Velocity (manipulability) ellipsoid
    E_vel = {dx | dx = J.dq, ||dq||<1 }
  • Acceleration (dynamic manipulability) ellipsoid
    E_acc = {ddx | ddx = J.M^(-1).t, ||t||<1 }
  • Force ellipsoid
    E_for = {f | J^T.f = t, ||t||<1 }

And polytopes:

  • Velocity polytope
    P_vel = {dx | dx = J.dq, dq_min < dq < dq_max}
  • Acceleration polytope
    P_acc = {ddx | ddx = J.M^(-1).t, t_min < t < t_max}
  • Force polytope
    P_for = {f | J^T.f = t, t_min < t < t_max}
  • NEW ๐Ÿ“ข: Reachable space of the robot with the horizon T
    P_x = {x | x = JM(-1)tT^2/2, t_min < t < t_max, dq_min < M^(-1)tT < dq_max, q_min < M^(-1)tT^2/2 < q_max}
  • Force polytopes Minkowski sum and intersection

Where J is the robot jacobian matrix, f is the vector of cartesian forces,dx and ddx are vectors fo cartesian velocities and accretions, dq is the vector of the joint velocities and t is the vector of joint torques.

Reachable space polytope approximation is based on this paper:
Approximating robot reachable space using convex polytopes
by Skuric, Antun, Vincent Padois, and David Daney.
In: Human-Friendly Robotics 2022: HFR: 15th International Workshop on Human-Friendly Robotics. Cham: Springer International Publishing, 2023.

The force polytope functions have been implemented according to the paper:
On-line force capability evaluation based on efficient polytope vertex search
by A.Skuric, V.Padois and D.Daney
Published on ICRA2021

The force polytope functions have been implemented according to the paper:
On-line force capability evaluation based on efficient polytope vertex search
by A.Skuric, V.Padois and D.Daney
Published on ICRA2021

And the velocity and acceleration polytopes are resolved using the Hyper-plane shifting method:
Characterization of Parallel Manipulator Available Wrench Set Facets
by Gouttefarde M., Krut S.
In: Lenarcic J., Stanisic M. (eds) Advances in Robot Kinematics: Motion in Man and Machine. Springer, Dordrecht (2010)

Human musculoskeletal models capacity metrics

For the human musculoskeletal models this package implements the ellipsoid and polytope evaluation functions. The implemented ellipsoids are:

  • Velocity (manipulability) ellipsoid
    E_vel = {dx | dx = J.dq, dl = L.dq, ||dl||<1 }
  • Acceleration (dynamic manipulability) ellipsoid
    E_acc = {ddx | ddx = J.M^(-1).N.F, ||F||<1 }
  • Force ellipsoid
    E_for = {f | J^T.f = N.F, ||F||<1 }

And polytopes:

  • Velocity polytope
    P_vel = {dx | dx = J.dq, dl = L.dq dl_min < dl < dl_max}
  • Acceleration polytope
    P_acc = {ddx | ddx = J.M^(-1).N.F, F_min < F < F_max}
  • Force polytope
    P_for = {f | J^T.f = N.F, F_min < F < F_max}

Where J is the model's jacobian matrix, L si the muscle length jacobian matrix, N= -L^T is the moment arm matrix, f is the vector of cartesian forces,dx and ddx are vectors fo cartesian velocities and accretions, dq is the vector of the joint velocities, t is the vector of joint torques, dl is the vector of the muscle stretching velocities and F is the vector of muscular forces.

The force and velocity polytope functions have been implemented according to the paper:
On-line feasible wrench polytope evaluation based on human musculoskeletal models: an iterative convex hull method
by A.Skuric, V.Padois, N.Rezzoug and D.Daney
Submitted to RAL & ICRA2022

And the acceleration polytopes are resolved using the Hyper-plane shifting method:
Characterization of Parallel Manipulator Available Wrench Set Facets
by Gouttefarde M., Krut S.
In: Lenarcic J., Stanisic M. (eds) Advances in Robot Kinematics: Motion in Man and Machine. Springer, Dordrecht (2010)

Polytope evaluation algorithms

There are three methods implemented in this paper to resolve all the polytope calculations:

  • Hyper-plane shifting method (HPSM)
  • Iterative convex hull method (ICHM)
  • Vertex enumeration algorithm (VEPOLI2)

All of the methods are implemented in the module pycapacity.algorithms and can be used as standalone functions. See in docs for more info.

Hyper-plane shifting method (HPSM)

Characterization of Parallel Manipulator Available Wrench Set Facets
by Gouttefarde M., Krut S.
In: Lenarcic J., Stanisic M. (eds) Advances in Robot Kinematics: Motion in Man and Machine. Springer, Dordrecht (2010)

This method finds the half-space representation of the polytope of a class:

P = {x | x = By, y_min <= y <= y_max }

To find the vertices of the polytope after finding the half-space representation Hx <= d an convex-hull algorithm is used.

The method is a part of the pycapacity.algorithms module hyper_plane_shift_method, See in docs for more info.

Iterative convex-hull method (ICHM)

On-line feasible wrench polytope evaluation based on human musculoskeletal models: an iterative convex hull method
by A.Skuric, V.Padois, N.Rezzoug and D.Daney
Submitted to RAL & ICRA2022

This method finds both vertex and half-space representation of the class of polytopes:

P = {x | Ax = By, y_min <= y <= y_max }

And it can be additionally extended to the case where there is an additional projection matrix P making a class of problems:

P = {x | x= Pz, Az = By, y_min <= y <= y_max }

The method is a part of the pycapacity.algorithms module iterative_convex_hull_method. See the docs for more info

Vertex enumeration algorithm (VEPOLI2)

On-line force capability evaluation based on efficient polytope vertex search
by A.Skuric, V.Padois and D.Daney
Published on ICRA2021

This method finds vertex representation of the class of polytopes:

P = {x | Ax = y, y_min <= y <= y_max }

To find the half-space representation (faces) of the polytope after finding the vertex representation an convex-hull algorithm is used.

The method is a part of the pycapacity.algorithms module vertex_enumeration_vepoli2. See the docs for more info

Installation

All you need to do to install it is:

pip install pycapacity

And include it to your python project

import pycapacity.robot 
# and/or
import pycapacity.human 
#and/or
import pycapacity.algorithms 
#and/or
import pycapacity.visual 
#and/or
import pycapacity.objects 

Other way to install the code is by installing it directly from the git repo:

pip install git+https://github.com/auctus-team/pycapacity.git

Package API docs

See full docs at the link

Contributing and discussions

For all the questions regarding the potential implementation, applications, supported hardware and similar please don't hesitate to leave an issue or start a discussion

It is always helpful to hear the stories/problems/suggestions of people implementing the code!

Github Issues & Pull requests

Please do not hesitate to leave an issue if you have problems/advices/suggestions regarding the code!

If you'd like to contribute to this project but you are not very familiar with github, don't worry, let us know either by starting the discussion or posting a github issue.

Citing pycapacity in scientific publications

We are very happy that pycapacity has been used as a component of several research project and has made its way to several scientific papers. We are hoping that this trend is going to continue as the project matures and becomes more robust!

A short resume paper about pycapacity has been published in the Journal of Open Source Software:

pycapacity: a real-time task-space capacity calculation package for robotics and biomechanics
A. Skuric, V. Padois and D. Daney
Journal of Open Source Software, 8(89), 5670, https://doi.org/10.21105/joss.05670

If you are interested in citing pycapacity in your research, we suggest you to cite our paper:

@article{Skuric2023pycapacity,
    author = {Skuric, Antun and Padois, Vincent and Daney, David},
    doi = {10.21105/joss.05670},
    journal = {Journal of Open Source Software},
    month = sep,
    number = {89},
    pages = {5670},
    title = {{Pycapacity: a real-time task-space capacity calculation package for robotics and biomechanics}},
    url = {https://joss.theoj.org/papers/10.21105/joss.05670},
    volume = {8},
    year = {2023}
}

Code examples

See demo_notebook.ipynb for more examples of how ot use the module.

Randomised serial robot example

"""
A simple example program for 3d force polytope 
evaluation of a randomised 6dof robot 
"""
import pycapacity.robot as capacity # robot capacity module
import numpy as np

m = 3 # 3d forces
n = 6 # robot dof

J = np.array(np.random.rand(m,n)) # random jacobian matrix

t_max = np.ones(n)  # joint torque limits max and min
t_min = -np.ones(n)

f_poly = capacity.force_polytope(J,t_min, t_max) # calculate the polytope vertices and faces

print(f_poly.vertices) # display the vertices

# plotting the polytope
import matplotlib.pyplot as plt
from pycapacity.visual import * # pycapacity visualisation tools
fig = plt.figure(4)

# draw faces and vertices
plot_polytope(polytope=f_poly, plot=plt, label='force polytope', vertex_color='blue', edge_color='blue', alpha=0.2)

plt.legend()
plt.show()

Randomised muslucoskeletal model example

"""
A simple example program for 3d force polytope 
evaluation of a randomised 30 muscle 7dof 
human musculoskeletal model 
"""

import pycapacity.human as capacity # robot capacity module
import numpy as np

L = 30 # number of muscles
m = 3 # 3d forces
n = 6 # number of joints - dof

J = np.array(np.random.rand(m,n))*2-1 # random jacobian matrix
N = np.array(np.random.rand(n,L))*2-1 # random moment arm matrix

F_max = 100*np.ones(L)  # muscle forces limits max and min
F_min = np.zeros(L)

f_poly = capacity.force_polytope(J,N, F_min, F_max, 0.1) # calculate the polytope vertices and faces

print(f_poly.vertices) # display the vertices


# plotting the polytope
import matplotlib.pyplot as plt
from pycapacity.visual import * # pycapacity visualisation tools
fig = plt.figure(4)

# draw faces and vertices
plot_polytope(polytope=f_poly, plot=plt, label='force polytope', vertex_color='blue', edge_color='blue', alpha=0.2)

plt.legend()
plt.show()

pycapacity's People

Contributors

askuric avatar kevin-mattheus-moerman avatar laisnegautier avatar nakami avatar sea-bass 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

Watchers

 avatar  avatar  avatar

pycapacity's Issues

[JOSS Review] Add "interesting" doc examples to the examples folder

The docs have lots of great examples of PyCapacity integrating with Peter Corke's robotics toolbox, Pinocchio, etc. However, these standalone Python files are not available in the repo itself -- you have to copy-paste them from the docs. The examples folder only has simple randomized robot examples.

Please consider adding these doc examples in as "official" examples so it's easy to run them directly without having to make a new file and copy the docs contents. You can also have the docs point to the path of these example files, for example python3 examples/robotics_toolbox_example.py

Totally understandable if users have to pip install a few extra dependencies, simply mark this in the comments for each example as appropriate. You could also share those anaconda / pip configs in the examples folder for the users to easily set up.

openjournals/joss-reviews#5670

[JOSS REVIEW] Additional Paper Feedback

General Feedback

As mentioned in #6, I would suggest not saying the software is real-time as there are no guarantees that the software will produce calculations within a certain time frame. Moreover, it is technically possible for system interrupts to cause a python function call to take much longer than the times listed because of various OS functions. Because you mention safety applications in your paper, I would stress that this software is at best near-real-time or online. However, as you still would like to mention the performance, timing variance or distribution would be useful to add.

Additionally, I believe there should be a mention of the rate at which the functions are called. The execution times are useful to see, but if I need to call the Acceleration polytope metric more than 3 times per second, then this software is no longer even near real-time. It is my understanding that inverse kinematics and other constraints are calculated tens or hundreds of times per second and I wonder if this would be a limitation when considering musculoskeletal models.

There should be additional discussion and citations on the current state of the field in regards to alternative software solutions and where this work differs.

Lastly, the paper ends very abruptly. The addition of concluding remarks would help greatly as the introduction and statement of need are already strong.

Introduction

  • "where he lacks" use the "they"
  • It can be interesting to be able to compute these metrics

Statement of Need

  • "real-time" should be updated to "near real-time" or "online"
  • "aslo" -> "also"

Iterative convex-hull method

  • Remove "And" from the start of the third sentence and remove the paragraph break

Robotic manipulator metrics

  • "For the robotics manipulators, the package integrates"

Polytopes

  • Move "This approach is described by..." to the end of the following paragraph

Polytope evaluation algorithms used

  • Create captions for the performance tables
  • Reference the table itself in the text, similar to how the figures were done

[JOSS Review] Issues with Doc Examples

In addition to #4, I have some feedback on the examples themselves:

Robotics Toolbox Example

I can't get the Swift example working in my Python 3.10 environment -- I keep getting this error when visualizing

Traceback (most recent call last):
  File "/home/sebastian/Workspace/pycapacity/.virtualenvs/pycapacity/lib/python3.10/site-packages/websockets/legacy/server.py", line 240, in handler
    await self.ws_handler(self)
  File "/home/sebastian/Workspace/pycapacity/.virtualenvs/pycapacity/lib/python3.10/site-packages/websockets/legacy/server.py", line 1186, in _ws_handler
    return await cast(
  File "/home/sebastian/Workspace/pycapacity/.virtualenvs/pycapacity/lib/python3.10/site-packages/swift/SwiftRoute.py", line 320, in serve
    await self.expect_message(websocket, expected)
  File "/home/sebastian/Workspace/pycapacity/.virtualenvs/pycapacity/lib/python3.10/site-packages/swift/SwiftRoute.py", line 325, in expect_message
    recieved = await websocket.recv()
  File "/home/sebastian/Workspace/pycapacity/.virtualenvs/pycapacity/lib/python3.10/site-packages/websockets/legacy/protocol.py", line 568, in recv
    await self.ensure_open()
  File "/home/sebastian/Workspace/pycapacity/.virtualenvs/pycapacity/lib/python3.10/site-packages/websockets/legacy/protocol.py", line 935, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedOK: received 1001 (going away); then sent 1001 (going away)

Also, I had to additionally pip install networkx because it was another missing dependency not listed anywhere.


Pinocchio Example

The pip instructions just say pip install pin, but actually you need other things like example-robot-data, meshcat, etc. Make sure this is consistent.

Also, the first (static) Meshcat example works for me but it's all blank... any ideas?
image

The animation one works fine...
image

Actually, if in the first example I stick these lines at the end, the robot ends up rendering fine.

while True:
    viz.display(q0)

Four Link Planar Robot

If running from the top of the module, this import fails:

from four_link_utils import *

The doc says to copy files to a four_link_utils.py, but maybe worth having an easier way to just use the one that already exists in the examples folder? Or tell people to just define the necessary utils in the same example file?

openjournals/joss-reviews#5670

[JOSS Review] Paper Feedback

Thank you for submitting this cool toolbox! Here is my feedback on the paper.

General Feedback

  • I may debate the claim that a Python package should be used for real-time applications. If that was critical, then this package should have been implemented in C++, Rust, or something like that. I think Python is good for ease of use and prototyping, but I may pull back on some of these claims.
  • In addition to the citations, which you already have, I think it would be helpful to have a brief introduction to these evaluation metrics (ellipsoids and polytopes) and what they do. As such, I think your "Physical Capacity Metrics" would be better served BEFORE the "Implemented Polytope Evaluation Algorithms" section. First say what these things are, and what they are used for, and then get into which algorithms are in PyCapacity.
  • The tables of evaluation times need to have some notion of variance. Instead of saying things like ~5ms, I (and readers) would be mostly interested in something like 5ms +/- 1ms, as well as a brief description of how this data was collected (how many samples, etc.) -- see e.g., https://jhavl.github.io/mmc/ for an example.
  • Please add a Conclusion section at the end
  • Capitalize Python, Jacobian, and Cartesian throughout

Summary

  • Typo in line 7: "the robot's are required" --> "robots are often required"
  • Typo in line 9: "One of ways to quantify" --> "One way to quantify"
  • Line 11: Consider gender-neutral language in line 11 "where he lacks" --> "where they lack"
  • Typo in line 13: "as todays collaborative" --> "as today's collaborative"
  • Missing : in line 19 -- "Most of these metrics can be represented by two families of geometric shapes: ellipsoids and polytopes"
  • Finish your summary by saying what this paper does: It introduces a new package named PyCapacity!

Statement of Need


Physical Capacity Metrics

  • Typo in line 83: "Reachable space approximation of in the desired horizon" -- of what? I think it is either missing a word, or the "of" should be deleted
  • The caption in Figure 2 is missing a period after "visualized with biorbd".

openjournals/joss-reviews#5670

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.