Problem with Initializing a MarkersReference Object

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Ali Baradaran
Posts: 3
Joined: Tue Nov 16, 2021 11:02 am

Problem with Initializing a MarkersReference Object

Post by Ali Baradaran » Sun Jun 19, 2022 12:41 pm

I am trying to initialize a MarkersReference object for Arm26 model, which comes originally with three markers.

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);
Everything is fine so far. row1 value is also equal to the markers location, read from the model file. The output of

Code: Select all

model.getVisualizer().show(state);
looks like: Image
However, once I assemble the solver, i.e.

Code: Select all

iksolver.assemble(state);
,
the model visulaizer shows a deformed model:
Image
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?

Tags:

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

Re: Problem with Initializing a MarkersReference Object

Post by Thomas Uchida » Mon Jun 20, 2022 8:03 pm

An ampersand may be required after CoordinateSet in the line CoordinateSet coordinset = model.getCoordinateSet(); since presumably you want to hold onto a reference to the CoordinateSet in the Model rather than create a new one. You may want to look through the testInverseKinematicsSolver.cpp file on GitHub (https://github.com/opensim-org/opensim- ... Solver.cpp) to rule out a typo in the code as being a source of the issue.

POST REPLY