GRF in FD model

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Shivangi Giri
Posts: 51
Joined: Sun Jul 02, 2017 3:04 am

GRF in FD model

Post by Shivangi Giri » Thu Oct 12, 2023 4:21 am

Hi,
The pipeline I am following is that I calculate ID torque for each coordinate in the Rajagopal full body model and use the torques to calculate muscle excitations.
For this I have two models. One (ID model) that has no muscles and is only use to calculate the ID torques. I have been able to successfully incorporate GRF in this model and was able to perform the ID analysis (viewtopicPhpbb.php?f=91&t=16990&p=47125&start=0&view=).
Now when I pass these instantaneous torques to the FD model (model with muscles and with GRF added the way I did for the ID model), however the motion I am getting is all wrong.

The overview of the code being implemented
## Models used
ID_model = osim.Model('Rajagopal2015_noMusc.osim')
FD_model = osim.Model('Rajagopal2015.osim');

## Adding GRF to both the above models
grffile_r="grf_walk_right.mot"
grffile_l="grf_walk_left.mot"

GRF_r = osim.ExternalForce(osim.Storage(grffile_r), 'ground_force_r_v', 'ground_force_r_p','ground_torque_r_', 'calcn_r', 'ground', 'ground')
GRF_r.setName("R_GRF")

FD_model.addForce(GRF_r)

## This re-addition of source is due to a known bug
r_GRF_storage = osim.Storage('grf_walk_right.mot', False);
right_GRF_in_model = FD_model.getForceSet().get(249); #This model has 240 muscles, 3 lumbar actuators and 6 pelvis actuators. Therefore index 249 indicates to the grf right
GRF_r.safeDownCast(right_GRF_in_model).setDataSource(r_GRF_storage);
FD_model.finalizeConnections();


GRF_l = osim.ExternalForce(osim.Storage(grffile_l), 'ground_force_l_v', 'ground_force_l_p','ground_torque_l_', 'calcn_l', 'ground', 'ground')
GRF_l.setName("L_GRF")
FD_model.addForce(GRF_l)
l_GRF_storage = osim.Storage('grf_walk_left.mot', False);
left_GRF_in_model = main_model.getForceSet().get(250);
GRF_l.safeDownCast(left_GRF_in_model).setDataSource(l_GRF_storage);
FD_model.finalizeConnections();

# Now adding GRF to the ID model
GRF_r_ID = osim.ExternalForce(osim.Storage(grffile_r), 'ground_force_r_v', 'ground_force_r_p','ground_torque_r_', 'calcn_r', 'ground', 'ground')
GRF_r_ID.setName("R_GRF_ID")
ID_model.addForce(GRF_r_ID)
r_GRF_ID_storage = osim.Storage('grf_walk_right.mot', False);
right_GRF_in_IDmodel = ID_model.getForceSet().get(0);
GRF_r_ID.safeDownCast(right_GRF_in_IDmodel).setDataSource(r_GRF_ID_storage);
ID_model.finalizeConnections();

GRF_l_ID = osim.ExternalForce(osim.Storage(grffile_l), 'ground_force_l_v', 'ground_force_l_p','ground_torque_l_', 'calcn_l', 'ground', 'ground')
GRF_l_ID.setName("L_GRF_ID")
ID_model.addForce(GRF_l_ID)
l_GRF_ID_storage = osim.Storage('grf_walk_left.mot', False);
left_GRF_in_IDmodel = ID_model.getForceSet().get(1);
GRF_l_ID.safeDownCast(left_GRF_in_IDmodel).setDataSource(l_GRF_ID_storage);
ID_model.finalizeConnections()

# forloop for the simulation time duration
1. Calculating ID torque
2. calculating muscle excitation using optimization with minimized sum squared of muscle activations
3. Using a controller to assign calculated excitations to drive the FD model
4. Integrating to the next step
state.setTime(time)
manager = osim.Manager(FD_model,state)
state = manager.integrate(time[i+1])
# end of loop

I trust that GRF data will be pulled as per the time stamp. However, I am not getting the correct motion and it seems that GRF is also not being applied correctly.
Please can anyone guide me what I can check or implement?

Regards,
Shivangi
Attachments
wrong_FD.png
wrong_FD.png (169.84 KiB) Viewed 512 times

Tags:

User avatar
Mohammadreza Rezaie
Posts: 407
Joined: Fri Nov 24, 2017 12:48 am

Re: GRF in FD model

Post by Mohammadreza Rezaie » Fri Oct 13, 2023 3:00 pm

Hi, it might be due to dynamic inconsistencies. Using RRA kinematics as well as appending residual/reserve actuators may help.
https://simtk-confluence.stanford.edu:8 ... d+with+RRA

User avatar
Shivangi Giri
Posts: 51
Joined: Sun Jul 02, 2017 3:04 am

Re: GRF in FD model

Post by Shivangi Giri » Fri Oct 13, 2023 6:10 pm

Thank you for replying Mohammadreza. Yes I too was thinking on the same lines.
However, I am trying to find a way to append reserve actuators in python api. I am not using the opensim toolboxes directly therefore I am not sure how I can pass reserves actuators and get my code to fetch the amount of actuation at each instant of time as per the need.
I am using a prescribed controller to pass muscle excitations per time instant. How do I do that for reserve actuators?
Please advice. Your help is much appreciated.

Regards,
Shivangi

POST REPLY