Giter Club home page Giter Club logo

robotoc's Introduction

robotoc - efficient ROBOT Optimal Control solvers

build codecov

     

     

Features for efficient optimal control of robotic systems

  • Direct multiple-shooting method based on the lifted contact dynamics / inverse dynamics.
  • Riccati recursion algorithm for switching time optimization (STO) problems and efficient pure-state equality constraint handling.
  • Primal-dual interior point method for inequality constraints.
  • Very fast computation of rigid body dynamics and its sensitivities thanks to Pinocchio.

Requirements

  • Ubuntu 22.04, 20.04, and 18.04 (possibly Mac OSX, but not well tested)
  • gcc (at least C++11 is required), CMake (at least version 3.11)
  • Eigen3, Pinocchio ,
  • Python3, NumPy (for Python binding)
  • gepetto-viewer-corba and/or meshcat-python (optional to visualize the solution trajectory in Python)
  • PyBullet (optional to simulate MPC examples)

Installation

  1. Install the latest stable version of Eigen3 by
sudo apt install libeigen3-dev
  1. Install the latest stable version of Pinocchio by following the instruction
  2. Clone this repository and change the directory as
git clone https://github.com/mayataka/robotoc
cd robotoc 
  1. Build and install robotoc as
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release 
make install -j$(nproc)

NOTE: if you want to maximize the performance, use CMake option

cmake .. -DCMAKE_BUILD_TYPE=Release -DOPTIMIZE_FOR_NATIVE=ON
  1. If you want to visualize the solution trajectory with Python, you have to install gepetto-viewer-corba by
sudo apt update && sudo apt install robotpkg-py38-qt5-gepetto-viewer-corba -y

and/or meshcat-python by

pip install meshcat
  1. If you do not want to install the Python bindings, change the CMake configuration as
cmake .. -DBUILD_PYTHON_INTERFACE=OFF
  1. In OSX, explicitly set g++ as the complier. First, find the path of g++ as
ls -l /usr/local/bin | grep g++

Then set the full path in the cmake as

cmake .. -DCMAKE_CXX_COMPILER=FULL_PATH_TO_GPLUSPLUS

Usage

C++:

You can link your executables to robotoc by writing CMakeLists.txt, e.g., as

find_package(robotoc REQUIRED)

add_executable(
    YOUR_EXECTABLE
    YOUR_EXECTABLE.cpp
)
target_link_libraries(
    YOUR_EXECTABLE
    PRIVATE
    robotoc::robotoc
)

Python:

Suppose that the Python version is 3.8. The Python bindings will then be installed at ROBOTOC_INSTALL_DIR/lib/python3.8/site-packages where ROBOTOC_INSTALL_DIR is the install directory of robotoc configured in CMake (e.g., by -DCMAKE_INSTALL_PREFIX). To use the installed Python library, it is convenient to set the environment variable as

export PYTHONPATH=ROBOTOC_INSTALL_DIR/lib/python3.8/site-packages:$PYTHONPATH 

e.g., in ~/.bashrc. Note that if you use another Python version than python3.8, please adapt it.

Solvers

The following three solvers are provided:

  • OCPSolver : Solves the OCP for rigid-body systems (possibly with contacts) by using Riccati recursion. Can optimize the switching times and the trajectories simultaneously.
  • UnconstrOCPSolver : Solves the OCP for "unconstrained" rigid-body systems by using Riccati recursion.
  • UnconstrParNMPCSolver : Solves the OCP for "unconstrained" rigid-body systems by using ParNMPC algorithm.

where "unconstrained" rigid-body systems are systems without any contacts or a floating-base.

Examples

Examples of these solvers are found in examples directory. Further explanations are found at https://mayataka.github.io/robotoc/page_examples.html.

Switching time optimization (STO) examples

  • OCPSolver can solve the switching time optimization (STO) problem, which optimizes the trajectory and the contact timings simultaneously.
  • The following videos display the solution trajectory of the STO problems (anymal/python/jumping_sto.py and icub/python/jumping_sto.py).

 

