Adding a force through matlab
Adding a force through matlab
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?
- Thomas Uchida
- Posts: 1789
- Joined: Wed May 16, 2012 11:40 am
Re: Adding a force through matlab
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
Re: Adding a force through matlab
Unspecified as in any type of force. It is not a simulation I am performing. I want to know how to add in a force by using either the GUI or MATLAB
- Thomas Uchida
- Posts: 1789
- Joined: Wed May 16, 2012 11:40 am
Re: Adding a force through matlab
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.
Re: Adding a force through matlab
Rather than imaging or a simulation, I am just trying to learn how to modulate opensim by using Matlab since I am new to this. To be more specific in what I want, 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. The code below is what I have as of now but I am stuck on what to do from here on.
Can anyone give any in doing what I specified above?
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);
- Thomas Uchida
- Posts: 1789
- Joined: Wed May 16, 2012 11:40 am
Re: Adding a force through matlab
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');
Re: Adding a force through matlab
Thank you for the reply. How would I set the magnitude of the force? This is the code that I am trying to run but I am getting errors. I am having problems in setting the magnitude of the force.
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');
- Thomas Uchida
- Posts: 1789
- Joined: Wed May 16, 2012 11:40 am
Re: Adding a force through matlab
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));
Re: Adding a force through matlab
Thank you, I think I solved the problem. Another question I had was that 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?
- Thomas Uchida
- Posts: 1789
- Joined: Wed May 16, 2012 11:40 am
Re: Adding a force through matlab
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?