{"id":15043592,"url":"https://github.com/ami-iit/adam","last_synced_at":"2025-05-16T13:05:25.494Z","repository":{"id":37094132,"uuid":"370610855","full_name":"ami-iit/adam","owner":"ami-iit","description":"adam implements a collection of algorithms for calculating rigid-body dynamics in Jax, CasADi, PyTorch, and Numpy.","archived":false,"fork":false,"pushed_at":"2024-10-26T10:36:24.000Z","size":1946,"stargazers_count":131,"open_issues_count":10,"forks_count":20,"subscribers_count":14,"default_branch":"main","last_synced_at":"2024-10-29T19:59:46.387Z","etag":null,"topics":["adam-robotics","automatic-differentiation","casadi","jax","motion-planning","numpy","optimization","python","pytorch","reinforcement-learning","rigid-body-dynamics","robotics","urdf"],"latest_commit_sha":null,"homepage":"https://adam-docs.readthedocs.io/en/latest/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ami-iit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-25T07:55:26.000Z","updated_at":"2024-10-26T10:36:24.000Z","dependencies_parsed_at":"2023-10-12T23:35:33.912Z","dependency_job_id":"e6719cb4-0c01-4332-835f-88d1fd1c582e","html_url":"https://github.com/ami-iit/adam","commit_stats":{"total_commits":449,"total_committers":10,"mean_commits":44.9,"dds":"0.16926503340757237","last_synced_commit":"7c855ca5466e385caae188d50b964ef34fb4b089"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ami-iit%2Fadam","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ami-iit%2Fadam/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ami-iit%2Fadam/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ami-iit%2Fadam/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ami-iit","download_url":"https://codeload.github.com/ami-iit/adam/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254535827,"owners_count":22087399,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adam-robotics","automatic-differentiation","casadi","jax","motion-planning","numpy","optimization","python","pytorch","reinforcement-learning","rigid-body-dynamics","robotics","urdf"],"created_at":"2024-09-24T20:49:19.015Z","updated_at":"2025-05-16T13:05:25.424Z","avatar_url":"https://github.com/ami-iit.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# adam\n\n[![adam](https://github.com/ami-iit/ADAM/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/ami-iit/ADAM/actions/workflows/tests.yml)\n[![](https://img.shields.io/badge/License-BSD--3--Clause-blue.svg)](https://github.com/ami-iit/ADAM/blob/main/LICENSE)\n\n**Automatic Differentiation for rigid-body-dynamics AlgorithMs**\n\n**adam** implements a collection of algorithms for calculating rigid-body dynamics for **floating-base** robots, in _mixed_ and _body fixed representations_ (see [Traversaro's A Unified View of the Equations of Motion used for Control Design of Humanoid Robots](https://www.researchgate.net/publication/312200239_A_Unified_View_of_the_Equations_of_Motion_used_for_Control_Design_of_Humanoid_Robots)) using:\n\n- [Jax](https://github.com/google/jax)\n- [CasADi](https://web.casadi.org/)\n- [PyTorch](https://github.com/pytorch/pytorch)\n- [NumPy](https://numpy.org/)\n\n**adam** employs the **automatic differentiation** capabilities of these frameworks to compute, if needed, gradients, Jacobian, Hessians of rigid-body dynamics quantities. This approach enables the design of optimal control and reinforcement learning strategies in robotics.\n\n**adam** is based on Roy Featherstone's Rigid Body Dynamics Algorithms.\n\n### Table of contents\n\n- [🐍 Dependencies](#-dependencies)\n- [💾 Installation](#-installation)\n  - [🐍 Installation with pip](#-installation-with-pip)\n  - [📦 Installation with conda](#-installation-with-conda)\n    - [Installation from conda-forge package](#installation-from-conda-forge-package)\n  - [🔨 Installation from repo](#-installation-from-repo)\n- [🚀 Usage](#-usage)\n  - [Jax interface](#jax-interface)\n  - [CasADi interface](#casadi-interface)\n  - [PyTorch interface](#pytorch-interface)\n  - [PyTorch Batched interface](#pytorch-batched-interface)\n- [🦸‍♂️ Contributing](#️-contributing)\n- [Todo](#todo)\n\n## 🐍 Dependencies\n\n- [`python3`](https://wiki.python.org/moin/BeginnersGuide)\n\nOther requisites are:\n\n- `urdf_parser_py`\n- `jax`\n- `casadi`\n- `pytorch`\n- `numpy`\n- `jax2torch`\n\nThey will be installed in the installation step!\n\n## 💾 Installation\n\nThe installation can be done either using the Python provided by apt (on Debian-based distros) or via conda (on Linux and macOS).\n\n### 🐍 Installation with pip\n\nInstall `python3`, if not installed (in **Ubuntu 20.04**):\n\n```bash\nsudo apt install python3.8\n```\n\nCreate a [virtual environment](https://docs.python.org/3/library/venv.html#venv-def), if you prefer. For example:\n\n```bash\npip install virtualenv\npython3 -m venv your_virtual_env\nsource your_virtual_env/bin/activate\n```\n\nInside the virtual environment, install the library from pip:\n\n- Install **Jax** interface:\n\n  ```bash\n  pip install adam-robotics[jax]\n  ```\n\n- Install **CasADi** interface:\n\n  ```bash\n  pip install adam-robotics[casadi]\n  ```\n\n- Install **PyTorch** interface:\n\n  ```bash\n  pip install adam-robotics[pytorch]\n  ```\n\n- Install **ALL** interfaces:\n\n  ```bash\n  pip install adam-robotics[all]\n  ```\n\nIf you want the last version:\n\n```bash\npip install adam-robotics[selected-interface]@git+https://github.com/ami-iit/ADAM\n```\n\nor clone the repo and install:\n\n```bash\ngit clone https://github.com/ami-iit/adam.git\ncd adam\npip install .[selected-interface]\n```\n\n### 📦 Installation with conda\n\n#### Installation from conda-forge package\n\n\n- Install **CasADi** interface:\n\n  ```bash\n  mamba create -n adamenv -c conda-forge adam-robotics-casadi\n  ```\n  \n- Install **Jax** interface (warning: not available on Windows):\n\n  ```bash\n  mamba create -n adamenv -c conda-forge adam-robotics-jax\n  ```\n\n- Install **PyTorch** interface (warning: not available on Windows):\n\n  ```bash\n  mamba create -n adamenv -c conda-forge adam-robotics-pytorch\n  ```\n\n- Install **ALL** interfaces (warning: not available on Windows):\n\n  ```bash\n  mamba create -n adamenv -c conda-forge adam-robotics-all\n  ```\n\n\u003e [!NOTE]\n\u003e Check also the conda JAX installation guide [here](https://jax.readthedocs.io/en/latest/installation.html#conda-community-supported)\n\n### 🔨 Installation from repo\n\nInstall in a conda environment the required dependencies:\n\n- **Jax** interface dependencies:\n\n  ```bash\n  mamba create -n adamenv -c conda-forge jax numpy lxml prettytable matplotlib urdfdom-py\n  ```\n\n- **CasADi** interface dependencies:\n\n  ```bash\n  mamba create -n adamenv -c conda-forge casadi numpy lxml prettytable matplotlib urdfdom-py\n  ```\n\n- **PyTorch** interface dependencies:\n\n  ```bash\n  mamba create -n adamenv -c conda-forge pytorch numpy lxml prettytable matplotlib urdfdom-py jax2torch\n  ```\n\n- **ALL** interfaces dependencies:\n\n  ```bash\n  mamba create -n adamenv -c conda-forge jax casadi pytorch numpy lxml prettytable matplotlib urdfdom-py jax2torch\n  ```\n\nActivate the environment, clone the repo and install the library:\n\n```bash\nmamba activate adamenv\ngit clone https://github.com/ami-iit/ADAM.git\ncd adam\npip install --no-deps .\n```\n\n## 🚀 Usage\n\nThe following are small snippets of the use of **adam**. More examples are arriving!\nHave also a look at the `tests` folder.\n\n### Jax interface\n\n\u003e [!NOTE]\n\u003e Check also the Jax installation guide [here](https://jax.readthedocs.io/en/latest/installation.html#)\n\n```python\nimport adam\nfrom adam.jax import KinDynComputations\nimport icub_models\nimport numpy as np\nimport jax.numpy as jnp\nfrom jax import jit, vmap\n\n# if you want to icub-models https://github.com/robotology/icub-models to retrieve the urdf\nmodel_path = icub_models.get_model_file(\"iCubGazeboV2_5\")\n# The joint list\njoints_name_list = [\n    'torso_pitch', 'torso_roll', 'torso_yaw', 'l_shoulder_pitch',\n    'l_shoulder_roll', 'l_shoulder_yaw', 'l_elbow', 'r_shoulder_pitch',\n    'r_shoulder_roll', 'r_shoulder_yaw', 'r_elbow', 'l_hip_pitch', 'l_hip_roll',\n    'l_hip_yaw', 'l_knee', 'l_ankle_pitch', 'l_ankle_roll', 'r_hip_pitch',\n    'r_hip_roll', 'r_hip_yaw', 'r_knee', 'r_ankle_pitch', 'r_ankle_roll'\n]\n\nkinDyn = KinDynComputations(model_path, joints_name_list)\n# choose the representation, if you want to use the body fixed representation\nkinDyn.set_frame_velocity_representation(adam.Representations.BODY_FIXED_REPRESENTATION)\n# or, if you want to use the mixed representation (that is the default)\nkinDyn.set_frame_velocity_representation(adam.Representations.MIXED_REPRESENTATION)\nw_H_b = np.eye(4)\njoints = np.ones(len(joints_name_list))\nM = kinDyn.mass_matrix(w_H_b, joints)\nprint(M)\nw_H_f = kinDyn.forward_kinematics('frame_name', w_H_b, joints)\n\n# IMPORTANT! The Jax Interface function execution can be slow! We suggest to jit them.\n# For example:\n\ndef frame_forward_kinematics(w_H_b, joints):\n    # This is needed since str is not a valid JAX type\n    return kinDyn.forward_kinematics('frame_name', w_H_b, joints)\n\njitted_frame_fk = jit(frame_forward_kinematics)\nw_H_f = jitted_frame_fk(w_H_b, joints)\n\n# In the same way, the functions can be also vmapped\nvmapped_frame_fk = vmap(frame_forward_kinematics, in_axes=(0, 0))\n# which can be also jitted\njitted_vmapped_frame_fk = jit(vmapped_frame_fk)\n# and called on a batch of data\njoints_batch = jnp.tile(joints, (1024, 1))\nw_H_b_batch = jnp.tile(w_H_b, (1024, 1, 1))\nw_H_f_batch = jitted_vmapped_frame_fk(w_H_b_batch, joints_batch)\n\n\n```\n\n\u003e [!NOTE]\n\u003e The first call of the jitted function can be slow, since JAX needs to compile the function. Then it will be faster!\n\n### CasADi interface\n\n```python\nimport casadi as cs\nimport adam\nfrom adam.casadi import KinDynComputations\nimport icub_models\nimport numpy as np\n\n# if you want to icub-models https://github.com/robotology/icub-models to retrieve the urdf\nmodel_path = icub_models.get_model_file(\"iCubGazeboV2_5\")\n# The joint list\njoints_name_list = [\n    'torso_pitch', 'torso_roll', 'torso_yaw', 'l_shoulder_pitch',\n    'l_shoulder_roll', 'l_shoulder_yaw', 'l_elbow', 'r_shoulder_pitch',\n    'r_shoulder_roll', 'r_shoulder_yaw', 'r_elbow', 'l_hip_pitch', 'l_hip_roll',\n    'l_hip_yaw', 'l_knee', 'l_ankle_pitch', 'l_ankle_roll', 'r_hip_pitch',\n    'r_hip_roll', 'r_hip_yaw', 'r_knee', 'r_ankle_pitch', 'r_ankle_roll'\n]\n\nkinDyn = KinDynComputations(model_path, joints_name_list)\n# choose the representation you want to use the body fixed representation\nkinDyn.set_frame_velocity_representation(adam.Representations.BODY_FIXED_REPRESENTATION)\n# or, if you want to use the mixed representation (that is the default)\nkinDyn.set_frame_velocity_representation(adam.Representations.MIXED_REPRESENTATION)\nw_H_b = np.eye(4)\njoints = np.ones(len(joints_name_list))\nM = kinDyn.mass_matrix_fun()\nprint(M(w_H_b, joints))\n\n# If you want to use the symbolic version\nw_H_b = cs.SX.eye(4)\njoints = cs.SX.sym('joints', len(joints_name_list))\nM = kinDyn.mass_matrix_fun()\nprint(M(w_H_b, joints))\n\n# This is usable also with casadi.MX\nw_H_b = cs.MX.eye(4)\njoints = cs.MX.sym('joints', len(joints_name_list))\nM = kinDyn.mass_matrix_fun()\nprint(M(w_H_b, joints))\n\n```\n\n### PyTorch interface\n\n```python\nimport adam\nfrom adam.pytorch import KinDynComputations\nimport icub_models\nimport numpy as np\n\n# if you want to icub-models https://github.com/robotology/icub-models to retrieve the urdf\nmodel_path = icub_models.get_model_file(\"iCubGazeboV2_5\")\n# The joint list\njoints_name_list = [\n    'torso_pitch', 'torso_roll', 'torso_yaw', 'l_shoulder_pitch',\n    'l_shoulder_roll', 'l_shoulder_yaw', 'l_elbow', 'r_shoulder_pitch',\n    'r_shoulder_roll', 'r_shoulder_yaw', 'r_elbow', 'l_hip_pitch', 'l_hip_roll',\n    'l_hip_yaw', 'l_knee', 'l_ankle_pitch', 'l_ankle_roll', 'r_hip_pitch',\n    'r_hip_roll', 'r_hip_yaw', 'r_knee', 'r_ankle_pitch', 'r_ankle_roll'\n]\n\nkinDyn = KinDynComputations(model_path, joints_name_list)\n# choose the representation you want to use the body fixed representation\nkinDyn.set_frame_velocity_representation(adam.Representations.BODY_FIXED_REPRESENTATION)\n# or, if you want to use the mixed representation (that is the default)\nkinDyn.set_frame_velocity_representation(adam.Representations.MIXED_REPRESENTATION)\nw_H_b = np.eye(4)\njoints = np.ones(len(joints_name_list))\nM = kinDyn.mass_matrix(w_H_b, joints)\nprint(M)\n```\n\n### PyTorch Batched interface\n\n\u003e [!NOTE]\n\u003e When using this interface, note that the first call of the jitted function can be slow, since JAX needs to compile the function. Then it will be faster!\n\n```python\nimport adam\nfrom adam.pytorch import KinDynComputationsBatch\nimport icub_models\n\n# if you want to icub-models\nmodel_path = icub_models.get_model_file(\"iCubGazeboV2_5\")\n# The joint list\njoints_name_list = [\n    'torso_pitch', 'torso_roll', 'torso_yaw', 'l_shoulder_pitch',\n    'l_shoulder_roll', 'l_shoulder_yaw', 'l_elbow', 'r_shoulder_pitch',\n    'r_shoulder_roll', 'r_shoulder_yaw', 'r_elbow', 'l_hip_pitch', 'l_hip_roll',\n    'l_hip_yaw', 'l_knee', 'l_ankle_pitch', 'l_ankle_roll', 'r_hip_pitch',\n    'r_hip_roll', 'r_hip_yaw', 'r_knee', 'r_ankle_pitch', 'r_ankle_roll'\n]\n\nkinDyn = KinDynComputationsBatch(model_path, joints_name_list)\n# choose the representation you want to use the body fixed representation\nkinDyn.set_frame_velocity_representation(adam.Representations.BODY_FIXED_REPRESENTATION)\n# or, if you want to use the mixed representation (that is the default)\nkinDyn.set_frame_velocity_representation(adam.Representations.MIXED_REPRESENTATION)\nw_H_b = np.eye(4)\njoints = np.ones(len(joints_name_list))\n\nnum_samples = 1024\nw_H_b_batch = torch.tensor(np.tile(w_H_b, (num_samples, 1, 1)), dtype=torch.float32)\njoints_batch = torch.tensor(np.tile(joints, (num_samples, 1)), dtype=torch.float32)\n\nM = kinDyn.mass_matrix(w_H_b_batch, joints_batch)\nw_H_f = kinDyn.forward_kinematics('frame_name', w_H_b_batch, joints_batch)\n```\n\n## 🦸‍♂️ Contributing\n\n**adam** is an open-source project. Contributions are very welcome!\n\nOpen an issue with your feature request or if you spot a bug. Then, you can also proceed with a Pull-requests! :rocket:\n\n\u003e [!WARNING]\n\u003e REPOSITORY UNDER DEVELOPMENT! We cannot guarantee stable API\n\n## Todo\n\n- [x] Center of Mass position\n- [x] Jacobians\n- [x] Forward kinematics\n- [x] Mass Matrix via CRBA\n- [x] Centroidal Momentum Matrix via CRBA\n- [x] Recursive Newton-Euler algorithm (still no acceleration in the algorithm, since it is used only for the computation of the bias force)\n- [ ] Articulated Body algorithm\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fami-iit%2Fadam","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fami-iit%2Fadam","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fami-iit%2Fadam/lists"}