Skip to main content

Tracking Optimization

Tutorial Developers: Robert Salati, B.J. Fregly, Rice Computational Neuromechanics Lab, Rice University

Last Updated: 3/10/2026

For this step in the soccer kicking example, you will use the Tracking Optimization (TO) tool to fit synergy controls that reproduce the experimental motion with and without a ground contact model. As mentioned in previous sections, this motion was cropped so that it starts right after the subject jumps off the ground, and ends when the subject kicks the ball. Only the left foot is in contact with the ground, and so we only need a ground contact model forthe left foot.

This tutorial will use the same previously calibrated OpenSim model Kicking_Model_JMP.osim

The data used in this tutorial are in preprocessed and are the same as the previous tutorial.

info

The NMSM Pipeline is set up so that you can process your data early on and then the same data can be used for the rest of the tools. It is important that you maintain the structure of the preprocessed folder or it will not parse properly.

Setting up a TO settings file

We will first set up a settings file that uses a GCP calibrated foot-ground contact model.

  1. Activate the NMSM GUI in OpenSim by navigating to Tools>User Plugins, and click rcnlPlugin.dll.
  2. With Walking_Model_jmp.osim selected in the OpenSim GUI, navigate to Tools>Treatment Optimization>Tracking Optimization.
  3. Set the Osimx file to Kicking_Model_jmp_gcp_ncp.osimx
  4. Set the intial guess directory to NCPResults We use NCP results as the initial guess for synergy-driven TO so that it can parse an initial guess for synergy activations.
  5. Set the tracked quantities directory to preprocessed
  6. Set the trial prefix to drive_kick1
  7. Set the results directory to TOResultsContact
  8. Set the optimal control solver settings file to gpopsSettings.xml
  9. Set your states coordinate list to pelvis_tilt pelvis_tx pelvis_ty hip_flexion_r knee_angle_r ankle_angle_r hip_flexion_l knee_angle_l ankle_angle_l lumbar_extension arm_flex_r arm_flex_l These are all the saggital plane coordinates.
  10. Go to the RCNL Controllers Tab
  11. Check Optimize Synergy Vectors
  12. Set the coordinate list to hip_flexion_r hip_adduction_r hip_rotation_r knee_angle_r ankle_angle_r subtalar_angle_r
  13. Set the surrogate model data directory to surrogateData
  14. Go to the Cost/Constraints tab
  15. Add the following cost terms:
Name: Generalized_Coordinate_Rotation_Tracking
Type: generalized_coordinate_tracking
Component list:
pelvis_tilt
hip_flexion_r
knee_angle_r
ankle_angle_r
hip_flexion_l
knee_angle_l
ankle_angle_l
lumbar_extension
arm_flex_r
arm_flex_l
Max allowable error: 0.3491
Name: Generalized_Coordinate_Translation_Tracking
Type: generalized_coordinate_tracking
Component list:
pelvis_tx
Max allowable error:
0.01
Name: Generalized_Speed_Rotation_Tracking
Type: generalized_speed_tracking
Component list:
pelvis_tilt
hip_flexion_r
knee_angle_r
ankle_angle_r
hip_flexion_l
knee_angle_l
ankle_angle_l
lumbar_extension
arm_flex_r
arm_flex_l
Max allowable error: 3.491
Name: Generalized_Speed_Translation_Tracking
Type: generalized_speed_tracking
Component list:
pelvis_tx
Max allowable error: 0.1
Name: Inverse_Dynamic_Load_Tracking
Type: inverse_dynamics_load_tracking
Component list:
hip_flexion_r_moment
knee_angle_r_moment
ankle_angle_r_moment
Max allowable error: 20
Name: Muscle_Activation_Tracking
Type: muscle_activation_tracking
Component list:
bflh_r
bfsh_r
gasmed_r
glmax2_r
iliacus_r
recfem_r
soleus_r
tibant_r
vasmed_r
Max allowable error: 0.1
Name: Synergy_Activation_Tracking
Type: controller_tracking
Component list:
RightLeg_1
RightLeg_2
RightLeg_3
RightLeg_4
Max allowable error: 0.1
Name: Synergy_Vector_Tracking
Type: synergy_vector_tracking
Component list:
RightLeg_1
RightLeg_2
RightLeg_3
RightLeg_4
Max allowable error: 0.1
  1. Add the following constraint terms
