Plug in development

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Nirav Maniar
Posts: 32
Joined: Tue May 12, 2015 11:03 pm

Plug in development

Post by Nirav Maniar » Wed Jul 17, 2019 6:39 pm

Hi all,

I am attempting to develop a simple plug in to compute body segment momentum about the centre of mass. I have managed to achieve my first successful build, but the resulting .sto file only has -1.#IND0000000000000000 for every value, suggesting I have made a mistake (I am a complete novice at C++).

Due to my inexperience, I am hoping someone can tell me what I have done wrong? The main portion of the code is below. Please note that I developed this as a modification to the example (for body kinematics) provided in the original OpenSim 3.3 distribution, hence there may be a couple of things in there that are no longer needed.

Code: Select all


int AnalysisPlugin_Template::
record(const SimTK::State& s)
{
	/*
	These variables are no longer needed, so I have commented out
	
	// VARIABLES
	SimTK::Vec3 vec;
	SimTK::SpatialVec vec6;
	double Mass = 0.0;
	
	*/
	
	
	// GROUND BODY
	const Body& ground = _model->getGroundBody();

	// POSITION
	const BodySet& bodySet = _model->getBodySet();

	for(int i=0;i<_bodyIndices.getSize();i++) {

		const Body& body = bodySet.get(_bodyIndices[i]);

		// GET MOMENTUM
		 SimTK::SpatialVec vec6 = _model->getMatterSubsystem().getMobilizedBody(MobilizedBodyIndex(i)).calcBodyMomentumAboutBodyMassCenterInGround(s); 
		 // the argument for "getMobilizedBody" is probably the issue, but I am not sure what I have done wrong and how to fix it
		 
		// FILL ARRAY, currently called "_bodypos", but that does not matter
		int I=6*i;
		memcpy(&_bodypos[I],&vec6[0],6*sizeof(double));
	}
	_storePos.append(s.getTime(),_bodypos.getSize(),&_bodypos[0]);


	return(0);
}


Tags:

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Plug in development

Post by jimmy d » Wed Jul 17, 2019 7:07 pm

You may need to realize the system;
https://simbody.github.io/simbody-3.6-d ... f1d1cca906

User avatar
Nirav Maniar
Posts: 32
Joined: Tue May 12, 2015 11:03 pm

Re: Plug in development

Post by Nirav Maniar » Wed Jul 17, 2019 10:36 pm

jimmy wrote:
Wed Jul 17, 2019 7:07 pm
You may need to realize the system;
https://simbody.github.io/simbody-3.6-d ... f1d1cca906
Legend, thanks James that would make sense.

Based on that info, I believe I need to realizeDynamics() first. I have tried to do this (in a few different ways) but keep getting the same error:
error C2248: 'OpenSim::ModelComponent::realizeDynamics': cannot access protected member declared in class 'OpenSim::ModelComponent'

I tried searching for "realizeDynamics" on the opensim github to get an understanding as to how this is usually implemented (and what I have done wrong), but cannot see a clear distinction. As this is probably just my amateurish C++ knowledge, can you (or anyone else) provide suggestion? Here is the updated code:

Code: Select all

int AnalysisPlugin_Template::
record(const SimTK::State& s)
{
	/*
	These are not needed, so commented out
	
	// VARIABLES
	SimTK::Vec3 vec;
	SimTK::SpatialVec vec6;
	double Mass = 0.0;
	
	*/
	
	
	// GROUND BODY
	const Body& ground = _model->getGroundBody();

	// POSITION
	const BodySet& bodySet = _model->getBodySet();

	for(int i=0;i<_bodyIndices.getSize();i++) {

		const Body& body = bodySet.get(_bodyIndices[i]);
		
		//try to realize the model first, have also tried:  _model.getModel().realizeDynamics() but it still returns  error C2248:  'OpenSim::ModelComponent::realizeDynamics': cannot access protected member declared in class 'OpenSim::ModelComponent'
		_model->realizeDynamics(s); 

		// GET MOMENTUM
		 SimTK::SpatialVec vec6 = _model->getMatterSubsystem().getMobilizedBody(MobilizedBodyIndex(i)).calcBodyMomentumAboutBodyMassCenterInGround(s); 
		 // the argument for "getMobilizedBody" is probably the issue
		 
		// FILL ARRAY, currently called _bodypos but that does not matter
		int I=6*i;
		memcpy(&_bodypos[I],&vec6[0],6*sizeof(double));
	}
	_storePos.append(s.getTime(),_bodypos.getSize(),&_bodypos[0]);


	return(0);
}

POST REPLY