Page 1 of 1

add external force in matlab

Posted: Sun Apr 14, 2019 10:44 am
by saeedaram
hello
I want to add external force through Matlab to my model but I occur this error. what should I do?

Re: add external force in matlab

Posted: Mon Apr 15, 2019 6:37 am
by jimmy
You must successfully connect your force to a frame. The error message implies the force didn't get connected to a frame and suggests trying to call finalizeConnections() before printing your model to file.

It would be helpful if you posted the code you wrote to add the force.

Re: add external force in matlab

Posted: Mon Apr 15, 2019 3:32 pm
by saeedaram
jimmy wrote:
Mon Apr 15, 2019 6:37 am
You must successfully connect your force to a frame. The error message implies the force didn't get connected to a frame and suggests trying to call finalizeConnections() before printing your model to file.

It would be helpful if you posted the code you wrote to add the force.
thanks for your reply. this is my code. I didnt face any error in matlab after run this code but when I called finalizeconnections() matlab had errored.
import org.opensim.modeling.*
model = Model('gait2354_simbody.osim');
body = model.getBodySet().get('tibia_r');
force = PrescribedForce('saeed',body);
force.setForceFunctions(Constant(30), Constant(0), Constant(0));
model.addForce(force);
model.print('gait2354_simbody_withPrescribedForce.osim');

Re: add external force in matlab

Posted: Tue Apr 16, 2019 6:42 am
by jimmy
The below code seems to work for me;

Code: Select all

import org.opensim.modeling.*
model = Model('gait2354_simbody.osim');
body = model.getBodySet().get('tibia_r');
force = PrescribedForce('saeed',body);
force.setForceFunctions(Constant(30), Constant(0), Constant(0));
model.addForce(force);
model.finalizeConnections()
model.print('gait2354_simbody_withPrescribedForce.osim');

Re: add external force in matlab

Posted: Wed Apr 17, 2019 9:45 am
by saeedaram
jimmy wrote:
Tue Apr 16, 2019 6:42 am
The below code seems to work for me;

Code: Select all

import org.opensim.modeling.*
model = Model('gait2354_simbody.osim');
body = model.getBodySet().get('tibia_r');
force = PrescribedForce('saeed',body);
force.setForceFunctions(Constant(30), Constant(0), Constant(0));
model.addForce(force);
model.finalizeConnections()
model.print('gait2354_simbody_withPrescribedForce.osim');
Thanks for your response. I have another question. I want to add another external force on that body(tibia_r) simultaneously. So what should I script on the above code to add this force?

Re: add external force in matlab

Posted: Fri Apr 19, 2019 2:33 pm
by saeedaram
jimmy wrote:
Tue Apr 16, 2019 6:42 am
The below code seems to work for me;

Code: Select all

import org.opensim.modeling.*
model = Model('gait2354_simbody.osim');
body = model.getBodySet().get('tibia_r');
force = PrescribedForce('saeed',body);
force.setForceFunctions(Constant(30), Constant(0), Constant(0));
model.addForce(force);
model.finalizeConnections()
model.print('gait2354_simbody_withPrescribedForce.osim');
would you please answer my question that how can I add another external forces simultaneously on tibia_r on different force points

Re: add external force in matlab

Posted: Sun Apr 21, 2019 12:59 pm
by tkuchida
would you please answer my question that how can I add another external forces simultaneously on tibia_r on different force points
You can simply duplicate the code (with appropriate modifications) and specify the point of application using the setPointFunctions() method. See the following:
- Documentation for setPointFunctions(): https://simtk.org/api_docs/opensim/api_ ... 4cfdab1fbd
- Examples in testPrescribedForce.cpp: https://github.com/opensim-org/opensim- ... dForce.cpp

Re: add external force in matlab

Posted: Mon Apr 22, 2019 2:50 pm
by saeedaram
tkuchida wrote:
Sun Apr 21, 2019 12:59 pm
would you please answer my question that how can I add another external forces simultaneously on tibia_r on different force points
You can simply duplicate the code (with appropriate modifications) and specify the point of application using the setPointFunctions() method. See the following:
- Documentation for setPointFunctions(): https://simtk.org/api_docs/opensim/api_ ... 4cfdab1fbd
- Examples in testPrescribedForce.cpp: https://github.com/opensim-org/opensim- ... dForce.cpp
thank you