Update set force functions while running a forward simulation [Matlab script]

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Ana de Sousa
Posts: 58
Joined: Thu Apr 07, 2016 4:21 pm

Update set force functions while running a forward simulation [Matlab script]

Post by Ana de Sousa » Wed Jan 09, 2019 11:44 am

Hello, I would like some help updating a force value.

I am currently running a script in Matlab with the leg6dof9musc with some adaptations:

1) I looked all coordinates, except for hip_flexion_r, knee_angle_r and pelvis_ty. So the hip and knee joints are free, also the pelvis position in the y-axis.

2) I created a torque between the pelvis and femur_r bodies:

Code: Select all

% Create torque
pelvis = osimModel.updBodySet().get('pelvis'); %get body
femur = osimModel.updBodySet().get('femur_r'); %get body
 
hip_Actuator = TorqueActuator (pelvis, femur, Vec3(0,0,-1), true);
hip_Actuator.setName('hip_torque');
hip_Actuator.setOptimalForce(100.0);

osimModel.addForce(hip_Actuator); % Add the torque to the model
3) I am also trying to create and control a Force, I created the force:

Code: Select all

% Create force
pelvis_Force = PrescribedForce(pelvis);

pelvis_Force.setName('pelvis_force');
pelvis_Force.setForceFunctions(Constant(0), Constant(250), Constant(0));

% Add the force to the model
osimModel.addForce(pelvis_Force); % Add the force to the model
With this "new" model, I am controlling the torque to generate hip movement, and the muscles (quadriceps and hamstrings) to generate knee movement.

The following step of my project is to create something similar to a "swing platform" (parachute harness?); therefore I want to apply a force that depends on the pelvis_ty. As the pelvis_ty is unlocked, if I run the system without any force, the leg falls because of gravity.

As a first trial, I added the force described above with the "Constant(250)" so it pushes the leg up. However, it is constant.

I would also like to add a contact force with the ground, so the leg would be able to also push the leg up, therefore, I would need this pelvis_force to be updated accordingly to the pelvis y-position. How may I change this ForceFunction while the Matlab is running?

For the actuator on the hip (the torque) it is easy and almost straightforward:

Code: Select all

osimModel.updActuators().get('hip_torque').addInControls(Vector(1, controlActionTorque(controlIteration)), modelControls);
where "controlActionTorque(controlIteration))" is the value to be applied at the torque.

Is there a similar way to do that for the pelvis_force? Or any other way that solves my problem?

Code: Select all

pelvis_force=osimModel.getForceSet.get('pelvis_force');
Thanks! :D

My system:
Windows 10
Matlab R2017b - student use
OpenSim 3.3

Tags:

POST REPLY