Whole-body MPC examples

  • The following example implementations of whole-body MPC are provided:
    • MPCCrawl : MPC with OCPSolver for the crawl gait of quadrupedal robots.
    • MPCTrot : MPC with OCPSolver for the trot gait of quadrupedal robots.
    • MPCPace : MPC with OCPSolver for the pace gait of quadrupedal robots.
    • MPCFlyingTrot : MPC with OCPSolver for the flying trot gait of quadrupedal robots.
    • MPCJump : MPC with OCPSolver for the jump motion of quadrupedal or bipedal robots.
    • MPCBipedWalk : MPC with OCPSolver for the walking motion of bipedal robots.
  • You can find the simulations of these MPC at a1/mpc, anymal/mpc, and icub/mpc.
  • You need PyBullet for the MPC simulations. (easy to install, e.g., by pip install pybullet)
  • The following videos display the simulation results of quadrupedal walking on rough terrain (a1/mpc/trot_terrain.py) and bipedal walking (icub/mpc/walk.py).

 

Documentation

More detailed documentation is available at https://mayataka.github.io/robotoc/.

Tutorial

Our tutorials on robotoc is available at robotoc_tutorial.

Citing robotoc

  • Citing the STO algorithm of OCPSolver:
@misc{katayama2021sto,
  title={Structure-exploiting {N}ewton-type method for optimal control of switched systems}, 
  author={Sotaro Katayama and Toshiyuki Ohtsuka},
  url={arXiv:2112.07232},
  eprint={2112.07232},
  archivePrefix={arXiv}
  year={2021}}
  • Citing OCPSolver without the switching time optimization (STO):
@inproceedings{katayama2022lifted,
  title={Lifted contact dynamics for efficient optimal control of rigid body systems with contacts}, 
  author={Sotaro Katayama and Toshiyuki Ohtsuka},
  booktitle={{2022 IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS 2022) (to appear)}},
  year={2022}}
@inproceedings{katayama2021idocp,
  title={Efficient solution method based on inverse dynamics for optimal control problems of rigid body systems},
  author={Sotaro Katayama and Toshiyuki Ohtsuka},
  booktitle={{2021 IEEE International Conference on Robotics and Automation (ICRA)}},
  pages={2070--2076},
  year={2021}}

Related publications

  • S. Katayama and T. Ohtsuka, "Whole-body model predictive control with rigid contacts via online switching time optimization," 2022 IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS 2022) (to appear), https://arxiv.org/abs/2203.00997, 2022
  • S. Katayama and T. Ohtsuka, "Structure-exploiting Newton-type method for optimal control of switched systems," https://arxiv.org/abs/2112.07232, 2021
  • S. Katayama and T. Ohtsuka, Lifted contact dynamics for efficient optimal control of rigid body systems with contacts, 2022 IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS) (to appear), https://arxiv.org/abs/2108.01781, 2022
  • S. Katayama and T. Ohtsuka, Efficient Riccati recursion for optimal control problems with pure-state equality constraints, 2022 American Control Conference (ACC), pp. 3579-3586, 2022
  • S. Katayama and T. Ohtsuka, Efficient solution method based on inverse dynamics for optimal control problems of rigid body systems, 2021 IEEE International Conference on Robotics and Automation (ICRA), pp.2070-2076, 2021
  • H. Deng and T. Ohtsuka, A parallel Newton-type method for nonlinear model predictive control, Automatica, Vol. 109, pp. 108560, 2019

robotoc's People

Contributors

6293 avatar mayataka 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

robotoc's Issues

MJtJinv matrix is not full of rank when robot has multiple contacts

Thank you for such an excellent code. However, when I apply your code to the OCP of my snake robot, snake robot makes multiple contacts with the ground and Jacobian matrix is singular, then MJtJinv matrix can not be evaluated well. I try use pseudoinverse of JMinvJt to evaluate MJtJinv matrix, it also doesn't work because of the divergence. Could you give me some suggestions? Thanks.

related code gives as follows:
d.dbetamu().noalias() = - data.MJtJinv() * data.laf();

C++ visualization not working

Hi Sotaro,

Thanks for open-sourcing such nice software!

