Scale Tool: Manually setting marker weights (3.3)

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Patrick Laurin
Posts: 6
Joined: Tue Mar 06, 2018 12:41 pm

Scale Tool: Manually setting marker weights (3.3)

Post by Patrick Laurin » Fri Oct 26, 2018 8:58 am

Hi,

I've been trying to make the scale tool work within my c++ code.

I've managed to make a simple example work by feeding an OpenSim generated scale file (.xml) to the Scale Tool. This scale file loads the .trc and applies correctly to the .osim model.

Now, I had to remove that .xml scale file dependency and replace it with extra code, which essentially just sets weights for every marker:

Code: Select all

	
	OpenSim::Set<OpenSim::MarkerWeight> markerWeights;
	markerWeights.setSize(3);
	scaleTool.getMarkerPlacer().getIKTaskSet().createMarkerWeightSet(markerWeights);
	
	OpenSim::MarkerWeight markerWeight1;
	markerWeight.setName("Marker1");
	markerWeight.setWeight(1);
	markerWeights.set(0, markerWeight1, false);
	
	OpenSim::MarkerWeight markerWeight2;
	markerWeight.setName("Marker2");
	markerWeight.setWeight(2);
	markerWeights.set(1, markerWeight2, false);

	OpenSim::MarkerWeight markerWeight3;
	markerWeight.setName("Marker3");
	markerWeight.setWeight(2);
	markerWeights.set(2, markerWeight3, false);
... but when I run

Code: Select all

scaleTool.getMarkerPlacer().processModel(myState, &myModel, folder_containing_files);
, I get the following error:

Code: Select all

AssemblySolver::assemble() Failed: SimTK Exception thrown at assembler.cpp:227:
  Error detected by Simbody method AssemblerSystem::objectiveFunc(): calcGoal() method of assembly condition Markers returned a negative or non-finite value -nan(ind).
  (Required condition 'goalValue >= 0' was not met.)
  
I tried to load the exact same model + .trc file inside OpenSim's Scale Tool (without specifying a .xml scale file) and it runs! Is there anything more I need to do?

Tags:

User avatar
Patrick Laurin
Posts: 6
Joined: Tue Mar 06, 2018 12:41 pm

Re: Scale Tool: Manually setting marker weights (3.3)

Post by Patrick Laurin » Fri Oct 26, 2018 9:16 am

Here is my entire code:

Code: Select all

	Model myModel = Model::Model(osimFullFilePath, true);
	State myState = myModel.initSystem();
	
	ScaleTool scaleTool = ScaleTool();
	scaleTool.getGenericModelMaker().setModelFileName(osimFullFilePath);
	
	Array <double> TimeArray;
	TimeArray.set(0, 0.0);
	TimeArray.set(1, 0.0);
	
	scaleTool.getModelScaler().setApply(1);
	scaleTool.getModelScaler().setMarkerFileName("marker.trc");
	scaleTool.getModelScaler().setOutputScaleFileName("scale_result.xml");
	
	scaleTool.getModelScaler().processModel(myState, &myModel, osimFolderPath, 0); // This executes
	
	scaleTool.getMarkerPlacer().setApply(1);
	scaleTool.getMarkerPlacer().setTimeRange(TimeArray);
	scaleTool.getMarkerPlacer().setStaticPoseFileName("marker.trc");
	scaleTool.getMarkerPlacer().setOutputModelFileName("scaledModel.osim");
	scaleTool.getMarkerPlacer().setOutputMotionFileName("outputmotion.mot");
	scaleTool.setPrintResultFiles(true);
	scaleTool.getMarkerPlacer().setMoveModelMarkers(true);
	
	// Weights
	OpenSim::Set<OpenSim::MarkerWeight> markerWeights;
	markerWeights.setSize(3);
	scaleTool.getMarkerPlacer().getIKTaskSet().createMarkerWeightSet(markerWeights);
	
	OpenSim::MarkerWeight markerWeight1;
	markerWeight1.setName("Marker1");
	markerWeight1.setWeight(1);
	markerWeights.set(0, markerWeight1, false);
	
	OpenSim::MarkerWeight markerWeight2;
	markerWeight2.setName("Marker2");
	markerWeight2.setWeight(1);
	markerWeights.set(1, markerWeight2, false);

	OpenSim::MarkerWeight markerWeight3;
	markerWeight3.setName("Marker3");
	markerWeight3.setWeight(1);
	markerWeights.set(2, markerWeight3, false);
	
	
	scaleTool.getMarkerPlacer().processModel(myState, &myModel, osimFolderPath); // This crashes

User avatar
Patrick Laurin
Posts: 6
Joined: Tue Mar 06, 2018 12:41 pm

Re: Scale Tool: Manually setting marker weights (3.3)

Post by Patrick Laurin » Sun Oct 28, 2018 6:56 pm

My code works if I instantiate the ScaleTool class using the overloaded constructor that asks for a .xml scale file. Are there any methods I can use to generate that file in C++?

User avatar
Thomas Uchida
Posts: 1793
Joined: Wed May 16, 2012 11:40 am

Re: Scale Tool: Manually setting marker weights (3.3)

Post by Thomas Uchida » Sun Oct 28, 2018 7:24 pm

My code works if I instantiate the ScaleTool class using the overloaded constructor that asks for a .xml scale file. Are there any methods I can use to generate that file in C++?
print(). MATLAB example:

Code: Select all

myScaleTool = ScaleTool();
myScaleTool.print('setup_scale.xml');

POST REPLY