You are viewing the documentation for OpenSim 2.4. Are you looking for the latest OpenSim 4.0 Documentation?
Guide to OpenSim Workflow and Tools
Overview of the OpenSim Workflow
OpenSim has a broad range of capabilities for generating and analyzing musculoskeletal models and dynamic simulations. This chapter provides an overview of these capabilities and a list of resources to find more information about each component of the OpenSim workflow.
The OpenSim Model
One of the major goals of the OpenSim project is to provide a common platform for creating and sharing models of the musculoskeletal system. Thus, the first component of any analysis is an OpenSim model. An OpenSim model represents the dynamics of a system of rigid bodies and joints that are acted upon by forces to produce motion. The OpenSim model file is made up of components corresponding to parts of the physical system. These parts include bodies, joints, forces, constraints, and controllers.
Additional information is also available in the section on OpenSim Models. A large repository of existing models is available at SimTK.org (https://simtk.org/home/nmblmodels). This library includes models of the lower extremity, head and neck, spine, and wrist. We encourage you to contribute your own models to this library to enable other researchers to build on your work and further advance the field. For example, in a model used for simulation of human walking, the bodies represent the geometry and inertial properties of the body segments. The joints specify the articulations at the pelvis, hip, knee, and ankle joints, while a constraint could be used, for example, to couple the motion of the patella with the model’s knee flexion angle. The forces in the model include both internal forces from muscles and ligaments and external forces from interaction with the ground. Finally, the model’s controller determines the activation of muscles (e.g., computed muscle control).
Importing Experimental Data
In many cases, you will use OpenSim to analyze experimental data that you have collected in your laboratory. This data typically includes:
- Marker trajectories or joint angles from motion capture
- Force data, typically ground reaction forces and moments and/or centers of pressure
- Electromyography
See Preparing Your Data for detailed information about preparing and importing your experimental data.
Scaling
If you are using a generic model from the existing library of models, the next step is to scale the model to match the experimental data collected for your subject—functionality provided by the Scale Tool in OpenSim. The purpose of scaling a generic musculoskeletal model is to modify the anthropometry, or physical dimensions, of the generic model so that it matches the anthropometry of a particular subject. Scaling is one of the most important steps in solving inverse kinematics and inverse dynamics problems because these solutions are sensitive to the accuracy of the scaling step. In OpenSim, the scaling step adjusts both the mass properties (mass and inertia tensor), as well as the dimensions of the body segments.
See the section on Scaling for more details. Tutorial 3 - Scaling, Inverse Kinematics, and Inverse Dynamics includes an example using the Scale Tool. This tutorial is also accessible from the OpenSim application Help menu.
The Inverse Problem
OpenSim enables researchers to solve the Inverse Dynamics problem, using experimental measured subject motion and forces to generate the kinematics and kinetics of a musculoskeletal model (see figure below).
In inverse dynamics, experimentally measured marker trajectories and force data are use to estimate a model’s kinematics and kinetics.
Inverse Kinematics
The Inverse Kinematics (IK) Tool in OpenSim finds values for the generalized coordinates (joint angles and positions) in the model that best match the experimental kinematics recorded for a particular subject (see figure below). The experimental kinematics targeted by IK can include experimental marker positions, as well as experimental generalized coordinate values (joint angles). The IK Tool goes through each time step of motion and computes generalized coordinate values which position the model in a pose that "best matches" experimental marker and coordinate values for that time step. Mathematically, the "best match" is expressed as a weighted least-squares problem, whose solution aims to minimize both marker and coordinate errors.
Experimental markers are matched by model markers throughout the motion by varying the generalized coordinates (e.g., joint angles) through time. See Inverse Kinematics for full documentation on running IK in OpenSim. Tutorial 3 - Scaling, Inverse Kinematics, and Inverse Dynamics walks through an example of using Inverse Kinematics for human walking.
Inverse Dynamics
Dynamics is the study of motion and the forces and moments that produce that motion. The Inverse Dynamics (ID) Tool determines the generalized forces (e.g., net forces and torques) that cause a particular motion, and its results can be used to infer how muscles are actuated to generate that motion. To determine these internal forces and moments, the equations of motion for the system are solved with external forces (e.g., ground reaction forces) and accelerations given (estimated by differentiating angles and positions twice). The equations of motion are automatically formulated using the kinematic description and mass properties of a musculoskeletal model in Simbody™.
See Inverse Dynamics for full documentation on running ID in OpenSim. Tutorial 3 - Scaling, Inverse Kinematics, and Inverse Dynamics walks through an example of using ID for human walking.
Static Optimization
Static optimization is an extension of inverse dynamics that further resolves the net joint moments into individual muscle forces at each instant in time based on some performance criteria, like minimizing the sum of squared muscle forces. See Static Optimization for more details.
The Forward Problem
OpenSim is also capable of generating muscle-driven forward simulations of gait and other movements (see figure below).
In a forward dynamic simulation of motion, simulated muscle excitations are used to drive the motion of a model to follow some observed movement.
The Forward Dynamics Tool takes a set of controls (e.g., muscle excitations) to drive a model's motion by integrating forward in time. Typically, muscle excitations are generated using the Computed Muscle Control (CMC) Tool. As a pre-cursor to running CMC, the Residual Reduction Algorithm (RRA) is used to minimize the effects of modeling and marker data processing errors that aggregate and lead to large nonphysical compensatory forces called "residuals". Specifically, RRA alters the torso mass center of a subject-specific model and permits the kinematics of the model from inverse kinematics to vary in order to be more dynamically consistent with the ground reaction force data. Thus, the typical workflow for generating a muscle-driven simulation after importing experimental data is Scale → IK → RRA → CMC → Forward Dynamics (see figure below).
Full documentation of Forward Dynamics, the Residual Reduction Algorithm, and Computed Muscle Control is available in the respective sections.
Analyzing Simulations
Answering your research questions often requires delving deeper into the details of a simulation. Thus, OpenSim includes an Analyze Tool that allows you to estimate, for example, muscle fiber or tendon lengths during a motion, or the loads on the knee joint. The Analyze Tool enables you to analyze a model or simulation based on a number of inputs that can include time histories of model states, controls, and external loads applied to the model. The following analyses are available in OpenSim:
- Body Kinematics: Reports the spatial kinematics (position and orientation, linear and angular velocity, linear and angular acceleration) of specified bodies for the duration of the analysis.
- Point Kinematics: Reports the global position, velocity and acceleration of a point defined local to a body during a simulation.
- Muscle Analysis: Reports all attributes of all muscles (including fiber length and velocity, normalized fiber length, pennation angle, active-fiber force, passive-fiber force, tendon force, and more).
- Joint Reactions: Reports joint reaction forces. These are forces that enforce the motion of the joint. The force applied to either parent or child and expressed relative to ground, parent or child can be reported.
- Induced Acceleration: Computes accelerations caused or "induced" by individual forces acting on a model—for example, the contribution of individual muscle forces to the mass center acceleration.
- Force Reporter: Reports all forces acting in the model. For ligaments and muscles, the tension along the path is reported; for ideal actuators, the scalar force or torque is reported. For all other forces, the resultant body forces (force and moment acting at the center of mass of the body) are reported. For example, contact forces from an ElasticFoundationForce element yield the resultant body force on the contacting bodies separately, expressed in the ground frame. For constraints, the same is true, except the forces are expressed relative to the most distal common ancestor body. Whenever a constraint involves ground, this is the ground body; however, if (for example) a model of the arm has a hand with fingers touching via a point constraint, then the forces are expressed in the nearest common ancestor, which would be the palm (if modeled as a single body).
More details about the analyses available in OpenSim are available in the sections Analyses, Joint Reactions Analysis, and Induced Acceleration Analysis.
Next: Scaling
Scaling
The Scale Tool alters the anthropometry of a model so that it matches a particular subject as closely as possible. Scaling is typically performed by comparing experimental marker data to virtual markers placed on a model. In addition to scaling a model, the Scale Tool can be used to adjust the locations of virtual markers so that they better match the experimental data.
The Scale Tool is accessed by selecting Tools → Scale Model… from the OpenSim main menu bar. Like all tools, the operations performed by the Scale Tool apply to the current model.
Overview
The figure below shows the required inputs and outputs for the Scale Tool. Each is described in more detail in the following sections.
Inputs and Outputs of the Scale Tool. Experimental data are shown in green; OpenSim files (.osim) are shown in red; settings files are shown in blue.
The file names are examples that can be found in the Models/Gait2354_Simbody directory installed with the OpenSim distribution.
Settings Files
The subject01_Setup_Scale.xml file is the setup file for the Scale Tool. It contains settings, described in detail in How Scaling Works, and refers to other files that contain additional settings. These other files are listed below.
gait2354_Scale_MarkerSet.xml: Marker set for the Scale Tool. It contains the set of virtual markers that are placed on the body segments of the model.
gait2354_Scale_Tasks.xml: Inverse kinematics tasks for the Scale Tool. In addition to scaling the model, the Scale Tool moves the virtual markers on the model so that their positions match the experimental marker locations. To do this, the Scale Tool must position the model so that it best matches the position of the subject. This requires an inverse kinematics problem to be solved. This file contains the inverse kinematics tasks describing which virtual and experimental markers should be matched up during the inverse kinematics phase. The file also contains marker weights, which are relative and determine how "well" the virtual markers track experimental markers (a larger weight will result in less error between the corresponding virtual and experimental marker positions).
gait2354_Scale_MeasurementSet.xml: Measurement set for the Scale Tool. It contains pairs of experimental markers, the distance between which are used to scale the generic musculoskeletal model.
AND/OR
subject01_Scale_ScaleSet.xml: Scale set for the Scale Tool. It contains a set of manual scale factors to be applied to the generic musculoskeletal model.
Inputs
Two data files are required by the Scale Tool:
subject01_static.trc: Experimental marker trajectories for a static trial. A static trial is usually several seconds of data with the subject posed in a known static position. A segment of a regular motion file can be used as a static trial if desired, but this is not typically done. The static pose should include the subject wearing the full marker set. The marker trajectories are specified in the global frame. You can find more information about collecting and preparing motion data in the section on Preparing Your Data.
gait2354_simbody.osim: OpenSim musculoskeletal model. This generic model will be scaled to match the anthropometry of your subject.
You can also provide an additional, optional file:
subject01_static.mot: Experimental generalized coordinate values (joint angles) for a trial obtained from alternative motion capture devices or other specialized algorithms. You can specify coordinate weights in the Tasks file, if joint angles are known a priori. Coordinate weights are also relative and determine how "well" a joint angle will track the specified angle.
Outputs
The Scale Tool generates a single file:
subject01_simbody.osim: OpenSim musculoskeletal model scaled to the dimensions of the subject.
Best Practices and Troubleshooting
Data Collection and Other Preparation:
- When collecting data, take pictures of your subjects in the static pose. These pictures are valuable for evaluating the results of the Scale Tool.
- Measure subject specifics, like height, mass, body segment lengths, mass distribution (if DXA is available), and strength (if a Biodex is available). You can use this data, along with marker positions, to best match the generic model to a specific subject.
- Have your subjects perform movements to calculate functional joint centers at the hip, knee, ankle, and/or shoulders, and append the joint centers to your static trial data (see Appending Data to a Motion).
- These are just a few tips. Also review our full guide to Collecting Experimental Data.
Scale Settings:
- Rely on markers that correspond to anatomical landmarks and functional joint centers (FJC) to position and scale the generic model.
- See How to Use the Scale Tool for information about defining the measurement set for scaling and setting weights when positioning the model in the static pose.
- Some segments, like the pelvis and torso, are often best scaled non-uniformly. For example, see the torso scale settings in the section on the Scale Factors Pane in How to Use the Scale Tool.
- Review How Scaling Works for more information about Scale Settings.
Evaluating your Results:
- Scaling a model is an iterative process. Use the "preview static pose" option in the GUI. See the section on "Previewing Scale" in the How to Use the Scale Tool section for more information. After running preview, perform steps 2 to 5 described below.
- Check the "Messages" window, which has information about the results of scaling, including the overal RMS marker error and the maximum marker error.
- In general, maximum marker errors for bony landmarks should be less than 2 cm.
- RMS error should typically be less than 1 cm.
- Pay close attention to errors in the bony landmark and FJC markers when assessing the quality of your scaling results.
- Visualize the scaled model's anatomical marker positions relative to the corresponding experimental markers to see how well the model "fits" the data. Use the pictures you took to assess the results, comparing the joint angles in the "Coordinates" window to the angles you observe in the pictures.
- Do the hip, knee, and ankle angles after scaling match what you observe in the picture?
- Are there any large mismatches between experimental and model markers? Can these mismatches be explained by examining the pictures you took?
- If pictures aren't available, use what you know about a typical static pose capture. For example, the ankle angle is generally less than 5º and hip flexion angle is less than 10º.
- Again, pay close attention to errors in the landmark and FJC markers when assessing the quality of your scaling results.
- After examining the "Messages" window and performing a visual comparison, adjust the virtual markers and marker weightings to improve your results.
- Again, avoid adjusting the positions of the landmark and FJC virtual markers to match the experimental markers.
- Once you've adjusted the virtual marker positions and the scale settings, preview the new static pose. Reassess your results using steps 2 to 4 above. Once you are happy with your results, hit "Run" to generate a scaled model and adjust the virtual markers on the model to match all of the experimental markers.
Troubleshooting Tips:
- It is common to iterate through Scale and Inverse Kinematics to fine-tune segment dimensions and marker positions that yield low marker errors for the task of interest.
- Use coordinate tasks (Static Pose Weights) to set joint angles for troublesome joints that are very sensitive to how the markers are placed (commonly the ankle joint and lumbar joint). For example, if it is known that the foot is flat, an ankle angle can be provided and then the markers can be adjusted in order to match the known pose.
- If using coordinates from a motion capture system, make sure that the joint/coordinate definitions match—otherwise, you may cause more harm than good.
- The model has a built-in assumption that the global Y-axis is up. If your data doesn't fit this assumption, then consider transforming your data. You can use Previewing Motion Capture (Mocap) Data to determine the proper transform to apply.
Video Tutorials
Setting up the scale tool:
Evaluating your results:
Next: How Scaling Works
Home: Scaling
Inverse Kinematics
The Inverse Kinematics (IK) Tool steps through each time frame of experimental data and positions the model in a pose that "best matches" experimental marker and coordinate data for that time step. This "best match" is the pose that minimizes a sum of weighted squared errors of markers and/or coordinates. Obtaining accurate results from the IK Tool is essential for using later tools like Static Optimization, Residual Reduction Algorithm, and Computed Muscle Control.
To launch the IK Tool, select Tools → Inverse Kinematics from the OpenSim main menu bar.
Inverse Kinematics (IK) Tool Overview. Experimental markers are matched by model markers throughout the motion by varying the joint angles (generalized coordinates) through time.
Overview
Inputs and Outputs of the IK Tool. Experimental data are shown in green; OpenSim files (.osim) are shown in red; settings files are shown in blue.
The file names are examples that can be found in the examples/Gait2354_Simbody directory installed with the OpenSim distribution.
Inputs
The primary inputs to IK are the following files:
- subject01_simbody.osim: A subject-specific OpenSim model generated by scaling a generic model with the Scale Tool or by other means, along with an associated marker set containing adjusted virtual markers.
- subject01_walk1.trc: Experimental marker trajectories for a trial obtained from a motion capture system, along with the time range of interest.
- gait2354_IK_tasks.xml: A file containing marker weightings. As in the Scale Tool, marker weights are relative and determine how "well" the virtual markers track experimental markers (a larger weight will mean less error between virtual and experimental marker positions).
- subject01_coords.mot (optional): Experimental generalized coordinate values (joint angles) for a trial obtained from alternative motion capture devices or other specialized algorithms. You can optionally specify relative coordinate weights in the Tasks file, if joint angles are known a priori.
Outputs
- subject01_walk1_ik.mot: A motion file containing the generalized coordinate trajectories (joint angles and/or translations) computed by IK.
Best Practices and Troubleshooting
Data Collection and Other Preparation:
- When collecting experimental data, place three non-collinear markers per body segment that you want to track. You need at least three markers to track the 6-degree-of-freedom motion (position and orientation) of a body segment.
- Place markers on anatomical locations with minimum skin/muscle motion.
- These are just a few tips. Also review our full guide to Collecting Experimental Data.
Inverse Kinematics Settings:
- Weight "motion" segment markers (from a triad placed on the thigh segment, for example) more heavily than anatomical markers affixed to landmarks like the greater trochanter and the acromion, which can be helpful for scaling, but are influenced by muscle and other soft tissue movements during motion.
- Relative marker weightings are more important than their absolute values. Therefore, a weighting of 10 vs. 1 is 10 times more important, whereas 20 vs. 10 is only twice as important. Markers are not necessarily tracked better because they both have higher weightings.
- See How Inverse Kinematics Works and How to Use the IK Tool for more information about IK settings.
Evaluating your Results:
- Total RMS and maximum marker errors are reported in the "Messages" window. Use these values to guide changes in weightings or, if necessary, to redo marker placement and possibly scaling. Maximum marker error should generally be less than 2-4 cm, and RMS under 2 cm is achievable. These guidelines will vary depending on the nature of the model and the motion being examined.
- If using coordinates from a motion capture system, make sure that the joint/coordinate definitions match—otherwise, you may cause more harm than good.
- Compare your results to similar data reported in the literature. Your results from an unimpaired average adult should generally be within one standard deviation.
- If you are unsatisfied with the results, recheck the results of scaling.
Next: How Inverse Kinematics Works
Home: Inverse Kinematics
Inverse Dynamics
The Inverse Dynamics (ID) Tool determines the generalized forces (e.g., net forces and torques) at each joint responsible for a given movement. Given the kinematics (e.g., states or motion) describing the movement of a model and perhaps a portion of the kinetics (e.g., external loads) applied to the model, the ID Tool uses these data to perform an inverse dynamic analysis. Classical mechanics mathematically expresses the mass-dependent relationship between force and acceleration, F = ma, with equations of motion. The Inverse Dynamics Tool solves these equations, in the inverse dynamics sense, to yield the net forces and torques at each joint which produce the movement.
To launch the ID Tool, select Tools → Inverse Dynamics from the OpenSim main menu bar.
Overview
This figure shows the required inputs and outputs for the Inverse Dynamics Tool.
Inputs and Outputs of the Inverse Dynamics Tool. Experimental data are shown in green; OpenSim files (.osim) are shown in red; settings files are shown in blue; files generated by the workflow are shown in purple.
The file names are examples that can be found in the examples/Gait2354_Simbody directory installed with the OpenSim distribution.
Settings File
The subject01_Setup_InverseDynamics.xml file is the setup file for the Inverse Dynamics Tool. It contains settings, as described in detail in How to Use the Inverse Dynamics Tool.
Inputs
Three data files are required as input by the Inverse Dynamics Tool:
subject01_walk1_ik.mot: Motion file containing the time histories of generalized coordinates that describe the movement of the model. This file could be generated by the Inverse Kinematics Tool, or manually. The file does not need to contain values for all coordinates. The coordinates that were not specified are assumed to have default values.
subject01_walk1_grf.xml: External load data (i.e., ground reaction forces, moments, and center of pressure location). Note that it is necessary to measure and apply or model all external forces acting on a subject during the motion to calculate accurate joint torques and forces. This file includes the name of the ground reaction force data file (e.g., subject01_grf.mot) as well as the names of the bodies to which they are applied. Options to specify the forces, points of application, and torques in a global or local body frame (relative to the body to which the force is being applied) are also defined here. Details are provided in How to Use the Inverse Dynamics Tool.
subject01_simbody.osim:Â A subject-specific OpenSim model generated by scaling a generic model with the Scale Tool or by other means, along with an associated marker set containing adjusted virtual markers. The model must include inertial parameters. Note that forces such as contact, ligaments, bushings, and even muscles will be applied to the model based on the kinematic state of the model and defaults for the muscle states, unless these forces are specifically excluded in the calculation.
Outputs
The Inverse Dynamics Tool generates a single file in a folder specified in the setup file:
subject01_walk1_InverseDynamics_force.sto: Storage file containing the time histories of the net joint torques and forces acting along the coordinate axes that produce the accelerations estimated (via double differentiation) from your measured experimental motion and the external forces applied.
Best Practices and Troubleshooting
- Filter your raw coordinate data, since noise is amplified by differentiation. Without filtering, the calculated forces and torques will be very noisy.
- Compare your results to data reported in the literature. Your results should be within one standard deviation of reported values.
- Inspect results from Inverse Dynamics to check whether ground reaction forces were applied correctly or not. Are there large and unexpected forces at the pelvis? For gait, applying ground reaction forces should help reduce the forces computed by Inverse Dynamics at the pelvis.
- See How Inverse Dynamics Works and How to Use the Inverse Dynamics Tool for more information about using the Inverse Dynamics Tool.
Next: How Inverse Dynamics Works
Home: Inverse Dynamics
Static Optimization
Static optimization is an extension to inverse dynamics that further resolves the net joint moments into individual muscle forces at each instant in time. The muscle forces are resolved by minimizing the sum of squared (or other power) muscle activations.
To launch the Static Optimization Tool, select Static Optimization… from the Tools menu. The Static Optimization Tool dialog window, like all other OpenSim tools, operates on the current model open and selected in OpenSim.
Overview
The figure below shows the required inputs and outputs for the Static Optimization Tool. Each is described in more detail in the following sections.
Inputs and Outputs of the Static Optimization Tool. Experimental data are shown in green; OpenSim files (.osim) are shown in red; settings files are shown in blue; files generated by the workflow are shown in purple. To run static optimization, you use the analyze command.
The file names are examples that can be found in the examples/Gait2354_Simbody directory installed with the OpenSim distribution.
Inputs
Three files are required as input by the Static Optimization Tool:
subject01_walk1_ik.mot: Motion file containing the time histories of generalized coordinates that describe the movement of the model. This can be kinematic data (i.e., joint angles) from IK or states (i.e., joint angles AND velocities) from RRA for the time range of interest.
subject01_walk1_grf.xml: External load data (i.e., ground reaction forces, moments, and center of pressure location). Note that you must measure or model all external forces acting on a subject during the motion to calculate accurate muscle forces. The .xml file describes how to apply the measured ground reaction forces to the model during the analysis.
subject01_simbody.osim: A subject-specific OpenSim model generated by scaling a generic model with the Scale Tool or by other means, along with an associated marker set containing adjusted virtual markers. The model must include inertial parameters (segment masses, etc.).
x: The exponent for the activation-based cost function to be minimized (i.e., the criterion used to solve the muscle force distribution problem).
Outputs
The Static Optimization Tool generates three files in a specified folder:
subject01_walk1_StaticOptimization_controls.xml: Contains the time histories of muscle activations. These controls were minimized by the Static Optimization Tool.
subject01_walk1_StaticOptimization_activation.sto: Storage file containing the time histories of muscle activations.
subject01_walk1_StaticOptimization_force.sto: Storage file containing the time histories of muscle forces.
Best Practices and Troubleshooting
Static Optimization Settings:
- You can use IK or RRA results as input kinematics. If using IK results, you usually need to filter them, either externally or using the OpenSim analyze/static optimization field; if using RRA results, you usually do not have to filter.
- For gait and many other motions, you need to add (append) residual actuators to the first free joint in the model (typically the ground-pelvis joint).
- There should be one actuator for each degree-of-freedom (i.e., FX, FY, FZ, MX, MY, MZ).
- These residual actuators are required because there is dynamic inconsistency between the estimated model accelerations and the measured ground reaction forces. This inconsistency can result from marker measurement error, differences between the geometry of the model and the subject, and inertial parameters.
- Running RRA will reduce—but not eliminate—these residuals. Thus, appending actuators is still necessary.
- See How Static Optimization Works and How to Use the Static Optimization Tool for more information.
Troubleshooting:
- If the residual actuators or the model's muscles are weak, the optimization will take a long time to converge or will never converge at all.
- If the residual actuators are weak, increase the maximum control value of a residual, while lowering its maximum force. This allows the optimizer to generate a large force (if necessary) to match accelerations, but large control values are penalized more heavily. In static optimization, ideal actuator excitations are treated as activations in the cost function.
- If the muscles are weak, append Coordinate Actuators to the model at the joints in the model. This will allow you to see how much "reserve" actuation is required at a given joint and then strengthen the muscles in your model accordingly.
- If troubleshooting a weak model and optimization is slow each time, try reducing the parameter that defines the maximum number of iterations.
- Static optimization works internally by solving the inverse dynamics problem, then trying to solve the redundancy problem for actuators/muscles using the accelerations from the inverse dynamics solution as a constraint. If a constraint violation is reported, this could be a sign that the optimizer couldn't solve for muscle forces while enforcing the inverse dynamics solution.
- This likely means that there is noise in the data or there is a sudden jump in accelerations in one frame.
- In this case, you should examine the inverse dynamics solution to determine the problematic frame, and fix/interpolate the data during this portion of the motion.
Evaluating your Results:
- Are there any large or unexpected residual actuator forces?
- Find EMG or muscle activation data for comparison with your simulated activations. Does the timing of muscle activation/deactivation match? Are the magnitudes and patterns in good agreement?
Next: How Static Optimization Works
Home: Static Optimization
Residual Reduction Algorithm
The purpose of residual reduction is to minimize the effects of modeling and marker data processing errors that aggregate and lead to large nonphysical compensatory forces called residuals. Specifically, residual reduction alters the torso mass center of a subject-specific model and permits the kinematics of the model from Inverse Kinematics to vary in order to be more dynamically consistent with the ground reaction force data.
The Residual Reduction Algorithm (RRA) Tool is accessed by selecting Tools → Residual Reduction Algorithm… from the OpenSim main menu bar. Like all tools, the operations performed by the Residual Reduction Algorithm Tool apply to the current model.
Overview
The figure below shows the required inputs and outputs for performing the residual reduction algorithm. Each is described in more detail below.
Inputs and Outputs for performing residual reduction. Experimental data are shown in green; OpenSim files (.osim) are shown in red; settings files are shown in blue; files generated by the workflow are shown in purple.
Settings File
The subject01_Setup_RRA.xml file is a setup file for the RRA Tool, which specifies settings, inputs, and outputs that affect the behavior of the residual reduction algorithm, which can be defined using the GUI or by hand. Details of the settings are described in the section on using the Graphical User Interface.
The setup file identifies the actuators (i.e., the ideal residual and reserve joint actuators required by RRA) as well as the kinematic tracking tasks. Furthermore, control constraints on the actuators (to limit the maximum residual force) can be specified.
Inputs
Several files are required as input to the RRA Tool to perform residual reduction:
subject01_walk1_ik.mot: Contains the time histories of model kinematics, including the joint angles and pelvis translations.
gait2345_RRA_Tasks.xml: A tracking tasks file specifying which coordinates to track and the corresponding tracking weight (weights are relative and determine how "well" a joint angle will track the specified joint angle from IK). Two key considerations:
- Selection of kp and kv are not arbitrary; they define the behavior of the error dynamics for each q as a second-order linear system. We can write the kp and kv for the desired system behavior in terms of system poles. For a (stable) critically-damped system (real negative poles), kp = λ2 and kv = -2λ.
- This enables kinematics of joints (coordinates) for which we have high confidence (e.g., knee flexion, hip flexion) to be weighted more heavily compared to those of less confidence (e.g., hip internal rotation and ankle inversion).
gait2345_RRA_ControlConstraints.xml: Contains limits on the RRA actuators. The actuator constraints file specifying the maximum and minimum "excitation" (i.e., control signal) for each actuator. A few key considerations:
- Note that the maximum/minimum force or torque generated by an ideal actuator is the product of the maximum/minimum force and maximum/minimum excitation.
- Joint torques (and muscles) have a maximum magnitude of 1.
- Residuals have bounds exceeding their anticipated force requirement. Weightings are implicit in this description. A high optimal_force means that a large output force (torque) does not require a large control value (i.e., low cost). Conversely, residuals with low optimal force require high control values that incur higher costs.
subject01_walk1_grf.xml: ExternalLoads file specifying the measured ground reaction forces that should be applied to the model during simulation and how to apply them.
subject01_simbody.osim: A subject-specific OpenSim model generated by scaling a generic model with the Scale Tool or by other means, along with an associated marker set containing adjusted virtual markers. The model must include inertial parameters.
gait2345_RRA_Actuators.xml: Ideal joint actuators used to replace muscles. The Actuator Set specifies the residual and reserve actuators to be applied and their parameters, such as maximum/minimum force and body, joint, or location (depending on the actuator type). A few key considerations:
- Each degree-of-freedom (DOF) in the model should have an ideal torque or force (reserve) actuator. This includes the 6 DOFs of the model's base segment, which are called the "residual actuators".
- In most circumstances, these ideal joint actuators are used to replace the muscles in the model (by checking "Replace model actuators" in the Actuators tab).
- Optimal forces are the maximum output of ideal actuators (torques, linear forces). Torque (force) applied is optimal_force*control_value.
- Residual at the pelvis should be applied at the scaled COM location.
Outputs
The Residual Reduction Algorithm Tool generates the following outputs:
subject01_RRA_states.sto: Adjusted kinematics (i.e., joint angles) and corresponding model states of the simulated motion (i.e., joint angles AND velocities).
subject01_adjusted.osim (optional): A model with adjusted mass properties.
subject01_RRA_forces.sto: Actuator forces and torques (i.e., joint torques corresponding to adjusted kinematics).
subjcet01_RRA_controls.xml: Actuator excitations (i.e., control signals needed to generate actuator forces and torques).
Best Practices and Troubleshooting
RRA Settings:
- You should replace the muscles in your model with residual actuators and ideal joint actuators. Residual reduction is a form of forward dynamics simulation that utilizes a tracking controller to follow model kinematics determined from the inverse kinematics. Computed Muscle Control (CMC) serves as the controller, but without muscles, the skeleton of the model can be used to determine a mass distribution and joint kinematics that are more consistent with ground reaction forces.
- Optimal forces for residuals should be low to prevent the optimizer from "wanting" to use residual actuators (an actuator with large optimal force and low excitation is "cheap" in the optimizer cost).
- To help minimize residuals, make an initial pass with default inputs, then check residuals and coordinate errors. To reduce residuals further, decrease tracking weights on coordinates with low error. You can also try decreasing the maximum excitation on residuals or the actuator optimal force.
- Typically, you should "lock" the subtalar and mtp joints in the *.osim file.
- Make sure "use_fast_optimization_target" is false (unchecked). This allows the kinematics to be slightly adjusted to account for dynamic inconsistencies. This is the default in the settings files distributed with OpenSim or created from the GUI. See How CMC Works for a comparison of the "slow" and "fast" targets.
- The "cmc_time_window" in the settings file should be 0.001 s for RRA. This is the default in the settings files distributed with OpenSim or created from the GUI.
- See How RRA Works and How to Use the RRA Tool for more information about RRA settings.
Troubleshooting:
- Check the pelvis COM location in the Actuator files.
- If RRA is failing, try increasing the maximum excitation for residuals by orders of magnitude until the simulation runs, then try working your way back down while also "relaxing" tracking weights on coordinates.
- If residuals are very large (typically, this is greater than 2-3 times body weight, depending on the motion), there is probably something wrong with either (i) the scaled model, (ii) the IK solution, or (iii) the applied GRFs. To double-check that forces are being applied properly, visualize GRFs with IK data (you can use the Previewing Motion Capture (Mocap) Data function in the GUI).
- If there is pelvis drift and/or FY is not centered around zero, check that the body mass and force calibration are correct.
- When using the example RRA Actuators .xml file, you should note that residual forces are applied to the center of mass (COM) of the unscaled pelvis; however, if you scale the model, the COM of the pelvis can change. Although the effect may be small, you should change the location of the residual force actuators in the RRA Actuators file to correspond to the scaled pelvis COM.
Evaluating your Results:
- RMS difference in joint angle during the movement should be less than 2-5º (or less than 2 cm for translations).
- Peak residual forces should typically be less than 10-20 N. Average residuals should typically be less than 5-10 N.
- The size of residuals will depend on the type of motion being studied. For example, residuals for high-speed activities like sprinting will typically be larger than walking.
- Residuals will also be larger if there are external forces that you have not accounted for, such as a subject walking with a handrail.
- Compare the residual moments from RRA to the moments from Inverse Dynamics. You should see a 30-50% reduction in peak residual moments.
- Compare the joint torques/forces to established literature (if available). Try to find data with multiple subjects. Your results should be within one standard deviation of the literature.
The table below shows an example of threshold values used to evaluate RRA results for full-body simulations of walking and running.
Next: How RRA Works
Computed Muscle Control
The purpose of Computed Muscle Control (CMC) is to compute a set of muscle excitations (or, more generally, actuator controls) that will drive a dynamic musculoskeletal model to track a set of desired kinematics in the presence of applied external forces (if applicable).
The Computed Muscle Control Tool is accessed by selecting Tools → Computed Muscle Control… from the OpenSim main menu bar. Like all tools, the operations performed by the Computed Muscle Control Tool apply to the current model.
Overview
The figure below shows the required inputs and outputs for the Computed Muscle Control Tool. Each is described in more detail in the following sections.
Inputs and Outputs of the Computed Muscle Control Tool. Experimental data are shown in green; OpenSim files (.osim) are shown in red; settings files are shown in blue; files generated by the workflow are shown in purple.
The file names are examples that can be found in the examples/Gait2354_Simbody directory installed with the OpenSim distribution.
Settings File
The subject01_Setup_CMC.xml file is a setup file for the CMC Tool, which specifies settings, inputs, and outputs that affect the behavior of the tracking controller to determine actuator (including muscles) controls. These can be defined using the GUI or by hand. Details of the settings are described in the section on the Graphical User Interface.
The setup file identifies the actuators (i.e., the residual actuators, as required for dynamic consistency) as well as the kinematic tracking tasks. Furthermore, control constraints on the actuators (to limit the maximum residual force) can be specified.
Inputs
Several data files are required as input by the Computed Muscle Control Tool:
subject01_walk1_RRA_Kinematics_q.sto: Contains the time histories of model kinematics, including the joint angles and pelvis translations from RRA.
gait2345_CMC_Tasks.xml: The tracking tasks file specifying which coordinates to track and the corresponding tracking weight (weights are relative and determine how "well" a joint angle will track the specified joint angle from RRA).
gait2345_CMC_ControlConstraints.xml: Contains limits on model actuators, which include muscles, reserve and residual actuators. The control constraints file specifies the maximum and minimum "excitation" (i.e., control signal) for each actuator. Control constraints can also be used to enforce when certain actuators are "on" or "off" and the range in which they can operate.
subject01_walk1_grf.xml: External load data (i.e., ground reaction forces, moments, and center of pressure location). See Inverse Dynamics for more details.
subject01_simbody_adjusted.osim: A subject-specific OpenSim model generated by scaling a generic model with the Scale Tool or by other means, along with an associated marker set containing adjusted virtual markers. The model must include inertial parameters. The model should have an adjusted torso center of mass to reduce residuals.
gait2345_CMC_Actuators.xml: Contains the residual and reserve actuators, as in RRA.
Outputs
The Computed Muscle Control Tool primarily reports the necessary controls:
subject01_walk1_controls.xml: Contains the excitations to individual muscles as well as controls for any residual and/or reserve actuators.
subject01_CMC_forces.sto: Muscle forces and reserve/residual forces and torques.
For completeness, CMC outputs the state trajectories (these are joint coordinate values and their speeds, as well as muscle states such as activation and fiber length).
subject01_walk1_states.sto: Model states and muscle states of the simulated motion (i.e., joint angles AND velocities, muscle fiber lengths AND activations).
Best Practices and Troubleshooting Tips
CMC Settings:
- The reserve actuators are torques that are added about each joint to augment the actuator’s force in order to enable the simulation to run (reserves turn on when an actuator cannot produce the needed force at a given time point). To help minimize reserve torques, make an initial pass with default inputs, and then check reserves, residuals, and joint angle errors. To reduce reserves further, decrease tracking weights on coordinates with low error.
- Optimal forces for reserves should be low to prevent the optimizer from "wanting" to use reserve actuators (an actuator with a large optimal force and a low excitation is "cheap" in the optimizer cost). If larger forces are needed for a successful simulation, increase the maximum control value of residuals. The residuals will then be able to generate sufficient force, but will be penalized for doing so.
- If you are still getting high reserves for a particular degree-of-freedom during a particular time range in the simulation, it may be useful to examine more closely the muscles which span the degree-of-freedom during that time region (see TipsForDebuggingMuscleActuatedSimulations.pdf). In particular:
- Check passive muscle forces (e.g., quadriceps). Large passive forces (from large knee flexion angles) may induce active forces in the antagonistic muscles (e.g., hamstrings, gastrocnemius), which may not be desired. Passive forces cannot be controlled in CMC; they are purely a function of the whole-body kinematics of the motion. Although tempting, do not increase the maximum isometric force excessively unless you know its consequences in the muscle model. Since the passive muscle force is modeled as a function of maximum isometric force, if you increase the maximum isometric force in the hope of making your active muscles stronger, you will also be increasing the passive forces in the muscles as well, thereby not helping the situation. To decrease passive muscle forces, you want to reduce the passive muscle stiffness property of muscle (or, more specifically, increase the FmaxMuscleStrain parameter in the Thelen2003Muscle).
- Check normalized fiber length during the motion (using the Plotter Tool). Is the muscle acting at suboptimal fiber lengths (i.e., less than 0.8 or greater than 1.2) at the time where the reserves are being generated? If so, then you may consider modifying either the tendon slack length or the optimal fiber length of the muscle so that it is operating more optimally (and, thus, capable of generating a greater force) during this time in the simulation. Although many cadaver studies report the optimal fiber length of a muscle, the tendon slack length is almost never reported, even though it is especially sensitive to the operating region on the force-length curve. Small adjustments to the tendon slack lengths can, therefore, be justified in reducing the reserves on the basis that we don't have as much confidence in this value to begin with.
- You should almost always use the "fast" target for CMC. This requires the joint accelerations at each time step to be matched to the RRA results. "Fast" target should work for normal subjects; "slow" target may be needed for subjects with pathologies.
- Start CMC at least 0.03 seconds before the point where you want to start analyzing your data, as CMC requires 0.03 seconds to initialize.
- See How CMC Works and How to Use the CMC Tool for more information.
CMC Troubleshooting:
- If CMC is failing, try increasing the maximum excitation for reserves and residuals by orders of magnitude until the simulation runs, then try working your way back down while also "relaxing" tracking weights on coordinates.
Evaluating your Results:
- Peak reserve actuator torques should typically be less than 10% of the peak joint torque.
- Peak residual forces should typically be less than 10-20 N; peak residual moments, less than 75 Nm (depending on the type of motion).
- Double-check your kinematics in comparison to RRA. Generally, they should match well as long as you are using the "fast" target.
- If performing an Induced Acceleration Analysis, you should verify that reserves and residuals contribute less than 5% to the net acceleration of interest.
Compare the simulated activations to experimental EMG data (either recorded from your subject or from the literature). Activations should exhibit similar timing and magnitude to EMG data. You can also compare your muscle activations and/or forces to other simulations from SimTK or the literature.
The table below shows an example of threshold values used to evaluate CMC results for full-body simulations of walking and running.
Next: How CMC Works
Home: Computed Muscle Control
Forward Dynamics
Given the controls (e.g., muscle excitations) computed by the Computed Muscle Control (CMC) or another approach, the Forward Dynamics Tool can drive a forward dynamic simulation. A forward dynamics simulation is the solution (integration) of the differential equations that define the dynamics of a musculoskeletal model. By focusing on specific time intervals of interest, and by using different analyses, more detailed biomechanical data for the trial in question can be collected.
To launch the Forward Dynamics Tool select Forward Dynamics… from the Tools menu. The Forward Dynamics Tool dialog, like all other OpenSim tools, operates on the Current Model open and selected in OpenSim.
Overview
The figure shows the required inputs and outputs for the Forward Dynamics Tool. Each is described in more detail in the following sections.
Inputs and Outputs of the Forward Dynamics Tool. Experimental data are shown in green; OpenSim files (.osim) are shown in red; settings files are shown in blue; files generated by the workflow are shown in purple.
The file names are examples that can be found in the examples/Gait2354_Simbody directory installed with the OpenSim distribution.
Inputs
Four data files are required as input by the Forward Dynamics Tool:
subject01_walk1_controls.xml: Contains the time histories of the model controls (e.g., muscle excitations) to the muscles and/or joint torques. It is possible to specify the controls as .sto files instead, with columns corresponding to desired excitations. This file may be generated by the user, the Static Optimization Tool, or the Computed Muscle Control Tool. If no controls are provided, they are assumed to be zero for any actuators in the model.
subject01_walk1_states.sto: Contains the time histories of model states, including joint angles, joint speeds, muscle activations, muscle fiber lengths, and more. These states are used by the Forward Dynamics Tool to set the initial states of the model for forward integration. Alternately, the simulation can begin from the default pose of the model without providing initial states. Muscle states can be estimated by solving for tendon and muscle fiber force equilibrium when the Solve for equilibrium for actuator states is checked.
subject01_walk1_grf.xml: An .xml file describing the external loads applied, based (for example) on measured ground reaction forces that should be applied to the model during the simulation.
subject01_simbody_adjusted.osim: Subject-specific OpenSim model generated by scaling a generic model with the Scale Tool or by other means, along with an associated marker set containing adjusted virtual markers. The model must include inertial parameters (segment masses, etc.).
The subject01_Setup_Forward.xml file is the setup file for the Forward Dynamics Tool. It contains settings, as described in How to Use the Forward Dynamics Tool, and refers to another settings file, gait2354_CMC_Actuators.xml, which contains a set of actuators that supplement the muscles of the model. Refer to Computed Muscle Control for more details. These actuators must be included in the forward simulation so that the CMC solution can be reproduced.
Outputs
The Forward Dynamics Tool generates results in a folder specified in the setup file.
Results: Additional data can be generated and written to files by adding analyses to the Forward Dynamics Tool. These analyses are specified in the setup file (subject01_Setup_Forward.xml) and are discussed in the Analyses section.
Best Practices and Troubleshooting Tips
- Forward dynamics simulations are sensitive to initial conditions, and it is good practice to double-check that the initial conditions are appropriate for the desired simulation.
- If the Forward Dynamics Tool fails gracefully (i.e., without crashing OpenSim) or the output of the Tool drifts too much (i.e., the model "goes crazy"), shorten the interval over which the Forward Dynamics Tool runs (i.e., make initial_time and final_time closer to each other in the Forward Dynamics Tool setup dialog box or setup file). Open-loop forward dynamics tends to drift over time due to the accumulation of numerical errors during integration.
Checklist - Evaluating your Simulation
The following is a list of necessary, but not sufficient, questions for evaluating your simulation. You may not be able to answer "yes" to all of these questions, but if the answer is "no", you should be able to provide a plausible explanation to convince yourself (and reviewers) that your results are meaningful.
Scaling
- If you are using any coordinates from a motion capture system, do the definitions match your model?
- Is the maximum marker error for bony landmarks and functional joint centers less than 2 cm?
- Is the RMS error less than ~1 cm?
- Do the joint coordinates in the static pose match your knowledge about experimental data collection (comparison to photos, etc.)?
Inverse Kinematics
- If you are using any coordinates from a motion capture system, do the definitions match your model?
- Is the maximum marker error less than 4 cm?
- Is the RMS error less than ~2 cm?
- Is there data for similar motions in the literature or other past studies? Are your results within 1 standard deviation?
Inverse Dynamics
- Are there any large or unexpected forces at the pelvis (how large)?
- Is there data for similar motions in the literature or from other past studies? Are your results within 1 standard deviation?
Static Optimization
- Are there any large or unexpected residual actuator forces?
- Find EMG or muscle activation data for comparison with your simulated activations. Do the timings of muscle activations/deactivations match? Are the magnitudes and patterns in good agreement?
RRA
- Is the RMS difference between experimental and simulated joint angles less than 2-5º (or less than 2 cm for translations)?
- Are the peak residual forces less than 10-25 N? Are the RMS residual forces less than 5-15 N?
- Are the peak residual moments less than 75 Nm? Are the RMS residual moments less than 50 Nm?
- Are the residual moments reduced 30-50% compared to inverse dynamics?
- Is there joint torque data for similar motions in the literature or from other past studies? Are your results within 1 standard deviation?
CMC
- Are the peak reserve actuator torques less than 10% of the corresponding peak joint torques?
- Is the RMS difference between experimental and simulated joint angles less than 2-5º (or less than 2 cm for translations)?
- Are the peak residual forces less than 10-20 N? Are the average residual forces less than 5-10 N?
- Are the peak residual moments less than 75 Nm? Are the average residual moments less than 50 Nm?
- Find EMG or muscle activation data for comparison with your simulated activations. Do the timings of muscle activations/deactivations match? Are the magnitudes and patterns in good agreement?
Extending the Capabilities of OpenSim
Overview
OpenSim provides several mechanisms for extending its existing capabilities by either adding new model elements, computing new quantities, or computing existing quantities in a new way. For example, you may want to model the drag acting on bodies moving through a fluid, which OpenSim does not provide. Another example is being able to extract the linear and angular momenta of the model during a simulation. In order to extend OpenSim, it is important to know what functionality exists and have a sense of where to add new functionality.
Organization of OpenSim
OpenSim is built on the computational and simulation core provided by SimTK. This core includes low-level, efficient math and matrix algebra libraries, such as LAPACK, as well as the infrastructure for defining a dynamic system and its state. One can think of the system as the set of differential equations, and the state as its variables.
Empowering the computational layer is SimbodyTM, an efficient multibody dynamics solver, which provides an extensible multibody system and state. The OpenSim modeling layer maps biomechanical structures (bones, muscles, tendons, etc.) into bodies and forces so that the dynamics of the system can be computed by Simbody.
The three interface layers of OpenSim built on SimTK:
OpenSim is essentially a set of modeling libraries for building complex actuators (e.g., muscles) and other forces (e.g., contact), and enabling the motion (kinematics) of highly articulated bodies (bones). Actuators can then be controlled by model controllers (e.g., Computed Muscle Control) to estimate the neural control and muscle forces required to reproduce human movement. An analysis layer is equipped with solvers and optimization resources for performing calculations with the model and to report results. At the highest level, these blocks are assembled into specialized applications (ik.exe, forward.exe, analyze.exe) to simulate and analyze model movement and internal dynamics. The OpenSim application is a Java-based program that calls Tools, Models, and underlying computations in SimTK to provide an interactive graphical user interface (GUI).
OpenSim Model and ModelComponents
The job of an OpenSim::Model is to organize (hierarchically) the pieces (components) of a musculoskeletal system and to create a representative computational (mathematical) system that can be solved accurately and efficiently using Simbody and the flat SimTK::System framework.
Organizational Context vs. Computation
By separating the contextual organization of a model from its computational representation, OpenSim can exploit the conceptual benefits of hierarchically-organized models and software without sacrificing computational efficiency. One can then think of the system as the set of system equations, while the state is a coherent set of system variable values that satisfies the system equations. Model components know about the parts they add to the multibody system (e.g., another rigid body, a force, or a constraint) and are free to mix and match. For example, a Coordinate component knows how to access its underlying degree-of-freedom value, velocity, and even its acceleration, provided the system has been "solved" for accelerations. A Coordinate also adds different constraints to the underlying system, in the case that Coordinate is locked or if its motion is prescribed. It provides context to organize locking constraints with the Coordinates being locked, but computationally it is just another constraint equation. The Coordinate, therefore, acts to manage the bookkeeping (which degree-of-freedom, constraint, etc.) and provide an interface that has context.
OpenSim Model and its ModelComponents
All model components in OpenSim have a similar responsibility to create their underlying system representation (createSystem()). A setup() method ensures that a model is appropriately defined (e.g., a Body is being connected to a parent that exists) before creating the system. Two additional methods allow the ModelComponent to initialize the state of the system (from default properties) and also to hold the existing state in the ModelComponent's defaults. For example, a Coordinate's default may indicate that it should be locked, in which case its initState would set the state of its underlying constraint as "enabled". Similarly, after performing an analysis to find the coordinates to satisfy a static pose, calling setDefaultsFromState(state) will update the Coordinate's default values for the coordinate value from the desired state. Next time the model is initialized, it will be in the desired pose.
OpenSim Application Programming Interface (API)
In order to build custom components, it is necessary to have a general understanding of which objects (classes) are responsible for which actions/behaviors. The functions (methods) that OpenSim's public classes provide (that other applications/programs can call) define its Application Programming Interface, or API.
We have already seen four methods that a model component must implement to behave as a ModelComponent in OpenSim. This defines the ModelComponent interface. Each type of ModelComponent, in turn, specifies additional methods in order to satisfy that type of component. For example, a Force in OpenSim must implement a computeForce() method (in addition to the ModelComponent methods), a Controller must implement computeControls(), etc. The set of all Classes and their interfaces defines the OpenSim API.
The OpenSim API is undergoing rapid development and improvement. We, therefore, rely on Doxygen to automatically generate .html documentation of the latest source, which describes the classes that are available and the accessible methods. The Doxygen pages can be viewed using a web browser and are available with your OpenSim installation in: <OpenSim_Install_Dir>/sdk/doc/index.html. This provides the latest organization of the available classes where one can see the list of available controllers, for example.
Example Doxygen documentation for available controllers:
What is an OpenSim plug-in?
When creating a new component (e.g., a force controller) or a new analysis, you may want to include it in an existing model, run it with existing tools, and/or share your contribution with colleagues. An OpenSim plug-in is a way of packaging your code in a dynamically linked library so that an existing OpenSim application can recognize it, load it, and make your code "runnable". For an example of creating an analysis as a plug-in, see <OpenSim_Install_Dir>/sdk/examples/plugin.
What is an OpenSim "main" program?
A main program in C/C++ results in a standalone executable that you can run from a command prompt or by double-clicking in Windows. All C/C++ programs have a main() function, which can be as simple as printing "Hello World", or it can invoke several libraries to produce complex applications (e.g., Microsoft® Word and Excel). By including the OpenSim libraries, your main program can call the OpenSim API, and you may also include any other (C++) libraries that provide additional computational and/or visualization resources. Main programs are extremely flexible, but they are particularly useful for streamlining/automating processes independent of the GUI. For example, ik.exe, id.exe, and cmc.exe (available with the OpenSim distribution) are main programs that take setup files and perform tasks related to the OpenSim workflow. Alternatively, users have created their own main programs to systematically scale strengths of all muscles in a model, run forward simulations with their own controllers, perform design optimizations, etc. An advantage of a main program (compared to a plug-in) is that any classes you define in the project are immediately useable by your program. This can make prototyping and testing of your new component or analysis faster and easier without having to wrap, load, and call your plug-in from the GUI.
OpenSim Developer's Guide
The developer's guide provides a step-by-step example of calling the OpenSim API to build a model, including muscles and contact forces, and to perform a simulation in a main program. Please refer to the OpenSim Developer's Guide for more details.
Command-line Utilities
All of the OpenSim Tools are available as command-line utilities that take as input the same setup (or settings) file loaded into or saved from the OpenSim GUI application. For example, to perform Inverse Kinematics from the command line (the Command Prompt in Windows), one can execute the following command:
ik –S arm26_Setup_InverseKinematics.xml
Similarly, these command line arguments work for CMC or any other tool, with the complete set of command-line executables available in <OpenSim_Install_Dir>/bin. In addition to the –Setup option, there are –Help, –PrintSetup and –PropertyInfo options. Help provides this list of options. Print Setup prints a default setup file for that Tool with all available properties (XML tags) for Tool settings.
The –PropertyInfo option can be a very handy resource to obtain information about existing settings for Tools and ModelComponents, including the XML tags needed in the model and/or setup file. This is the same information listed in the "Available Objects…" panel under the Help menu in the OpenSim GUI. Executing ik –PI lists all the available classes (components, analyses, utilities and tools) available in OpenSim. For more information about a particular object, such as adding a point constraint to the model, executing
ik –PI PointConstraint
yields:
PROPERTIES FOR PointConstraint (5) 1. isDisabled 2. body_1 3. body_2 4. location_body_1 5. location_body_2
The information returned lists the properties for defining a point constraint in OpenSim.
MATLAB Utilities for Data Import
There are several MATLAB® scripts for reading .trc, .c3d, .mot, and .sto files into MATLAB and writing out the data file formats required by OpenSim. Scripts provided by the Neuromuscular Biomechanics Lab at Stanford University are available on the OpenSim Utilities project on SimTK.org: https://simtk.org/home/opensim-utils. Additional utilities by OpenSim users are posted on SimTK.org and can be found using the search tool on SimTK.org.
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.