Scripting - Inconsistent muscle and ACL length compared to GUI
Posted: Mon Jul 08, 2019 2:27 am
Hi all,
I am currently trying to compute the ACL strain of the right knee ('Knee model with ligaments') via Matlab.
The procedure is to update the coordinates from a .mot file computed by the IK Tool and further to calculate the ACL length for each frame.
Since the GUI does not provide a function to calculate ACL strain, I also extract the muscle length of the biceps femoris computed by Matlab to compare with the results from the GUI.
See the code:
In Matlab, the following error appears, which is not present in the GUI:
It seems that the coordinates are updated incorrectly, but I don't know what I'm doing wrong here. I think it has also something to do with the Assembly error.
Can anyone help me with this issue?
Thanks to all and greetings from Germany,
Sven
Model:
https://simtk.org/projects/kneeligament
I am currently trying to compute the ACL strain of the right knee ('Knee model with ligaments') via Matlab.
The procedure is to update the coordinates from a .mot file computed by the IK Tool and further to calculate the ACL length for each frame.
Since the GUI does not provide a function to calculate ACL strain, I also extract the muscle length of the biceps femoris computed by Matlab to compare with the results from the GUI.
See the code:
Code: Select all
import org.opensim.modeling.*
% Import the model
model = Model('MODELDIR\ResultsScale\orth_no_simbody_tester.osim');
state = model.initSystem();
&Load the .mot file generated by IK in the GUI
motSto = Storage('FILEDIR\IKResults\orth_no_gen_02_pointed_ik.mot');
nmotSto = motSto.getSize();
timeStep=motSto.getMinTimeStep();
coords = model.getCoordinateSet();
nCoords = coords.getSize();
%Update each model coordinate for each frame
for j=1:nmotSto
for i=0:nCoords-16 % only update coordinates from right knee
coordvalue = ArrayDouble();
currentcoord = coords.get(i);
motSto.getDataColumn(currentcoord.getName(),coordvalue);
q = coordvalue.getitem(j-1);
model.updCoordinateSet().get(i).setValue(state, q);
end
model.realizePosition(state);
%%%% aACL_r %%%%
% access ligament in models forceset; get ligament length after safedowncast
aACL_r = model.getForceSet().get(0);
aACL_r_as_lig = Ligament.safeDownCast(aACL_r);
aACL_r_length(j) = aACL_r_as_lig.getLength(state);
%%%% bicfemlh_r %%%%
bifemlh_r = model.getMuscles().get(3);
bifemlh_r_length(j) = bifemlh_r.getLength(state);
end
%% Plot results
%%%% bicfemlh_r %%%%
% plot absolute length
figure
plot(bifemlh_r_length);
%%%% aACL_r %%%%
% calculate strain, plot strain and absolute length
aACL_r_L0 = aACL_r_as_lig.getRestingLength();
aACL_r_strain = (aACL_r_length-aACL_r_L0)/aACL_r_L0;
figure
plot(aACL_r_strain);
Also, ACL strains are way to high (>50%) and the length of the biceps femoris does not correspond to the GUI result (see ATTACHMENT).AssemblySolver::track() attempt Failed: SimTK Exception thrown at assembler.cpp:973:
Method Assembler::track() failed because:
Unable to achieve required assembly error tolerance.
Assembly error tolerance achieved: 2.0932349631408442e-08 required: 1e-10.
Model unable to assemble: AssemblySolver::assemble() Failed: SimTK Exception thrown at assembler.cpp:897:
Method Assembler::assemble() failed because:
Unable to achieve required assembly error tolerance.
Assembly error tolerance achieved: 2.0939234790517958e-08 required: 1e-10.
Model relaxing constraints and trying again.
It seems that the coordinates are updated incorrectly, but I don't know what I'm doing wrong here. I think it has also something to do with the Assembly error.
Can anyone help me with this issue?
Thanks to all and greetings from Germany,
Sven
Model:
https://simtk.org/projects/kneeligament