Struggling with MocoOutputGoals

OpenSim Moco is a software toolkit to solve optimal control problems with musculoskeletal models defined in OpenSim using the direct collocation method.
POST REPLY
User avatar
Daniel Gordon
Posts: 34
Joined: Fri May 06, 2016 7:57 am

Struggling with MocoOutputGoals

Post by Daniel Gordon » Mon Feb 14, 2022 9:07 am

Hello,

I can't figure out how to get MocoOutputGoal costs to work through the Matlab or C++ API's.

Here's how I've been defining the goals:

Code: Select all

    
    // Set up kinetic energy goal
    if (w_kinetic > 0) 
    {
        auto* kinetic_goal = problem.addGoal<MocoOutputGoal>("kinetic", w_kinetic);
        kinetic_goal->setOutputPath(kinetic_path);
        kinetic_goal->setDivideByDisplacement(true);
        kinetic_goal->setDivideByMass(true);
    }

    // Set up potential energy goal
    if (w_potential > 0)
    {
        auto* potential_goal = problem.addGoal<MocoOutputGoal>("potential", w_potential);
        potential_goal->setOutputPath(potential_path);
        potential_goal->setDivideByDisplacement(true);
        potential_goal->setDivideByMass(true);
    }
As you can probably tell by the naming, I've been trying with the model potential/kinetic energy paths, but when that didn't work I also tried with other outputs (e.g. actuation levels).

