Page 1 of 1

Problem in C++ API on PointKinematics

Posted: Thu Dec 18, 2014 2:44 am
by fantasymew
Hello, everyone,

I am using PointKinematics in tracking interested points on the model. It runs well in GUI, but when I implement it using C++ API, I encounter some problems. The following is my example code for setting PointKinematics:

Code: Select all

	
	// Set Point Kinematics
	PointKinematics pk = PointKinematics();
	pk.setName("PointKinematics");
	pk.setOn(true);
	pk.setStartTime(10.0);
	pk.setEndTime(markerData.getLastFrameTime());
	pk.setStepInterval(10);
	pk.setInDegrees(true);

	Model pkModel = Model(pkModelFile);
	OpenSim::Body& ground = pkModel.getGroundBody();
	OpenSim::Body& torso = pkModel.updBodySet().get("torso");
	//pk.setBody(&torso);
	//pk.setRelativeToBody(&ground);
	
	pk.setPointName("TEST");
	//pk.setPoint(Vec3(0.0, 0.0, 0.0));
There are 3 functions which I commented always throw exception. I have no idea how to fix it? Could anyone help me? Thanks very much.

Best regards,
Yu-Wei

Re: Problem in C++ API on PointKinematics

Posted: Thu Dec 18, 2014 11:43 am
by aymanh
Hi Yu-Wei,

Please use the call sequence below (taken from testConstraints.cpp in our source distribution) instead, as your current code creates a PointKinematics analysis with no model underneath it.
PointKinematics *pointKin = new PointKinematics(osimModel);
// Get the point location of the shank origin in space
pointKin->setBodyPoint("shank", Vec3(0));
// You can call any method you want on pointKin here
osimModel->addAnalysis(pointKin);
Please let us know if that works for you.

Best regards,
-Ayman

Re: Problem in C++ API on PointKinematics

Posted: Thu Dec 18, 2014 11:13 pm
by fantasymew
Hello, Ayman,

I add pk.setModel(pkModel) so that the functions do not throw exceptions, and it works for me. My flow is that I output the setup file first (I want to save the configuration file) and then read it to run. I use this trick in my StaticOptimization and JointReaction analysis before.

Thank you very much. :D

Best regards,
Yu-Wei