GRF in FD model
Posted: 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
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