Adding a force through matlab
Posted: Tue Mar 28, 2017 12:07 pm
For the arm26.osim model, if I wanted to add a force (unspecified but not a torque) on the r_humerus through Matlab, how would it be done?
A short text to describe your forum
https://simtk.org/plugins/phpBB/
What do you mean by adding an unspecified force to the model? What type of simulation are you performing?I wanted to add a force (unspecified but not a torque) on the r_humerus
The code required to add a force to a model depends on the type of force you're adding. The OpenSim::Force page in the API documentation (https://simtk.org/api_docs/opensim/api_ ... Force.html) lists the forces that are available (expand the "Inheritance diagram"). Perhaps you mean an ExternalForce (https://simtk.org/api_docs/opensim/api_ ... Force.html)?Unspecified as in any type of force.
If you aren't performing a simulation, it isn't clear why you would want to add a force to the model. Are you just trying to generate an image?It is not a simulation I am performing.
Code: Select all
import org.opensim.modeling.*
myModel = Model('C:\Users\Yong Cho\Documents\OSFolder\arm26e2.osim')
r_humerus = myModel.getBodySet().get('r_humerus');
mass_center = Vec3(0, -.180496, 0);
force_applied = 8;
direction = Vec3(1,0 , 0);
There might be some helpful information on the "Scripting with Matlab" page in the documentation (http://simtk-confluence.stanford.edu:80 ... ith+Matlab).I am just trying to learn how to modulate opensim by using Matlab since I am new to this.
Thank you for clarifying. The class you're looking for is OpenSim::PrescribedForce (https://simtk.org/api_docs/opensim/api_ ... Force.html). Here's a code snippet:I am trying to find a way to a add a force to the r_humerus of the model arm26.osim in the (1,0,0) direction.
Code: Select all
import org.opensim.modeling.*
model = Model('arm26.osim');
body = model.getBodySet().get('r_humerus');
force = PrescribedForce('myForce', body);
force.setForceFunctions(Constant(1), Constant(0), Constant(0));
model.addForce(force);
model.print('arm26_withPrescribedForce.osim');
Code: Select all
import org.opensim.modeling.*
model = Model('C:\Users\Yong Cho\Documents\OSFolder\arm26e2.osim');
body = model.getBodySet().get('r_ulna_radius_hand');
force = PrescribedForce('myForce', body);
force.setForceFunctions(Constant(0), Constant(0), Constant(1));
model.addForce(force);
model.print('C:\Users\Yong Cho\Documents\OSFolder\arm26e2PrescribedForce.osim');
The lineHow would I set the magnitude of the force?
Code: Select all
force.setForceFunctions(Constant(1), Constant(0), Constant(0));
What are the error messages? Many things could be going wrong (e.g., MATLAB is incorrectly configured, the model file you've specified doesn't exist, the body you've specified doesn't exist).This is the code that I am trying to run but I am getting errors.
To apply a force of 50 N in the global X direction, for example, you would replace the line above withI am having problems in setting the magnitude of the force.
Code: Select all
force.setForceFunctions(Constant(50), Constant(0), Constant(0));
It depends what type of simulation you're running. If you're performing a forward dynamic simulation, the trajectory should be different when you add an external force (assuming the coordinates aren't locked or prescribed). If you're performing a tracking simulation, the motion would be the same but the joint torques, muscle forces, etc. would be different.when I attempted to run a simulation on the arm26 model with a 50 newton force in the y direction, nothing different happened when compared to the control arm26 model. Is this normal or am I doing something wrong?