Extracting force analysis with manager tool in Matlab

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
atabak mehrabani
Posts: 5
Joined: Sun Mar 10, 2019 7:18 am

Extracting force analysis with manager tool in Matlab

Post by atabak mehrabani » Fri Mar 03, 2023 10:58 am

Hello,

I'm trying to run a simulation and I'm using Manager tool with MATLAB API. Simulation runs perfectly and I can get the states.sto file and investigate/visualize it but I can't seem to find the functions to print out the forces (or any type of analysis that you could add while running Forward dynamic within the GUI). I'm just not sure how to extract the forces after I ran the simulation...
It would be amazing if someone could help me with this or to reference a code/file... I attached the portion of the code that runs the simulation in my code

import org.opensim.modeling.*
modelPath='D:\...
model = Model(modelPath);

%adding Reporters
forcerep = ForceReporter(model);
model.addAnalysis(forcerep);

%Running Simulation
state = model.initSystem();

manager = Manager(model);
manager.setPerformAnalyses(true);
state.setTime(0);
manager.initialize(state);
state = manager.integrate(0.5);

sTable = manager.getStatesTable();
stofiles = STOFileAdapter();
if ~isdir('ResultsFWD')
mkdir ResultsFWD
end
stofiles.write(sTable, 'ResultsFWD/simulation_states.sto');

display('Simulation Finished.');

Tags:

User avatar
Jiabiao Yi
Posts: 2
Joined: Mon Mar 21, 2022 7:24 pm

Re: Extracting force analysis with manager tool in Matlab

Post by Jiabiao Yi » Tue Mar 07, 2023 11:46 pm

I'm not sure but maybe you can insert these sentences before 'state = model.initSystem();' to see if it works:
'Forceset=model.get_ForceSet();
reporter = ConsoleReporter();
reporter.set_report_time_interval(1.0); %1.0 is the time interval which can be changed
for i=0:N-1 %N is the number of objects in Forceset. I didn't find a function to measure the size of Forceset, so you have to check your model and specify it yourself
reporter.addToReport(Forceset.get(i).getOutput('fiber_force')); %'fiber_force' can also be 'fiber_length', 'activation' and 'tendon_force', as far as I know
end
model.addComponent(reporter);'
If it does work, please notify me.
By the way, do you have a way to specify the initial state? Or you just use the default values?

POST REPLY