2 Problems with Raycast Vehicle

Post Reply
javier_macross
Posts: 6
Joined: Mon Dec 30, 2019 9:49 pm

2 Problems with Raycast Vehicle

Post by javier_macross »

Hi. The first problem I have is that when I apply a force to the engine, doing this.

Code: Select all

if(key_press)velocidad = -2.0f;
vehicle->applyEngineForce(velocidad,2);
vehicle->applyEngineForce(velocidad,3);
The problem is that I notice that the speed continues to increase and does not remain constant. Does anyone know what I should do so that the speed is always constant?

The second problem is that I notice that both the chassis and the wheels "tremble" when using the raycast technique, even when the vehicle does not move. I get the position and orientation doing this.

Code: Select all

int i;
float mat_wheel[4][16];

for(i=0;i<4;i++){
  vehicle->getWheelInfo(i).m_worldTransform.getOpenGLMatrix(mat_wheel[i]);
}
To start the library I do this.

Code: Select all

btDefaultCollisionConfiguration *colisionconfig = new btDefaultCollisionConfiguration();
btCollisionDispatcher *dispatcher = new btCollisionDispatcher(colisionconfig);
btBroadphaseInterface *broadphase = new btDbvtBroadphase();
btSequentialImpulseConstraintSolver *solver = new btSequentialImpulseConstraintSolver;
btDiscreteDynamicsWorld *world = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,colisionconfig);
world->setGravity(btVector3(0.0f,-10.0f,0.0f));
Wheel Parameters.

Code: Select all

for(i=0;i<4;i++){
  btWheelInfo &wheel = vehicle->getWheelInfo(i);
  wheel.m_suspensionStiffness = 20.0f;
  wheel.m_wheelsDampingRelaxation = 2.3f;
  wheel.m_wheelsDampingCompression = 1.0f;
  wheel.m_frictionSlip = 1000.0f;
  wheel.m_rollInfluence = 0.1f;
}
And in the main loop I do this.

Code: Select all

world->stepSimulation(1.0f/60f,10);

for(i=0;i<4;i++){
  vehicle->updateWheelTransform(i,true);
}
Does anyone know why this happens? Thank you very much in advance for your help.

Regards. :shock:
javier_macross
Posts: 6
Joined: Mon Dec 30, 2019 9:49 pm

Re: 2 Problems with Raycast Vehicle

Post by javier_macross »

Hi, me again. I still can't find the solution for the problems. I have seen the forklift example and I have a doubt, The wheels need to have a body and a shape assigned? Because in the example I've seen that only its shape is defined, but I don't know what is done with this shape.

Thanks for your help.
:mrgreen:
javier_macross
Posts: 6
Joined: Mon Dec 30, 2019 9:49 pm

Re: 2 Problems with Raycast Vehicle

Post by javier_macross »

Does anyone know anything? Does anyone have this same problem? :cry:
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: 2 Problems with Raycast Vehicle

Post by drleviathan »

As to your first problem (non-zero acceleration when setting non-zero force):

You may recall one of Newton's law of motion is "the acceleration of the object is proportional to the net force on it and inversely proportional to its mass". This is often written mathematically as: force = mass * acceleration

If that law were true then you would expect a non-zero acceleration of the vehicle when the force on it from its engine is non-zero... until the net force is zero: e.g. when friction or other forces counterbalance the engine's force. What are the other forces? It really depends on the circumstances. Bullet supports contact friction, but it also has damping which is an approximation of friction from moving through an ambient fluid, and if your vehicle is rolling in a gravitational field then there is a force from that.

So, what you probably want to do is modulate the engine's force in proportion to the acceleration you want it to have. When you want it to accelerate --> apply force, but when it is moving at the right velocity --> apply zero force.

In simplified pseudo code it might look something like this:

Code: Select all

deltaSpeed = targetSpeed - currentSpeed
if (deltaSpeed > 0):
    vehicle->applyEngineForce(k * deltaSpeed)
where k is some coupling coefficient which you must tune to get your desired acceleration rates. Large values of k would make the vehicle accelerate faster, low values of k would make it take a long time to reach the targetSpeed.

