MODULE 4: SYNERGY-DRIVEN VERIFICATION AND DESIGN OPTIMIZATION
In this module, you will use the Design Optimization (DO) tool with your previously generated Tracking Optimization (TO) walking simulation results to design a synergy-based FES treatment protocol for a stroke subject. You will first use Verification Optimization (VO) to sanity check your TO solution, and then you will implement cost terms in DO to modify the subject’s gait in the desired way.
Because strokes involve neural impairments, your modeled treatments will focus on modifying the synergy controls produced by TO. This contrasts with the previous project with torque-driven Treatment Optimization, where the changes in DO were primarily in the subject’s kinematics. This different treatment methodology means that the results might be a little bit less intuitive and take more effort to analyze.
Task 1: Verification Optimization
For this module task, you will use the NMSM Pipeline Verification Optimization (VO) tool to verify that the muscle synergy controls found by your Tracking Optimization (TO) produce the same walking motion and ground reactions as the TO did, but without tracking those quantities. VO will seek to minimize changes in your TO muscle synergy controls so that a dynamically consistent, periodic walking motion is produced. Results generated by your TO will provide the starting point for your VO.
VO serves as a “sanity check” for your TO results before moving further into the Treatment Optimization Process. It is possible that your TO run could have converged to a good-looking solution but had problems that will make a Design Optimization (DO) difficult. VO allows you to test that the input data that you give to DO is consistent with itself. Additionally, VO may serve as a “dry run” for your DO run. In other words, your VO run will be identical to your DO run, but without any of the design elements of the DO run. For example, in this project, we will design a new walking motion that changes synergy activations and ground reactions. As such, the VO run will look identical to the DO run, with all relevant constraints that will be used in DO, but without the cost terms that change the synergy activations and ground reactions.
A synergy-driven VO should converge in around 50 iterations, and the VO solution should look close to identical to the TO solution. In the case that your VO does not converge quickly, it is likely caused by one or more of the following:
- You added constraint terms to your VO that are inconsistent with the solution. This often leads to the optimizer going into restoration mode.
- The cost terms used in your VO somehow conflict with each other or other constraint terms
- Your TO solution itself has a problem that needs to be fixed.
Step 1: Create your VO settings file
Create a copy of
TrackingOptimization\TOSettings.xmlintoVerificationOptimization.Rename the copied file
VOSettingsTemplate.xmlOpen
VOSettingsTemplate.xmlin a text editor and change the XML headings at the top and bottom of the file from<TrackingOptimizationTool>to<VerificationOptimizationTool>Disable
<optimize_synergy_vectors>Load your post-JMP model
UF_Subject_4_Scaled_JMP.osiminto the OpenSim GUIOpen the Verification Optimization GUI
Load your settings file
VOSettings.xmlinto the Verification Optimization GUI.Set the Input Osimx File to
NeuralControlPersonalization\NCPResultsBilateral\UF_Subject_4_Scaled_JMP_gcp_mtp_mtp_ncp.osimxWarningIf the text box is red when you load the GUI in, you must re-select this file or the GUI will not be able to find it. The GUI does some basic parsing through this file to locate ground reaction force and moment names.
Set the Tracked Quantities and Initial Guess Directories to
TrackingOptimization\TOResults.Set the Results Directory to
VerificationOptimization\VOResultsSet the Surrogate Model Data Directory to
TrackingOptimization\surrogateDataClick to Cost/Constraints
Delete all cost terms except for
Upper Limb Coordinate Tracking,Pelvis Translation Tracking, andPelvis Rotation TrackingAdd the following cost and constraint terms:
Cost Terms:
Name: Synergy activation tracking
Type: controller_tracking
Components:
right_leg_1
right_leg_2
right_leg_3
right_leg_4
right_leg_5
left_leg_1
left_leg_2
left_leg_3
left_leg_4
left_leg_5
Max Allowable Error: 1
Name: Toes Coordinate Tracking
Type: generalized_coordinate_tracking
Components:
mtp_angle_r
mtp_angle_l
Max Allowable Error: 0.025
Constraint Terms:
An important part of VO is adding in constraints that will be necessary later in DO.
One such constraint is on the initial states. Because we are no longer tracking experimental joint angles and velocities, the DO solution might "cheat" by tracking the same controls but changing the initial angles and velocities to achieve a motion that minimizes the given cost function.
This obviously is not ideal, and so we constrain the initial coordinate positions and speeds to be within ± 0.01 of the tracked quantities.
Name: Initial Coordinate Deviation
Type: initial_generalized_coordinate_deviation
Components:
All coordinates in the States Coordinate List
Max/Min Error: 0.01/-0.01
Name: Initial Speed Deviation
Type: initial_generalized_speed_deviation
Components:
All coordinates in the States Coordinate List
Max/Min Error: 0.01/-0.01
Another common problem with DO runs is that they may predict motions that have ground reactions during swing phase, which is a very undesirable gait motion.
To address this, we can add constraints that force the ground reactions during swing phase to be zero.
First, we will use the GUI to add the desired constraint terms to the settings file, and then we will manually edit the settings files to add time ranges for which those constraint terms are active.
Name: Ground Reaction Forces 1 Swing Phase
Type: external_force_value
Components:
ground_force_1_vx
ground_force_1_vy
ground_force_1_vz
Max/Min Error: 1/-1
Name: Ground Reaction Forces 2 Swing Phase
Type: external_force_value
Components:
ground_force_2_vx
ground_force_2_vy
ground_force_2_vz
Max/Min Error: 1/-1
Name: Ground Reaction Moments 1 Swing Phase
Type: external_moment_value
Components:
ground_moment_1_mx
ground_moment_1_my
ground_moment_1_mz
Max/Min Error: 1/-1
Name: Ground Reaction Moments 2 Swing Phase
Type: external_moment_value
Components:
ground_moment_2_mx
ground_moment_2_my
ground_moment_2_mz
Max/Min Error: 1/-1
- Save this settings file as
VerificationOptimization\VOSettings.xml - Open
VOSettings.xmlin a text editor. - Inside your
Ground Reaction Forces 1 Swing PhaseandGround Reaction Moments 1 Swing Phase constraintterms, copy and paste the following:
<time_ranges>0.17 0.48</time_ranges>
- Inside your
Ground Reaction Forces 2 Swing PhaseandGround Reaction Moments 2 Swing Phaseconstraint terms, copy and paste the following:
<time_ranges>0.7 1</time_ranges>
The time_ranges element works with normalized time, where 0 is 0% of the gait cycle, and 1 is 100% of the gait cycle.
Run the Matlab script
VerificationOptimization\runVO.mRuntimeThis VO run will take approximately 50 iterations to converge
If the optimization enters restoration mode as explained in the previous subproject, cancel the optimization and review your settings file.
As explained earlier, the purpose of VO is to be sanity check for your TO results and DO problem formulation. Your VO results should be closely identical to your TO results. If you get VO results that are different from your TO results, you have a problem. An example of a problematic VO run is inside VOResultsFailed. You can run the code on line 9 to explore the results. You will be asked about them in the deliverables section.
Task 2: Plan the Treatment
As we analyzed during NCP in the second module, the synergies in this run all have distinct functions throughout the gait cycle. These functions and the muscles in each synergy are summarized in the table below:
| Synergy Number | Synergy Function | Primary Muscle Groups in Synergy Vector |
|---|---|---|
| 1 | Weight Acceptance | Hip Flexors, Hip Extensors |
| 2 | Propulsion | Ankle Plantarflexors |
| 3 | Propulsion/Weight Acceptance | Ankle Plantarflexors, Hip Abductors |
| 4 | Leg Swing | Hip Extensors, Hip Flexors |
| 5 | Flexion | Hip Flexors |
| Synergy Number | Right Leg Activation Magnitude | Left Leg Activation Magnitude |
|---|---|---|
| 1 | 0.30 | 0.21 |
| 2 | 0.18 | 0.22 |
| 3 | 0.18 | 0.3 |
| 4 | 0.12 | 0.17 |
| 5 | 0.22 | 0.22 |
The primary impairment for this subject occurs in right leg synergy 3, where the magnitude of synergy activation 3 is much higher on the non-paretic (left) side than on the paretic (right) side. In addition to the primary impairment, synergies 2 and 4 are moderately impaired on the right side, and synergy 1 is compensatory on the right side. Synergy 5 has the same magnitude between legs.
These synergy asymmetries manifest themselves in the ground reaction forces. Specifically, the braking and propulsive impulses are highly asymmetric between the legs. The paretic side (right) has a lower propulsive and higher braking impulse compared to the non-paretic side. The specific numbers are shown in the table below.
| Propulsive Impulse | Braking Impulse | |
|---|---|---|
| Right Leg | 5.92 | 15.64 |
| Left Leg | 18.42 | 5.35 |
Your goal for this section is to plan a treatment to simulate for this subject. Your goal is to design a treatment that eliminates the asymmetries in synergy activations and analyze how the propulsive and braking impulses respond to that treatment. For simplicity, this treatment will only involve scaling the synergy activation magnitudes, and as such, the shapes will not change. You may equalize the synergy activations using one of the following methods:
- Meet in the middle – Calculate the average magnitude of both synergy activations, and scale the larger synergy activation down to the average, and the larger synergy activation up to the average.
- Increase the smaller synergy – Scale the smaller synergy activation up to the magnitude of the larger synergy activation
- Decrease the larger synergy – Scale the larger synergy activation down to the magnitude of the smaller synergy activation
- Any combination of the above.
Your job for this task is to choose a method of equalizing synergy activations between the legs and calculate the scale factors required for your method. Fill out the following table with the scale factors you are applying to each synergy activation. The scale factors should be calculated with simple multiplications on the max magnitude of the synergy activations. If one synergy has a magnitude of 0.5 and you want it to increase to 0.75, then the scale factor is 0.75/0.5=1.5. There is no "correct" way to scale the synergies, but you should choose a method that you feel makes sense and that you can justify.
The goal of our synergy FES protocol is to make the subject more symmetric by increasing or decreasing the magnitude of synergy activations. With FES treatments, it is important to consider the subject’s limitations, and how FES can be used to change their synergies. Importantly, FES can only ever add to muscle activations. FES cannot reduce muscle activations. However, when equalizing synergy activations, we might want to reduce the magnitude of certain compensatory synergies. When planning a treatment of this type, we are making an implicit assumption that we are using FES to increase impaired synergies, and the subject will respond on their own by equalizing compensatory synergies without needing to directly stimulate those synergies. By extension, we are also assuming that the subject will be able to change their other synergies that are not being directly stimulated, which might not be true. This is a possible limitation that can only be truly studied by implementing our desired treatment on the original subject.
| Synergy | Right Leg Scale Factor | Left Leg Scale Factor |
|---|---|---|
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 5 |
Task 3: Design Optimization
Now that you have a planned treatment design that equalizes the synergy activations, you can create a DO settings file that implements your treatment design. This DO will have two components – First we will scale the synergy activations as you designed in task 2, and then we will add cost terms that equalize the propulsive and braking impulses. will be done in two stages – First, we will just scale the synergy activations as prescribed in task 2. Next, we will add cost terms for the propulsive and braking impulses that track the scaled synergy activations.
- Create a copy of
VerificationOptimization\VOSettings.xmlinto DesignOptimization. - Rename this copied file to
DOSettingsTemplate.xml. - Open
DOSettingsTemplate.xmlin a text editor and change the XML headings at the top and bottom of the file from<VerificationOptimizationTool>to<DesignOptimizationTool> - Load your post-JMP model
UF_Subject_4_Scaled_JMP.osiminto the OpenSim GUI - Open the Design Optimization GUI
- Load your settings file
DOSettingsTemplate.xmlinto the Design Optimization GUI. - Set the Input Osimx File to
NeuralControlPersonalization\NCPResultsBilateral\UF_Subject_4_Scaled_JMP_gcp_mtp_mtp_ncp.osimxWarningIf the text box is red when you load the GUI in, you must re-select this file or the GUI will not be able to find it. The GUI does some basic parsing through this file to locate ground reaction force and moment names.
- Set the Tracked Quantities and Initial Guess Directories to
VerificationOptimization\VOResults. - Set the Results Directory to
DesignOptimization\DOResults - Set the Surrogate Model Data Directory to
TrackingOptimization\surrogateData - Save this settings file as
DOSettings.xml - Open
DOSettings.xmlin a text editor. - Inside
<RCNLCostTermSet>, setSynergy Controller Trackingto false - Copy and paste the following cost terms into your
<RCNLCostTermSet>
<RCNLCostTerm name="Synergy activation tracking right 1">
<is_enabled>true</is_enabled>
<type>controller_tracking</type>
<controller_list>right_leg_1</controller_list>
<scale_factor></scale_factor>
<max_allowable_error>1</max_allowable_error>
</RCNLCostTerm>
<RCNLCostTerm name="Synergy activation tracking left 1">
<is_enabled>true</is_enabled>
<type>controller_tracking</type>
<controller_list>left_leg_1</controller_list>
<scale_factor></scale_factor>
<max_allowable_error>1</max_allowable_error>
</RCNLCostTerm>
<RCNLCostTerm name="Synergy activation tracking right 2">
<is_enabled>true</is_enabled>
<type>controller_tracking</type>
<controller_list>right_leg_2</controller_list>
<scale_factor></scale_factor>
<max_allowable_error>1</max_allowable_error>
</RCNLCostTerm>
<RCNLCostTerm name="Synergy activation tracking left 2">
<is_enabled>true</is_enabled>
<type>controller_tracking</type>
<controller_list>left_leg_2</controller_list>
<scale_factor></scale_factor>
<max_allowable_error>1</max_allowable_error>
</RCNLCostTerm>
<RCNLCostTerm name="Synergy activation tracking right 3">
<is_enabled>true</is_enabled>
<type>controller_tracking</type>
<controller_list>right_leg_3</controller_list>
<scale_factor></scale_factor>
<max_allowable_error>1</max_allowable_error>
</RCNLCostTerm>
<RCNLCostTerm name="Synergy activation tracking left 3">
<is_enabled>true</is_enabled>
<type>controller_tracking</type>
<controller_list>left_leg_3</controller_list>
<scale_factor></scale_factor>
<max_allowable_error>1</max_allowable_error>
</RCNLCostTerm>
<RCNLCostTerm name="Synergy activation tracking right 4">
<is_enabled>true</is_enabled>
<type>controller_tracking</type>
<controller_list>right_leg_4</controller_list>
<scale_factor></scale_factor>
<max_allowable_error>1</max_allowable_error>
</RCNLCostTerm>
<RCNLCostTerm name="Synergy activation tracking left 4">
<is_enabled>true</is_enabled>
<type>controller_tracking</type>
<controller_list>left_leg_4</controller_list>
<scale_factor></scale_factor>
<max_allowable_error>1</max_allowable_error>
</RCNLCostTerm>
<RCNLCostTerm name="Synergy activation tracking right 5">
<is_enabled>true</is_enabled>
<type>controller_tracking</type>
<controller_list>right_leg_5</controller_list>
<scale_factor></scale_factor>
<max_allowable_error>1</max_allowable_error>
</RCNLCostTerm>
<RCNLCostTerm name="Synergy activation tracking left 5">
<is_enabled>true</is_enabled>
<type>controller_tracking</type>
<controller_list>left_leg_5</controller_list>
<scale_factor></scale_factor>
<max_allowable_error>1</max_allowable_error>
</RCNLCostTerm>
- Inside each cost term, fill out
<scale_factor>with the scale factors you calculated in task 2. - Inside of your
<RCNLCostTermSet>, copy and paste the following cost terms:
<RCNLCostTerm name="Propulsive impulse">
<is_enabled>true</is_enabled>
<type>propulsive_impulse_goal</type>
<hindfoot_body_list>calcn_r calcn_l</hindfoot_body_list>
<error_center>10.7</error_center>
<max_allowable_error>4.3</max_allowable_error>
</RCNLCostTerm>
<RCNLCostTerm name="Braking impulse">
<is_enabled>true</is_enabled>
<type>braking_impulse_goal</type>
<hindfoot_body_list>calcn_r calcn_l</hindfoot_body_list>
<error_center>10.7</error_center>
<max_allowable_error>4.3</max_allowable_error>
</RCNLCostTerm>
a. This cost term sets a design goal for the optimization to equalize the propulsive and braking impulses between the feet. The cost term imposes that the braking and propulsive impulses for both the left and the right feet must be 10.7 Ns. The value of 10.7 was obtained by averaging the propulsive impulses between the legs before the treatment, and then assuming the braking impulses should also be equal to that number.
- Run DOSettings.xml
- After running DO, open the file
calcPropAndBrakeImpulses.xmland change the initial guess directory to be the results directory from your stage 1 DO run. Run line 11 inRunDO.mand record the calculated propulsive and braking impulses. - Edit
calcPropAndBrakeImpulses.xmland change the initial guess directory to be the results directory from your stage 2 DO run. Runline 11inRunDO.mand record the calculated propulsive and braking impulses.
Deliverables:
One purpose of VO is to diagnose potential problems with a TO solution before getting caught up in a DO run. Diagnosing problems with a TO solution is rarely straightforward, however. Inside the VO results directory named
VOResultsFailed, you can see VO results that tracked the synergy activations nearly perfectly, but did not reproduce the same joint angles, ID loads, and ground reactions. The diagnosis for this problem was that the kinetic consistency term in TO was too loose and needed to be tightened. Changing kinetic consistency in TO from 0.1 to 0.01 fixed the problem. Explain why too loose of a kinetic consistency in TO might lead to the result seen inVOResultsFailed. Remember that a kinetic consistency constraint enforces that the joint moments produced by muscles must be equal to the ID loads to within a given tolerance.Fill out the table with your synergy activation scale factors:
| Synergy | Right Leg Scale Factor | Left Leg Scale Factor |
|---|---|---|
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 5 |
- Explain and justify the method you used to decide on synergy activation scale factors.
- Fill out the table with the propulsive and braking impulses from your TO and DO runs.
| Propulsive Impulse | Braking Impulse | ||
|---|---|---|---|
| TO Results | Right Leg | ||
| Left Leg | |||
| DO Results | Right Leg | ||
| Left Leg |
- Do you think your treatment design was a success? Why or why not? If not, what do you think you could do to make it better?
- If you were to do another DO iteration to get a better treatment design, what would you change in your problem formulation?
- Given your treatment design, which synergies would you stimulate with FES, and which synergies would you assume that the subject can change on their own in response to the FES treatment?
- Do you think that your treatment design can be readily translated into a clinical synergy FES stimulation pattern? Why or why not? If not, what could you change to more accurately simulate FES for this subject?
- What are the primary limitations of this computational treatment design?