Closed EmanueleFeola closed 3 months ago
Solved by Michael Sherman on the Opensim forum.
The solution is the following:
you need to get a reference to the existing SimbodyMatterSubsystem rather than a copy
const SimbodyMatterSubsystem& smss = model->getMatterSubsystem();
My goal is to compute the jacobian of the model. Using matlab's api, it works as expected, but I'm having some trouble making it work using c++ api. Do you have any idea what I'm doing wrong? Here it follows both the matlab and the c++ code I'm testing, and some debug information at the end. Thank you in advance for any suggestion.
Using matlab it works correctly:
If I use c++ api, an exception is raised (Access violation reading location 0x0000000000000000):
Debugging I found the following info. The model is loaded correctly, since
model->printBasicInfo();
prints the correct number of joints (4) and bodies (4).If I loop through the body set (model->getBodySet()) I can print the bodies names, but if I try to access their mobilizedbody another excpetion is thrown.
If I loop through the joint set, I can print the joints names but I can't access their child frames (joints[i].getChildFrame()) without raising another exception.
state.getNQ()
andstate.getNU()
return the correct number.model->getNumBodies();
returns the correct number of bodiessmss->getNumBodies();
returns 0, as if the model was not initialized correctly