rcnl-org / nmsm-core

Neuromusculoskeletal Modeling (NMSM) Pipeline codebase
https://nmsm.rice.edu
Other
17 stars 3 forks source link

Should IK settings file be required for all tasks? #47

Closed cvhammond closed 2 years ago

cvhammond commented 2 years ago

It was suggested by @bfregly that we require an IK settings file (<ik_settings_file> for each task. This would remove the need for a <time_range> and <marker_file_name> element at the task level because they can be inferred from the IK settings file.

I think this boils down to: do we expect most/all of the GUI simulations to have done an IKSolver round before JMP and will they likely have a IK settings file already? If so, we should implement this change.

cvhammond commented 2 years ago

Written by @bfregly:

Jason,

I am glad that we are discussing this issue now, as it highlights that there is a higher-level issue that we need to resolve first before we can answer the immediate question of whether or not to require a pre-existing IK settings file for Joint Model Personalization.

Whatever we decide, we want the design of our four modules for model personalization to be:

Self-consistent with each other in terms of how inputs and outputs are defined, and
Consistent with OpenSim to the extent possible.

Based on the information provided by Marleny, it appears that Joint Model Personalization is the ONLY model personalization module that could make use of an OpenSim .xml settings file. Since all of the other model personalization modules do not require any OpenSim settings file, I think it would be best for Joint Model Personalization not to require one either. Otherwise, Joint Model Personalization would require two settings files - an OpenSim settings file and an NMSM settings file. Since we will set all marker tracking weights to one during Joint Model Personalization anyway, and since we can extract which markers to track from the list of joints being calibrated (the list will contain the markers on the proximal and distal segment of each joint being calibrated), the marker tracking weights in an OpenSim IK settings file won't matter anyway.

I am now asking myself the question of whether any of the other model personalization modules will require an OpenSim settings file to run standard OpenSim analyses repeatedly. If we stick with the design philosophy that the user has to pre-generate and pre-process all the necessary input data to get it into shape for a module to do its job, then I don't think any of the other three modules would need an OpenSim settings file of any kind (Mohammad - please correct me if I am wrong). We will make users run their own Inverse Kinematics, Inverse Dynamics and Muscle Analyses to generate the inputs needed for Muscle-tendon Model Personalization, Ground Contact Model Personalization, and Neural Control Model Personalization. So what makes Joint Model Personalization different is that an explicit OpenSim analysis has to be run repeatedly as part of the module's calibration process (Oops! Maybe I am wrong here. I guess for Ground Contact Model Personalization, we have to run an OpenSim Point Kinematics analysis over and over as we tweak the motion of the feet and get updated positions and velocities of all the spring elements under each foot. I'll verify with Marleny that this is the case.)

The main challenge I see with eliminating the OpenSim IK settings file is the coordinates functionality. People need to use the coordinates functionality to a) impose motion on certain joints motions measured by some other means (e.g., knee motion measured using dynamic x-ray methods), or b) keep a joint near a certain angle (e.g., keep the lower back joint in a slightly flexed position rather than snapping back and forth between slightly flexed and slightly extended). So my current inclination is to include those capabilities in our JMP module. We could kill two birds with one stone simply by adding a field like in an IK settings file. If the user wants the coordinate to remain constant for all time, then the user would simply create a file where the coordinate had the same value for all time. That way, no special functionality would be needed to get a coordinate to stay close to a specified constant value (the OpenSim IK GUI has extra functionality for tracking coordinates compared to tracking markers).

Adding coordinate tracking will require an addition to our cost function. Starting out, I would suggest simply adding coordinate error terms to the cost function identical to how we include marker error terms in the cost function. That way, coordinate tracking errors would be equally weighted with marker tracking errors. After we try some examples (I have some Knee Grand Challenge data with dynamic x-ray measurement of knee motion) that I can use to test out the combined cost function. Note that coordinate tracking will matter only in situations where multiple joints are being calibrated at the same time (e.g., if the ankle and hip are being calibrated while the knee motion uses tracked coordinates). It may be necessary to make the user input a that would force JMP to track specified coordinates more accurately than markers.

Given all of these observations, I propose that we do NOT read in an OpenSim IK settings file when doing JMP and instead read in the following IK settings information using our own JMP settings file:

(default is Inf - not sure how this is used, but probably for closed kinematic chains) (which markers and coordinates to track, and what weight to put on each tracked quantity - we don't need this) Let me know what you think of this proposed path forward. I am putting this entire e-mail thread on GitHub as an issue. B.J. On Tue, Nov 23, 2021 at 10:35 PM Jason Hammond jph9@rice.edu wrote: Dr. Fregly, Attached is the version of a JMP Settings file that I'm using for the simulations right now. FYI the optimizer options (diff_min_change, optimiality_tolerance, function_tolerance, step_tolerance, max_function_evaluations) don't work, but accuracy does. Regarding your comments, should we require the use of an IK Settings file, or still allow people to simply pass a marker file and time range and set all marker weights to one by default? If we require everyone to include an IK Settings file then we should remove the time_range and marker_file_name elements. Doing that (requiring an IK Settings file) would clean up the JMP Settings file pretty nicely. I also noted an issue with 'accuracy' overlap between IK Settings and JMP Settings files. Also, the IK Settings file element is called (see attached file). The 'InverseKinematicsTool.populateReferences()' function should be taking the coordinate file from the element of the IK Settings file if it is included, but this functionality has not been tested yet. I will write up (or you can) new GitHub issues regarding the points you made so I can fix them in the next couple days. If you are looking to run some of your own tests on JMP, it's a little scattered right now, but I'll clean it up a little tomorrow and let you know when the 'main' branch is usable. I can also include a working example (not a MATLAB Live Script) in the /examples/JointModelPersonalization directory. Let me know what you think. Jason On Tue, Nov 23, 2021 at 9:55 PM B.J. Fregly wrote: Jason and Mohammad, I was updating my JMP settings file where I keep track of how the file should work, and I made an interesting realization. The one item I forgot in the first pass was the name of the IK settings file that a Task in the TaskSet should use. If you look in an IK settings file (example attached), you will see that it contains the following information that is also in our JMP settings file: r_ankle_markers.trc 0.1 1.1 FYI, in an IK settings file, is called just . For each , since we now specify an (not sure what we decided to call it), should we remove and from our JMP settings file and suck them out of the specified IK settings file instead? Also note that an IK settings file has a field for , which is sometimes used to step a coordinate from flipping back and forth in "snap through" situations (which I have had to do for the lower back joint). So we should make sure that if an IK settings file specifies a to use, we will read in that file and use it for the repeated IK analyses. B.J.
cvhammond commented 2 years ago

It was decided in a group meeting on 12/2/21 that we will not include ik_settings files because no assumptions can be made on the confidence of the markers on the distal or proximal bodies, thus all marker weights should be 1 if on the proximal or distal body and 0 otherwise.