hello
I want to add external force through Matlab to my model but I occur this error. what should I do?
add external force in matlab
- saeed aram
- Posts: 20
- Joined: Mon Oct 09, 2017 2:26 pm
Re: add external force in matlab
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.
It would be helpful if you posted the code you wrote to add the force.
- saeed aram
- Posts: 20
- Joined: Mon Oct 09, 2017 2:26 pm
Re: add external force in matlab
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.jimmy wrote: ↑Mon Apr 15, 2019 6:37 amYou 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.
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
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');
- saeed aram
- Posts: 20
- Joined: Mon Oct 09, 2017 2:26 pm
Re: add external force in matlab
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?jimmy wrote: ↑Tue Apr 16, 2019 6:42 amThe 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');
- saeed aram
- Posts: 20
- Joined: Mon Oct 09, 2017 2:26 pm
Re: add external force in matlab
would you please answer my question that how can I add another external forces simultaneously on tibia_r on different force pointsjimmy wrote: ↑Tue Apr 16, 2019 6:42 amThe 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');
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: add external force in matlab
You can simply duplicate the code (with appropriate modifications) and specify the point of application using the setPointFunctions() method. See the following:would you please answer my question that how can I add another external forces simultaneously on tibia_r on different force points
- Documentation for setPointFunctions(): https://simtk.org/api_docs/opensim/api_ ... 4cfdab1fbd
- Examples in testPrescribedForce.cpp: https://github.com/opensim-org/opensim- ... dForce.cpp
- saeed aram
- Posts: 20
- Joined: Mon Oct 09, 2017 2:26 pm
Re: add external force in matlab
thank youtkuchida wrote: ↑Sun Apr 21, 2019 12:59 pmYou can simply duplicate the code (with appropriate modifications) and specify the point of application using the setPointFunctions() method. See the following:would you please answer my question that how can I add another external forces simultaneously on tibia_r on different force points
- Documentation for setPointFunctions(): https://simtk.org/api_docs/opensim/api_ ... 4cfdab1fbd
- Examples in testPrescribedForce.cpp: https://github.com/opensim-org/opensim- ... dForce.cpp