pyoptas

OpTaS: An optimization-based task specification library for trajectory optimization and model predictive control.

https://github.com/cmower/optas

Science Score: 77.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in README
  • Academic publication links
    Links to: arxiv.org, ieee.org
  • Committers with academic emails
    2 of 6 committers (33.3%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.3%) to scientific vocabulary

Keywords

forward-kinematics inverse-kinematics library model-predictive-control nonlinear optimal-control optimization planning python robotics task-specification trajectory-optimization
Last synced: 4 months ago · JSON representation ·

Repository

OpTaS: An optimization-based task specification library for trajectory optimization and model predictive control.

Basic Info
Statistics
  • Stars: 125
  • Watchers: 3
  • Forks: 17
  • Open Issues: 9
  • Releases: 0
Topics
forward-kinematics inverse-kinematics library model-predictive-control nonlinear optimal-control optimization planning python robotics task-specification trajectory-optimization
Created over 3 years ago · Last pushed 8 months ago
Metadata Files
Readme License Citation

README.md

OpTaS

Code style: black Lint Run tests Build documentation

OpTaS is an OPtimization-based TAsk Specification library for trajectory optimization and model predictive control.

In the past, OpTaS supported ROS from an internal module. This functionality, with additional updates, has now been moved to a dedicated repository: optas_ros.

Example

In this example we implement an optimization-based IK problem. The problem computes an optimal joint configuration $q^*\in\mathbb{R}^n$ given by

$$ q^* = \underset{q}{\text{arg}\min}~||q - qN||^2\quad\text{subject to}\quad p(q) = pg, q^-\leq q \leq q^+ $$

where * $q\in\mathbb{R}^n$ is the joint configuration for an $n$-dof robot (in our example, we use the KUKA LWR in the above figure with $n=7$), * $qN\in\mathbb{R}^n$ is a nominal joint configuration, * $||\cdot||$ is the Euclidean norm, * $p: \mathbb{R}^n\rightarrow\mathbb{R}^3$ computes the end-effector position via the forward kinematics, * $pg\in\mathbb{R}^3$ is a goal position, and * $q^-, q^+\in\mathbb{R}^n$ is the lower and upper joint position limits respectively.

The example problem has a quadratic cost function with nonlinear constraints. We use the nominal configuration $q_N$ as the initial seed for the problem.

The following example script showcases some of the main features of OpTaS: creating a robot model, building an optimization problem, passing the problem to a solver, computing an optimal solution, and visualizing the robot in a given configuration.

```python import os import pathlib

import optas

Specify URDF filename

cwd = pathlib.Path(file).parent.resolve() # path to current working directory urdffilename = os.path.join( cwd, "robots", "kukalwr", "kuka_lwr.urdf" ) # KUKA LWR, 7-DoF

Setup robot model

robot = optas.RobotModel(urdffilename=urdffilename) name = robot.get_name()

Setup optimization builder

T = 1 builder = optas.OptimizationBuilder(T, robots=robot)

Setup parameters

qn = builder.addparameter("qnominal", robot.ndof) pg = builder.addparameter("pgoal", 3)

Constraint: end goal

q = builder.getmodelstate(name, 0) endeffectorname = "endeffectorball" p = robot.getgloballinkposition(endeffectorname, q) builder.addequalityconstraint("endgoal", p, pg)

Cost: nominal configuration

builder.addcostterm("nominal", optas.sumsqr(q - qn))

Constraint: joint position limits

builder.enforcemodellimits(name) # joint limits extracted from URDF

Build optimization problem

optimization = builder.build()

Interface optimization problem with a solver

solver = optas.CasADiSolver(optimization).setup("ipopt")

solver = optas.ScipyMinimizeSolver(optimization).setup("SLSQP")

Specify a nominal configuration

q_nominal = optas.deg2rad([0, 45, 0, -90, 0, -45, 0])

Get end-effector position in nominal configuration

pnominal = robot.getgloballinkposition(endeffectorname, q_nominal)

Specify a goal end-effector position

pgoal = pnominal + optas.DM([0.0, 0.3, -0.2])

Reset solver parameters

solver.resetparameters({"qnominal": qnominal, "pgoal": p_goal})

Reset initial seed

solver.resetinitialseed({f"{name}/q": q_nominal})

Compute a solution

solution = solver.solve() q_solution = solution[f"{name}/q"]

Visualize the robot

vis = optas.Visualizer(quitafterdelay=2.0)

Draw goal position and start visualizer

vis.sphere(0.05, rgb=[0, 1, 0], position=p_goal.toarray().flatten().tolist())

vis.robot(robot, q=qnominal,displaylinknames=True,showlinks=True) # nominal

vis.robot(robot, q=qsolution, displaylinknames=True, showlinks=True) # solution

vis.start() ```

