Page 1 of 1

EMG tracking cost

Posted: Tue Apr 30, 2024 11:48 pm
by grevec
Dear Moco Community,

I am running a MocoStudy with EMG tracking. The EMG tracking has by far the highest weight in my cost function (10). But when I investigate the solution, it seems that control effort has a larger weight in the overall cost function. This would match with the computed muscle activations which do not really match the measured EMG signals.

My question is why is the solver not prioritizing the EMG goal since its'weight was highest?


+++Solution header++++++++++++++

num_controls=155
num_derivatives=47
num_iterations=1784
num_multipliers=0
num_parameters=0
num_slacks=0
num_states=154
objective=2.734561
objective_activation_effort=0.196823
objective_auxiliary_derivatives=0.000000
objective_effort2=1.120349
objective_emg_tracking2=0.297037
objective_excitation_effort=1.120349
objective_initial_velocity_equilibrium2=0.000003
solver_duration=16668.439883
status=Solve_Succeeded
success=true
DataType=double
version=3
OpenSimVersion=4.2
endheader
++++++++++++++++++++++++++++++++


My code:

I first use MocoInverse and .set_minimize_sum_squared_activations(True);

next, I build a MocoStudy and modify the control effort goal:

Code: Select all

controlEffortWeight = 1
effort2 = osim.MocoControlGoal("control_effort2") #.safeDownCast(problem.updGoal("control_effort"))
effort2.setName('effort2')
effort2.setWeight(controlEffortWeight).

finally I add a TendonVGoal and an EMG tracking goal with different weights for different muscles

TendonVGoal2 = osim.MocoInitialVelocityEquilibriumDGFGoal()
TendonVGoal2.setName("initial_velocity_equilibrium2")
# The problem converges in fewer iterations when this goal is in cost mode.
TendonVGoal2.setMode("cost")
TendonVGoal2.setWeight(0.0000001)
 problem2.addGoal(TendonVGoal2)

emgTracking2 = osim.MocoControlTrackingGoal('emg_tracking2')
emgTracking2.setWeight(10)
controlsRef = osim.TimeSeriesTable(EMG_Filename)
emgTracking2.setReference(osim.TableProcessor(controlsRef))
for label, activation in reference_labels.items():
   emgTracking2.setReferenceLabel(label, activation)
    emgTracking2.setWeightForControl(label, reference_weights[label])
    
 problem2.addGoal(emgTracking2)

Re: EMG tracking cost

Posted: Wed May 01, 2024 3:48 pm
by nbianco
Hi Christian,

A higher weight in the cost function doesn't necessarily mean that that term will contribute less to the overall objective function. Tracking goals can theoretically achieve zero cost if the reference data is tracked perfectly, but effort goals will never be exactly zero since there needs to be some non-zero control to achieve a motion. Use the objective function breakdown as a guide for choosing the weights for each cost term.

-Nick