As to your second problem: I don't know enough to answer it. I have ideas, which I will list, but these are only guesses at what might cause a problem like that:

(1) You appear to be running in 32-bit (because you use 1.0f formatting for floats). If your objects located very far from the origin then you can get variational results from 32-bit floating point numerical error.

(2) When the inertia tensor of objects are very incorrect (e.g. too small) for their sizes you can sometimes get vibrations where the objects never settle down for deactivation.

(3) It doesn't look like you're using world->stepSimulation() correctly and I wonder if varying real-time frame rates are causing visible movement variations. What you really should do is:

(a) measure the real deltaTime of your frame
(b) step the physics simulation forward by deltaTime, using fixed substeps like so:

Code: Select all

deltaTime = now - lastNow;
lastNow = now;
maxSubsteps = 10;
substepDuration = 1.0 / 60.0;
world->stepSimulation(deltaTime, maxSubsteps, substepDuration);
javier_macross
Posts: 6
Joined: Mon Dec 30, 2019 9:49 pm

Re: 2 Problems with Raycast Vehicle

Post by javier_macross »

First of all, thank you very much for using your valuable time to answer me. :mrgreen:

The second is that I will put into practice your great advice and shortly write an answer.

Thank you very much friend.
:P
javier_macross
Posts: 6
Joined: Mon Dec 30, 2019 9:49 pm

Re: 2 Problems with Raycast Vehicle

Post by javier_macross »

Hello again. I just located the error in problem 2. It is quite curious but the ground defined it as follows.

Code: Select all

btCollisionShape *geom_suelo = new btBoxShape(btVector3(1000.0f/2.0f,0.1f/2.0f,1000.0f/2.0f));
btTransform transf_suelo;
transf_suelo.setIdentity();
transf_suelo.setOrigin(btVector3(0.0,-0.05,0.0));

btScalar masa_suelo(0.0);
dinamic = (masa_suelo != 0.0);

btVector3 inercia_suelo(0,0,0);
if(dinamic)geom_suelo->calculateLocalInertia(masa_suelo,inercia_suelo);

btDefaultMotionState *motion_suelo = new btDefaultMotionState(transf_suelo);
btRigidBody::btRigidBodyConstructionInfo info_suelo(masa_suelo,motion_suelo,geom_suelo,inercia_suelo);
btRigidBody *body_suelo = new btRigidBody(info_suelo);
world->addRigidBody(body_suelo);
The error is in this line:

btCollisionShape *geom_suelo = new btBoxShape(btVector3(1000.0f/2.0f,0.1f/2.0f,1000.0f/2.0f));

If I change it for this:

btCollisionShape *geom_suelo = new btBoxShape(btVector3(100.0f/2.0f,0.1f/2.0f,100.0f/2.0f));

The trembling of the wheels disappear!

Which makes me wonder, why does the problem start with a size of 1000/2?. Does this body type have a limited size? This is a bug? Or, as Drleviathan says, it's a problem of inertia tensor?

If anyone can contribute more about this problem, I would greatly appreciate it.

Thank you.
:mrgreen:
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: 2 Problems with Raycast Vehicle

Post by drleviathan »

It is good you found a workaround for the trembling problem, however its source is still a mystery. It is definitely not a problem with inertia tensors because the ground object would be static (mass = 0.0). Meanwhile for the record: Bullet's shape utilities use a simple box inertia tensor approximation for most of the non-trivial convex shapes and that tensor is expected to be stable.
javier_macross
Posts: 6
Joined: Mon Dec 30, 2019 9:49 pm

Re: 2 Problems with Raycast Vehicle

Post by javier_macross »

I begin to think that it is indeed a bug of the bullet library. (By the way I am using version 2.87, on GNU / Linux). When I compile the library, in the ForkLiftdemo, If I change the line 316:

btVector3 groundExtents(50 , 50, 50);

For this one.

btVector3 groundExtents(1000, 50, 1000);

The wheels of the example trembling too! This is no accident, something happens with the bullet library :x

And once again drleviathan, thank you very much for your help.
:mrgreen:
Post Reply