Name: Kinetic_Consistency
Type: kinetic_consistency
Component list:
hip_flexion_r_moment
knee_angle_r_moment
ankle_angle_r_moment
Max error: 0.1
Min error: -0.1
Name: Residual_Load_Reduction
Type: root_segment_residual_load
Component list:
pelvis_tilt_moment
pelvis_tx_force
pelvis_ty_force
Max error: 1
Min error: -1
  1. Save this settings file as TOSettingsContact.xml
  2. Open TOSettingsContact.xml in a text editor and copy and paste the following fields in
<synergy_vector_normalization_value>0.5</synergy_vector_normalization_value>
<maximum_allowable_synergy_activation>3</maximum_allowable_synergy_activation>
Question

How does the contact model get included in the TO settings file?

Expand for answer
The contact model is contained entirely in the Osimx file. If you include an Osimx file in your settings file which has the required fields for a contact model, it will be included in your TO run. It's that easy!

Running TO

Open runTOTool.m in Matlab and click run

Runtime

This TO run takes 46 iterations to finish.

Analyzing TO Results

Plots should be automatically created by the runTOTool.m script.

Questions
  • Did the ground contact model produce accurate ground reaction forces? Note that we did not track the ground reactions at all.
  • Why did we not reduce the pelvis_tz_force residual load?

TO without contact

Next, you can try a TO run without contact. Because the contact model is entirely contained in the Osimx file, you can just change the Osimx file in your settings to Kicking_Model_jmp_ncp.osimx. Next, you need to disable the residual load reduction constraint.

Question

Why do we need to turn off the residual load reduction constraint?

Expand for answer

Because we are getting rid of the contact model, there are always going to be some residual loads that we cannot get rid of. However, we can still apply a residual reduction constraint while the model is out of contact in the air.

For the sake of the tutorial, you can also get rid of all model coordinates in your settings file except for hip_flexion_r knee_angle_r ankle_angle_r.

Your cost terms will thus be:

Name: Generalized_Coordinate_Rotation_Tracking
Type: generalized_coordinate_tracking
Component list:
hip_flexion_r
knee_angle_r
ankle_angle_r
Max allowable error: 0.3491
Name: Generalized_Speed_Rotation_Tracking
Type: generalized_speed_tracking
Component list:
hip_flexion_r
knee_angle_r
ankle_angle_r
Max allowable error: 3.491
Name: Inverse_Dynamic_Load_Tracking
Type: inverse_dynamics_load_tracking
Component list:
hip_flexion_r_moment
knee_angle_r_moment
ankle_angle_r_moment
Max allowable error: 20
Name: Muscle_Activation_Tracking
Type: muscle_activation_tracking
Component list:
bflh_r
bfsh_r
gasmed_r
glmax2_r
iliacus_r
recfem_r
soleus_r
tibant_r
vasmed_r
Max allowable error: 0.1
Name: Synergy_Activation_Tracking
Type: controller_tracking
Component list:
RightLeg_1
RightLeg_2
RightLeg_3
RightLeg_4
Max allowable error: 0.1
Name: Synergy_Vector_Tracking
Type: synergy_vector_tracking
Component list:
RightLeg_1
RightLeg_2
RightLeg_3
RightLeg_4
Max allowable error: 0.1

Save this new settings file as TOSettings.xml Run this settings file in runTOTool.m

Runtime

This TO run takes 31 iterations to finish.

For runtime sake, we will do the rest of the Treatment Optimization process without a contact model.