Forward dynamics in C++ and OpenSim 4.1
Posted: Thu Dec 03, 2020 6:46 am
Hi guys,
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:
Then, I start a loop, in which I'll get the current time, call the openSimPlantFunction (supposed to call functions for forward dynamics) and update the visualizer:
In this minimal example, excitations is a vector with some muscles at maximum excitation and all others at zero.
2. My openSimPlantFunction function:
Get states, get controls, apply addInControls for each muscle, set initial time, integrate, and compute state variable derivatives:
The system runs, but the response is the same for any excitation values that I set, so it does not seem to be actually assigning muscle excitations.
I appreciate it if someone could let me know what I am missing here.
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.