Run the example script example.py. Other examples, including dual-arm planning, Model Predictive Control, Trajectory Optimization, etc can be found in the example/ directory.

Support

The following operating systems and python versions are officially supported:

  • Ubuntu 20.04 and 22.04
    • Python 3.7, 3.8, 3.9
  • Windows
    • Python 3.8, 3.9
  • Mac OS
    • Python 3.9

Note that OpTaS makes use of dataclasses that was introduced in Python 3.7, and so Python versions from 3.6 and lower are not supported on any operating system. Other operating systems or higher Python versions will likely work. If you experience problems, please submit an issue.

Install

Make sure pip is up-to-date by running $ python -m pip install --upgrade pip.

Via pip

$ pip install pyoptas

Alternatively, you can also install OpTaS using:

$ python -m pip install 'optas @ git+https://github.com/cmower/optas.git'

From source

  1. $ git clone --recursive git@github.com:cmower/optas.git (if you do not want to build the documentation then the --recursive flag is not necessary)
  2. $ cd optas
  3. $ pip install .
    • if you want to run the examples use: $ pip install .[example]
    • if you want to run the tests use: $ pip install .[test]

Build documentation

  1. $ cd /path/to/optas/doc
  2. $ sudo apt install doxygen graphviz
  3. $ python gen_mainpage.py
  4. $ doxygen
  5. Open the documentation in either HTML or PDF:
    • html/index.html
    • latex/refman.pdf

Run tests

  1. $ cd /path/to/optas
  2. Each test can be run as follows
    • $ pytest tests/test_builder.py
    • $ pytest tests/test_examples.py
    • $ pytest tests/test_models.py
    • $ pytest tests/test_optas_utils.py
    • $ pytest tests/test_optimization.py
    • $ pytest tests/test_solver.py
    • $ pytest tests/test_spatialmath.py
    • $ pytest tests/test_sx_container.py

Known Issues

  • Loading robot models from xacro files is supported, however there can be issues if you are running this in a ROS agnositic environment. If you do not have ROS installed, then the xacro file should not contain ROS-specific features. For further details see here.
  • If NumPy ver 1.24 is installed, an AttributeError error is thrown when you try to solve an unconstrained problem with the OSQP interface. A temporary workaround is to add a constraint, e.g. x >= -1e9 where x is a decision variable. See details on the issue here and pull request here.

Citation

If you use OpTaS in your work, please consider including the following citation.

bibtex @inproceedings{mower23optas, author={Mower, Christopher E. and Moura, João and Behabadi, Nazanin Zamani and Vijayakumar, Sethu and Vercauteren, Tom and Bergeles, Christos}, booktitle={2023 IEEE International Conference on Robotics and Automation (ICRA)}, title={OpTaS: An Optimization-based Task Specification Library for Trajectory Optimization and Model Predictive Control}, year={2023}, volume={}, number={}, pages={9118-9124}, doi={10.1109/ICRA48891.2023.10161272} }

The preprint can be found on arXiv.

Contributing

We welcome contributions from the community. If you come across any issues or inacuracies in the documentation, please submit an issue. If you would like to contribute any new features, please fork the repository, and submit a pull request.

Acknowledgement

