Modifying Model after Model::initSystem()
Posted: Thu May 13, 2010 8:53 am
Hi,
I tried to make a simple program using OpenSim API according to the following flow:
Model osimModel("Arm26_Optimize.osim");
// Get the state variables to modify the coordinate values of the model
State& si = Model.initSystem();
// Modify a coordinate as a desired value
OpenSim::Set<OpenSim::Coordinate>& refCoordinateSet = pModel->updCoordinateSet();
OpenSim::Coordinate& refCoord = refCoordinateSet.get("r_elbow_flex");
refCoord.setValue(si, 0.000);
// Add a constraint between a body and the ground
Model.invalidateSystem();
OpenSim::PointConstraint* constraint1 = new OpenSim::PointConstraint();
constraint1->setBody1ByName("ground");
constraint1->setBody1PointLocation(Vec3(a,b,c));
constraint1->setBody2ByName(“r_ulna_radius_hand”);
constraint1->setBody2PointLocation(Vec3(x,y,z));
Model.addConstraint(constraint1);
si = Model.initSystem();
constraint1->initState(si);
But when I debug the above code, a critical error occurred at ‘si= Model.initSystem()’ operation. It is a crash.
I found that most of OpenSim API examples in the OpenSim developer’s guide called this Model::initSystem() function after constructing the model before simulation. But in my case, to change the human posture to find a correct initial configuration considering the environment, Coordinate::setValue() and Coordinate::getValue() functions are needed. To use these functions, I have to call ‘si = Model.initSystem()’ to use the state variables.
I found ‘Model::invalidateSystem()’ function. I thought that if I use this function, I can change the OpenSim model by adding some constraints or forces even after calling Model::initSystem() function. But when I see a critical error, I think that my guess may be wrong.
My question is that whether adding some constraints, forces or even bodies(joints) can be allowed after calling Model::initSystem() function? Is there any possible way to do this?
If it is now allowed, I think that users should know all coordinate values of the initial configuration that satisfies the kinematic constraints of the system. But it is very hard if we try to model a product with an OpenSim human model.
My idea is as follows:
(1) Load an Osim model that includes a human.
(2) Render a product model that is not an OpenSim object yet.
(3) Change the posture of human model to have interaction with the product model.
(4) Add the bodies(joints) that represent the product model to existing OpenSim Model by OpenSim API.
(5) Add some constraints to make interaction between the product and human model by OpenSim API
(6) Perform a simulation
If my idea is not achievable, would you please give me some advice?
Best regards,
Moonki
I tried to make a simple program using OpenSim API according to the following flow:
Model osimModel("Arm26_Optimize.osim");
// Get the state variables to modify the coordinate values of the model
State& si = Model.initSystem();
// Modify a coordinate as a desired value
OpenSim::Set<OpenSim::Coordinate>& refCoordinateSet = pModel->updCoordinateSet();
OpenSim::Coordinate& refCoord = refCoordinateSet.get("r_elbow_flex");
refCoord.setValue(si, 0.000);
// Add a constraint between a body and the ground
Model.invalidateSystem();
OpenSim::PointConstraint* constraint1 = new OpenSim::PointConstraint();
constraint1->setBody1ByName("ground");
constraint1->setBody1PointLocation(Vec3(a,b,c));
constraint1->setBody2ByName(“r_ulna_radius_hand”);
constraint1->setBody2PointLocation(Vec3(x,y,z));
Model.addConstraint(constraint1);
si = Model.initSystem();
constraint1->initState(si);
But when I debug the above code, a critical error occurred at ‘si= Model.initSystem()’ operation. It is a crash.
I found that most of OpenSim API examples in the OpenSim developer’s guide called this Model::initSystem() function after constructing the model before simulation. But in my case, to change the human posture to find a correct initial configuration considering the environment, Coordinate::setValue() and Coordinate::getValue() functions are needed. To use these functions, I have to call ‘si = Model.initSystem()’ to use the state variables.
I found ‘Model::invalidateSystem()’ function. I thought that if I use this function, I can change the OpenSim model by adding some constraints or forces even after calling Model::initSystem() function. But when I see a critical error, I think that my guess may be wrong.
My question is that whether adding some constraints, forces or even bodies(joints) can be allowed after calling Model::initSystem() function? Is there any possible way to do this?
If it is now allowed, I think that users should know all coordinate values of the initial configuration that satisfies the kinematic constraints of the system. But it is very hard if we try to model a product with an OpenSim human model.
My idea is as follows:
(1) Load an Osim model that includes a human.
(2) Render a product model that is not an OpenSim object yet.
(3) Change the posture of human model to have interaction with the product model.
(4) Add the bodies(joints) that represent the product model to existing OpenSim Model by OpenSim API.
(5) Add some constraints to make interaction between the product and human model by OpenSim API
(6) Perform a simulation
If my idea is not achievable, would you please give me some advice?
Best regards,
Moonki