Page 1 of 1

Using SimTK Assemblar object to assemble Closed-Chain systems

Posted: Thu Jul 11, 2024 9:58 am
by mlaudu
We are trying to enforce constraints for a system with closed-chains using the Assembler object using the following:

Code: Select all

auto &system = osimModel.getMultibodySystem();
Assembler assembler(system);
assembler.assemble(state);
This assembles the model but most of the generalized coordinate bounds were violated. So we tried to enforce the bounds by adding the following before invoking assembler.assemble(state):

Code: Select all

for (i = 0; i < numGenCoords; ++i)
{
	SimTK::MobilizedBodyIndex mbx = coords[i].getBodyIndex();
	SimTK::MobilizerQIndex qx = coords[i].getMobilizerQIndex();
	double lb = coords[i].getRangeMin()*180/Pi;
	double ub = coords[i].getRangeMax() * 180 / Pi;
	assembler.restrictQ(mbx, qx, lb, ub); 
}
However this causes a compiler error because the second argument of the function restrictQ requires a SimTK:: MobilizerQIndex type while OpenSim:Coordinate class function getMobilizerQIndex() returns an integer! We tried the following which did not work:

Code: Select all

SimTK::MobilizerQIndex qx = MobilizerQIndex::safeDownCast(coords[i].getMobilizerQIndex());
This resulted in the error:

Code: Select all

'safeDownCast': is not a member of 'SimTK::MobilizerQIndex'.
Can anybody give us insight on how to get around this problem?

Re: Using SimTK Assemblar object to assemble Closed-Chain systems

Posted: Thu Jul 11, 2024 10:20 am
by sherm
I think all you need is a C-style cast like
SimTK::MobilizerQIndex(int)

Re: Using SimTK Assemblar object to assemble Closed-Chain systems

Posted: Thu Jul 11, 2024 12:13 pm
by mlaudu
Thanks a lot Sherm. That works for compilation. Now I have another problem. The assembler only runs once: assembler.getNumAssemblySteps() = 1 and assembler.getNumGoalEvals() = 1. The gen coords are not changed from their mis-assembled values. Am I doing something wrong or missing a step somewhere? Thanks.