Static and Dynamic Optimization via Matlab

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Lars van Rengs
Posts: 16
Joined: Sat Jan 08, 2022 7:21 am

Static and Dynamic Optimization via Matlab

Post by Lars van Rengs » Tue Jan 17, 2023 10:09 am

Hi OpenSim experts,

We aim to compare several biomechanical parameters (muscle forces, joint contact forces, etc.) between different running speeds. To this purpose we are using dynamic optimization (DO) in Matlab (CasADi optimization; De Groote 2016) to determine muscle forces over a period of steady-state running. However we encountered an issue when we performed the JRA. Specifically, we noticed that the muscle forces determined with DO are not included in the calculation of the joint contact forces because loading a TendonForce-file with the computed muscle forces from DO gives exactly the same ankle contact force as loading a TendonForce-file with the muscle forces multiplied by 0.1. As a result, our ankle contact force is ~2.7x body weight, which is substantially lower than the 10.7x BW reported by Edwards (2008) at a similar running speed. When we manually sum the muscle forces with the ankle contact force from the JRA tool, we do obtain a similar value of ~11x BW.

Note that we obtained similar results when we manually loaded the muscle forces from DO in the JRA tool in the OpenSim GUI and subsequently computed the ankle contact force, thus it is not a Matlab issue perse. We therefore thought that this issue could be caused by the use of DO instead of Static Optimization (SO) and therefore also performed the JRA analysis with muscle forces derived from SO. This yielded values comparable to published values.

While the muscle forces differ between DO and SO, we noticed another more important difference that explains why the JRA output is not correct when using the DO output. Specifically, after running the SO-tool in OpenSim we noticed that not only the muscle forces (80 columns) were saved to the force_file, but also the lumbar ext/bend/rot (3 columns), reserve_Actuators (31 columns), and external loads (18 columns) were saved. In contrast, when we performed the DO (or SO) in Matlab, most of these output were not saved to the force_file output. For example, we only have the time and muscle forces of the DO-output (nColumns = 81), and therefore we were wondering how to get the values for the lumbar ext/bend/rot, reserve_Actuators, and external loads in the force_file of the DO-output (and also SO-output) in Matlab so we can load all variables in the JRA tool to correctly compute joint contact forces?

Note that we did think of the possibility to run the SO for all trials, and only overwrite the muscle forces from the SO output with the DO output and then load this file into the JRA tool. However, this is problematic for the following reasons:

- First, the contribution of the reserve actuators likely differs between the DO and SO, and this may influence the computed contact forces?
- Second, when we perform the SO in Matlab, some outputs are also missing, which therefore also produced incorrect results in the JRA tool.

This therefore suggests that the only options are 1) to obtain the missing values from Matlab, or 2) manually perform the SO in the OpenSim GUI. Of course, the latter is very time-consuming and not preferred. Moreover, we noticed that the computed muscle forces differ between the SO ran in OpenSim and Matlab (See figure below). Since we now have two options for SO (SO in Matlab and SO-tool OpenSim), we are wondering which of these methods should produce the most accurate results and why do they differ?
Muscle forces - gasmed_r + recfem_r + vasmed_r.png
Muscle forces - gasmed_r + recfem_r + vasmed_r.png (80.03 KiB) Viewed 679 times

Tags:

User avatar
James Cowburn
Posts: 4
Joined: Tue Sep 27, 2016 8:26 am

Re: Static and Dynamic Optimization via Matlab

Post by James Cowburn » Wed Jan 18, 2023 2:46 am

Hi Lars,

I have previously done something very similar to you whereby I performed a DO using CasADi and De Groote's/Falisse's formulations in matlab, and subsequently performed JRA to obtain JRF.

I wrote functions to write the muscle forces, reserve actuators, and net joint moments of the torque driven DoFs into one .sto file, and then another to write the external loads (i.e. GRFs) to .sto file for calling within an External_Loads.xml file. I then constructed an instance of the AnalyzeTool with a Joint Reaction Analysis and called the actuator.sto file as a forces file within the analysis and the External_Loads.xml within the tool. I have included a zip file with the function inside and example .sto/.xml files, which will hopefully save you some time. The top of each function has a brief explanation of what the inputs are, although it has been at least a year or more since I have used them so haven't had chance to double check them. At the very least it will give you something to compare with your functions/files.

I can't speak to the differences between SO in matlab and the OpenSim GUI, so perhaps someone else could shed some light on that.

cheers,

James
Attachments
ExampleMatlabFunctions.zip
(8.83 KiB) Downloaded 63 times

User avatar
Lars van Rengs
Posts: 16
Joined: Sat Jan 08, 2022 7:21 am

Re: Static and Dynamic Optimization via Matlab

Post by Lars van Rengs » Wed Jan 18, 2023 10:05 am

Hi James,

First of all, thank you for your quick response. We have looked at both scripts, however, unfortunately we have not yet been able to fully use them to solve our problem.

We had previously managed to create the xml file of the External Loads, however, we would like to get the raw data output from this and not just the settings file (fx, fy, fz, px, py, pz, torque_x, torque_y, torque_z appended to calcn_r and calcn_l).

The other script could possibly be useful for us, however we don't fully understand it yet since it is only the function of making a sto-file. We previously succeeded in creating a sto-file of the data from the DO ourselves. However, we now have only time and muscle forces in this sto-file. However, the script does not indicate from where the data of the reserve actuators, residual actuators and external loads is called from the DO output, while this is exactly what we need.

If you could possibly have some time to look into this, we would greatly appreciate it.

Thanks in advance!

User avatar
Lars van Rengs
Posts: 16
Joined: Sat Jan 08, 2022 7:21 am

Re: Static and Dynamic Optimization via Matlab

Post by Lars van Rengs » Fri Feb 03, 2023 8:39 am

Hi,

Meanwhile, we have solved part of our problem. We now managed to implement the DO output into the JRA. For this, we basically, like James, paste the muscle forces into the SO force file. However, we did some comparisons and found that it makes no difference at all which data is in the columns for lumbar ext/bend/rot (3 columns), reserve actuators (31 columns), and external loads (18 columns). Regardless of whether this contains the original SO data or whether these columns are filled with all zeros, the output of the JRA remains the same.

As for the difference between the SO in Matlab and OpenSim, we have not yet figured out what causes this. However, for our study, we therefore basically don't need the SO anymore, since we can now use the DO output in the JRA.

POST REPLY