Cannot find the objectiveFunction of InverseKinematics
Cannot find the objectiveFunction of InverseKinematics
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
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
- Yanis AMMOUCHE
- Posts: 23
- Joined: Mon Apr 24, 2017 6:09 am
Re: Cannot find the objectiveFunction of InverseKinematics
Hello,
What kind of constraints do you want to use ?
Yanis.
What kind of constraints do you want to use ?
Yanis.
Re: Cannot find the objectiveFunction of InverseKinematics
Hello,y_ammouche wrote:Hello,
What kind of constraints do you want to use ?
Yanis.
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
- Yanis AMMOUCHE
- Posts: 23
- Joined: Mon Apr 24, 2017 6:09 am
Re: Cannot find the objectiveFunction of InverseKinematics
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
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
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
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
Where is this functionality realised in the source code ?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.
- Yanis AMMOUCHE
- Posts: 23
- Joined: Mon Apr 24, 2017 6:09 am
Re: Cannot find the objectiveFunction of InverseKinematics
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
Yanis
Re: Cannot find the objectiveFunction of InverseKinematics
Hi Yanis,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
Thanks for your help although I have already been working on this class
Ye YUAN
Re: Cannot find the objectiveFunction of InverseKinematics
AssemblySolver is probably what you are after;
https://github.com/opensim-org/opensim- ... Solver.cpp
https://github.com/opensim-org/opensim- ... Solver.cpp
Re: Cannot find the objectiveFunction of InverseKinematics
Hi,jimmy wrote:AssemblySolver is probably what you are after;
https://github.com/opensim-org/opensim- ... Solver.cpp
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