The (rather messy) output I get from trying to run this is:
CasADi - CasADi - CasADi - CasADi - CasADi - CasADi - CasADi - CasADi - 2022-02-14 15:58:232022-02-14 15:58:23 WARNING("Exception raised: Error in Function::operator() for 'map13_cost_kinetic_integrand' [Map] at .../casadi/core/function.cpp:1368:
Error in Function::operator() for 'cost_kinetic_integrand' [CallbackInternal] at .../casadi/core/function.cpp:1368:
.../casadi/core/function_internal.cpp:3363: Failed to evaluate 'eval_dm' for cost_kinetic_integrand:
.../casadi/core/callback_internal.cpp:122: Error calling "eval" for object cost_kinetic_integrand:
SimTK Exception thrown at State.cpp:974:
Error detected by Simbody method getCacheEntry: State Cache entry was out of date at Stage Velocity. This entry depends on version 2 of Stage Velocity but was last updated at version 0.
(Required condition 'version == m_dependsOnVersionWhenLastComputed' was not met.)
") [.../casadi/core/map.cpp:419]
2022-02-14 15:58:23 WARNING("2022-02-14 15:58:23 WARNING(" WARNING("Exception raised: Error in Function::operator() for 'map13_cost_kinetic_integrand' [Map] at .../casadi/core/function.cpp:1368:
Error in Function::operator() for 'cost_kinetic_integrand' [CallbackInternal] at .../casadi/core/function.cpp:1368:
.../casadi/core/function_internal.cpp:3363: Failed to evaluate 'eval_dm' for cost_kinetic_integrand:
.../casadi/core/callback_internal.cpp:122: Error calling "eval" for object cost_kinetic_integrand:
SimTK Exception thrown at State.cpp:974:
Error detected by Simbody method getCacheEntry: State Cache entry was out of date at Stage Velocity. This entry depends on version 2 of Stage Velocity but was last updated at version 0.
(Required condition 'version == m_dependsOnVersionWhenLastComputed' was not met.)
") [.../casadi/core/map.cpp:419Exception raised: Error in Function::operator() for 'map13_cost_kinetic_integrand' [Map] at .../casadi/core/function.cpp:1368:
Error in Function::operator() for 'cost_kinetic_integrand' [CallbackInternal] at .../casadi/core/function.cpp:1368:
.../casadi/core/function_internal.cpp:3363: Failed to evaluate 'eval_dm' for cost_kinetic_integrand:
.../casadi/core/callback_internal.cpp:122: Error calling "eval" for object cost_kinetic_integrand:
SimTK Exception thrown at State.cpp:974:
Error detected by Simbody method getCacheEntry: State Cache entry was out of date at Stage Velocity. This entry depends on version 2 of Stage Velocity but was last updated at version 0.
(Required condition 'version == m_dependsOnVersionWhenLastComputed' was not met.)
2022-02-14 15:58:23 WARNING("Exception raised: Error in Function::operator() for 'map13_cost_kinetic_integrand' [Map] at .../casadi/core/function.cpp:1368:
Error in Function::operator() for 'cost_kinetic_integrand' [CallbackInternal] at .../casadi/core/function.cpp:1368:
.../casadi/core/function_internal.cpp:3363: Failed to evaluate 'eval_dm' for cost_kinetic_integrand:
.../casadi/core/callback_internal.cpp:122: Error calling "eval" for object cost_kinetic_integrand:
SimTK Exception thrown at State.cpp:974:
Error detected by Simbody method getCacheEntry: State Cache entry was out of date at Stage Velocity. This entry depends on version 2 of Stage Velocity but was last updated at version 0.
(Required condition 'version == m_dependsOnVersionWhenLastComputed' was not met.)
") [") [Exception raised: Error in Function::operator() for 'map13_cost_kinetic_integrand' [Map] at .../casadi/core/function.cpp:1368:
Error in Function::operator() for 'cost_kinetic_integrand' [CallbackInternal] at .../casadi/core/function.cpp:1368:
.../casadi/core/function_internal.cpp:3363: Failed to evaluate 'eval_dm' for cost_kinetic_integrand:
.../casadi/core/callback_internal.cpp:122: Error calling "eval" for object cost_kinetic_integrand:
SimTK Exception thrown at State.cpp:974:
Error detected by Simbody method getCacheEntry: State Cache entry was out of date at Stage Velocity. This entry depends on version 2 of Stage Velocity but was last updated at version 0.
(Required condition 'version == m_dependsOnVersionWhenLastComputed' was not met.)
") [.../casadi/core/map.cpp:419]
2022-02-14 15:58:23.../casadi/core/map.cpp:419 WARNING("]
Exception raised: Error in Function::operator() for 'map13_cost_kinetic_integrand' [Map] at .../casadi/core/function.cpp:1368:
Error in Function::operator() for 'cost_kinetic_integrand' [CallbackInternal] at .../casadi/core/function.cpp:1368:
.../casadi/core/function_internal.cpp:3363: Failed to evaluate 'eval_dm' for cost_kinetic_integrand:
.../casadi/core/callback_internal.cpp:122: Error calling "eval" for object cost_kinetic_integrand:
SimTK Exception thrown at State.cpp:974:
Error detected by Simbody method getCacheEntry: State Cache entry was out of date at Stage Velocity. This entry depends on version 2 of Stage Velocity but was last updated at version 0.
(Required condition 'version == m_dependsOnVersionWhenLastComputed' was not met.)
") [.../casadi/core/map.cpp:419]
]
.../casadi/core/map.cpp:419]
2022-02-14 15:58:23 WARNING("2022-02-14 15:58:23 WARNING("Exception raised: Error in Function::operator() for 'map13_cost_kinetic_integrand' [Map] at .../casadi/core/function.cpp:1368:
Error in Function::operator() for 'cost_kinetic_integrand' [CallbackInternal] at .../casadi/core/function.cpp:1368:
.../casadi/core/function_internal.cpp:3363: Failed to evaluate 'eval_dm' for cost_kinetic_integrand:
.../casadi/core/callback_internal.cpp:122: Error calling "eval" for object cost_kinetic_integrand:
SimTK Exception thrown at State.cpp:974:
Error detected by Simbody method getCacheEntry: State Cache entry was out of date at Stage Velocity. This entry depends on version 2 of Stage Velocity but was last updated at version 0.
(Required condition 'version == m_dependsOnVersionWhenLastComputed' was not met.)
") [.../casadi/core/map.cpp:419]
Exception raised: Error in Function::operator() for 'map13_cost_kinetic_integrand' [Map] at .../casadi/core/function.cpp:1368:
Error in Function::operator() for 'cost_kinetic_integrand' [CallbackInternal] at .../casadi/core/function.cpp:1368:
.../casadi/core/function_internal.cpp:3363: Failed to evaluate 'eval_dm' for cost_kinetic_integrand:
.../casadi/core/callback_internal.cpp:122: Error calling "eval" for object cost_kinetic_integrand:
SimTK Exception thrown at State.cpp:974:
Error detected by Simbody method getCacheEntry: State Cache entry was out of date at Stage Velocity. This entry depends on version 2 of Stage Velocity but was last updated at version 0.
(Required condition 'version == m_dependsOnVersionWhenLastComputed' was not met.)
") [.../casadi/core/map.cpp:419]
The exact same code works fine if I add, for example, an effort term using a MocoControlGoal, so it seems to me it must be something to do with how I'm specifying these output goals, but as far as I can tell I've followed the same format as used in the example2DWalkingMetabolics.cpp example.

Can anyone see anything obvious that I'm doing wrong here?

Cheers,

Daniel

User avatar
Nicholas Bianco
Posts: 992
Joined: Thu Oct 04, 2012 8:09 pm

Re: Struggling with MocoOutputGoals

Post by Nicholas Bianco » Mon Feb 14, 2022 12:40 pm

Hi Daniel,

The key error I'm seeing is that the SimTK::State cache is invalid when calling the cost integrand function. Just to clarify: this works when using a MocoControlGoal AND one of the kinetic/potential energy goals? If so, then there might be a bug when using a MocoOutputGoal by itself.

-Nick

User avatar
Nicholas Bianco
Posts: 992
Joined: Thu Oct 04, 2012 8:09 pm

Re: Struggling with MocoOutputGoals

Post by Nicholas Bianco » Mon Feb 14, 2022 12:40 pm

Hi Daniel,

The key error I'm seeing is that the SimTK::State cache is invalid when calling the cost integrand function. Just to clarify: this works when using a MocoControlGoal AND one of the kinetic/potential energy goals? If so, then there might be a bug when using a MocoOutputGoal by itself.

-Nick

POST REPLY