itbellix / opensimAD

Libraries for OpenSimAD - OpenSim with support for Algorithmic Differentiation
Apache License 2.0
1 stars 0 forks source link

SimbodyAD - OpenSimAD

Libraries for SimbodyAD and OpenSimAD - Simbody and OpenSim with support for Algorithmic Differentiation.

How to generate an external function for use with CasADi?

OpenSimAD is used to formulate trajectory optimization problems with OpenSim musculoskeletal models. To leverage the benefits of algorithmic differentiation, we use CasADi external functions. In our case, the external functions typically take as inputs the multi-body model states (joint positions and speeds) and controls (joint accelerations) and return the joint torques after solving inverse dynamics. The external functions can then be called when formulating trajectory optimization problems (e.g., https://github.com/antoinefalisse/3dpredictsim and https://github.com/antoinefalisse/predictsim_mtp).

Here we provide code and examples to generate external functions automatically given an OpenSim musculoskeletal model (.osim file). Visit https://github.com/antoinefalisse/predsim_tutorial for a tutorial about how to use these external functions when formulating and solving trajectory optimization problems.

Install requirements

  1. Third-party packages
    • Windows only: Install Visual Studio
      • The Community variant is sufficient and is free for everyone.
      • During the installation, select the workload Desktop Development with C++.
      • The code was tested with the 2017, 2019, and 2022 Community editions.
    • Linux only: Install OpenBLAS libraries
      • sudo apt-get install libopenblas-base
  2. Conda environment
    • Install Anaconda
    • Open Anaconda prompt
    • Create environment (python 3.9 recommended): conda create -n opensim-ad python=3.9
    • Activate environment: conda activate opensim-ad
    • Install OpenSim: conda install -c opensim-org opensim=4.4=py39np120
      • Test that OpenSim was successfully installed:
        • Start python: python
        • Import OpenSim: import opensim
          • If you don't get any error message at this point, you should be good to go.
        • You can also double check which version you installed : opensim.GetVersion()
        • Exit python: quit()
      • Visit this webpage for more details about the OpenSim conda package.
    • (Optional): Install an IDE such as Spyder: conda install spyder
    • Clone the repository to your machine:
      • Navigate to the directory where you want to download the code: eg. cd Documents. Make sure there are no spaces in this path.
      • Clone the repository: git clone https://github.com/antoinefalisse/opensimAD.git
      • Navigate to the directory: cd opensimAD
    • Install required packages: python -m pip install -r requirements.txt

Examples

Limitations

Tutorial

Citation

Please cite this paper in your publications if OpenSimAD helps your research:

Please cite this paper in your publications if you used OpenSimAD for simulations of human walking:

Source code

The OpenSimAD libraries were compiled from here.