exampleSquatToStand- MocoPeriodicityGoal
- Nicholas Bianco
- Posts: 1028
- Joined: Thu Oct 04, 2012 8:09 pm
Re: exampleSquatToStand- MocoPeriodicityGoal
Hi Mouaad,
Could you check that the variables you're passing to createExternalLoadsTableForGait are the same as in example2DWalking? It's hard to know what the issue is without a larger snippet of code.
-Nick
Could you check that the variables you're passing to createExternalLoadsTableForGait are the same as in example2DWalking? It's hard to know what the issue is without a larger snippet of code.
-Nick
- Mouaad BOUFADNA
- Posts: 22
- Joined: Mon Mar 16, 2020 3:24 am
Re: exampleSquatToStand- MocoPeriodicityGoal
Hi Nicholas
I wrote the variables like in example2DWalking (while withdrawing what was useless for me)
I wrote the variables like in example2DWalking (while withdrawing what was useless for me)
Code: Select all
LiftPredictionSolution = study.solve();
study.visualize(LiftPredictionSolution);
LiftPredictionSolution.write('LiftPrediction_solution.sto');
contact_l = StdVectorString();
contact_r.add('contactHeel_r');
contact_r.add('contactFront_r');
contact_l.add('contactHeel_l');
contact_l.add('contactFront_l');
externalForcesTableFlat = opensimMoco.createExternalLoadsTableForGait(model, contact_r, contact_l);
opensimMoco.writeTableToFile(externalForcesTableFlat,'LiftPrediction_solutionGRF.sto');
- Nicholas Bianco
- Posts: 1028
- Joined: Thu Oct 04, 2012 8:09 pm
Re: exampleSquatToStand- MocoPeriodicityGoal
You need to include the solution in your call to createExternalLoadsTableForGait():
Code: Select all
externalForcesTableFlat = opensimMoco.createExternalLoadsTableForGait(model, LiftPredictionSolution, contact_r, contact_l);
- Mouaad BOUFADNA
- Posts: 22
- Joined: Mon Mar 16, 2020 3:24 am
Re: exampleSquatToStand- MocoPeriodicityGoal
It's working now ! I get the .sto file for GRF.
Only another problem
My values are 0 except when the feet touche the ground at the end of the motion. My model is not on the ground at the beginning
I think I should define a Contact constraint between the ground and the feet to avoid such kinematic disorder
I thought about problem.addContactGeomtry or problem.addContactConstraint, but for the arguments I don't know how to define them .
I wondered two possibilities for:
("ground",'feet")
Or '('/bodyset/ground','/bodyset/talus')
Or may be add the ControlTrackingGoal and addContactGroup like in the Tracking Solution of example2DWalking ?
Sorry for asking so much question I'm beginner in Moco and not very familiar with OpsenSim/Matlab interface
Thank you for your help !
Only another problem
My values are 0 except when the feet touche the ground at the end of the motion. My model is not on the ground at the beginning
I think I should define a Contact constraint between the ground and the feet to avoid such kinematic disorder
I thought about problem.addContactGeomtry or problem.addContactConstraint, but for the arguments I don't know how to define them .
I wondered two possibilities for:
("ground",'feet")
Or '('/bodyset/ground','/bodyset/talus')
Or may be add the ControlTrackingGoal and addContactGroup like in the Tracking Solution of example2DWalking ?
Sorry for asking so much question I'm beginner in Moco and not very familiar with OpsenSim/Matlab interface
Thank you for your help !
- Nicholas Bianco
- Posts: 1028
- Joined: Thu Oct 04, 2012 8:09 pm
Re: exampleSquatToStand- MocoPeriodicityGoal
Hi Mouaad,
Does your model have similar contact geometry as in example2DWalking? You shouldn't need to add any additional constraints.
I'd need to know more about your problem to know why the model isn't on the ground at the beginning. You can check the model's default configuration in the OpenSim GUI. Also check that they're are no actuators at the pelvis that would artificially lift the model off the ground.
-Nick
Does your model have similar contact geometry as in example2DWalking? You shouldn't need to add any additional constraints.
I'd need to know more about your problem to know why the model isn't on the ground at the beginning. You can check the model's default configuration in the OpenSim GUI. Also check that they're are no actuators at the pelvis that would artificially lift the model off the ground.
-Nick
- Mouaad BOUFADNA
- Posts: 22
- Joined: Mon Mar 16, 2020 3:24 am
Re: exampleSquatToStand- MocoPeriodicityGoal
Hi Nick
This is my entire code :
I wrote the same contact as in example2DWalking
But now I'm thinking I withdrew the solver.setGuess(GaitTrackingSolution), because I didn't need anymore the tracking solution.
What I undertsood is that when we don't set an inital guess, Moco use a default one based on the bounds we defined previously.
Should I restaure the setGuess with 'bounds' as argument ?
This is my entire code :
Code: Select all
% Load the Moco libraries
import org.opensim.modeling.*;
% Define the optimal control problem
% ==================================
study = MocoStudy();
study.setName('LiftPrediction');
problem = study.updProblem();
modelProcessor = ModelProcessor('2D_gait.osim');
problem.setModelProcessor(modelProcessor);
model = modelProcessor.process();
model.initSystem();
% Bounds
% ======
problem.setTimeBounds(0,[0.6,0.8]);
problem.setStateInfo('/jointset/groundPelvis/pelvis_tilt/value', [-20*pi/180, -10*pi/180]);
problem.setStateInfo('/jointset/groundPelvis/pelvis_tx/value', [0, 1]);
problem.setStateInfo('/jointset/groundPelvis/pelvis_ty/value', [0.75, 1.25]);
problem.setStateInfo('/jointset/hip_l/hip_flexion_l/value', [10*pi/180,2], 2, 10*pi/180);
problem.setStateInfo('/jointset/hip_r/hip_flexion_r/value', [10*pi/180,2], 2, 10*pi/180);
problem.setStateInfo('/jointset/knee_l/knee_angle_l/value',[-2, 0], -2, 0);
problem.setStateInfo('/jointset/knee_r/knee_angle_r/value',[-2, 0], -2, 0);
problem.setStateInfo('/jointset/ankle_l/ankle_angle_l/value', [0,0.5], 0.5, 0);
problem.setStateInfo('/jointset/ankle_r/ankle_angle_r/value', [0,0.5], 0.5, 0);
problem.setStateInfo('/jointset/lumbar/lumbar/value', [-20*pi/180,10*pi/180],-20*pi/180,10*pi/180);
% % Velocity bounds: all model coordinates should start and end at rest.
problem.setKinematicConstraintBounds(MocoBounds(0,0));
% Cost.
% -----
problem.addGoal(MocoFinalTimeGoal("time"));
% Configure the solver
% ====================
solver = study.initCasADiSolver();
solver.set_num_mesh_intervals(50);
solver.set_verbosity(2);
solver.set_optim_solver('ipopt');
solver.set_optim_convergence_tolerance(1e-4);
solver.set_optim_constraint_tolerance(1e-4);
solver.set_optim_max_iterations(1000);
% Solve problem
% =============
LiftPredictionSolution = study.solve();
LiftPredictionSolution.write('LiftPrediction_solution3.sto');
% study.visualize(LiftPredictionSolution);
%Plot trajectories for the different states
mocoPlotTrajectory('LiftPrediction_solution3.sto');
% Extract ground reaction forces
% ==============================
contact_r = StdVectorString();
contact_l = StdVectorString();
contact_r.add('contactHeel_r');
contact_r.add('contactFront_r');
contact_l.add('contactHeel_l');
contact_l.add('contactFront_l');
% Create a conventional ground reaction forces file by summing the contact
% forces of contact spheres on each foot.
% For details, navigate to
% User Guide > Utilities > Model and trajectory utilities
% in the Moco Documentation.
% %
externalForcesTableFlat = opensimMoco.createExternalLoadsTableForGait(model, LiftPredictionSolution,contact_r, contact_l);
opensimMoco.writeTableToFile(externalForcesTableFlat,'LiftPrediction_solutionGRF.sto');
I wrote the same contact as in example2DWalking
But now I'm thinking I withdrew the solver.setGuess(GaitTrackingSolution), because I didn't need anymore the tracking solution.
What I undertsood is that when we don't set an inital guess, Moco use a default one based on the bounds we defined previously.
Should I restaure the setGuess with 'bounds' as argument ?
- Nicholas Bianco
- Posts: 1028
- Joined: Thu Oct 04, 2012 8:09 pm
Re: exampleSquatToStand- MocoPeriodicityGoal
You should remove this line:
It does not set the initial and final speeds to zero, but rather sets the bounds on any kinematic constraints included in the model (e.g., CoordinateCoupler constraints dictating patellar motion). You can specify zero initial and final speeds for all coordinates using the setStateInfoPattern() interface:
Since you don't want the model to translate along the x-direction, you could consider tightening the bounds on the 'pelvis_tx' coordinate.
I'm still not sure what the issue is. You could consider constructing an initial guess that includes the initial and final lifting positions you would expect to see. You should try visualizing the model in the GUI to make sure that the initial pose you are specifying in the coordinates makes sense.
-Nick
Code: Select all
problem.setKinematicConstraintBounds(MocoBounds(0,0));
Code: Select all
problem.setStateInfoPattern('/jointset/.*/speed', [], 0, 0);
I'm still not sure what the issue is. You could consider constructing an initial guess that includes the initial and final lifting positions you would expect to see. You should try visualizing the model in the GUI to make sure that the initial pose you are specifying in the coordinates makes sense.
-Nick
- Mouaad BOUFADNA
- Posts: 22
- Joined: Mon Mar 16, 2020 3:24 am
Re: exampleSquatToStand- MocoPeriodicityGoal
Ok I didn't undertand the setKinematicConstraints in that way
I removed it and replace by the StateInfoPattern but I didn't get a solution. The moco MocoCasADiSolver. failed.
So now the point is to config the initial guess in the solver
I wrote the inital guess as follows :
I got this message
Even if I change the brackets type it' not working.
So I try to wrote guess.setTime([0,0.8]); and it returns another message
I removed it and replace by the StateInfoPattern but I didn't get a solution. The moco MocoCasADiSolver. failed.
So now the point is to config the initial guess in the solver
I wrote the inital guess as follows :
Code: Select all
%Create an initial guess from the defined bounds
guess=solver.createGuess('bounds'); % Use bounds as initial guess
guess.setTime(0,0.8);
guess.setState('/joinset/hip_l/hip_flexion_l/value',2, 10*pi/180);
guess.setState('/joinset/hip_r/hip_flexion_r/value',2, 10*pi/180);
guess.setState('/joinset/knee_l/knee_angle_l/value',-2, 0);
guess.setState('/joinset/knee_r/knee_angle_r/value',-2, 0);
guess.setState('/joinset/ankle_l/ankle_angle_l/value',0.5, 0);
guess.setState('/joinset/ankle_r/ankle_angle_r/value',0.5, 0);
guess.setState('jointset/lumbar/lumbar/value',-20*pi/180,10*pi/180);
solver.setGuess(guess);
Code: Select all
Check for missing argument or incorrect argument data type in call to function 'setTime'.
Error in example2DWalking (line 122)
guess.setTime(0.6,0.8);
So I try to wrote guess.setTime([0,0.8]); and it returns another message
Code: Select all
Error using example2DWalking (line 122)
Java exception occurred:
java.lang.RuntimeException: Expected 101 times but got 2.
Thrown at MocoTrajectory.cpp:156 in setTime().
at org.opensim.modeling.opensimMocoJNI.MocoTrajectory_setTime(Native Method)
at org.opensim.modeling.MocoTrajectory.setTime(MocoTrajectory.java:203)
at org.opensim.modeling.MocoTrajectory.setTime(MocoTrajectory.java:42)
- Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Re: exampleSquatToStand- MocoPeriodicityGoal
The syntax `guess.setTime([0,0.8])` is correct but as the error message indicates, the guess has 101 time points and thus you must provide a vector containing 101 values. If you want to provide just 2 values, then first call `guess.resampleWithNumTimes(2)`.
https://github.com/opensim-org/opensim- ... #L152-L156
https://github.com/opensim-org/opensim- ... #L152-L156
- Mouaad BOUFADNA
- Posts: 22
- Joined: Mon Mar 16, 2020 3:24 am
Re: exampleSquatToStand- MocoPeriodicityGoal
Hi Nick
I resolved my problem. The pelvis_ty was to high to have the feet on the ground.
After seeing the model coordinates in the GUI, I reduced pelvis_ty interval of values and fixed initial/final values to the ones where the model has feet on the ground.
But during the motion, feet are moving from the ground and go in backward (see in attached images).
I tried by optimizing my angle values, but it failed.
I withdrew KinematicConstraint and initial/final velocity but still unchanged.
Chris, Thank you ! That seems now clever !
I tried again but now the Command window indicates that :
But I didn't changed the syntax of my states from the problem.StateInfo :
I resolved my problem. The pelvis_ty was to high to have the feet on the ground.
After seeing the model coordinates in the GUI, I reduced pelvis_ty interval of values and fixed initial/final values to the ones where the model has feet on the ground.
But during the motion, feet are moving from the ground and go in backward (see in attached images).
I tried by optimizing my angle values, but it failed.
I withdrew KinematicConstraint and initial/final velocity but still unchanged.
Chris, Thank you ! That seems now clever !
I tried again but now the Command window indicates that :
Code: Select all
Error using example2DWalking (line 125)
Java exception occurred:
java.lang.RuntimeException: Cannot find state named /joinset/hip_l/hip_flexion_l/value.
Thrown at MocoTrajectory.cpp:169 in setState().
at org.opensim.modeling.opensimMocoJNI.MocoTrajectory_setState(Native Method)
at org.opensim.modeling.MocoTrajectory.setState(MocoTrajectory.java:207)
at org.opensim.modeling.MocoTrajectory.setState(MocoTrajectory.java:48)
Code: Select all
%Create an initial guess from the defined bounds
guess=solver.createGuess('bounds'); % Use bounds as initial guess
guess.resampleWithNumTimes(2)
guess.setTime([0,0.8]);
guess.setState('/joinset/hip_l/hip_flexion_l/value',[2, 10*pi/180]);
guess.setState('/joinset/hip_r/hip_flexion_r/value',[2, 10*pi/180]);
guess.setState('/joinset/knee_l/knee_angle_l/value',[-2, 0]);
guess.setState('/joinset/knee_r/knee_angle_r/value',[-2, 0]);
guess.setState('/joinset/ankle_l/ankle_angle_l/value',[0.5, 0]);
guess.setState('/joinset/ankle_r/ankle_angle_r/value',[0.5, 0]);
guess.setState('jointset/lumbar/lumbar/value',[-20*pi/180,10*pi/180]);
solver.setGuess(guess);
- Attachments
-
- Ending motion
- sim_lift_ascending 3.png (202.33 KiB) Viewed 1411 times
-
- Feet moving backward
- sim_lift_ascending 2.jpg (98.72 KiB) Viewed 1411 times
-
- Start of the motion
- sim_lift_ascending 1.jpg (87.22 KiB) Viewed 1411 times