Page 1 of 1
Trouble running MocoTrack in implicit mode?
Posted: Thu Sep 09, 2021 7:42 am
by danielfng
Hello,
I'm trying to run the MocoTrack tool for a problem in implicit mode using Matlab, but am running in to this error:
java.lang.RuntimeException: casVector should be 1-dimensional, but has size 0 x 0.
Thrown at MocoCasOCProblem.h:108 in convertToSimTKVector().
The same code when run in explicit mode seems to work fine and produces a solution in 70-100 iterations or so.
To enter implicit mode, I've been using the following:
Code: Select all
solver = MocoCasADiSolver.safeDownCast(study.updSolver());
solver.set_multibody_dynamics_mode('implicit');
Has anyone else run in to this problem, or is anyone a bit more familiar with the error message to point me in the right direction?
Cheers
Re: Trouble running MocoTrack in implicit mode?
Posted: Thu Sep 09, 2021 11:09 am
by nbianco
Hi Daniel,
How are you creating the initial guess? This type of error usually has something with the guess being incompatible, which can happen when switching between implicit and explicit mode due to missing acceleration variables. (This is technically a bug though, we should account for this during the compatibility checks we do).
You could try creating a fresh initial guess after changing the dynamics mode, that way you can ensure the guess is compatible with the problem.
-Nick
Re: Trouble running MocoTrack in implicit mode?
Posted: Thu Nov 21, 2024 5:07 pm
by pvb
Hi Nick,
Sorry to resurrect this thread, but I just wanted to mention I ran into the same issue, and how I avoided it.
I ran a MocoTrack study in explicit mode, which worked fine. I then set the following code:
Code: Select all
solver.set_multibody_dynamics_mode('implicit');
solver.set_minimize_implicit_multibody_accelerations(true);
solver.set_implicit_multibody_accelerations_weight(myweight);
This resulted in the casVector error in the OP. The problem was how I set the the guess - I'd done the following:
Code: Select all
guess = solver.createGuess();
[several lines of code that modified the default guess
I had subsequently forgotten to call: solver.setGuess(guess).
So I wasn't setting the guess that I'd modified. Is this a bug, or is this user error?
The steps to reproduce are:
MocoTrack
Set implicit multibody dynamics
Create Guess
Don't set the guess after modifying it.
Cheers,
Pasha
Re: Trouble running MocoTrack in implicit mode?
Posted: Mon Nov 25, 2024 11:16 am
by nbianco
Hi Pasha,
I'd say this is more of a design limitation of MocoTrack, rather than a bug. By default, MocoTrack sets the initial guess based on explicit dynamics mode. If you switch to implicit dynamics mode, the default guess set by MocoTrack will be incompatible with the problem, which is why you need to update the guess.
It is a bug that we don't catch the incompatible problem before encountering the casVector error. I'll track this issue on GitHub and look into a fix.
Best,
Nick