[Odejava] Centre Of Gravity Prob

Hi all,
Im having a little difficulty with the centre of gravity:

When i do this:


body.setMassParameters(mass, 0, -10, 0, 1, 1, 1, 0, 0, 0);

I get this:


ODE Message 2: vector has zero size (ode/src/odemath.cpp:128)

repeatidly and the whole body shakes and wobbles and eventually flies off the screen.

Any ideas what im doing wrong? Btw, im changing its mass properties after ive added it to the world/space

DP

Have you tried altering it before adding it to the world?

I wounder if you are getting the error because your last three numbers are 0?

Do you understand what effect the inertia matrix has? I’ve read this page: http://ode.org/ode-latest-userguide.html#sec_6_3_0 but it doesn’t explain that.

Will.

well, i dont understand the inertia matrix, and ive read the same thing you have read before i posted this.

It seems the problem with the error disappears when instead of the 1’s, i use the actual mass. But then, the centre of gravity has no effect at all on the object…

I’l try setting the centre of gravity before adding it…

DP

Ok, when i set it like:


body.setMassParameters(mass, 0, -10, 1, 1, 1, 0, 0, 0);

before i add it to the world, i get a new error:



ODE Message 2: center of mass inconsistent with mass parameters (ode/src/mass.cpp:68)

However, when i change the 0’s to 1’s also before adding it, i get teh same error as before, which is:


 ODE Message 2: vector has zero size (ode/src/odemath.cpp:128) 

DP

First of all, the inertia tensor that you give is for a sphere. Is this what you want? You can find the inertia tensors for various objects here: http://scienceworld.wolfram.com/physics/MomentofInertia.html

As for the errors, I don’t think your allowed to have the centre of gravity different from (0,0,0). However, there is a workaround: http://q12.org/pipermail/ode/2005-March/015372.html

Also, from memory, you may have to use adjustMass() to set the actual mass after using setMassParameters().

Sorry, i need a box, so i obviously need to change the inertia tensor.

But because this is for a car, there is no way for me to make it more stable by lowering the centre of gravity?!

This seems rather stupid as one of Ode’s main advantages is that its good for vehicles…

DP

maybe you should use a GeomTransform?

Arne

PS: My thread about it being buggy was garbage, because GeomsTransforms start working fine, when you start simulating. At least It seems to me so now :wink:

Geom transform encapsulates a Geom and shifts it position, so it can work. This is a good idea, i.e. to offset the entire Body, but if the functionality is already in there in terms of dMassParameters and its buggy, i would rather fix it instead of having a workaround…

DP

Yes… It’s a little troubling that we can’t easily adjust a BodyS COM. This sure seems like an ODE bug. I would hope the ODE people are working on fixing this.

From the ODE-docs: "When assigning a mass to a rigid body, the center of mass must be (0,0,0) relative to the body’s position. But in fact this limitation has been in ODE from the start, so we can now regard it as a ``feature’’ :slight_smile: "

So… I’m guessing, if its regarded as a feature its not likely to get fixed in the near future.

But I’m also trying to build a car and it is difficult to get it stable since the CM is way to high. Placing the geomtry lower using a geomtransform is not a good solution, since the geoms are also used for collision testing and the actual 3D-model the geoms are representing, is placed higher. One solution would be to have a displaced geom representing the mass of the car, and another geom for collisiontesting which I would set the position and orientation according to the mass-geometry minus the displacement. But this feels like a bad solution :slight_smile: Any other ideas?

Has anyone implemented a arcade-feel car using odejava? I’d like some examples other than the cars in the test-package.

Nice feature :slight_smile: Hmm… At one point, I wanted to make a box difficult to tip over so I set its COM way under ground. I could have sworn that moving the COM helped… maybe not :slight_smile:

As for the car, it seems like you could use a GeomTransform to move the car geometry significantly above the Body. The geometry is used for collision detection, so the geometry should rest on the ground and the Body (and COM) should be below that.

Edit:
Just checked my code… I also made the MOI insanely high. That would account for the box not tipping over :slight_smile:

Looks like im going to have to fake COM! Basically, fake down force…

Dang it! >:(

DP

Ok, thought of a good solution to this problem!

Take a box (as a car or something), the box will be top heavy and the car rolls around alot because i can’t change the COM (i know this is a fact, ive tried it!).

So the solution is (that i have not tried yet) is to stuff the bottom box by a smaller, much heavier box that has the same width and length as the big box, but not the same height. That height can vary to vary the centre of gravity.

Then simply create a JointFixed between them two boxes and viola…you have a lowered centre of gravity!

Lets hope this works! :slight_smile:

DP

I have modified all of my code to get COMs working. Here’s the strategy:

Add the COM to each Body’s position when I initially position it.

Attach the Geom using a GeomTransform that is offset by the negation of the COM.

It’s working great! A total hack and I wish Body.setMassParameters worked in ODE, but it’s working great :slight_smile:

only problem is that it cant be modified during runtime :frowning:

But your strategy sure is a heck of a lot better than mine :slight_smile:

DP

I actually do allow modification of the COM during runtime. In my experience, both a Body’s position and a GeomTransform’s offset can be adjusted between collision and step calls. Modifying a GeomTransform’s offset seems to work pretty well, but modifying a Body’s position causes discontinuities (understandably). So long story short, it works if you occasionally need to make an adjustment, but not if you to constantly vary your COM (why would you want to do this anyway?).