Dear Staff of OpenSim and researchers in OpenSim community,
I am Hide Kimpara from WPI. I have started to learn OpenSim with MatLab.
My project is an interactive analyses between human and machines items.
The machine dynamics would be determined from external system. I am interested in the methods to set item's motions with the functions of prescribed force (or prescribed motion).
When I found an example of prescribed force on osim file, the function was set with piecewiseLinearFunction. In this example, user can define curves with x1, x2, x3, ... and y1, y2, y3, ...
I think this would be one of method and representing interface to reproduce item motions which were determined from external system.
But it is not so flexible format for me to modify as demands.
Now I have three questions.
1) Can I refer the function plot of piecewiseLinearFunction with external files, such as STO file?
2) Can I change functional parameters during the analyses? For example, we may be possible to change state variables using OpenSim API functions. Does OpenSim have similar modification capabilities for function curve data?
3) I assume currently available method to obtain prescribed motion would be only prescribed force. But does OpenSim API have an interface or functions of prescribed motion by desired velocity or acceleration?
Also I have further two questions. I am also modeling a flexible mechanical structures supported with 4 spring suspensions. In order to analyse the mechanical system, the definition of gravity was too strong to get stable responses. Initial state of system does not have balanced against gravity forces, therefore, system represents a transient response. Sometimes, 1G of sudden acceleration is severe for a system. On the contrary, FE engineers sometimes use a technical know-how of gravity acceleration with soft gradients. Some software allows user to apply a functional curve for gravity definition. Can OpenSim represent similar solutions?
The last question is constraint definition. I used a constraint definition in order to fix the ends of 4 suspensions on the ground. Currently available options for constraints are point constraint or point on line constraint. However, I'd like to use a kind of point on plane constraint which may fix only one translational DOF. In case of this demand, how can I represent using existing options?
Thank you and Best,
Hide
Functions for prescribed force/motion managed by MATLAB
- Hide Kimpara
- Posts: 135
- Joined: Mon Sep 19, 2016 5:12 am
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: Functions for prescribed force/motion managed by MATLAB
Hi,
Please see the API for more details:
https://simtk.org/api_docs/opensim/api_ ... Force.html
https://simtk.org/api_docs/simbody/3.5/ ... otion.html
1) You can Load an external force from a file (https://simtk.org/api_docs/opensim/api_ ... Loads.html) and then add this force to the model (please see how it is used in the source code https://github.com/opensim-org/opensim- ... l.cpp#L221).
2) Yes, PrescribedForce can accept a function. You can implement your own function by deriving form Function (https://simtk.org/api_docs/opensim/api_ ... ction.html) that will calculate its value. But I am not sure if it is possible from Matlab.
3) Yes see second link.
Hope this helps!
Please see the API for more details:
https://simtk.org/api_docs/opensim/api_ ... Force.html
https://simtk.org/api_docs/simbody/3.5/ ... otion.html
1) You can Load an external force from a file (https://simtk.org/api_docs/opensim/api_ ... Loads.html) and then add this force to the model (please see how it is used in the source code https://github.com/opensim-org/opensim- ... l.cpp#L221).
2) Yes, PrescribedForce can accept a function. You can implement your own function by deriving form Function (https://simtk.org/api_docs/opensim/api_ ... ction.html) that will calculate its value. But I am not sure if it is possible from Matlab.
3) Yes see second link.
Why should it be balanced? You can assign a state variables prior to integrating the system. Maybe you have to find an equilibrium point of the system and use this state as a starting point.Initial state of system does not have balanced against gravity forces, therefore, system represents a transient response. Sometimes, 1G of sudden acceleration is severe for a system.
I am not sure if I understood this technique. You can change the gravity from model.setGravity() but this is a property of the model (https://github.com/opensim-org/opensim- ... del.h#L151) so the model will be invalidated. OpenSim is a little strict on this type of changes. I am not sure if it is possible to achieve this by changing the gravity.On the contrary, FE engineers sometimes use a technical know-how of gravity acceleration with soft gradients. Some software allows user to apply a functional curve for gravity definition. Can OpenSim represent similar solutions?
Maybe you can define a body that is permitted to translate in some directions. Then you would connect your suspensions to the body.However, I'd like to use a kind of point on plane constraint which may fix only one translational DOF. In case of this demand, how can I represent using existing options?
Hope this helps!
- Hide Kimpara
- Posts: 135
- Joined: Mon Sep 19, 2016 5:12 am
Re: Functions for prescribed force/motion managed by MATLAB
Dear Dimitar,
Thank you for your suggestion.
I found an example of prescribed motion "prescribeMotionInModel.m" from MATLAB_Scripting. This example may change model input osim file with additional SimmSpline function and prescribedMotion switch-on.
Since I could not find any methods to call PrescribedMotion method of SimBody from MatLab, I modified scripts of this example and placed them before the initSystem().
However, when I placed them after initSystem, the scripts won't work.
Do you know any scripts to update modifications of coordinate set into the model?
Also I realized that OpenSim can set gravity as constant variables. As you say, it may be better to input motions on body.
However, in case of the body running with greater speeds, how can we visualize those motions? Some of other software or post-processer has a function that visual frame anchors a selected body. So visual frame can move associated with a target item body.
Do you know any solutions to visualize with moving frame?
Best regards,
Hide
Thank you for your suggestion.
I found an example of prescribed motion "prescribeMotionInModel.m" from MATLAB_Scripting. This example may change model input osim file with additional SimmSpline function and prescribedMotion switch-on.
Since I could not find any methods to call PrescribedMotion method of SimBody from MatLab, I modified scripts of this example and placed them before the initSystem().
However, when I placed them after initSystem, the scripts won't work.
Do you know any scripts to update modifications of coordinate set into the model?
Also I realized that OpenSim can set gravity as constant variables. As you say, it may be better to input motions on body.
However, in case of the body running with greater speeds, how can we visualize those motions? Some of other software or post-processer has a function that visual frame anchors a selected body. So visual frame can move associated with a target item body.
Do you know any solutions to visualize with moving frame?
Best regards,
Hide
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: Functions for prescribed force/motion managed by MATLAB
Hi,
http://simtk-confluence.stanford.edu:80 ... Simulation
(there are other examples in the user guide)
Best
If you post the script I may point out where the problem is, because there are some specifics regarding the initialization of the system.However, when I placed them after initSystem, the scripts won't work.
Please see the user guide examples (C++) and adapt them accordingly for Matlab.Do you know any scripts to update modifications of coordinate set into the model?
http://simtk-confluence.stanford.edu:80 ... Simulation
(there are other examples in the user guide)
I am not sure if you can achieve this with Simbody visualizer, whose purpose is limited to inspect the model and the simulation results. I would suggest to check whether you can have a workaround to your problem and if not to implement your own visualizer or extend Simbody's.However, in case of the body running with greater speeds, how can we visualize those motions? Some of other software or post-processer has a function that visual frame anchors a selected body. So visual frame can move associated with a target item body.
Do you know any solutions to visualize with moving frame?
Best
- Hide Kimpara
- Posts: 135
- Joined: Mon Sep 19, 2016 5:12 am
Re: Functions for prescribed force/motion managed by MATLAB
Dear Dimitar,
Thank you for your kind proposal of review scripts.
I am happy to share my MATLAB code here. The sample script what I post here includes reading prescribed motion and initial states from sto file.
Can I ask you to indicate what sentences from OpenSim API are necessary to execute those in MATLAB environment?
For the viewer issue; if I wish to add a new function into OpenSim GUI such as a fixing view frame onto a selected body coordinate, do you know where or whom I can ask a development request?
Thank you and Best,
Hide
Thank you for your kind proposal of review scripts.
I am happy to share my MATLAB code here. The sample script what I post here includes reading prescribed motion and initial states from sto file.
Can I ask you to indicate what sentences from OpenSim API are necessary to execute those in MATLAB environment?
For the viewer issue; if I wish to add a new function into OpenSim GUI such as a fixing view frame onto a selected body coordinate, do you know where or whom I can ask a development request?
Thank you and Best,
Hide
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: Functions for prescribed force/motion managed by MATLAB
Hi,
Is it possible to send all the files so I can run your script and see the error, because its hard to tell otherwise?
https://github.com/simbody/simbody/tree ... Visualizer
You can either ask a question in:
indexPhpbb.php?group_id=47&pluginname=phpBB
or request an issue:
https://github.com/simbody/simbody
** BodyFollower
Please have a look at this:
https://github.com/simbody/simbody/blob ... zer.h#L150
Maybe this can help you in your problem, but I am not sure how much assess to the underlying visualizer you can get from Matlab.
Best
Is it possible to send all the files so I can run your script and see the error, because its hard to tell otherwise?
You can find the code of the visualizer here:For the viewer issue; if I wish to add a new function into OpenSim GUI such as a fixing view frame onto a selected body coordinate, do you know where or whom I can ask a development request?
https://github.com/simbody/simbody/tree ... Visualizer
You can either ask a question in:
indexPhpbb.php?group_id=47&pluginname=phpBB
or request an issue:
https://github.com/simbody/simbody
** BodyFollower
Please have a look at this:
https://github.com/simbody/simbody/blob ... zer.h#L150
Maybe this can help you in your problem, but I am not sure how much assess to the underlying visualizer you can get from Matlab.
Best
- Hide Kimpara
- Posts: 135
- Joined: Mon Sep 19, 2016 5:12 am
Re: Functions for prescribed force/motion managed by MATLAB
Hello,
I share a simple sample model with script. It's a modified bouncing block model.
The zip file contains following 8 files;
main_w_prescmot_1_share.m (MatLab script with reading prescribed motion and initial states)
main_w_prescmot_2_share.m (place initSystem before setting prescribed motion)
bouncing_block_slide_wG.osim (bouncing block model with gravity)
bouncing_block_slide_noG.osim (without gravity)
block_mot.mot (prescribed motion of vertical kinematics)
block_mot2.mot (prescribed motion for keep vertical position)
toy_with_forces_init_states.sto (initial state file)
toy_with_forces_init_states_2.sto (initial state file with different slider joint state)
The MatLab scripts are only different in position of osimModel.initSystem(); type 1 has line# 96, while type 2 has line# 46.
When you execute "main_w_prescmot_1_share.m" with "bouncing_block_slide_noG.osim" and "block_mot.mot", you may see a motion from output state file. However, when you execute "main_w_prescmot_2_share.m" with same input files, we do not see any motions.
I'd like to activate prescribed motion definition even in type 2 MatLab script.
Thank you,
Hide
I share a simple sample model with script. It's a modified bouncing block model.
The zip file contains following 8 files;
main_w_prescmot_1_share.m (MatLab script with reading prescribed motion and initial states)
main_w_prescmot_2_share.m (place initSystem before setting prescribed motion)
bouncing_block_slide_wG.osim (bouncing block model with gravity)
bouncing_block_slide_noG.osim (without gravity)
block_mot.mot (prescribed motion of vertical kinematics)
block_mot2.mot (prescribed motion for keep vertical position)
toy_with_forces_init_states.sto (initial state file)
toy_with_forces_init_states_2.sto (initial state file with different slider joint state)
The MatLab scripts are only different in position of osimModel.initSystem(); type 1 has line# 96, while type 2 has line# 46.
When you execute "main_w_prescmot_1_share.m" with "bouncing_block_slide_noG.osim" and "block_mot.mot", you may see a motion from output state file. However, when you execute "main_w_prescmot_2_share.m" with same input files, we do not see any motions.
I'd like to activate prescribed motion definition even in type 2 MatLab script.
Thank you,
Hide
- Attachments
-
- Share.zip
- (15.67 KiB) Downloaded 20 times
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: Functions for prescribed force/motion managed by MATLAB
I am not sure what experiment you would like to perform. I tried to play a little bit with the model and it seems that it does not behave well. Some observations:
It seems that the model is restricted to move in the y-direction. Unfortunately for some reason if you perform forward simulation in the default pose the model behaves similarly as to the case of the script #2 (a very small movement is observed, but the model don't bounce on the ground). If you lower the model near the ground (yTranslation~=1) and perform a forward simulation the model bounces and goes up. My guess is that near the ground large forces are applied by the contact model and the model overcomes its restrictive forces (constraints) and bounces. When the model is in its default position and you perform a forward simulation, no ground reaction force is applied and for some reasons the joint implicit constraints and actual constraints do not permit the model to move.
Then I tried to adjust the integrator error tolerance by reducing it 1e-10 from 1e-5 which is the default for the forward tool. Then it seems that the system begun to move normally. My guess is that small constraint violation during numerical integration produced forces that do not permit the model to move correctly. I was able to change the "Integrator error tolerance" in the "Integrator Settings" from the gui but I am not sure if it is possible through Matlab, since SimTK::Integrator is not exposed.
## About your second script, probably the prescribed motion is not used since the model was initialized prior to adding the prescribe functions.
Best
It seems that the model is restricted to move in the y-direction. Unfortunately for some reason if you perform forward simulation in the default pose the model behaves similarly as to the case of the script #2 (a very small movement is observed, but the model don't bounce on the ground). If you lower the model near the ground (yTranslation~=1) and perform a forward simulation the model bounces and goes up. My guess is that near the ground large forces are applied by the contact model and the model overcomes its restrictive forces (constraints) and bounces. When the model is in its default position and you perform a forward simulation, no ground reaction force is applied and for some reasons the joint implicit constraints and actual constraints do not permit the model to move.
Then I tried to adjust the integrator error tolerance by reducing it 1e-10 from 1e-5 which is the default for the forward tool. Then it seems that the system begun to move normally. My guess is that small constraint violation during numerical integration produced forces that do not permit the model to move correctly. I was able to change the "Integrator error tolerance" in the "Integrator Settings" from the gui but I am not sure if it is possible through Matlab, since SimTK::Integrator is not exposed.
## About your second script, probably the prescribed motion is not used since the model was initialized prior to adding the prescribe functions.
Best
- Hide Kimpara
- Posts: 135
- Joined: Mon Sep 19, 2016 5:12 am
Re: Functions for prescribed force/motion managed by MATLAB
Dear Dimitar,
Thank you for taking time of executing test models and scripts.
I learned many things through the conversation with you.
I appreciate your voluntary helps!
Best regards,
Hide
Thank you for taking time of executing test models and scripts.
I learned many things through the conversation with you.
I appreciate your voluntary helps!
Best regards,
Hide