You are viewing the documentation for OpenSim 3.x. Are you looking for the latest OpenSim 4.0 Documentation?
Creating a Controller
Overview
In this section, we will add to the tug-of-war example from Chapter 2 by creating a controller that will calculate excitations for the two muscles in the model. The controller we will build computes excitations that naively try to track a desired trajectory of the block in the tug-of-war model. Through this example, you will see how to implement a proportional-derivative (PD) like muscle controller to control a model using the OpenSim API.
We will build the example up in pieces. First, we will write a function that returns the desired position of the model in the z-direction (the direction of the line connecting the origins of both muscles in the ground) at a given time. Then, we will implement a PD controller that extends OpenSim's base Controller class to calculate excitations for the muscles based on the desired position of the model and the model's current state. Finally, we will connect the controller to the model to run a forward dynamics simulation that attempts to make the model follow the desired trajectory by controlling the model's muscle excitations. We can observe the final trajectory of the model to assess how well this controller is able to reproduce the model's desired motion. The resulting source code and associated files for this example come with the OpenSim 2.0 distribution under the directory:
<OPENSIM_INSTALL_DIR>\sdk\APIExamples\ControllerExample
The following sections will describe the blocks of code needed to implement this example:
OpenSim is supported by the Mobilize Center , an NIH Biomedical Technology Resource Center (grant P41 EB027060); the Restore Center , an NIH-funded Medical Rehabilitation Research Resource Network Center (grant P2C HD101913); and the Wu Tsai Human Performance Alliance through the Joe and Clara Tsai Foundation. See the People page for a list of the many people who have contributed to the OpenSim project over the years. ©2010-2024 OpenSim. All rights reserved.