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
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
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);
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');
My system:
Windows 10
Matlab R2017b - student use
OpenSim 3.3