How to record the errors output using InverseKinematicsTool in python

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Hongyuan Chen
Posts: 8
Joined: Wed Mar 20, 2024 6:37 pm

How to record the errors output using InverseKinematicsTool in python

Post by Hongyuan Chen » Tue Jul 23, 2024 4:15 am

I am trying to using the python and opensim4.5 to do the IK with python. The following sentences is written:

Code: Select all

import opensim as osim
model = osim.Model('mypath/model.osim')
state = model.initSystem()
ik_tool = osim.InverseKinematicsTool()
ik_tool.setModel(model)
ik_tool.setMarkerDataFileName(trc_file_path)
ik_task_set=osim.IKTaskSet(xml_file_path)
ik_tool.set_IKTaskSet(ik_task_set)
ik_tool.setOutputMotionFileName(mot_file_path)
ik_tool.setStartTime(0.0)  
ik_tool.setEndTime(float(99 * Decimal('0.005')))  
ik_tool.run()
The terminal will show the error like below:

Code: Select all

[info] Frame 60 (t = 0.3):       total squared error = 0.000647981, marker error: RMS = 0.00804972, max = 0.0152582 (R.Bicep)
In Opensim 4.5 API documentary, I can't find a function that could set the error message file name ('.sto') which could be created if I use the Opensim GUI.
Could anyone could help me to solve the problem? (Note: I have tried to track the info printed in the terminal, but failed)

Tags:

User avatar
Aaron Fox
Posts: 293
Joined: Sun Aug 06, 2017 10:54 pm

Re: How to record the errors output using InverseKinematicsTool in python

Post by Aaron Fox » Tue Jul 23, 2024 3:58 pm

Hi Hongyuan,

I've noticed running IK in Python that the marker error info gets output to a generic '_ik_marker_errors.sto' file by default in the directory of wherever your code is being run from. I typically add a line of code after running IK that moves and renames this file to where I want it.

Aaron

User avatar
Hongyuan Chen
Posts: 8
Joined: Wed Mar 20, 2024 6:37 pm

Re: How to record the errors output using InverseKinematicsTool in python

Post by Hongyuan Chen » Tue Jul 23, 2024 7:09 pm

Thank you so much Aaron,

I've noticed the '_ik_marker_errors.sto' file in directory of my python file. I used to think it will appear in the folder of my model. By following your way, I've succeeded in recording the errors output.

Hongyuan

POST REPLY