Page 1 of 1

Enabling and Disabling Constraints

Posted: Tue May 21, 2013 11:52 am
by omarzarifi
Hello,
I'm having a little problem with constraints. I have defined two ConstantSpeed (set at 0) constraints (to model brakes). The definitions are:

Code: Select all

upperConstraint = new Constraint::ConstantSpeed(*arm->getUpper()->getBody(), 0);
lowerConstraint = new Constraint::ConstantSpeed(*arm->getLower()->getBody(), 0);
At some point in the simulation, I'd like to disable (and re-enable) these constraints. However, the disable() and enable() methods aren't working for some reason. The states I provide to these methods are obtained via updAdvancedState() from the Integrator (which is itself obtained through updIntegrator() from a TimeStepper). Any ideas on why I'm encountering this? I've also tried calling reinitialize up to the Instance stage on the integrator after the manipulation of the constraints; still no luck... Also, I don't know if this is relevant, but the constraints are updated both when the simulation is paused and during a simulation.
Any help would be appreciated. Thanks in advance.
Omar

Re: Enabling and Disabling Constraints

Posted: Tue May 21, 2013 1:48 pm
by sherm
Hi, Omar. The most likely explanation is that the State object within which you are disabling the constraint is not the one being used to advance the simulation. That can easily happen if there is a missing "&". For example,

Code: Select all

State s = integ.updAdvancedState(); // s is a new copy
State& s = integ.updAdvancedState(); // s refers to integrator's state
There are other possibilities, but I would need to see exactly the code you're using.

The Simbody "adhoc test" LockUnlockConstraint.cpp has code that disables and enables a ConstantSpeed constraint -- you might want to have a look at that to see if you spot anything different you're doing.

Regards,
Sherm

Re: Enabling and Disabling Constraints

Posted: Tue May 21, 2013 2:06 pm
by omarzarifi
That was exactly it. Thank you very much for your help.
Omar

Re: Enabling and Disabling Constraints

Posted: Tue May 21, 2013 5:14 pm
by sherm
You're very welcome!

Sherm