When I am playing with your code, I bumped into a visualization error in C++. To be more exact, I would like to build the cpp files in examples/anymal with ENABLE_VIEWER to be 'ON' from the CMakeLists.txt to see the visualization effect. All examples (trot, crawl, pace, bounce, jump, run, jump_sto) can be successfully built. However, when executing, the following messages jumped out:

Failed in connecting to CORBA!!
omniORB: (0) 2022-08-24 15:51:55.371327: Error: the application attempted to invoke an operation on a nil reference.
terminate called after throwing an instance of 'CORBA::INV_OBJREF'
Aborted (core dumped)

After some investigation, I realized that it is at this line where the pinocchio::gepetto::Viewer cannot be initialized, which is pretty weird, because model_ and vmodel_ are all well-initialized according to my understanding. I did some search, but sadly found nothing valuable for debugging.

P.S. I have installed gepetto-viewer-corba and pinocchio-gepetto-viewer properly. The python visualization (from jupyter notebook) works well.

Any help are greatly appreciated! And thanks for your time in advance.

Best regards,
Shaohui Yang

Install the Python binding via pip

The current install procedure of the Python binding is inconvenient.
It would be nice if we can install it through pip, .e.g, by pip install . --user.
An install script (setup.py or something like that) that satisfies

  • Builds and installs C++ shared library as well as Python binding
  • Enables CMake options (-DOPTIMIZE_FOR_NATIVE and -DBUILD_VIEWER)

is desired.

Porting to Pinocchio 3.0

The new version Pinocchio 3.0 will be released and has many improvements from the past version.
We then have to update the followings:

  • : PointContact
  • : SurfaceContact
  • : Robot
  • : ContactDynamics
  • : ImpulseDynamics

This is related to #52.

Surface contacts

Surface contacts are necessary to model contacts in humanoid robots.
The following classes should be implemented:

  • SurfaceContact (similar to PointContact)
  • FrictionWrenchCone (similar to FrictionCone)
  • ImpulseFrictionWrenchCone (similar to ImpulseFrictionCone)
  • ContactWrenchCost (similar to ContactForceCost)

Real time iteration scheme

The real time iteration (RTI) scheme can improve the performance of MPC.
For this purpose, we need to decompose updateSolution() into the following two functions:

  • preparationStepRTI(t, q, v)
  • feedbackStepRTI(t, q, v)

Back-tracking line-search

Currently, only the filter line search is implemented.
To ensure global convergence, back-tracking line-search should be incorporated into the filter line-search method.
The following class should be implemented:

  • LineSearchBackTracking

Installation issues

Hi I built the robotoc code but when I try to import it I get the following image

import robotoc
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.10/site-packages/robotoc/init.py", line 1, in
from .robot import *
File "/usr/local/lib/python3.10/site-packages/robotoc/robot/init.py", line 1, in
from .contact_status import *
ModuleNotFoundError: No module named 'robotoc.robot.contact_status'
import math
import robotoc
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.10/site-packages/robotoc/init.py", line 1, in
from .robot import *
File "/usr/local/lib/python3.10/site-packages/robotoc/robot/init.py", line 1, in
from .contact_status import *
ModuleNotFoundError: No module named 'robotoc.robot.contact_status'

Any idea what the issue is?

Tips on tuning the OCP_SOLVER for other URDFs

Hi, thanks for this very cool software. I am trying to use it on my custom URDFs, however I struggle to make the algorithm converge using the default parameters. I adapted the anymal_jump_sto.cpp example with my custom quadruped. However I cant make it converge. Do you have any tips for tuning? Thanks in advance!

Contact surface

The current implementation assumes that the contact surface is just the ground, i.e., its normal vector is z-axis and the height is zero.
The class

  • ContactSurface

must be implemented, which contains information regarding the contact, .e.g, the normal vector and the height from the ground.
Accordingly, PointContact, Robot, or FrictionCone must also be modified.

Terminal constraints

Terminal constraints are often needed to ensure the stability of MPC.
Therefore, it is nice if we can design the terminal constraints independently from the constraints on the other time stages.
The following classes should be implemented:

  • TerminalConstraintComponentBase
  • TerminalJointPositionLowerLimit
  • TerminalJointPositionUpperLimit
  • TerminalBasePositionLowerLimit
  • TerminalBasePositionUpperLimit
  • TerminalJointVelocityLowerLimit
  • TerminalJointVelocityUpperLimit
  • TerminalBaseVelocityLowerLimit
  • TerminalBaseVelocityUpperLimit

