getForceAtTime

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
shayan moradkhani
Posts: 41
Joined: Fri May 05, 2017 5:12 pm

getForceAtTime

Post by shayan moradkhani » Wed Jul 26, 2017 7:33 am

hi,
i have uploaded an .m file which loads a model simulates it only by gravity and with a very in accurate strategy extract something called settletime (when the objects is somehow standing still). when the settletime is achieved, a prescribed force is added which starts applying the force from a bit later than settletime. with the same inaccurate strategy (as for settletime) the sliptime is extracted.
it runs fine, however i am not sure about couple of things:
as i have put the settletime and sliptime monitoring in "for" loops, i doubt that the force will still be applied when i call only "manager.integrate" in the second "for" loop. as a results, when i call "getForceAtTime", it always shows zero.
i appreciate any suggestions
regards
Shayan
Attachments
share.zip
(1.09 KiB) Downloaded 127 times

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

Re: getForceAtTime

Post by Thomas Uchida » Wed Jul 26, 2017 5:13 pm

One problem appears to be that you have sliptime=s.getTime() on line 67, which gets the time from the old state vector. I think line 67 should be sliptime=s2.getTime().

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

Re: getForceAtTime

Post by shayan moradkhani » Wed Jul 26, 2017 9:48 pm

hi,
thank you very much for your reply. still i am getting zero as for the force. does this zero indicate that the force is not applied?
or is it enough that i append the force once and put only the manager.integrate in the for loop?
if i understand right, i have to realize the system for dynamics? (how can i do that in matlab)
regards
Shayan

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

Re: getForceAtTime

Post by Thomas Uchida » Wed Jul 26, 2017 9:57 pm

still i am getting zero as for the force. does this zero indicate that the force is not applied?
Either the force isn't being applied or you are calling the wrong API method. An easy way to check is to compare the simulation results with and without adding the force.

Before running your simulation, you should use Model.print() to save a copy of the model. You can then check the .osim file directly and/or open the model in the GUI to make sure the force component has been correctly added.

If you need additional help, please upload the model file so I can reproduce the issue.

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

Re: getForceAtTime

Post by shayan moradkhani » Wed Jul 26, 2017 10:12 pm

hi,
thank you for your reply. i have uploaded the model. the force is applied. :?
regards
Shayan
Attachments
model-20170712T165116Z-001.zip
(190.96 KiB) Downloaded 121 times

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

Re: getForceAtTime

Post by Thomas Uchida » Thu Jul 27, 2017 12:18 am

Your MATLAB script doesn't run; I get the following error message, which points to the problem:

??? No appropriate method or public field PrescribedForce for class org.opensim.modeling.Body.

Error in ==> share at 69
force=body.PrescribedForce.getForceAtTime(sliptime)

If you want to measure forces during a simulation, you might consider using a ForceReporter (https://simtk.org/api_docs/opensim/api_ ... orter.html).

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

Re: getForceAtTime

Post by shayan moradkhani » Thu Jul 27, 2017 12:37 am

hi,
thank you for your reply. i run the same files even changing the names, and there were no problems.i don't really know what goes wrong there. anyway, i try the force reporter and in case i have difficulties i will come back to you.
regards
Shayan

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

Re: getForceAtTime

Post by shayan moradkhani » Thu Jul 27, 2017 1:46 am

hi,
i have added some codes in fig.1 and the forcereporter builds an empty file as attached in fig.2. :cry:
regards
Shayan
Attachments
2.JPG
2.JPG (33.18 KiB) Viewed 2238 times
1.JPG
1.JPG (77.88 KiB) Viewed 2238 times

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

Re: getForceAtTime

Post by Thomas Uchida » Thu Jul 27, 2017 2:58 am

I think the easiest approach will be to use the ForwardTool (https://simtk.org/api_docs/opensim/api_ ... dTool.html). Here is a simple example:

Code: Select all

import org.opensim.modeling.*;
model = Model('foot1.osim');
forceReporter = ForceReporter();
model.addAnalysis(forceReporter);

forwardTool = ForwardTool();
forwardTool.setModel(model);
forwardTool.setInitialTime(0.);
forwardTool.setFinalTime(1.);
forwardTool.run();
You might want to look at the "Scripting with Matlab" page in the Confluence documentation (http://simtk-confluence.stanford.edu:80 ... ith+Matlab); the examples there might be helpful. The code

Code: Select all

foot1.ForceReporter.printResults(...);
appears to be incorrect because foot1 is a reference to a Model and there is no ForceReporter() method in the Model class (see the documentation for the Model class here: https://simtk.org/api_docs/opensim/api_ ... Model.html).

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

Re: getForceAtTime

Post by shayan moradkhani » Thu Jul 27, 2017 4:50 am

hi,
thank you for your patience. unfortunately this approach does not work for my purpose since through FD i get the results printed somewhere and then i have to load them from directory which becomes a post-simulation (at least sounds like this to me). before that, i could use state objects, initializing the integration of the state and using calcMassCenterVelocity(s2) and s2.getTime() to do the rest. all i want to do is to get the force at sliptime (already have this)
i even tried "force=foot1.PrescribedForce.getRecordValues(s2);": "No constructor 'org.opensim.modeling.PrescribedForce' with matching signature found." looking at doxygen, looks similar maybe has something to do with the the first part array<double> or Dynamics initialization beforehand. i dont know why my code could not be run, i am running the same code. maybe libraries that we are using are different!
i appreciate your help
regards
Shayan

POST REPLY