getForceAtTime
- shayan moradkhani
- Posts: 41
- Joined: Fri May 05, 2017 5:12 pm
getForceAtTime
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
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 134 times
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: getForceAtTime
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().
- shayan moradkhani
- Posts: 41
- Joined: Fri May 05, 2017 5:12 pm
Re: getForceAtTime
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
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
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: getForceAtTime
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.still i am getting zero as for the force. does this zero indicate that the force is not applied?
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.
- shayan moradkhani
- Posts: 41
- Joined: Fri May 05, 2017 5:12 pm
Re: getForceAtTime
hi,
thank you for your reply. i have uploaded the model. the force is applied.
regards
Shayan
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 124 times
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: getForceAtTime
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).
??? 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).
- shayan moradkhani
- Posts: 41
- Joined: Fri May 05, 2017 5:12 pm
Re: getForceAtTime
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
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
- shayan moradkhani
- Posts: 41
- Joined: Fri May 05, 2017 5:12 pm
Re: getForceAtTime
hi,
i have added some codes in fig.1 and the forcereporter builds an empty file as attached in fig.2.
regards
Shayan
i have added some codes in fig.1 and the forcereporter builds an empty file as attached in fig.2.
regards
Shayan
- Attachments
-
- 2.JPG (33.18 KiB) Viewed 2251 times
-
- 1.JPG (77.88 KiB) Viewed 2251 times
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: getForceAtTime
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:
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
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).
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();
Code: Select all
foot1.ForceReporter.printResults(...);
- shayan moradkhani
- Posts: 41
- Joined: Fri May 05, 2017 5:12 pm
Re: getForceAtTime
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
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