Page 1 of 2

Cannot find the objectiveFunction of InverseKinematics

Posted: Thu Jun 22, 2017 3:43 am
by yyuan
Hello,

I am currently working on InverseKinematics, I want to add a constraint when calculating marker errors, but I cannot find the objectiveFunction of InverseKinematics, can someone help me?

Thank you

Ye YUAN

Re: Cannot find the objectiveFunction of InverseKinematics

Posted: Thu Jun 22, 2017 4:06 am
by y_ammouche
Hello,

What kind of constraints do you want to use ?

Yanis.

Re: Cannot find the objectiveFunction of InverseKinematics

Posted: Thu Jun 22, 2017 4:18 am
by yyuan
y_ammouche wrote:Hello,

What kind of constraints do you want to use ?

Yanis.
Hello,

I am doing research on scapula, i add 2 markers on the scapula, and want to make sure that these 2 markers stay as close as possible to the thorax, so i create 100 markers on the thorax, for each frame, i try to find the minimun distance between the 2 markers and the 100 markers, the which will be my minimun distance between the scapula and the thorax. When I did all this, the result of inversekinematics(motion file) doesn't seem to change, so the problem is that these additional markers aren't used for IK.

That's what I found, maybe it's wrong, please don't hesitate if you have any remarks.

Thanks

Ye YUAN

Re: Cannot find the objectiveFunction of InverseKinematics

Posted: Thu Jun 22, 2017 6:31 am
by y_ammouche
Ok, I imagine you already know it, but here is how IK works.

You create virtual markers on your model that are at the same place of the real markers. The input will be a trc file containing the position of these markers.

Opensim will try to find the set of coordinates q that minimize the sum of the squared difference between the position of the virtual marker (function of q) and the position of the real markers specified on the trc file. You can specify weight on the IK control panel if you want the position of a virtual marker to be really close to the position of a real marker.

Now you specified 100 particular markers and you want to find the shoulder joint angle that alsominimizes the distances beetween your 2 markers and these 100 markers ?

So adding the sum of distances beetween your scapula marker and the 100 torso markers to the previous function.

Yanis

Re: Cannot find the objectiveFunction of InverseKinematics

Posted: Thu Jun 22, 2017 10:33 am
by yyuan
Hi Yanis,

I have a model which contains 24 markers, and I added 2 markers on the scapula, 100 markers on the thorax, but I don't have their real positions in .trc, so I added 102*3 NaN in the .trc file, to make sure that IK works.

Apart from doing the normal IK for the 24 markers, I want to ensure that the distance between the 2 markers and the 100 markers is as small as possible, I don't have their coordinates so I can only calculate the distance of their virtual positions.In AssemblyCondition_Markers.h we have:
Real findCurrentMarkerErrorSquared(MarkerIx mx) const {
const ObservationIx ox = getObservationIxForMarker(mx);
if (!ox.isValid()) return 0; // no observation for this marker
const Vec3& loc = getObservation(ox);
if (!loc.isFinite()) return 0; // NaN in observation; error is ignored
return (findCurrentMarkerLocation(mx) - loc).normSqr();
}
so I made a similar one:
Real function(MarkerIx mx1, MarkerIx mx2) const {
return (findCurrentMarkerLocation(mx1)-findCurrentMarkerLocation(mx2)).normSqr();
}
The problem is after doing all this, the result of IK is exactly the same as before, in my opinion the motion file should change a little bit to ensure that the distance between the 2 markers and the 100 markers is as small as possible, but I cannot see why this doesn't work.

Ye Yuan

Re: Cannot find the objectiveFunction of InverseKinematics

Posted: Fri Jun 23, 2017 7:57 am
by yyuan
y_ammouche wrote: Opensim will try to find the set of coordinates q that minimize the sum of the squared difference between the position of the virtual marker (function of q) and the position of the real markers specified on the trc file.
Where is this functionality realised in the source code ?

Re: Cannot find the objectiveFunction of InverseKinematics

Posted: Fri Jun 23, 2017 10:21 am
by y_ammouche
Sorry for the late answer, I was searching for the place where this function was called. It may not be that but try to have a look at this link https://github.com/opensim-org/opensim- ... Solver.cpp

Yanis

Re: Cannot find the objectiveFunction of InverseKinematics

Posted: Mon Jun 26, 2017 2:25 am
by yyuan
y_ammouche wrote:Sorry for the late answer, I was searching for the place where this function was called. It may not be that but try to have a look at this link https://github.com/opensim-org/opensim- ... Solver.cpp

Yanis
Hi Yanis,

Thanks for your help although I have already been working on this class :)

Ye YUAN

Re: Cannot find the objectiveFunction of InverseKinematics

Posted: Mon Jun 26, 2017 8:56 am
by jimmy
AssemblySolver is probably what you are after;
https://github.com/opensim-org/opensim- ... Solver.cpp

Re: Cannot find the objectiveFunction of InverseKinematics

Posted: Tue Jun 27, 2017 6:33 am
by yyuan
jimmy wrote:AssemblySolver is probably what you are after;
https://github.com/opensim-org/opensim- ... Solver.cpp
Hi,

When doing inverse kinematics, if I want to add a constraint that the distance between 2 specific markers should be constant(d12 = 0.01 for example), where in the source code should I add this?

Ye YUAN