Parameter tuning issue with MocoTrack
Posted: Thu Jul 25, 2024 8:01 am
Hi everyone,
I tried parameter tuning in OpenSim Moco using MocoTrack. I can run MocoTrack without any issues with a MocoControlGoal and a MocoContactTrackingGoal. However, as soon as I add a MocoParameter to the problem it fails.
My problem is set up as follows:
However, when I add a single MocoParameter to the problem (before the solver configuration), for example as in the the following lines of code:
I get the following error message:
My workflow currently is now going back an forth between MocoInverse and MocoTrack:
1. MocoInverse for contact parameter optimisation -> Receive GRF profiles and improved contact model
2. MocoTrack for dynamic consistency and residual reduction -> Receive new and improved kinematics
3. MocoInverse with new kinematics to calculate muscle activations -> Receive tuned muscle parameters and muscle activations to calculate cost of transport
Is there a way around it? Many thanks for your help!
Cheers,
Oliver
I tried parameter tuning in OpenSim Moco using MocoTrack. I can run MocoTrack without any issues with a MocoControlGoal and a MocoContactTrackingGoal. However, as soon as I add a MocoParameter to the problem it fails.
My problem is set up as follows:
Code: Select all
% initialise Moco Study
study = track.initialize();
problem = study.updProblem();
disp('Appending problems...');
% ==== Get excitation effort from the problem ==== %
% Get a reference to the MocoControlGoal that is added to every MocoTrack
% problem by default and change the weight
excitationEffort = MocoControlGoal.safeDownCast(problem.updGoal('control_effort'));
excitationEffort.setWeight(effortWeights(ef));
% ==== Add a MocoContactTrackingGoal to the problem ==== %
contactTracking = MocoContactTrackingGoal('contact');
contactTracking.setExternalLoadsFile(GRFPath);
contactTracking.setWeight(trackingWeights(tr));
% define contact groups
contactGroupR = MocoContactTrackingGoalGroup(forceNamesRight, 'Right_pes_GRF',StdVectorString(ContactBodies));
contactGroupL = MocoContactTrackingGoalGroup(forceNamesRight, 'Left_pes_GRF',StdVectorString(ContactBodies));
% append contact groups to problem
contactTracking.addContactGroup(contactGroupR);
contactTracking.addContactGroup(contactGroupL);
% append goal to problem
problem.addGoal(contactTracking);
% ==== configure the solver and solve the problem ==== %
solver = MocoCasADiSolver.safeDownCast(study.updSolver()); % get solver
solver.resetProblem(problem); % reset problem
% update the solver tolerances
solver.set_optim_convergence_tolerance(1e-3);
solver.set_optim_constraint_tolerance(1e-4);
solver.set_optim_max_iterations(1000);
% ==== solve problem ==== %
disp(append('Solving problem ',num2str(loopCount),' of ', num2str(length(effortWeights)*length(trackingWeights)), '...'));
solution = study.solve();
Code: Select all
stiffnessParam = MocoParameter('contactStiffness',StdVectorString(HalfSpaceForces),'stiffness',MocoBounds(1e-5,1e6));
problem.addParameter(stiffnessParam); % append contact stiffnes to problem
The same problem setup works absolutely fine in MocoInverse. Is it not possible to do parameter optimisation (e.g., for muscle parameters like lm opt or TSL) with MocoTrack and only with MocoInverse?Java exception occurred:
java.lang.RuntimeException: casVector should be 1-dimensional, but has size 0 x 0.
Thrown at MocoCasOCProblem.h:108 in convertToSimTKVector().
at org.opensim.modeling.opensimMocoJNI.MocoStudy_solve(Native Method)
at org.opensim.modeling.MocoStudy.solve(MocoStudy.java:282)
My workflow currently is now going back an forth between MocoInverse and MocoTrack:
1. MocoInverse for contact parameter optimisation -> Receive GRF profiles and improved contact model
2. MocoTrack for dynamic consistency and residual reduction -> Receive new and improved kinematics
3. MocoInverse with new kinematics to calculate muscle activations -> Receive tuned muscle parameters and muscle activations to calculate cost of transport
Is there a way around it? Many thanks for your help!
Cheers,
Oliver