I am trying to build an API, so I can control muscle excitation (forward dynamics).
A few years ago, I successfully used these scripts API (for OpenSim 3.3 and Matlab): https://github.com/anacsousa1/opensim-f ... simLibrary
I just call for addInControls with the correct excitations and controllers: https://github.com/anacsousa1/opensim-f ... _v2.m#L333
Now, I started working on OpenSim 4.1, C++, and Ubuntu 20.04. I am trying to create a similar application: control the excitation of muscles based on state response.
1. My main function:
After loading the model, I initiate the forward dynamics and the integrator:
Code: Select all
fdManager_.reset(new Manager(model_));
fdManager_->setIntegratorAccuracy(1.0e-4);
fdManager_->initialize(s_);
Code: Select all
for (int i{0}; i < n; ++i) {
t = i * Ts;
manager.openSimPlantFunction(t, t + Ts, excitations);
manager.updateVisualizer();
}
2. My openSimPlantFunction function:
Get states, get controls, apply addInControls for each muscle, set initial time, integrate, and compute state variable derivatives:
Code: Select all
s_.setTime(initialTime);
auto controls = model_.updControls(s_);
for (int i = 0; i < model_.updActuators().getSize(); i++){
model_.updActuators()[i].addInControls(Vector(1, excitations[i]), controls);
}
forwardIntegrate(finalTime);
model_.computeStateVariableDerivatives(s_);
I appreciate it if someone could let me know what I am missing here.