This research received funding from the European Union’s Horizon 2020 research and innovation program under grant agreement No. 101016985 (FAROS). Further, this work was supported by core funding from the Wellcome/EPSRC [WT203148/Z/16/Z; NS/A000049/1]. T. Vercauteren is supported by a Medtronic / RAEng Research Chair [RCSRF1819\7\34], and C. Bergeles by an ERC Starting Grant [714562]. This work has received funding from the European Union’s Horizon 2020 research and innovation programme under grant agreement No 101017008, Enhancing Healthcare with Assistive Robotic Mobile Manipulation (HARMONY).

Owner

  • Name: Chris Mower
  • Login: cmower
  • Kind: user
  • Location: London, UK
  • Company: Huawei Technologies R&D

Senior Research Scientist at Huawei Technologies R&D.

Citation (CITATION.bib)

@article{Mower2023,
  author={Mower, Christopher E. and Moura, João and Zamani Behabadi, Nazanin and Vijayakumar, Sethu and Vercauteren, Tom and Bergeles, Christos},
  journal={2023 International Conference on Robotics and Automation (ICRA)},
  title={OpTaS: An Optimization-based Task Specification Library for Trajectory Optimization and Model Predictive Control},
  year={2023},
  url = {https://github.com/cmower/optas},
}

GitHub Events

Total
  • Watch event: 21
  • Issue comment event: 7
  • Push event: 4
  • Pull request event: 2
  • Fork event: 2
Last Year
  • Watch event: 21
  • Issue comment event: 7
  • Push event: 4
  • Pull request event: 2
  • Fork event: 2

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 928
  • Total Committers: 6
  • Avg Commits per committer: 154.667
  • Development Distribution Score (DDS): 0.168
Past Year
  • Commits: 9
  • Committers: 2
  • Avg Commits per committer: 4.5
  • Development Distribution Score (DDS): 0.111
Top Committers
Name Email Commits
Christopher E. Mower c****r@k****k 772
Joao Moura J****a@e****k 80
TianHuanyu f****y@g****m 27
Nazanin Zamani Behabadi n****b@g****m 25
github-actions[bot] g****] 17
mhubii m****4@h****e 7
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 54
  • Total pull requests: 72
  • Average time to close issues: 30 days
  • Average time to close pull requests: 9 days
  • Total issue authors: 9
  • Total pull request authors: 5
  • Average comments per issue: 1.72
  • Average comments per pull request: 0.97
  • Merged pull requests: 68
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 1
  • Average time to close issues: N/A
  • Average time to close pull requests: 14 days
  • Issue authors: 1
  • Pull request authors: 1
  • Average comments per issue: 2.0
  • Average comments per pull request: 4.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • cmower (38)
  • joaomoura24 (6)
  • duISIR (3)
  • sandorfelber (1)
  • Tianhuanyu (1)
  • zhuhongwu0918 (1)
  • tvercaut (1)
  • OmidRezayof (1)
Pull Request Authors
  • cmower (59)
  • joaomoura24 (6)
  • Tianhuanyu (2)
  • FrankC96 (1)
  • mhubii (1)
Top Labels
Issue Labels
enhancement (17) help wanted (7) documentation (7) future (6) invalid (4) Something not right (3) bug (3) deprecation (2)
Pull Request Labels
enhancement (1) documentation (1) future (1)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 217 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 7
  • Total maintainers: 1
pypi.org: pyoptas

An optimization-based task specification library for task and motion planning (TAMP), trajectory optimization, and model predictive control.

  • Versions: 7
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 217 Last month
Rankings
Dependent packages count: 7.5%
Stargazers count: 8.9%
Forks count: 11.0%
Downloads: 14.8%
Average: 22.4%
Dependent repos count: 69.8%
Maintainers (1)
Last synced: 4 months ago

Dependencies

setup.py pypi
  • casadi *
  • cvxopt *
  • numpy *
  • osqp *
  • pyyaml *
  • scipy *
  • urdf-parser-py *
  • vtk *
  • xacro *