I am performing an optimization with MocoInverse and EMGTracking and try to incorporate tendon compliance. The problem: the solution would not start running and report the following error:
[/code]std::exception in 'OpenSim::MocoSolution OpenSim::MocoStudy::solve() const': casVector should be 1-dimensional, but has size 0 x 0.
Thrown at MocoCasOCProblem.h:108 in convertToSimTKVector()
The code I am using is below. When ignoring tendon compliance with modelProcessor2.append(osim.ModOpIgnoreTendonCompliance()) the code runs fine.....do you see any odd things in the code?
Thanks Christian
Code: Select all
modelProcessor2 = osim.ModelProcessor(Scaled_modelFileName)
modelProcessor2.append(osim.ModOpAddExternalLoads(GRF_SourceFilename))
modelProcessor2.append(osim.ModOpUseImplicitTendonComplianceDynamicsDGF())
modelProcessor2.append(osim.ModOpReplaceMusclesWithDeGrooteFregly2016())
modelProcessor2.append(osim.ModOpAddReserves(ReserveActuatorStrength))
#%% Construct MocoInverse
inverse2 = osim.MocoInverse()
inverse2.setModel(modelProcessor2)
inverse2.setKinematics(osim.TableProcessor(Coordinates_Filename))
inverse2.set_minimize_sum_squared_activations(True)
inverse2.set_initial_time(start_time)
inverse2.set_final_time(end_time)
inverse2.set_mesh_interval(0.02)
inverse2.set_kinematics_allow_extra_columns(True)
study2 = inverse2.initialize()
problem2 = study2.updProblem()
# %% modify effort goal; put more effort on muscles which are close to activation 1....this needs individual adjustments.
controlEffortWeight = 50.0
effort2 = osim.MocoControlGoal("control_effort2") #.safeDownCast(problem.updGoal("control_effort"))
effort2.setName('effort2')
effort2.setWeight(controlEffortWeight)
Muscles = ClubfootModel.updMuscles()
problem2.addGoal(effort2)
#%% Tendon force and velocity equilibrium
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.001)
problem2.addGoal(TendonVGoal2)
#%% Add electromyography tracking.
emgTracking2 = osim.MocoControlTrackingGoal('emg_tracking2')
emgTracking2.setWeight(100)
controlsRef = osim.TimeSeriesTable(EMG_Filename)
emgTracking2.setReference(osim.TableProcessor(controlsRef))
emgTracking2.setReferenceLabel('/forceset/soleus_r', 'soleus_r_activation')
emgTracking2.setReferenceLabel('/forceset/med_gas_r', 'med_gas_r_activation')
emgTracking2.setReferenceLabel('/forceset/lat_gas_r', 'med_gas_r_activation')
emgTracking2.setReferenceLabel('/forceset/tib_ant_r', 'tib_ant_r_activation')
emgTracking2.setReferenceLabel('/forceset/per_brev_r', 'per_brev_r_activation')
emgTracking2.setReferenceLabel('/forceset/per_long_r', 'per_long_r_activation')# brev en long are same data
emgTracking2.setWeightForControl('/forceset/soleus_r',10)
emgTracking2.setWeightForControl('/forceset/med_gas_r',10)
emgTracking2.setWeightForControl('/forceset/lat_gas_r',10)
emgTracking2.setWeightForControl('/forceset/tib_ant_r',10)
emgTracking2.setWeightForControl('/forceset/per_brev_r',5)
emgTracking2.setWeightForControl('/forceset/per_long_r',5)
problem2.addGoal(emgTracking2)
#%% Solve the problem and write the solution to a Storage file.
solver2 = osim.MocoCasADiSolver.safeDownCast(study2.updSolver())
solver2.resetProblem(problem2)
solver2.set_multibody_dynamics_mode('implicit')
solver2.set_num_mesh_intervals(100)
solver2.set_optim_convergence_tolerance(.01)#.....10^-1
solver2.set_optim_constraint_tolerance(1e-4)#1e-4 is default
solver2.set_optim_max_iterations(4000)
solver2.set_parameters_require_initsystem(False)
solution2 = study2.solve()
solution2.unseal()
solution2.write(Output_Filename.replace('.sto','_tendonCompliance.sto'))