add external force in matlab

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
saeed aram
Posts: 20
Joined: Mon Oct 09, 2017 2:26 pm

add external force in matlab

Post by saeed aram » Sun Apr 14, 2019 10:44 am

hello
I want to add external force through Matlab to my model but I occur this error. what should I do?
Attachments
Capture898.JPG
Capture898.JPG (44.05 KiB) Viewed 666 times

Tags:

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: add external force in matlab

Post by jimmy d » 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.

User avatar
saeed aram
Posts: 20
Joined: Mon Oct 09, 2017 2:26 pm

Re: add external force in matlab

Post by saeed aram » Mon Apr 15, 2019 3:32 pm

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');

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: add external force in matlab

Post by jimmy d » 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');

User avatar
saeed aram
Posts: 20
Joined: Mon Oct 09, 2017 2:26 pm

Re: add external force in matlab

Post by saeed aram » Wed Apr 17, 2019 9:45 am

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?

User avatar
saeed aram
Posts: 20
Joined: Mon Oct 09, 2017 2:26 pm

Re: add external force in matlab

Post by saeed aram » Fri Apr 19, 2019 2:33 pm

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

User avatar
Thomas Uchida
Posts: 1778
Joined: Wed May 16, 2012 11:40 am

Re: add external force in matlab

Post by Thomas Uchida » 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

User avatar
saeed aram
Posts: 20
Joined: Mon Oct 09, 2017 2:26 pm

Re: add external force in matlab

Post by saeed aram » Mon Apr 22, 2019 2:50 pm

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

POST REPLY