getForceAtTime

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Thomas Uchida
Posts: 1792
Joined: Wed May 16, 2012 11:40 am

Re: getForceAtTime

Post by Thomas Uchida » Thu Jul 27, 2017 10:49 am

i even tried "force=foot1.PrescribedForce.getRecordValues(s2);": "No constructor 'org.opensim.modeling.PrescribedForce' with matching signature found."
The code foot1.PrescribedForce doesn't seem to make sense. foot1 is of type Model; what comes after the period must be a method in the Model class but there is no PrescribedForce() method. PrescribedForce is the name of another class (you have created an instance called force on line 42). How would this code know what to do if you had added more than one PrescribedForce to the model?

You can replace line 69 with this code, which prints the contents of the Model's ForceSet:

Code: Select all

foot1.computeStateVariableDerivatives(s2);
forceSet = foot1.getForceSet();
for i = 1:forceSet.getSize()
    fi = forceSet.get(i-1);
    fprintf('Force name: ''%s''\n', char(fi.getName()));
    labels = fi.getRecordLabels();
    values = fi.getRecordValues(s2);
    for j = 1:labels.size()
        fprintf('-> %s = %0.12f\n', char(labels.get(j-1)), values.get(j-1));
    end
end
Please see the doxygen documentation (https://simtk.org/api_docs/opensim/api_docs/) for more information.

User avatar
shayan moradkhani
Posts: 41
Joined: Fri May 05, 2017 5:12 pm

Re: getForceAtTime

Post by shayan moradkhani » Fri Jul 28, 2017 1:30 am

tkuchida wrote:
i even tried "force=foot1.PrescribedForce.getRecordValues(s2);": "No constructor 'org.opensim.modeling.PrescribedForce' with matching signature found."
The code foot1.PrescribedForce doesn't seem to make sense. foot1 is of type Model; what comes after the period must be a method in the Model class but there is no PrescribedForce() method. PrescribedForce is the name of another class (you have created an instance called force on line 42). How would this code know what to do if you had added more than one PrescribedForce to the model?
hi,
thank you very much for your help. i used "https://simtk.org/api_docs/opensim/api_ ... 81378dda57" for the "force=foot1.PrescribedForce.getRecordValues(s2);", maybe my understanding from doxygen was wrong and i appreciate if you could say how to implement (read) that properly.

by the way, thank you so much for your code. when i replace that with the previous code, i get the results as "force" figure attached. i suppose none of the shown forces (which are all zero!) are externally applied forces (prescribed forces). so either it means the force instance does not recognize my prescribed forces despite the fact that they are in my .osim file. :cry: :cry: :cry:
regards
Shayan
Attachments
force.JPG
force.JPG (77.65 KiB) Viewed 986 times

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

Re: getForceAtTime

Post by Thomas Uchida » Fri Jul 28, 2017 2:21 pm

i used "https://simtk.org/api_docs/opensim/api_ ... 81378dda57" for the "force=foot1.PrescribedForce.getRecordValues(s2);", maybe my understanding from doxygen was wrong and i appreciate if you could say how to implement (read) that properly.
Here is the entry in doxygen:
virtual OpenSim::Array<double> OpenSim::PrescribedForce::getRecordValues ( const SimTK::State & state ) const
This is a virtual method that returns an Array of doubles. The method name is getRecordValues and can be called on instances of the PrescribedForce class. The Array and PrescribedForce classes reside in the OpenSim namespace. The getRecordValues method takes one argument (a const reference to a State; the State class resides in the SimTK namespace) and calling this method does not modify the PrescribedForce instance on which it is called. For more detail, please refer to a reference on C++ programming.

User avatar
shayan moradkhani
Posts: 6
Joined: Mon Apr 24, 2017 4:53 am

Re: getForceAtTime

Post by shayan moradkhani » Fri Aug 04, 2017 12:46 am

hello,
i am still struggling to get the force :cry:
using body.PrescribedForce.getForceAtTime(1.0) says that returns zero if the three functions are not defined. according to the below code the functions are defined. (i didnt put all the lines to avoid complexity)
body = foot1.getBodySet().get('foot');
force = PrescribedForce(body);
forceX = SimmSpline();
forceY = SimmSpline();
forceZ = SimmSpline();
force.setForceFunctions(forceX, forceY, forceZ);
force.setPointFunctions(Constant(0), Constant(0), Constant(0));
foot1.updForceSet().append(force);
and using force=body.PrescribedForce.getForceAtTime(1.0) exactly returns zero here (gives a Vec3(zeros)).
does the definition of three functions mean using the following as well:
OpenSim_DECLARE_PROPERTY (forceFunctions, FunctionSet,"Three functions describing the force to be applied.")?
if yes, please help what to put as the each three input in matlab
regards
Shayan

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

Re: getForceAtTime

Post by Thomas Uchida » Fri Aug 04, 2017 3:17 pm

using body.PrescribedForce.getForceAtTime(1.0) says that returns zero if the three functions are not defined. according to the below code the functions are defined.
I have commented above about the "body.PrescribedForce.getForceAtTime" line. I don't know why that line doesn't return an error (perhaps you have created a variable in MATLAB named PrescribedForce?), but it doesn't make sense. If such a method existed, you would at least need to tell OpenSim which PrescribedForce you were interested in since there could be more than one associated with a given body.

Here is an example that creates a PrescribedForce and displays the value of the force at a specified time:

Code: Select all

import org.opensim.modeling.*;

model = Model('arm26.osim');
body  = model.getBodySet().get('r_ulna_radius_hand');

presforce = PrescribedForce(body);
fx = SimmSpline(); fx.addPoint(0,0); fx.addPoint(1,1);
fy = SimmSpline(); fy.addPoint(0,0); fy.addPoint(1,2);
fz = SimmSpline(); fz.addPoint(0,0); fz.addPoint(1,3);
presforce.setForceFunctions(fx,fy,fz);
presforce.setPointFunctions(Constant(0),Constant(0),Constant(0));

presforce.getForceAtTime(0.5) %returns ~[0.5,1,1.5]

POST REPLY