I'm working on a post processing script in Matlab that takes all the (subjectively) relevant model outputs computed from a MocoTrajectory (from a prediction solution). Think: states, controls, all fiber lengths, tendon lengths, active/passive fiber forces, tendon forces, etc. The reason for this is that I'm running simulations while sequentially increasing the desired speed of a locomotion task, and I'd like to batch-process the simulation results later. The script stores all of the outputs of a simulation in structured arrays within a single matlab 'struct', with all the column names as cell arrays as well, and saves it as a .mat file. This makes batch processing in Matlab efficient, without having to type lengthy column names (since those are all stored in array tables as well). Once the script is finished I'd be happy to post it on here, if people are interested.
It all works the way it should, except for two issues that I've run into.
1): I can't seem to extract the outputs of the model itself (CoM pos, vel, E_kin, E_pot).
Code: Select all
outputPaths_model = StdVectorString();
outputPaths_model.add('.*com_acceleration');
outputPaths_model.add('.*com_position');
outputPaths_model.add('.*com_velocity');
outputPaths_model.add('.*kinetic_energy');
outputPaths_model.add('.*potential_energy');
model_outputs_table=study.analyze(gaitPredictionSolution, outputPaths_model);
model_outputs=osimTableToStruct(model_outputs_table);
2): I'd like to store the joint reaction forces/moments from a mocoTrajectory, so that I can get all the simulation data in a single data struct. The reason for this is that once I can access these, I'd like to work towards implementing a stress-constraint as a custom goal, similar to Sellers et al 2017. They showed that maximal running speed of T. rex was limited by stress on the limb bones. They compute limb stress using the following equations: (taken from their paper, I think they define Z as up instead of Y as up).
They compute the stress on the hindlimbs using Euler-Bernoulli beam equations, so stress is the sum of the bending moments & compressive stresses on the limbs. To easily implement this, I'll be adding weldjoints at the mid point of each hindlimb segment. Before adding these, however, I'd like to be able to access the jointreactions from a MocoTrajectory in Matlab, but I'm not sure how to best approach this. The examples that I found on the Opensim forum relate to running an analysis in the standalone Opensim program, which is not what I'm trying to achieve.
As an aside: I'd like to work towards running optimizations with different stress levels set as inequality constraints (i.e. 100 MPa, 200MPa, etc). Is this possible using a custom goal in Moco? I was confused by the wording of "endpoint constraint' in the documentation, but my thinking was that I could set an endpoint constraint to lie between 0 - 200, if I wanted it to work as an inequality constraint? Or would the correct route be a regular weighted cost? I also expect that I can approximate the effect of the stress constraint by adding the weldjoints, and then defining M_z and M_x and F_y as standard joint reaction costs, although I suspect that this route would require a lot of tuning of their relative weights.
Any suggestions are welcome!
Pasha