Metadata-Version: 2.4
Name: pycapacity
Version: 3.0.0
Summary: A real-time task space capacity calculation module for robotic manipulators and human musculoskeletal models
Home-page: https://github.com/auctus-team/pycapacity
Author: Antun Skuric
Author-email: antun.skuric@inria.fr
License: MIT
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Framework :: Robot Framework
Classifier: Framework :: Robot Framework :: Library
Classifier: Framework :: Robot Framework :: Tool
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: scipy
Requires-Dist: highspy
Requires-Dist: matplotlib
Provides-Extra: fast
Requires-Dist: pycapacity-cpp>=0.1; extra == "fast"
Provides-Extra: cvxopt
Requires-Dist: cvxopt>=1.2.6; extra == "cvxopt"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: summary

# pycapacity: task-space capacity of robots and humans

[![PyPI package](https://img.shields.io/pypi/v/pycapacity)](https://pypi.org/project/pycapacity/) [![Tests](https://github.com/auctus-team/pycapacity/actions/workflows/python-app.yml/badge.svg)](https://github.com/auctus-team/pycapacity/actions/workflows/python-app.yml) ![](https://img.shields.io/pypi/dm/pycapacity?color=blue&label=pip%20downloads)  [![Docs](https://github.com/auctus-team/pycapacity/actions/workflows/main.yml/badge.svg)](https://github.com/auctus-team/pycapacity/actions/workflows/main.yml) [![status](https://joss.theoj.org/papers/73f155afc0dfa7730792639ac374b348/status.svg)](https://joss.theoj.org/papers/73f155afc0dfa7730792639ac374b348)

<img src="https://raw.githubusercontent.com/auctus-team/pycapacity/master/images/comparison.gif" height="200px"><img src="https://github.com/auctus-team/pycapacity/blob/master/images/human_poly.gif?raw=true" height="200px"><img src="https://github.com/auctus-team/pycapacity/blob/master/images/reachable.gif?raw=true" height="200px">

`pycapacity` computes the physical capacity of robots and humans in the task space: the forces, velocities and accelerations they can produce, and the space they can reach, as polytopes and ellipsoids. Its algorithms bring most of these metrics to a few milliseconds, fast enough for online and interactive use. It takes plain matrices (Jacobians, mass matrices, limits), so it works with any robotics or biomechanics library: `pinocchio`, `robotics-toolbox`, `mujoco`, `biorbd`, `opensim`, ROS.

**Documentation: <https://auctus-team.github.io/pycapacity>**

> 📢 **v3.0** is out - [changelog](https://auctus-team.github.io/pycapacity/changelog.html)
> - **Polytope operations**: `P1 + P2`, `P1 & P2`, `A @ P`, `P + x`, `a * P`, `P.contains(x)`, `P.volume()`, `P.reduce()`
> - **Exact conversions** between the vertex and half-space representations, including flat (lower dimensional) polytopes
> - **Optional C++ acceleration** `pycapacity-cpp`: the same functions 6 to 50 times faster
> - Bug fixes in the HPSM (rank deficient Jacobians) and the ICHM (missed facets in some symmetric problems)

## Installation

```bash
pip install pycapacity
```

Optional extras: `pip install pycapacity[fast]` for the [C++ acceleration](https://auctus-team.github.io/pycapacity/backend.html) (pre-built for Linux, macOS and Windows, used automatically), `pip install pycapacity[cvxopt]` for faster small linear programs. See the [installation docs](https://auctus-team.github.io/pycapacity/install.html).

## Quick start

```python
import numpy as np
from pycapacity.robot import force_polytope, velocity_polytope

J = np.random.rand(3, 7)          # Jacobian of a 7-joint robot (position part)
t_max = 10 * np.ones(7)           # joint torque limits [Nm]
dq_max = np.ones(7)               # joint velocity limits [rad/s]

f_poly = force_polytope(J, t_max, -t_max)     # forces the robot can apply
v_poly = velocity_polytope(J, dq_max, -dq_max) # velocities it can reach

print(f_poly)                                  # a Polytope: vertices, half-spaces, faces
print(f_poly.contains([0, 0, 5]))              # can it push 5 N along z?
print(v_poly.volume())

two_arms = f_poly + force_polytope(np.random.rand(3, 7), t_max, -t_max)  # Minkowski sum
```

Polytopes can be combined (`+`, `&`, `@`, `*`), tested (`contains`) and measured (`volume`): see [working with polytopes](https://auctus-team.github.io/pycapacity/polytopes.html).

## Capacity metrics

Metric | Robot (`pycapacity.robot`) | Human (`pycapacity.human`) | Algorithm
--- | --- | --- | ---
Velocity, acceleration, force ellipsoids | `*_ellipsoid` | `*_ellipsoid` | SVD
Velocity polytope | [`velocity_polytope`](https://auctus-team.github.io/pycapacity/pycapacity.robot.html#pycapacity.robot.velocity_polytope) | [`velocity_polytope`](https://auctus-team.github.io/pycapacity/pycapacity.human.html#pycapacity.human.velocity_polytope) | HPSM / ICHM
Acceleration polytope | [`acceleration_polytope`](https://auctus-team.github.io/pycapacity/pycapacity.robot.html#pycapacity.robot.acceleration_polytope) | [`acceleration_polytope`](https://auctus-team.github.io/pycapacity/pycapacity.human.html#pycapacity.human.acceleration_polytope) | HPSM (or ICHM)
Force polytope | [`force_polytope`](https://auctus-team.github.io/pycapacity/pycapacity.robot.html#pycapacity.robot.force_polytope) | [`force_polytope`](https://auctus-team.github.io/pycapacity/pycapacity.human.html#pycapacity.human.force_polytope) | VEPOLI² / ICHM
Force polytope sum and intersection | [`force_polytope_sum`](https://auctus-team.github.io/pycapacity/pycapacity.robot.html#pycapacity.robot.force_polytope_sum), [`force_polytope_intersection`](https://auctus-team.github.io/pycapacity/pycapacity.robot.html#pycapacity.robot.force_polytope_intersection) | - | VEPOLI²
Reachable space | [`reachable_space_approximation`](https://auctus-team.github.io/pycapacity/pycapacity.robot.html#pycapacity.robot.reachable_space_approximation) (convex), [`reachable_space_nonlinear`](https://auctus-team.github.io/pycapacity/pycapacity.robot.html#pycapacity.robot.reachable_space_nonlinear) (non-convex) | - | ICHM / sampling
Joint torque polytope | - | [`joint_torques_polytope`](https://auctus-team.github.io/pycapacity/pycapacity.human.html#pycapacity.human.joint_torques_polytope) | HPSM

The formulas are in the [capacity metrics docs](https://auctus-team.github.io/pycapacity/README.html), the algorithms and their timings in the [algorithms docs](https://auctus-team.github.io/pycapacity/algorithms.html), and a comparison with general methods (Qhull, cdd, Bretl and Lall) in [comparison with other methods](https://auctus-team.github.io/pycapacity/comparison.html).

## Tutorials

Library | Tutorial
--- | ---
[pinocchio](https://github.com/stack-of-tasks/pinocchio) | [Tutorial](https://auctus-team.github.io/pycapacity/examples/pinocchio.html)
[Robotics toolbox](https://github.com/petercorke/robotics-toolbox-python) | [Tutorial](https://auctus-team.github.io/pycapacity/examples/robotics_toolbox.html)
[MuJoCo](https://mujoco.org/) | [Tutorial](https://auctus-team.github.io/pycapacity/examples/mujoco.html)
[Robot Operating System (ROS)](https://ros.org/) | [Tutorial](https://auctus-team.github.io/pycapacity/examples/ROS.html)
[pyomeca biorbd](https://github.com/pyomeca/biorbd) | [Tutorial](https://auctus-team.github.io/pycapacity/examples/pyomeca.html)
[OpenSim](https://github.com/opensim-org/opensim-core) | [Tutorial](https://auctus-team.github.io/pycapacity/examples/opensim.html)

More in the [tutorials](https://auctus-team.github.io/pycapacity/examples/index.html) and in the [`examples`](https://github.com/auctus-team/pycapacity/tree/master/examples) folder (scripts and notebooks).

## Upgrading from v2

The functions keep their names, arguments and return types. What can change in the results:
- the half-space representations `H`, `d` computed from vertices have one row per facet (v2 gave one row per triangle of the facet); `face_indices` are still triangles for plotting
- the Minkowski sum returns only the vertices of the sum (v2 could also return points on its boundary)
- the polytopes themselves are the same, except where v2 was wrong (rank deficient Jacobians in the HPSM, some symmetric problems in the ICHM)

## Contributing

Questions, ideas and bug reports are welcome as [issues](https://github.com/auctus-team/pycapacity/issues) or [discussions](https://github.com/auctus-team/pycapacity/discussions). If you are not familiar with GitHub, just start a discussion and we will help.

## Citing `pycapacity`

A short resume paper about `pycapacity` has been published in the Journal of Open Source Software: 
<p>
  <b><i>pycapacity</i></b>: a real-time task-space capacity calculation package for robotics and biomechanics<br>
  A. Skuric, V. Padois and D. Daney<br>
Journal of Open Source Software, 8(89), 5670, https://doi.org/10.21105/joss.05670
</p>

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

```bib
@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}
}
```

## AI statement

Parts of `pycapacity` v3.0 were developed with the help of the AI assistant Claude (Anthropic):
mainly the extension of the compiled cpp backend `pycapacity-cpp`, some new polytope operations and conversions (`*`,`@`,`+`), and some optimisations of the existing algorithms. All the changes are tested against the existing Python implementation and the reference methods (cdd, pypoman).
