any function to calc position of a point rel to ground?

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Sina Porsa
Posts: 99
Joined: Thu Feb 03, 2011 7:21 pm

any function to calc position of a point rel to ground?

Post by Sina Porsa » Tue Sep 30, 2014 7:17 pm

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

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: any function to calc position of a point rel to ground?

Post by jimmy d » Thu Oct 16, 2014 9:16 am

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

User avatar
Sina Porsa
Posts: 99
Joined: Thu Feb 03, 2011 7:21 pm

Re: any function to calc position of a point rel to ground?

Post by Sina Porsa » Sun Oct 19, 2014 8:42 pm

Thanks James, that was a nice trick and in solved the problem!
Sina

User avatar
Sina Porsa
Posts: 99
Joined: Thu Feb 03, 2011 7:21 pm

Re: any function to calc position of a point rel to ground?

Post by Sina Porsa » Wed Oct 22, 2014 11:57 pm

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

User avatar
Daniel Krueger
Posts: 24
Joined: Fri Jul 09, 2010 12:05 am

Re: any function to calc position of a point rel to ground?

Post by Daniel Krueger » Thu Oct 23, 2014 2:48 am

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

POST REPLY