[ODE] Calculating G force

Anders Olofsson anders.olofsson at biologigrand.ac
Mon May 8 14:07:00 MST 2006


Oh, I thought I replied to the list but I see I replied to Jon Watte. I got 
it to work as I wanted, if anyone is interested I enclose the code below. I 
think I did it as you describe it, converting the G force vector from world 
to body, instead of the velocity. I do divide the force by my gravity later 
at display time (9.81) to get the correct G. After the function has been 
called the force vector contains the G force in all 3 body axis.

The scalar variable dtime is the time passed since last time this function 
has been called, usually the frametime.

Yes, I really dont need to calculate G force on some offset point from the 
body pos. Its just for fun to see how many G's some body gets when turning 
or crashing.

Thanks!.


dVector3 vel,oldvel,force;
void CalculateGForces (dBodyID body)
{
         const dReal *tmp;
         dVector3 tmpv, f;

         tmp=dBodyGetLinearVel (body);
         vel[0]=tmp[0];
         vel[1]=tmp[1];
         vel[2]=tmp[2];
         if (dtime>0){
                 f[0]=(vel[0]-oldvel[0])/dtime;
                 f[1]=(vel[1]-oldvel[1])/dtime;
                 f[2]=(vel[2]-oldvel[2])/dtime;
                 f[1]+=9.81;
                 dBodyVectorFromWorld (body, f[0], f[1], f[2], force);
         }
         oldvel[0]=vel[0];
         oldvel[1]=vel[1];
         oldvel[2]=vel[2];
}


At 17:15 2006-05-08, you wrote:
>Well, I'm not that  much of an authority here, but I might add a few
>thoughts.
>1, I presume you are aware that you won't get the actual so-called
>"G-Forces" with this calculation because those are relative to the the
>gravitational acceleration constant, so you should devide your results
>with g.
>2, There is an actual real nasty problem with the code presented here
>and it actually took me quite a long time to notice it :)
>
>What you do is you take the *body-relative* velocity vectors at each
>timestep and subtract them to find the velocity difference and thus the
>acceleration. While the method of dividing the velocity difference with
>time to get (average) acceleration is OK, doing that with body-relative
>velocities isn't!
>Let me explain with two obvious examples:
>a, you have a body moving on a circlular path with a constant speed,
>always heading (pointing) towards the tangent of the circle. At every
>instance in time the velocity of the object in the body-relative frame
>will always point straight ahead, so differences would always lead to
>zero acceleration even though there certainly is an acceleration keeping
>the object on a circular path.
>b, even more obviously if you have an object moving at a constant speed
>(thus no G-forces) and spin the object around then the relative velocity
>vectors sampled at different times might be pointing anywhere falsely
>reporting acceleration.
>
>The fix is simple, make the subtraction in the world frame and then
>convert the difference to body-relative coordinates!
>This would also have a small error as the difference vector would not be
>perfectly perpendicular to the object in example a, but you would like
>the results much better I guess :)
>
>(I won't go into the case of the acceleration felt by a point on an
>object offset from its center of gravity, but from what I see that was
>not your intention anyway)
>
>Anders Olofsson wrote:
>
> >Well, it didn't work that good.. Am I thinking this all wrong?.
> >
> >dVector3 vel,oldvel,force;
> >void CalculateGForces (dBodyID body)
> >{
> >         const dReal *tmp;
> >         dVector3 tmpv;
> >
> >         tmp=dBodyGetLinearVel (body);
> >         dBodyVectorFromWorld (body, tmp[0], tmp[1], tmp[2], tmpv);
> >         vel[0]=tmpv[0];
> >         vel[1]=tmpv[1];
> >         vel[2]=tmpv[2];
> >         if (dtime>0){
> >                 force[0]=(vel[0]-oldvel[0])/dtime;
> >                 force[1]=(vel[1]-oldvel[1])/dtime;
> >                 force[2]=(vel[2]-oldvel[2])/dtime;
> >         }
> >         oldvel[0]=vel[0];
> >         oldvel[1]=vel[1];
> >         oldvel[2]=vel[2];
> >}
> >
> >_______________________________________________
> >ODE mailing list
> >ODE at q12.org
> >http://q12.org/mailman/listinfo/ode
> >
> >.
> >
> >
> >
>
>_______________________________________________
>ODE mailing list
>ODE at q12.org
>http://q12.org/mailman/listinfo/ode



More information about the ODE mailing list