Problems working with dGeomTransform

47 views
Skip to first unread message

Jim McM

unread,
Jul 22, 2012, 1:56:30 AM7/22/12
to ode-...@googlegroups.com
Hey all, 

I've been trying to move a capsule around my environment using my keyboard (wasd for up down left right). 

Instead of messing with my capsule on its own, i'm trying to place it within a transform geom so that i can have greater freedom in the center of mass, etc. I have been able to set my transform geom, create a capsule within it, and draw it. I'm also able apply forces and watch the drawn object move in my simulation. 

The problem is that my forces aren't acting the way i would expect them to. When i apply a force in the X direction, the capsule moves in the X direction but also starts rotating around the center of the capsule. I feel like this is probably a simple mistake on my part, but since it's getting late and I'm not succeeding in  finding it I figure i would post my code here to see if anyone could pick it out quickly. 

Ideally I want to get the center of rotation to be at one end of the capsule while having the forces be applied at the opposite end (i'm making a blimp). 

Thanks for the help! 

(and if you see any major misuse of the dGeomTransform() function please let me know :D)

-jim
temp_capsule.cpp

Patrick

unread,
Jul 22, 2012, 11:23:17 AM7/22/12
to ode-...@googlegroups.com
You cannot calculate transformations in any order. If its rotating around the center of mass and not at the the center of mass you'll want to apply force first before transforming the geom. 



Patrick


--
You received this message because you are subscribed to the Google Groups "ode-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ode-users/-/V5tQGox6SakJ.
To post to this group, send email to ode-...@googlegroups.com.
To unsubscribe from this group, send email to ode-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ode-users?hl=en.
<temp_capsule.cpp>

jcooper

unread,
Jul 23, 2012, 12:55:32 PM7/23/12
to ode-...@googlegroups.com
Any use of dGeomTransform is a misuse; this, in spite of the fact that some of the old demos may still use it.  That functionality is deprecated.  It's much better to use dGeomSetOffsetPosition and dGeomSetOffsetRotation/dGeomSetOffsetQuaternion.  These will establish a transformation between the body and the geom.  What you need to understand once you've done that, however, is that the geoms are taken into consideration for collision and the creation of contact joints, but nothing else dealing with forces.  If you want the blimp to move without also spinning around, you probably want to use dBodyAddRelForce or dBodyAddForce.  Any force applied to the body that doesn't go through the center of mass will add some torque to the body and that will start it spinning. 

jc

Jim McM

unread,
Jul 23, 2012, 11:09:19 PM7/23/12
to ode-...@googlegroups.com
Thanks for the info. I had already built a piece of code that was working using the dGeomSetOffsetPosition & dGeomSetOffsetRotation but I had thought it would be more beneficial to use the dGeomTransform so i could manually offset the center of mass (and i had thought it would have been easier). 

What exactly is the difference between dBodyAddRelForce and dBodyAddForce? 

-jim

Jim McM

unread,
Jul 24, 2012, 12:49:20 AM7/24/12
to ode-...@googlegroups.com
OK, So i think i see what I'm doing wrong here. 

What I want to do is apply a force relative to the center axis along the length of the capsule. When i apply a force using dGeomAddRelForceAtPos() and I apply a force in the Z direction, if the capsule isn't facing the Z direction it will begin to rotate around it's center of mass. 

What i'm not familiar with is how to take use the rotation matrix ( dGeomgGetRotation() )  and calculate the appropriate x,y, and z forces in order to have the capsule move along the center axis. 

I can't seem to find a section in the Howto or the manual that explains the output of the rotation matrix. Are you familiar with this, and how would you go about this problem? 

Thanks for your help!

-jim

On Monday, July 23, 2012 12:55:32 PM UTC-4, jcooper wrote:

jcooper

unread,
Jul 24, 2012, 11:49:43 AM7/24/12
to ode-...@googlegroups.com
It sounds like you want to use dBodyAddRelForce or possibly dBodyAddRelForceAtRelPos.
You should read the documentation, but here's a quick distinction:

dBodyAddForce will apply a force to the center of mass in the world's frame of reference.  E.g., a constant force along the x-axis applied at every step {dBodyAddForce(body, 10,0,0);} might be used to simulate wind because it pushes in the same direction regardless of how the body is oriented.  It will not introduce torque or spinning unless other forces (like friction) are in play.

dBodyAddRelForce will apply a force to the center of mass in the body's frame of reference.  This can be used for something like thrusters that always make the body move _forward_ in the direction that the body is 'facing'.  It will also not introduce torque or spinning.

dBodyAddRelForceAtPos is a bit weird.  The _direction_ of the force applied is to be provided in terms of the body's frame of reference, but the point on the body at which it's applied is given in the world's frame of reference.  Using this function with constant values for both force and position doesn't make sense.  At least, I can't think of an example.  It will cause the body to move and spin in strange ways.

dBodyAddRelForceAtRelPos pushes in a direction determined by the body's orientation and at point on the body provided in the body's frame of reference.  This is what you would use if you wanted a steerable propeller on the back of your blimp.  As long as the force vector points through the center of mass, there won't be turning, the body will accelerate forward or backward but not turn.  If the force turns to one side or another, the blimp will turn around.

There's also dBodyAddForceAtRelPos.  This expects a world-based direction to be applied at a body-based point.  You might use this to produce wind-resistance on the low-density envelope or something.

jc

Jim McM

unread,
Jul 24, 2012, 3:06:24 PM7/24/12
to ode-...@googlegroups.com
That's exactly what I was looking for, thanks!

-jim
Reply all
Reply to author
Forward
0 new messages