Using API for static analysis with forces
Posted: Mon May 10, 2010 12:48 am
Hello, I am trying to write a c++ program to use the OpenSim API to perform a static simulation using the Stanford upperlimb model. In a nutshell what I'm trying to do is:
1 - Position the arm into a specific pose
2 - Apply an external load to the model's hand
3 - Calculate the forces in the muscles
I am able to write a program which can open the existing model, change some parameters (mass, inertia, etc) and save the model with these changed parameters.
I am having difficulty with writing code to define a new external force at the hand. I have tried creating a "PerscribedForce" class with a "Constant" function, and adding it to the "lunate" body in the model. My program compiles but I get an unrecognized exception error. I suspect I am not using the pointers of the classes properly.
If someone could tell me the basic code I need to get this working, I would greatly appreciate. I expect once it's working I can open the modified model in the java gui and I should see the new force in the browser.
Even further, if you could give me a hint on where to head next with the rest of my program (putting the model into a particular pose, running static simulation, getting muscle forces ...) I would be so grateful
Thank you
PS, the following is my code (simplified):
// Load Existing opensim model
Model osimModel(osim_file);
osimModel.setName("Standford_modified");
// Create pointer to BodySet inside osimModel
BodySet& bodyset = osimModel.updBodySet();
// Add external force
OpenSim::Body * body = &bodyset.get("lunate");
PrescribedForce *force1 = new PrescribedForce(body);
force1->setForceFunctions(&OpenSim::Constant(1.0), &OpenSim::Constant(1.0), &OpenSim::Constant(1.0));
osimModel.addForce(force1);
// Save copy of the modified model
osimModel.print("model_modified.osim");
1 - Position the arm into a specific pose
2 - Apply an external load to the model's hand
3 - Calculate the forces in the muscles
I am able to write a program which can open the existing model, change some parameters (mass, inertia, etc) and save the model with these changed parameters.
I am having difficulty with writing code to define a new external force at the hand. I have tried creating a "PerscribedForce" class with a "Constant" function, and adding it to the "lunate" body in the model. My program compiles but I get an unrecognized exception error. I suspect I am not using the pointers of the classes properly.
If someone could tell me the basic code I need to get this working, I would greatly appreciate. I expect once it's working I can open the modified model in the java gui and I should see the new force in the browser.
Even further, if you could give me a hint on where to head next with the rest of my program (putting the model into a particular pose, running static simulation, getting muscle forces ...) I would be so grateful
Thank you
PS, the following is my code (simplified):
// Load Existing opensim model
Model osimModel(osim_file);
osimModel.setName("Standford_modified");
// Create pointer to BodySet inside osimModel
BodySet& bodyset = osimModel.updBodySet();
// Add external force
OpenSim::Body * body = &bodyset.get("lunate");
PrescribedForce *force1 = new PrescribedForce(body);
force1->setForceFunctions(&OpenSim::Constant(1.0), &OpenSim::Constant(1.0), &OpenSim::Constant(1.0));
osimModel.addForce(force1);
// Save copy of the modified model
osimModel.print("model_modified.osim");