Overview

In this chapter, we will write a main program to perform a forward dynamic simulation using the OpenSim API. We will build it up in pieces, starting from the simplest possible OpenSim model, a single block experiencing the force of gravity. In the end, we will have an OpenSim model with two muscles performing a tug-of-war on the block, with the muscles and ground reactions counteracting the gravitational force. The resulting source code and associated files for this example come with the OpenSim distribution under the directory:

<OpenSimInstallDir>\sdk\APIExamples\ExampleMain

Performing a forward dynamic simulation in OpenSim involves a series of steps. Each of these steps usually requires only a few lines of code. The following sections explain the steps by gradually developing a complete program, stopping at points where the partial program can be compiled, run, and its results visualized.

For your convenience, we have provided the source code as a series of exercise-labeled development snapshots, gradually leading up to the complete program which is called TugOfWar_Complete.cpp. After most steps, we will be using the OpenSim GUI to visualize the model and the motions that result from running the simulations. See the OpenSim User's Guide for details on using the OpenSim GUI. Each of the steps below generates output files with the same names: