WELCOME TO THE NEW PLATFORM FOR THE OPENSIM DOCUMENTATION

Remember to update your bookmarks with our new URL.
If you find missing content or broken links, let us know: opensim@stanford.edu


Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 36 Next »

















OpenSim Moco is a software package for solving common problems in simulation biomechanics including tracking simulations, predictive simulations, muscle-redundancy problems, and more. Moco brings state-of-the-art direct collocation optimal control methods to the wider biomechanics community without requiring numerical expertise to solve complex problems. Moco leverages OpenSim’s existing modeling capabilities to allow you to seamlessly make the transition from model building to simulation a seamless process in your research.


The objectives of the workshop are to introduce Moco's features and how to use them and walk through two hands-on examples demonstrating how to track accelerometer signals and perform EMG-driven simulations with Moco.

Preparing for the workshop

The tutorial assumes familiarity with Matlab or Python, but experience with OpenSim or direct collocation methods is not required.

To ensure the workshop starts smoothly, please set up and test the software before the workshop. We will allocate only 5 minutes during the workshop for set up.

Software requirements

  • Windows 10 (64-bit) or Mac (macOS 10.11 or later)
  • Matlab OR Python
    • Matlab 2016b or later (64-bit). Matlab 2018a or later is best.
    • Python 3.8, NumPy 1.20.2, Matplotlib, (Optional) Spyder

Instructions

  1. Download the OpenSim 4.3 beta software from SimTK.
    1. Go to the "Download Latest Releases" dropdown menu.
    2. Choose the option labeled "OpenSim Release Betas" that matches your platform ending in win64.exe (Windows) or mac.pkg (macOS).
  2. Install OpenSim to a location of your choice; perhaps C:\OpenSim 4.3 (on Windows).
  3. If you use Windows, edit your PATH environment variable to include OpenSim’s bin directory (e.g., C:\OpenSim 4.3\bin). See here for instructions. Make sure to remove any previous OpenSim installations from your PATH.
  4. Run the OpenSim application to open the GUI.
    1. Windows: open the Start menu and click OpenSim 4.3
    2. macOS: go to Applications and click OpenSim 4.3
  5. A prompt will appear to install the OpenSim resources to a location of your choice; perhaps C:\Users\<PROFILE_NAME_HERE>\Documents\OpenSim\4.3 (on Windows; replace <PROFILE_NAME_HERE> with your Windows profile name). These resources include the workshop example files. We will refer to this directory as <RESOURCES_DIR> in the remaining instructions below.


Matlab

  1. Configure OpenSim with Matlab by starting Matlab and running configureOpenSim.m, located at <RESOURCES_DIR>\Code\Matlab .

  2. After the script completes, restart Matlab and test the configuration by checking the timestamp from running 

    org.opensim.modeling.opensimCommon.GetVersionAndDate()

     in the Matlab command window; the date should be in July 2021. Test that the visualizer is working by running the following:

    >> cd 'C:\Users\<profile>\Documents\OpenSim\4.3\Code\Matlab\Moco'
    >> exampleSlidingMass

    You should see a visualizer window appear with a sliding mass animation. Hit ESC twice to close the window.

  3. Note for OpenSim 3.3 users: You cannot concurrently use OpenSim 3.3 and 4.3 in Matlab; to switch versions you must re-run configureOpenSim.m and edit your PATH environment variable.


