Page 1 of 1

Unable to replicate ID in GUI with InverseDynamicsTool

Posted: Thu Aug 03, 2023 11:35 am
by finn.eagen
Hello,

I'm running into an issue with InverseDynamicsTool. I'm getting very different results from the tool in Matlab as opposed to running the GUI. The GUI returns reasonable results, but running it via the tool gives results for an entirely different time range, and force values that are multiple magnitudes too high. This is even when calling the tool with the setup file that I saved from the GUI, like so:

Code: Select all

idTool = InverseDynamicsTool("idSetup.xml");
idTool.run();
Are there setup parameters unique to the InverseDynamicsTool that I need to alter in order to replicate the results? Looking through the documentation I didn't see any but I figure I may have missed them. Any help is appreciated.

Thanks,
Finn

Re: Unable to replicate ID in GUI with InverseDynamicsTool

Posted: Thu Aug 03, 2023 11:50 am
by syretted
Hi Finn,
When I run ID through MatLab, I have set the parameters manually rather than use the setup file. Maybe there is something that is not being pulled from the file. Here's the code I use:

Code: Select all

ikStorage=Storage(fullfile(ikFilePath));
idTool=InverseDynamicsTool();
excludedForces = ArrayStr();
excludedForces.append('Muscles');
idTool.setExcludedForces(excludedForces);
idTool.setModel(model);
idTool.setCoordinatesFileName(ikFilePath);
idTool.setStartTime(ikStorage.getFirstTime());
idTool.setEndTime(ikStorage.getLastTime());
idTool.setExternalLoadsFileName(loadsFilePath);
idTool.setLowpassCutoffFrequency(6);
idTool.setOutputGenForceFileName('inverse_dynamics.sto');
idTool.set_results_directory(subdirPath);
outfile='Setup_ID.xml';
idTool.print(fullfile(subdirPath, outfile));
idTool.run();
ikfilepath is the path to my IK file, loadsFilePath is the path to my external loads, and the "print" function prints out the resulting .xml setup (not strictly necessary). You would just need to define your model somewhere above the code. Also, apparently the GUI automatically de-activates the muscles in the model, so I did this manually here. I also create the IK storage so that it can pull the first and end times from that. I don't know if that's necessary, but my code works, so there ya go.

Hope this helps!

Dan

Re: Unable to replicate ID in GUI with InverseDynamicsTool

Posted: Thu Aug 03, 2023 12:07 pm
by finn.eagen
Thanks Dan, I appreciate the code block. I'd tried something similar before and got poor results, but I saw you've used some functions I hadn't, I think importantly the start and end times. I had assumed that if it wasn't given a time, it would assume the whole range, but I see now that's wrong. Upon running it gives the correct results now. Thanks for the help. Still interesting that it was messing up when given the setup file.

Re: Unable to replicate ID in GUI with InverseDynamicsTool

Posted: Fri Aug 04, 2023 9:46 am
by aymanh
Thanks Dan for the help and Finn for reporting.

Finn, if you can post the setup file and relevant info from the data files that would be useful so we can try to give more informative messages to help troubleshooting in the future.

Best regards,
-Ayman

Re: Unable to replicate ID in GUI with InverseDynamicsTool

Posted: Mon Aug 07, 2023 10:35 am
by finn.eagen
Hi Ayman,

When I went to gather the files to upload, I ran both again and was unable to recreate the error I originally described. Running ID via matlab with the setup file is now returning the same results as from the GUI. I even tried running IDTool without specifying the start and end times, as I had mentioned, and that too returned similar results. If I happen to come across the error again I will certainly update this thread. Lesson learned for the future to better document these things when they come up haha. In the case you happen to still be interested, I have linked the relevant files.

https://drive.google.com/drive/folders/ ... sp=sharing

Thanks,
Finn