Page 1 of 1

Default activation error in DeGrooteFregly2016Muscle

Posted: Fri Aug 16, 2024 12:10 am
by rickchu
Hi there,

I am trying to use MocoInverse in C++ to analyze muscle activation in a upper limb model. When I replaced the muscle in the model by DeGrooteFregly2016Muscle and run inverse.initialize(), I got an error shows that the DELT1 muscle's default activation must be greater than 0, and the current default activation is 0. I checked the muscle activation bound of DELT1 which is 0.01 to 1. Thus, I am quite confused about why the default activation of DELT1 is 0 instead of 0.01.

The error is shown below

Code: Select all

 Error detected by Simbody method DeGrooteFregly2016Muscle::extendFinalizeFromProperties: DELT1: default_activation must be greater than zero, but it is 0.
  (Required condition 'get_default_activation() > 0' was not met.)
and my code is:

Code: Select all

	try {

		MocoInverse inverse;
		inverse.setName("I_dynamic");

		ModelProcessor modelProcessor(model);
		modelProcessor.append(ModOpAddExternalLoads("D:/D/unimelb/capstone/open model/ExtForce.xml"));
		modelProcessor.append(ModOpAddReserves(0.01, 1));
		modelProcessor.append(ModOpIgnoreTendonCompliance());
		//modelProcessor.append(ModOpRemoveMuscles());

		//new
		
		modelProcessor.append(ModOpReplaceMusclesWithDeGrooteFregly2016());
		// Only valid for DeGrooteFregly2016Muscles.
		modelProcessor.append(ModOpIgnorePassiveFiberForcesDGF());
		// Only valid for DeGrooteFregly2016Muscles.
		modelProcessor.append(ModOpScaleActiveFiberForceCurveWidthDGF(1.5));
		modelProcessor.append(ModOpIgnoreTendonCompliance());
		// end new


		inverse.setModel(modelProcessor);

		inverse.setKinematics(TableProcessor("D:/D/unimelb/capstone/UpAndStopAndDown0.6s_JointsKin.sto"));


		// allowed extra columns to avoid error
		inverse.set_kinematics_allow_extra_columns(true);

		inverse.set_mesh_interval(0.002);
		inverse.set_initial_time(0);
		inverse.set_final_time(0.6);
		inverse.set_convergence_tolerance(0.01);
		//inverse.set_constraint_tolerance(0.01);
		//Muscle& muscle = model.updComponent<Muscle>("/forceset/DELT1");
		//muscle.setActivation(initialState, 0.5);
		// convert to moco study
		MocoStudy inverseStudy = inverse.initialize();
It is really appreciated if I may have some suggestion to solve this error.

Many thanks,

Rick

Re: Default activation error in DeGrooteFregly2016Muscle

Posted: Fri Aug 16, 2024 10:53 am
by nbianco
Hi Rick,

The default activation check is a check we perform internally for the model. In most OpenSim simulations (not necessarily Moco), you don't want muscle controls to get too small to avoid singularities in the muscle dynamics. To avoid the error, simply set the default activation for DELT1 in the model to a value greater than zero.

"problem.setStateInfo()" in Moco will allow you to change the bounds on the activation during trajectory optimization if that is what you desire.

Best,
Nick

Re: Default activation error in DeGrooteFregly2016Muscle

Posted: Mon Aug 19, 2024 2:05 am
by rickchu
Hi Nick,

Many thanks for your reply! :>

When I try to update the default activation of DELT1 muscle, which is the 0th muscle in Muscle set, I use the code below.

Code: Select all

 	initialState = model.initSystem();
	model.getMuscles().get(0).setActivation(initialState, 0.3);
I am not sure if setActivation() is the correct function I need to use, but it is the only function I found under muscle class to adjust the muscle activation. Even though I used this function, I still get the same error which mentioned that the default activation of DELT1 is 0. If it is possible, could you give me some hints about which function I need to use to change the default activation of muscle in the model?

Many thanks,

Rick

Re: Default activation error in DeGrooteFregly2016Muscle

Posted: Mon Aug 19, 2024 2:16 pm
by nbianco
Hi Rick,

You need to use `set_default_activation()` here. `setActivation()` sets the activation for the current state, not the default activation.

Best,
Nick