Python 

  1. If paths to previous OpenSim versions exist on your PYTHONPATH environment variable, remove them. (If you used OpenSim 4.2 with Python, this step is likely necessary.)
  2. Download Anaconda.
  3. Download the Anaconda environment file (conda_env_tgcs2021.yml) and place it directory of your choice; perhaps <RESOURCES_DIR>\Code\Python. This environment includes the following packages:
    1. Python 3.8
    2. NumPy 1.20.2
    3. Matplotlib
    4. Spyder (Python IDE)
  4. Open the Anaconda Prompt (terminal on macOS).
  5. Before proceeding, you may need to initialize conda for shell interaction by running

    C:\> conda init <shell-name>

    where <shell-name> is one of the following: cmd.exe (Windows default), bash (macOS default), powershell, fish, zsh, tcsh, xonsh.

  6. Navigate to the location of the Anaconda environment file. For example, if using cmd.exe on Windows:

    C:\> cd "C:\Users\<profile>\Documents\OpenSim\4.3\Code\Python"
  7. Create the environment from the file:

    C:\> conda env create -f conda_env_tgcs2021.yml
  8. Deactivate any existing environments and activate the Moco workshop environment. The prefix "opensim_moco_tgcs2021" should now appear in the Anaconda Prompt.

    (base) C:\> conda deactivate
    C:\> conda activate opensim_moco_tgcs2021
    (opensim_moco_tgcs2021) C:\>
  9. Navigate to folder sdk\Python in the OpenSim 4.3 installation; perhaps C:\OpenSim 4.3\sdk\Python (on Windows).
  10. If using Windows, first run the following:

    (opensim_moco_tgcs2021) C:\> python setup_win_python38.py
  11. Install OpenSim by running

    (opensim_moco_tgcs2021) C:\> python -m pip install .
  12. If using macOS, you may need to update the DYLD_LIBRARY_PATH to include the OpenSim and Simbody libraries:

    $ export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:<YOUR_INSTALL_DIRECTORY_HERE>/sdk/lib"
    $ export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:<YOUR_INSTALL_DIRECTORY_HERE>/sdk/Simbody/lib"

    where <YOUR_INSTALL_DIRECTORY_HERE> is the directory where you placed OpenSim installation.

  13. Once installation completes, test the configuration by checking the timestamp from running 

    (opensim_moco_tgcs2021) C:\> python
    >>> import opensim as osim
    >>> osim.GetVersionAndDate()
    >>> quit()

    in the Anaconda Prompt; the date should be in July 2021. Test that the visualizer is working by running the following

    (opensim_moco_tgcs2021) C:\> cd "C:\Users\<PROFILE_NAME_HERE>\Documents\OpenSim\4.3\Code\Python\Moco"
    (opensim_moco_tgcs2021) C:\> python exampleSlidingMass.py

    You should see a visualizer window appear with a sliding mass animation. Hit ESC twice to close the window. If you get an error about loading DLL failure check that PATH has been updated correctly before relaunching the shell.

  14. The workshop examples can be complete by using a text editor and running the scripts from the Anaconda Prompt via "python <script_name>.py". However, if you prefer using an interactive development environment (IDE) similar to Matlab, we've included the Spyder IDE in the Anaconda environment. Launch Spyder by simply running

    (opensim_moco_tgcs2021) C:\> spyder

Workshop examples

The examples for the hands-on portion of the workshop can be located in the following directories.

IMU-tracking example

(Matlab) <RESOURCES_DIR>/Code/Matlab/Moco/exampleSquatToStand/exampleIMUTracking
(Python) <RESOURCES_DIR>/Code/Python/Moco/exampleSquatToStand/exampleIMUTracking

EMG-tracking example

(Matlab) <RESOURCES_DIR>/Code/Matlab/Moco/exampleEMGTracking
(Python) <RESOURCES_DIR>/Code/Python/Moco/exampleEMGTracking

Each directory contains the example file with code portions removed that you will fill in during the workshop. There are also files ending in "_answers" that have the answers pre-filled in, if you prefer to follow along with that instead. The Python versions of the examples contain an extra file ending in "_helpers", containing helper functions for these examples; the same helper functions for the Matlab examples are located at the bottom of each example file.

OpenSim/Moco docs

View the Doxygen here.

Slides (coming soon!) and cheat sheet

Moco website

Visit the Moco website here.

Moco publication

Dembia CL, Bianco NA, Falisse A, Hicks JL, Delp SL (2020) OpenSim Moco: Musculoskeletal optimal control. PLoS Comput Biol 16(12): e1008493. https://doi.org/10.1371/journal.pcbi.1008493




  • No labels