I am trying to test the MocoParameter in Matlab and find the optimal stiffness of the SpringGeneralizedForce. The example of squat to stand which was originally provided with the Opensim Moco focused on a specific stiffness. I wonder how to predict the optimal stiffness in such a moco study (just like the Mocopaper) in matlab. I added a MocoParameter in part 5, however, it did not work. Here is my code (modified part 5 of exmpleSquatToStand )

Code: Select all

```
%% Part 5: Muscle-driven Inverse Problem with Passive Assistance
% Part 5a: Create a new muscle-driven model, now adding a SpringGeneralizedForce
% about the knee coordinate.
device = SpringGeneralizedForce('knee_angle_r');
device.setName('spring')
initialstiffness=0;
device.setStiffness(initialstiffness);
device.setRestLength(0);
device.setViscosity(0);
muscleDrivenModel.addForce(device);
newModelFile = 'model_with_knee_device.osim';
muscleDrivenModel.print(newModelFile);
% Add MocoParameter for the knee assistance device parameters
mypara = MocoParameter('stiffness','/forceset/spring','stiffness',MocoBounds(1,99));
problem.addParameter(mypara);
% Part 5b: Create a ModelProcessor similar to the previous one, using the same
% reserve actuator strength so we can compare muscle activity accurately.
modelProcessor = ModelProcessor(muscleDrivenModel);
modelProcessor.append(ModOpAddReserves(2));
inverse.setModel(modelProcessor);
% Part 5c: Solve! Write solution.
inverseDeviceSolution = inverse.solve();
inverseDeviceSolution.getMocoSolution().write('inverseDeviceSolution.sto');
```

- Is there anything wrong with my codes? If it is possible for you to provide the right version

- As a beginner of Moco, are there any ways to learn the Moco fast?

Sincerely

yours,

Yimeng