re. getVelocity() function

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Nithin Kurup
Posts: 149
Joined: Sat Jan 18, 2014 5:13 am

re. getVelocity() function

Post by Nithin Kurup » Tue May 12, 2015 2:34 am

Hi,

I am trying to find the velocity from the centre of mass of a body. I happen to use this code, but I have doubt on the result - whether
1. Its the average of the magnitude of the velocity components during the entire simulation?
2. or its the value of one of the velocity component (x, y or z) at the initial or final time of simulation, if its just one velocity component how can I get the components during full simulation so that I can find the avg. magnitude.

code:

Code: Select all

Vec3 massCenter;Vec3 velocity;
osimModel.getBodySet().get("hand").getMassCenter(massCenter);
osimModel.getMultibodySystem().realize(s, Stage::Velocity);
osimModel.getSimbodyEngine().getVelocity(s,osimModel.getBodySet()
.get("hand"),massCenter, velocity);
Ans: 0.52

thanks.

User avatar
Stefan Lambrecht
Posts: 13
Joined: Tue May 31, 2011 6:43 am

Re: re. getVelocity() function

Post by Stefan Lambrecht » Tue May 12, 2015 3:37 am

Hi Nithin

You should not get a scalar out of this. Using getVelocity() you are asking for the linear velocity [x,y,z] at a specific time (given by the state) of a point (in your case the center of mass) of a body (in your case the hand).
So in an attempt to answer your questions:
1. it is instantaneous velocity
2. Velocity is a vector (you have also defined it as such in your first line of code, Vec3 velocity). If you want to get the average then you could store the instantaneous values and compute the average later.

If your end goal is average velocity then you can maybe use the BodyKinematics analysis and calculate the average afterwards in Matlab or Python.

Stefan

User avatar
Nithin Kurup
Posts: 149
Joined: Sat Jan 18, 2014 5:13 am

Re: re. getVelocity() function

Post by Nithin Kurup » Tue May 12, 2015 3:54 am

Thank you so much Stefan.

Yeah this answers my question. I had already tried BodyKinematics Analysis (GUI) and found the magnitude of the velocity vector, which was different from the value I obtained via the above code, so got into a confusion regarding this.

Also stefan, is it possible to get the velocity vectors of eg. hand for the entire simulation using API (c++), as I need to calculate the avg velocity and then use it for other calculation in my code.

thanks again,
nithin

User avatar
Stefan Lambrecht
Posts: 13
Joined: Tue May 31, 2011 6:43 am

Re: re. getVelocity() function

Post by Stefan Lambrecht » Tue May 12, 2015 5:12 am

Hi Nithin

You can run BodyKinematics to get the (instantaneous) velocity, and then calculate the average velocity to use in subsequent computations. Alternatively you can get velocity from SimbodyEngine (this is what I am trying to do, my code is in a recent post on this forum but it is not working! I will make sure to update my post with a working version as soon as I have found the bug). I have additional computations that I am performing at runtime, and am therefore trying to not use BodyKinematics (I am still not sure if that is the best approach).
In you case it seems that you are processing offline (you use the average velocity, I am assuming this is over the entire trial). Under those assumptions I think (but might be wrong here) that it is best & easiest to use the BodyKinematics analysis. You can always add more analyses (either existing ones or ones that you include via a plugin/main code - there is a good tutorial in the OpenSim webpage on writing a plugin, you will find that it is strongly related to what you are trying to do!).

Stefan

User avatar
Nithin Kurup
Posts: 149
Joined: Sat Jan 18, 2014 5:13 am

Re: re. getVelocity() function

Post by Nithin Kurup » Tue May 12, 2015 5:21 am

Thanks stefan,

Yes, I have used plug- in before. yeah so it should be able to give the velocity components, which I can later process and use in my code.

Thank you so much for your time.

Nithin

POST REPLY