Crocoddyl Optimal Control Library

repository·devel·Indexed 22 days ago

https://github.com/loco-3d/crocoddyl

An optimal control library for robot control under contact sequences. It utilizes efficient differential dynamic programming (DDP) algorithms, including FDDP, OdynSQP, Intro, and Ipopt, and integrates with Pinocchio for fast dynamics computation. The library supports C++11/14/17/20 with Python bindings via Boost Python, and offers features such as automatic differentiation via CppAD and code generation via CppADCoGen.

Tokens
13.5K
Snippets
25
Records
37
Agent score
79%

What's inside Crocoddyl

  1. What is Crocoddyl?

    devel

    Crocoddyl is an optimal control library designed for robot control under contact sequences. It computes optimal trajectories and feedback gains using efficient differential dynamic programming (DDP) algorithms.

    Key technical features include:

    • Solvers: Supports various solvers like FDDP, OdynSQP, Intro, and Ipopt.
    • Dynamics: Uses Pinocchio for fast robot dynamics computation and analytical/sparse derivatives.
    • Differentiation: Supports analytical derivatives, numerical differentiation, and automatic differentiation via CppAD.
    • Flexibility: Supports various integrators, dynamics, costs, and constraints, with differential geometry support via Pinocchio.
    • Performance: Cache-friendly design with multi-threading support via OpenMP.
    • Language Support: C++11/14/17/20 compliant with Python bindings via Boost Python.
    • Code Generation: Supports code generation in both C++ and Python via CppADCoGen.
  2. Understand the Crocoddyl workflow (Python vs C++)

    devel

    Crocoddyl follows a specific development pattern that leverages both Python and C++:

    1. Prototyping in Python: Use the Python API to quickly prototype ideas. You can derive models, costs, and constraints directly in Python. The Python API mirrors the C++ interface but uses NumPy matrices instead of Eigen objects.
    2. Production in C++: Once a prototype is successful, translate it to C++ for maximum performance. The C++ interface is highly efficient and supports automatic code generation and automatic differentiation (currently only available in C++).
    3. Extending: If you need to extend the library, it is preferred to do so in C++ and then bind the API so the new functionality is available in Python.
  3. Run Crocoddyl examples and benchmarks

    devel

    After installation, you can run examples using the Python module or via the build directory if you have compiled from source.

    Running via Python: Use the -m flag to run specific examples. You can pass arguments like display or plot to enable visual outputs.

    Running from Build Directory: If you have a build directory, you can run tests, examples, or benchmarks using make.

    Enabling Visuals: You can enable display and/or plots by setting the following environment variables:

    • CROCODDYL_DISPLAY=1
    • CROCODDYL_PLOT=1
    # Run via Python
    python -m crocoddyl.examples.quadrupedal_gaits "display" "plot"
    
    # Run from build directory
    cd build
    make test
    make -s examples-quadrupedal_gaits INPUT="display plot"
    make -s benchmarks-cpp-quadrupedal_gaits INPUT="100 walk"
    
    # Using environment variables for visuals
    export CROCODDYL_DISPLAY=1
    export CROCODDYL_PLOT=1
  4. Explore Crocoddyl documentation and tutorials

    devel

    You can access Crocoddyl's technical documentation via Doxygen. For practical learning, it is highly recommended to explore the provided Jupyter notebooks which cover topics from basic introduction to scaling for robotics.

    Recommended Notebooks:

    • 01_introduction_to_crocoddyl.ipynb
    • 02_optimizing_a_cartpole_swingup.ipynb
    • 03_optimizing_an_unicycle.ipynb
    • 04_actuating_an_acrobot.ipynb
    • 05_codegenerating_a_cartpole.ipynb
    • 06_scaling_to_robotics.ipynb
  5. Install Crocoddyl via Nix

    devel

    Crocoddyl is available in nixpkgs as crocoddyl and python3Packages.crocoddyl.

    As a flake, you can:

    • Run a python shell with crocoddyl: nix run github:loco-3d/crocoddyl
    • Use it in your own flake by adding: crocoddyl.url = "github:loco-3d/crocoddyl";
  6. Install Crocoddyl from Source

    devel

    To build Crocoddyl from source, follow these steps:

    1. Install mandatory dependencies:

    2. (Optional) Install optional dependencies for extra features:

      • OpenMP (multi-threading)
      • CppADCoGen, pycppad (code-generation)
      • Ipopt (Ipopt support)
      • example-robot-data (examples/benchmarks)
      • gepetto-viewer-corba (GepettoDisplay)
      • meshcat-python (MeshcatDisplay)
      • whole_body_state_rviz_plugin, crocoddyl_msgs, urdf_parser_py (RvizDisplay)
      • jupyter, matplotlib (notebooks/plotting)
    3. Build and Install: Clone the repository with --recursive, create a build directory, and run:

    cmake .. && make && make install

    CMake Options:

    • BUILD_TESTING: Disable tests.
    • BUILD_EXAMPLES: Disable examples.
    • BUILD_BENCHMARK: Disable benchmarks.

    Note: Tests, examples, and benchmarks require example-robot-data.

  7. Install Crocoddyl

    devel

    Crocoddyl can be installed via several methods depending on your environment:

    • APT packaging: Available for Ubuntu 18.04 and 20.04.
    • Conda: Available via conda packages.
    • Pip: Available via the Python package index.
    • Source: Can be built from source on Linux and Mac OS X if binaries are not provided.
  8. Install Crocoddyl via Debian/Ubuntu (robotpkg)

    devel

    To install via robotpkg on Debian or Ubuntu, follow these steps:

    1. Add the robotpkg software repository:
    sudo tee /etc/apt/sources.list.d/robotpkg.list <<EOF
    deb [arch=amd64] http://robotpkg.openrobots.org/packages/debian/pub $(lsb_release -sc) robotpkg
    EOF
    
    curl http://robotpkg.openrobots.org/packages/debian/robotpkg.key | sudo apt-key add -
    sudo apt update
    1. Install Crocoddyl and its Python bindings:
    sudo apt install robotpkg-py3\*-crocoddyl
    1. Configure your environment variables:
    export PATH=/opt/openrobots/bin:$PATH
    export PKG_CONFIG_PATH=/opt/openrobots/lib/pkgconfig:$PKG_CONFIG_PATH
    export LD_LIBRARY_PATH=/opt/openrobots/lib:$LD_LIBRARY_PATH
    export PYTHONPATH=/opt/openrobots/lib/python3.10/site-packages:$PYTHONPATH