Page 1 of 1
any function to calc position of a point rel to ground?
Posted: Tue Sep 30, 2014 7:17 pm
by porsasina
Hi,
I was wondering if there is any function to calculate position of a point relative to the ground assuming a known set of joint angles?
I am an API user and I am using HuntCrossley contact forces. I need to calculate the position of the spheres respect to the ground(half space) within my script.
Code: Select all
Model OsimModel("test.osim");
SimTK::State& defaultStates = OsimModel.initSystem();
// here I set joint angles in "defaultStates" using this function: OpenSim::Coordinate::setValue
// here I need to calculate position of my contact spheres relative to ground.
thanks
Sina
Re: any function to calc position of a point rel to ground?
Posted: Thu Oct 16, 2014 9:16 am
by jimmy
Sina,
Unfortunately there doesn't seem to be a efficient baked in way of doing this. I would suggest placing a marker at the location of the sphere and use some of the Marker methods.
You could iteratively move the marker location from some body to the ground, get its location, and then move it back to the body using the method changeBodyPreserveLocation()
Hopefully that helps,
-james
Re: any function to calc position of a point rel to ground?
Posted: Sun Oct 19, 2014 8:42 pm
by porsasina
Thanks James, that was a nice trick and in solved the problem!
Sina
Re: any function to calc position of a point rel to ground?
Posted: Wed Oct 22, 2014 11:57 pm
by porsasina
Hi dear James
I tried this method both in MATLAB and C++. IT works in MATLAB but not in c++, which is annoying!
in my matlab script, after defining the joint angles in my defaultstate, I do this:
Code: Select all
for marker=0:11// I have 12 markers
markerSet.get(marker).changeBodyPreserveLocation(defaultstate,model.getBodySet().get(0));
y_pos(marker) = markerSet.get(marker).getOffset().get(1);
end
This works perfectly and the height of the markers relative to ground are stored in y_pos variable.
I tried to apply the same method in c++ to improve computational speed. But it does not work and I am totally confused:
Here is my c++ script
Code: Select all
// after setting joint angles in defaultStates
for (markerIndx=0; markerIndx<12; markerIndx++){
modelMarkerSet.get(markerIndx).changeBodyPreserveLocation(defaultStates,OsimModel.getBodySet().get(0));
*(y_pos+markerIndx) = modelMarkerSet.get(markerIndx).getOffset().get(1); }
Any ideas what the problem is with my c++ script?
Thanks
Sina
Re: any function to calc position of a point rel to ground?
Posted: Thu Oct 23, 2014 2:48 am
by krueger
Hey Sina,
there is a more direct way of transforming the coordinates from a local cos to the global "ground" cos.
Take a look at the method: model.getSimbodyEngine().transformPosition(..)
Best Regards,
Daniel