# loco-3d/crocoddyl architecture

> Architecture diagram of the GitHub repository loco-3d/crocoddyl, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/loco-3d/crocoddyl
- Repository: https://github.com/loco-3d/crocoddyl

## Overview

##### Main Components Architecture

a) Core Layer:
- Action Base System (actions/)
- State Management (states/)
- Cost Functions (costs/)
- Constraints System (constraints/)
- Solvers Framework (solvers/)
- Activation Functions (activations/)
- Actuation System (actuation/)
- Integrators (integrator/)

b) Multibody Layer:
- Contact Dynamics (contacts/)
- Impulse Handling (impulses/)
- Residual Systems (residuals/)
- Multibody States (states/)
- Force/Wrench Management (force-base.hpp, wrench-cone.hpp)

c) Python Bindings Layer:
- Core Bindings
- Multibody Bindings
- Utility Bindings

##### Component Relationships

a) Data Flow:
- How the solvers interact with actions and states
- Flow from multibody layer through core components
- Demonstrate how constraints and costs feed into the optimization process

b) Hierarchical Structure:
- Core mathematical foundation at the bottom
- Multibody dynamics in the middle
- High-level interfaces and bindings at the top

##### Key Design Elements

- DDP/FDDP Solvers
- Pinocchio Integration
- Numerical Differentiation
- Automatic Differentiation Support
- OpenMP Multi-threading

##### Implementation Details

- Blue: Core mathematical components
- Green: Physics/dynamics components
- Orange: Optimization solvers
- Purple: Python bindings
- Gray: Utility functions and tools

##### External Dependencies

Connections to:
- Pinocchio (for rigid body dynamics)
- Eigen (for linear algebra)
- Python ecosystem (for bindings)
- Optional components (CppAD, Ipopt, etc.)

##### Application Layer

- The modular design of the system
- The separation between core mathematical operations and robot-specific components
- The flexibility in solver selection and problem formulation
- The integration with external tools and libraries

This design captures both the mathematical sophistication of the optimal control library and its practical implementation for robot control applications.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef core fill:#b3d9ff,stroke:#333,stroke-width:2px
    classDef multibody fill:#90EE90,stroke:#333,stroke-width:2px
    classDef python fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef solver fill:#FFA500,stroke:#333,stroke-width:2px

    %% External Dependencies
    subgraph External ["External Dependencies"]
        Pinocchio["Pinocchio"]:::external
        Eigen["Eigen"]:::external
        Python["Python"]:::external
        CppAD["CppAD"]:::external
        Ipopt["Ipopt"]:::external
    end

    %% Core Layer
    subgraph CoreLayer ["Core Mathematical Layer"]
        ActionBase["Action Base System"]:::core
        StateManagement["State Management"]:::core
        CostFunctions["Cost Functions"]:::core
        ConstraintsSystem["Constraints System"]:::core
        SolversFramework["Solvers Framework"]:::solver
        ActivationFunctions["Activation Functions"]:::core
        ActuationSystem["Actuation System"]:::core
        Integrators["Integrators"]:::core
    end

    %% Multibody Layer
    subgraph MultibodyLayer ["Multibody Dynamics Layer"]
        ContactDynamics["Contact Dynamics"]:::multibody
        ImpulseHandling["Impulse Handling"]:::multibody
        ResidualSystems["Residual Systems"]:::multibody
        MultibodyStates["Multibody States"]:::multibody
        ForceWrench["Force/Wrench Management"]:::multibody
    end

    %% Python Bindings Layer
    subgraph BindingsLayer ["Python Bindings Layer"]
        CoreBindings["Core Bindings"]:::python
        MultibodyBindings["Multibody Bindings"]:::python
        UtilityBindings["Utility Bindings"]:::python
    end

    %% Relationships
    Pinocchio --> MultibodyLayer
    Eigen --> CoreLayer
    Python --> BindingsLayer
    CppAD -.-> CoreLayer
    Ipopt -.-> CoreLayer

    CoreLayer --> MultibodyLayer
    MultibodyLayer --> BindingsLayer

    %% Click events
    click ActionBase "https://github.com/loco-3d/crocoddyl/blob/master/include/crocoddyl/core/action-base.hpp"
    click StateManagement "https://github.com/loco-3d/crocoddyl/tree/master/include/crocoddyl/core/states/"
    click CostFunctions "https://github.com/loco-3d/crocoddyl/tree/master/include/crocoddyl/core/costs/"
    click ConstraintsSystem "https://github.com/loco-3d/crocoddyl/tree/master/include/crocoddyl/core/constraints/"
    click SolversFramework "https://github.com/loco-3d/crocoddyl/tree/master/include/crocoddyl/core/solvers/"
    click ActivationFunctions "https://github.com/loco-3d/crocoddyl/tree/master/include/crocoddyl/core/activations/"
    click ActuationSystem "https://github.com/loco-3d/crocoddyl/tree/master/include/crocoddyl/core/actuation/"
    click Integrators "https://github.com/loco-3d/crocoddyl/tree/master/include/crocoddyl/core/integrator/"
    click ContactDynamics "https://github.com/loco-3d/crocoddyl/tree/master/include/crocoddyl/multibody/contacts/"
    click ImpulseHandling "https://github.com/loco-3d/crocoddyl/tree/master/include/crocoddyl/multibody/impulses/"
    click ResidualSystems "https://github.com/loco-3d/crocoddyl/tree/master/include/crocoddyl/multibody/residuals/"
    click MultibodyStates "https://github.com/loco-3d/crocoddyl/tree/master/include/crocoddyl/multibody/states/"
    click ForceWrench "https://github.com/loco-3d/crocoddyl/blob/master/include/crocoddyl/multibody/force-base.hpp"
    click CoreBindings "https://github.com/loco-3d/crocoddyl/tree/master/bindings/python/crocoddyl/core/"
    click MultibodyBindings "https://github.com/loco-3d/crocoddyl/tree/master/bindings/python/crocoddyl/multibody/"

    %% Legend
    subgraph Legend
        CoreComponent["Core Component"]:::core
        MultibodyComponent["Multibody Component"]:::multibody
        PythonComponent["Python Component"]:::python
        ExternalComponent["External Dependency"]:::external
        SolverComponent["Solver Component"]:::solver
    end
```
