Problem with Initializing a MarkersReference Object
Posted: Sun Jun 19, 2022 12:41 pm
I am trying to initialize a MarkersReference object for Arm26 model, which comes originally with three markers.
Everything is fine so far. row1 value is also equal to the markers location, read from the model file. The output of
looks like:
However, once I assemble the solver, i.e.,
the model visulaizer shows a deformed model:
First of all I would like to know the error in the code.
Second of all I have a question regarding the constraints. The constraints weight is infinity in the solver. However, they seemed to be largely violated after assembly. Why is that?
Code: Select all
OpenSim::Model model("arm26.osim");
model.setUseVisualizer(true);
State& state = model.initSystem(); //reference to the model state
std::vector<std::string> labels{ "r_acromion", "r_humerus_epicondyle", "r_radius_styloid" };
std::size_t nc = labels.size();
std::size_t nr = 1;
TimeSeriesTable_<SimTK::Vec3> markerData;
markerData.setColumnLabels(labels);
SimTK::RowVector_<SimTK::Vec3> row1(nc);
row1[0] = model.getMarkerSet()[0].get_location();
row1[1] = model.getMarkerSet()[1].get_location();
row1[2] = model.getMarkerSet()[2].get_location();
std::cout << std::endl << "row 1 values" << row1 << std::endl;
markerData.appendRow(0, row1);
Set<MarkerWeight> markerWeights;
for (size_t m{0}; m < nc; ++m)
markerWeights.adoptAndAppend(
new MarkerWeight(labels[m], 1.0));
std::cout << markerWeights.dump() << std::endl;
MarkersReference markersRef(markerData, markerWeights);
CoordinateSet coordinset = model.getCoordinateSet();
Constant coordRefFunc(0.0);
SimTK::Array_<OpenSim::CoordinateReference> coorrefs(coordinset.getSize());
for (int i = 0; i < coordinset.getSize(); i++)
{
std::cout << coordinset[i].getName() << std::endl; //" = " << coordinset[i].getValue(state) << std::endl;
coorrefs[i].setName(coordinset[i].getName());
coorrefs[i].setValueFunction(coordRefFunc); //coordRefFunc
}
OpenSim::InverseKinematicsSolver iksolver(model, markersRef, coorrefs, SimTK::Infinity);
iksolver.setAccuracy(1.0e-9);
model.getVisualizer().show(state);
Code: Select all
model.getVisualizer().show(state);
However, once I assemble the solver, i.e.
Code: Select all
iksolver.assemble(state);
the model visulaizer shows a deformed model:
First of all I would like to know the error in the code.
Second of all I have a question regarding the constraints. The constraints weight is infinity in the solver. However, they seemed to be largely violated after assembly. Why is that?