Expose the contact sequence class

It is inconvenient to treat the ContactSequence through OCPSolver.
To expose ContactSequence, the following changes may be useful:

  • OCPSolver has std::shared_ptr<ContactSequence> contact_sequence_ instead of ContactSequence contact_sequence_.

CMake packaging

Dear @mayataka,

Very nice job. Your package seems really interesting, going in the common trend of developping real-time MPC for robots.
And I really appreciate that you rely on Pinocchio for computing the dynamics and their derivatives.

Among other things, I think the way you link your package to Pinocchio through CMake can now be updated.
You are no more obliged to rely on the pkg-config linkage procedure.

And again, if you need more featues from Pinocchio's side, do not hesitate to request them and/or to implement them inside Pinocchio. We do love external contributions: it makes our lives simpler.

Best,
Justin

Polynomial trajectory class for the warm starting MPC with the variable problem structure

In MPC for the legged robots, the problem structure of the OCP can change due to its discrete nature.
A little a bit complicated warm start strategy may be useful.
A class that represents the polynomially approximated continuous-time trajectory is useful for such cases, e.g., as

  1. Solve an MPC problem
  2. Construct the polynomially approximated continuous-time trajectory from the MPC solution
  3. Proceed to the next sampling time, and then the problem structure of the OCP can change.
  4. Guess the initial solution of the new MPC problem by the polynomially approximated continuous-time trajectory.

Local to world transformation of contact force

Robot has to have a function that transforms the local contact force (SplitSolution::f and ImpulseSplitSolution::f) into the contact force expressed in the world frame.
The transformation function for the Jacobian is also needed.
(Both of them are only implemented insides of FrictionCone and ImpulseFrictionCone)

Python bindings

The following Python bindings are not mandatory, but can be useful to check whether the formulation (settings of cost and constraints) are correct or not in Python:

  • SplitOCP
  • SplitKKTMatrix
  • SplitKKTResidual
  • StateEquation
  • ContactDynamics
  • ImpulseSplitOCP
  • ImpulseSplitKKTMatrix
  • ImpulseSplitKKTResidual
  • ImpulseStateEquation
  • ImpulseDynamics
  • SwitchingConstraint
  • SwitchingConstraintJacobian
  • SwitchingConstraintResidual
  • TerminalOCP

Fixed grasp constraints

Hello,

is it possible to define tight grasp contacts, i.e. fully constraining the movement of a frame like in the case of multi-arm robot manipulation? I have only seen the constraint placement for point or surface constraints.

Kind regards,
M.Dio

CMake version must be newer than 3.11

Hi. I found that this software requires CMake newer than 3.11 for the python binding.

As shown below, in building the python binding, CMake uses FetchContent module.

include(FetchContent)
FetchContent_GetProperties(pybind11)
if(NOT pybind11_POPULATED)
FetchContent_Populate(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG master
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/pybind11
SUBBUILD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/pybind11-build)
endif()

While this FetchContent module appears after version 3.11 (please see the 5th content of the CMake 3.11 Release Notes / Modules), the version requirement is still >=3.1.

cmake_minimum_required(VERSION 3.1)

I recommend you to set the minimum required version to 3.11 or higher


In my environment (Ubuntu 18.04 + default CMake (3.10.2)), a CMake error occurs (the error message is shown below), and updating CMake to the latest (3.22.2) resolves it.

