MocoExtendProblem

A framework for writing custom Moco optimal control goals without rebuilding OpenSim.

MocoExtendProblem repository file tree

The problem

OpenSim is an open-source platform for modeling musculoskeletal structures and simulating movement. It originally used single-shooting methods; Moco added direct collocation.

Direct collocation is easiest to think about as curve fitting. You discretize the state and control trajectories across a mesh of time points and solve one large nonlinear program, with the equations of motion enforced as equality constraints between adjacent points. Rather than integrating forward through time and hoping the dynamics work out, you fit the entire trajectory at once so it satisfies the physics everywhere. For long time horizons it is far cheaper than shooting, which is why it shows up throughout computational work on biological movement.

The catch is that Moco only provides a small predefined set of optimization goals. Anything beyond them requires understanding the C++ API and either building a custom plugin or rebuilding OpenSim from source. That is a real barrier: most of the biomechanics researchers who would benefit from a novel goal have no reason to have learned to build C++ software. MocoExtendProblem exists so they can write and test one without it.

Demonstrating it

To show the framework does something useful, we generated a two-dimensional walking simulation through the MATLAB-OpenSim API. The baseline used the built-in MocoControlEffortGoal and MocoAverageSpeedGoal to produce tracking and predictive simulations of minimum-effort walking at 1.3 m/s.

Moco has no built-in gait stability goals, so we wrote three with MEP:

Stability Analysis Results

Results

Multi-objective predictive simulations using the MEP-compiled stability criteria, compared against the tracking simulation data.

Where it stands

Nothing in MEP is specific to planar gait, and we are using it in ongoing research on locomotor performance in humans and other animals. The same approach also lets you back-port a goal from a newer OpenSim version to an older one.

The paper is under review at the Journal of Open Source Software. The tools, build instructions, and simulation results are all public:

This work was supported by the National Science Foundation (BCS 2018436 and BCS 2018523).