$ cmake .. -DCMAKE_BUILD_TYPE=Release -DOPTIMIZE_FOR_NATIVE=ON
-- pinocchio FOUND. pinocchio at /opt/openrobots/lib/libpinocchio.so
-- boost_filesystem FOUND. boost_filesystem at /usr/lib/x86_64-linux-gnu/libboost_filesystem.so
-- boost_serialization FOUND. boost_serialization at /usr/lib/x86_64-linux-gnu/libboost_serialization.so
-- boost_system FOUND. boost_system at /usr/lib/x86_64-linux-gnu/libboost_system.so
-- Boost version: 1.65.1
-- Found the following Boost libraries:
--   filesystem
--   serialization
--   system
-- hpp-fcl FOUND. hpp-fcl at /opt/openrobots/lib/libhpp-fcl.so
-- Boost version: 1.65.1
-- Found the following Boost libraries:
--   chrono
--   serialization
--   system
-- Default C++ standard: 201402
-- C++ standard sufficient: Minimal required 11, currently defined: 11
-- C++ standard sufficient: Minimal required 11, currently defined: 11
-- Found OpenMP_CXX: -fopenmp  
-- Found OpenMP: TRUE   
CMake Error at bindings/python/CMakeLists.txt:1 (include):
  include could not find load file:
    FetchContent

CMake Error at bindings/python/CMakeLists.txt:2 (FetchContent_GetProperties):
  Unknown CMake command "FetchContent_GetProperties".

-- Configuring incomplete, errors occurred!

References: CMake error "include could not find load file: FetchContent" - stackoverflow

Python bindings installation

Hello,

first of all, I'd like to say that what you're doing is amazing. I really like this project a simply reading through the code teaches me a lot.

I wanted to play around with the python bindings the other day, so I followed the installation procedure and installed everything according to the installation guide. However, when I try to import robotoc, the python interpreter complains that there's no robotoc.robot.contact_status module.

Do you know, why this could be?

Thanks.
image

Add data unique to each cost function component

The current cost function data is for all the cost function components.
It is convenient that users can define data to be only used with the cost function component as the ConstraintComponentData.

  • : CostFunctionComponentData or something like that

Centroidal dynamics model

Since the new STO algorithm is also valuable for the centroidal dynamics model, it is worth implementing such models.

Controlling joint positions

Hi,
Can you guide me on how I can go about simulating a quadruped for which I have an array of joint angle values? Are there any examples that I can look at to better understand this?
Thanks

Does Robotoc support other dynamics?

Does Robotoc support other dynamics? Such as SRBD?
I only see the Whole-body dynamics in the robotoc, what should i do if i want to use other dynamics formulation?

I want to generate motions using the toes of a robot.

 (日本語で失礼いたします)私は2足歩行ロボットの動作の生成にこのライブラリを使っており,実際のロボットでの実験を目指しています.今のところ,私達のロボットのURDFにおいても,面接触において動作生成は上手く行っているように見えます.素晴らしいライブラリを公開してくださり,ありがとうございます.
現在,画像のようにロボットのつま先を使う動作,つまり面接触から線接触に移行するような動作を生成したいと考えており,画像に示すA,B,C,Dの4つの方法を検討しましたが上手くいきませんでした.

  • Aについては,このissue(#124) と同じ問題で出来ませんでした.(kkt errorが発散してしまいます)
  • Bについても面接触から点接触に移行する際に滞空期を経由しなければkkt errorが発散してしまいます(私の実装の問題かもしれません)
  • C,Dについて,ロボットのつま先にあたる部分に,小さく質量が小さいダミーのつま先リンクをURDFに追加し,つま先接地を擬似的に行おうとしましたが,(B)と同様に出来ませんでした.

もし他につま先を使う方法があればお伺いしたいです.よろしくお願いいたします.

[English]
 I am using this library to generate motions for a biped robot and am aiming to experiment with it on a actual robot. So far, the motion generation seems to work well on our robot's URDF in surface contact. Thank you very much for releasing this excellent library.
Currently, we are trying to generate a motion that uses the robot's toes as shown in the image, i.e., a transition from surface contact to line contact, and we have considered four methods (A, B, C, and D) shown in the image, but they did not work.

  • For A, I could not do it due to the same problem as in this issue (#124) . (kkt error diverges).
  • For B, the kkt error diverges if the transition from surface contact to point contact does not go through a dwell period (this may be a problem with my implementation).
  • For C and D, I tried to add a small, low-mass dummy toe link to the URDF at the toe of the robot to simulate toe grounding, but as in (B), this did not work.

If there is another way to use the toe, I would like to hear about it. Thank you in advance.

issue

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.