RayCast Vehicle Problem

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

RayCast Vehicle Problem

Postby Stucuk » Thu Mar 11, 2010 2:45 pm

I tried to copy the code the SDK Demo uses into my project, but it does nothing. Tires seem to be touching the ground as the object bounces less when dropped from a height with Tires. I tried to copy as meny values from the demo (F1 Car) as possible, the only things that should be different are the Material it uses, width/radius of the tires and the vehicle's body. I Modifyed the Joint DLL so that it exposed the DGRaycastVehicleSetCustomTireTorque. Even if unrealistic values are used, it should do something....

//Render Loop
Code: Select all
 DGRaycastVehicleSetCustomTireTorque(Car.DGCar,0,500);
DGRaycastVehicleSetCustomTireTorque(Car.DGCar,1,500);
UpdateWorld(SystemTimer.FrameTime);


//Actual Car
Code: Select all
constructor TRayCastCar.Create(Size : TVec3f; World : PNewtonWorld);
var
 Collision : PNewtonCollision;
 Body      : PNewtonBody;
 origin,
 inertia   : TVec4f;
 Mass,
 Ixx,
 Iyy,
 Izz       : Single;
begin
 FMatrix   := IdentityMatrix;
 Collision := NewtonCreateBox(World,Size[0],Size[1],Size[2],0,Nil);
 Body      := NewtonCreateBody(World, Collision);

      // save the pointer to the graphic object with the body.
      NewtonBodySetUserData (Body, Self);

      // set the material group id for vehicle
      NewtonBodySetMaterialGroupID (Body, 0);

      // set a destructor for this rigid body
    //   NewtonBodySetDestructorCallback (rigidBody, PhysicsBodyDestructor);

      // set the force and torque call back function
      NewtonBodySetForceAndTorqueCallback (Body, @PhysicsApplyForceAndTorque);

      // set the transform call back function
      NewtonBodySetTransformCallback (Body, @PhysicsSetTransform);

      // set the matrix for both the rigid body and the graphic body
      NewtonBodySetMatrix (Body, @FMatrix[0][0]);

      origin  := SetVec4(0, 0, 0, 1);
      inertia := SetVec4(0, 0, 0, 1);

      // calculate the moment of inertia and the relative center of mass of the solid
      NewtonConvexCollisionCalculateInertialMatrix (Collision, @inertia[0], @origin[0]);
      mass := 800;

      Ixx := mass * inertia[0];
      Iyy := mass * inertia[1];
      Izz := mass * inertia[2];

      NewtonBodySetCentreOfMass (Body, @origin[0]);
      // set the mass matrix
      NewtonBodySetMassMatrix (Body, mass, Ixx, Iyy, Izz);


      // release the collision
      NewtonReleaseCollision (World, Collision);
                FMatrix   := IdentityMatrix;
                FDGCar := DGRaycastVehicleCreate(4,@FMatrix[0,0],Body);


                AddTire(SetVec3(5,0,-5));
                AddTire(SetVec3(5,0,5));
                AddTire(SetVec3(-5,0,5));
                AddTire(SetVec3(-5,0,-5));

                Matrix4fTransform(FMatrix,SetVec3(0,70,0));
                NewtonBodySetMatrix (Body, @FMatrix[0][0]);
end;

procedure TRayCastCar.AddTire(P : TVec3f);
begin
 DGRaycastVehicleAddTire(FDGCar,Nil,@P[0], 25, 5, 1,  2.5, 0.2, 200.0, 6.0, 1);
end;
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: RayCast Vehicle Problem

Postby Julio Jerez » Thu Mar 11, 2010 3:13 pm

is this the code from last 2.18?

one of the fixe I made to the car is tah now toruqe are with in realsitci values, but I guess you are no tehre yet.

The car should work juts liek any Raycast cat made usin Pacejka curves, I just have no put much work into it,
because each time I try to refine a demo I get the reply that it is too complicated.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: RayCast Vehicle Problem

Postby Stucuk » Thu Mar 11, 2010 4:22 pm

Iv been using 2.16 as it didn't seem like 2.18 was fully ready based on what you said in its Release topic.

The car should work juts liek any Raycast cat made usin Pacejka curves


Well my physics knowledge is non-existent so i have no clue how to do that on my own. I was hoping to just be able to copy and paste from the SDK Demo and then tweek the values. I can't see anything that i have missed out.

In the future it would be nice if there was a simplified Ray-cast Car demo that didn't rely on complex systems (I.E The car format, Tire animation System, Etc) and just was a Box with wheels so it was easier for people to copy and paste into there project and then modify.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: RayCast Vehicle Problem

Postby Julio Jerez » Thu Mar 11, 2010 6:00 pm

Stucuk wrote:In the future it would be nice if there was a simplified Ray-cast Car demo that didn't rely on complex systems (I.E The car format, Tire animation System, Etc) and just was a Box with wheels so it was easier for people to copy and paste into there project and then modify.


check out the one in the wiki
http://www.newtondynamics.com/downloads/NewtonTutorials.rar
It is not a box but it is very simple, I think
and it is using the last 2.18
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: RayCast Vehicle Problem

Postby Stucuk » Thu Mar 11, 2010 9:25 pm

I re-enabled the DGRayCarTireShape and now that i can properly see the car's tires it looks like they are rotating perfectly while in the air, they are however not moving at all when the vehicle touches the ground. (Im currently using 2.18's Joint Library with 2.16 Newton, tho i doubt this is a side effect as everything looks the same... i still need to modify the delphi header to 2.18). What could cause the tires to not rotate on the ground but rotate fine in the air?

BTW, why is alot of the DGRayCar exports disabled when they work fine when you re-enable them?
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: RayCast Vehicle Problem

Postby Julio Jerez » Thu Mar 11, 2010 10:03 pm

The tires shapes in the ray cast car do not rotate. only the tire matrix does.
are you rendering the visual tires, or the tire shapes.

Stucuk wrote:BTW, why is alot of the DGRayCar exports disabled when they work fine when you re-enable them?

because I have not had the time to go over then and re enable them after I made the change to the core joint.

I am hopping that afte I am doen with the Inteface BS I can spend time on the a bring the back.
some of them should still works, but some others need to be modified to work with the Curve stuff.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: RayCast Vehicle Problem

Postby Stucuk » Thu Mar 11, 2010 10:22 pm

I get the tire shapes collision after the car is made and make a body from them, i then update its matrix(NewtonBodysetMatrix()) each time the tire's matrix is changed. My app renders only the Newton Debug Display stuff.

- RayCastCar_Falls.rar <--- My App.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: RayCast Vehicle Problem

Postby Julio Jerez » Fri Mar 12, 2010 12:02 am

Stucuk wrote:I get the tire shapes collision after the car is made and make a body from them, i then update its matrix(NewtonBodysetMatrix()) each time the tire's matrix is changed. My app renders only the Newton Debug Display stuff.

that will be the problem,
the debug will show the shape but teh spin sicn eteh do no rotate, you need to call get tire Matrix to show the tire spin.
this in a sampel of a transform callback that shows the tire matrix of each tire.

Code: Select all
   static void SetTransform  (const NewtonBody* body, const dFloat* matrix, int threadIndex)
   {
      BasicCar* car;
      NewtonJoint* joint;


      // set the transform of the main body
      PhysicsSetTransform (body, matrix, threadIndex);

      // find the car joint attached to the body
      car = NULL;
      for (joint = NewtonBodyGetFirstJoint(body); joint; joint = NewtonBodyGetNextJoint(body, joint)) {
         car = (BasicCar*) NewtonJointGetUserData(joint);
         if (car->GetJointID() == CUSTOM_VEHICLE_JOINT_ID) {
            break;
         }
      }

      if (car) {
         // position all visual tires matrices

         int count;
         const dMatrix& carMatrix = *((dMatrix*)matrix);
         dMatrix rootMatrixInv (car->m_bodyBindMatrix * carMatrix);
         rootMatrixInv = rootMatrixInv.Inverse();
         count = car->GetTiresCount();

         // for each tire get the global matrix position, and calculate the local matrix relative to the main body   
         for (int i = 0; i < count; i ++) {

            dBone* tireNode;
            TireAnimation* tireAnim;

            const CustomDGRayCastCar::Tire& tire = car->GetTire (i);

            tireAnim = (TireAnimation*) tire.m_userData;
            tireNode = tireAnim->m_tire;

            // if the tire has an animation, update the animation matrices
            // calculate the tire local matrix
            dMatrix matrix (car->m_tireAlign * car->CalculateTireMatrix(i) * rootMatrixInv);
            tireNode->SetMatrix(matrix);

            if (DebugDisplayOn()) {
               // if debug display show the contact and tire collision shape in debug mode
               NewtonWorldCriticalSectionLock(world);
               dMatrix tireBaseMatrix (car->CalculateSuspensionMatrix(i, tire.m_posit) * car->GetChassisMatrixLocal() * carMatrix);
               DebugDrawCollision (tire.m_shape, tireBaseMatrix, dVector (1.0f, 1.0f, 0.0f, 1.0f));

               dVector span (tire.m_contactPoint + tire.m_contactNormal.Scale (1.0f));
               DebugDrawLine (tire.m_contactPoint, span, dVector (1.0f, 0.0f, 0.0f, 1.0f));

               //DebugDrawLine (tire.m_contactPoint, car->dbpos, dVector (0.5f, 0.0f, 1.0f, 1.0f));
               NewtonWorldCriticalSectionUnlock(world);
            }
         }
      }
   }




I will check your code code tomorrow by see if what I posted make sense to you.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: RayCast Vehicle Problem

Postby Stucuk » Fri Mar 12, 2010 12:35 am

I am getting the tire matrix.

Code: Select all
procedure TireCallback( car : PNewtonUserJoint ); cdecl;
var
 Count,
 X      : Integer;
 Tire   : TTire;
 Matrix : TMatrix4f;
begin
 Count := DGRaycastVehicleGetTiresCount(car);
 if Count > 0 then
 for X := 0 to Count-1 do
 begin
  Tire        := DGRaycastVehicleGetTiresUserData (car, X);
  DGRaycastVehicleGetTireMatrix (car, x, @Matrix[0][0]);
  Tire.Matrix := Matrix;

  NewtonBodySetMatrix(Tire.Body,@Matrix[0][0]);
 end;
end;
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: RayCast Vehicle Problem

Postby Julio Jerez » Fri Mar 12, 2010 3:05 am

I am still asuming we are talking about the Raycast car, if this the case I can see your mistake, in this code

Code: Select all
Tire        := DGRaycastVehicleGetTiresUserData (car, X);
  DGRaycastVehicleGetTireMatrix (car, x, @Matrix[0][0]);
  Tire.Matrix := Matrix;

// this do not look correct, you are applying the tire matrix to a Newton body, and the tire are no bodies.
  NewtonBodySetMatrix(Tire.Body,@Matrix[0][0]);



Raycats car only have one body, in the loop to do not call NewtonBodySetMatrix on each tire, you only call it for the car body.

// get the user data associate with tire x
Tire := DGRaycastVehicleGetTiresUserData (car, X);

// get the global matrix for for tire X,
DGRaycastVehicleGetTiresUserData (car, X);

// now with the tire matrix an dteh pointe to teh tire visual mesh, you cna eiethe compute the local matrix if the point is a chile node, of just set teh matrix into teh tire is teh tire is a mesh in global space.

in the code I posted the tire is a child node of the car body threfore it nee to be traform to a local space by multiplyin by the root invese

const dMatrix& carMatrix = *((dMatrix*)matrix);
dMatrix rootMatrixInv (car->m_bodyBindMatrix * carMatrix);
rootMatrixInv = rootMatrixInv.Inverse();

// calculate the tire local matrix
dMatrix matrix (car->CalculateTireMatrix(i) * rootMatrixInv);
tireNode->SetMatrix(matrix);


the traform to get the tire matrix corretly is like this.
you formulate tow expresion tha convert teh matrxi to teh same scape.
in the Rigid body the tire matrix in global space must be equal to the tire matrix in global space inteh visual model.

this say T is teh tire matrix in global space.
B is th body matrix,
b1, b2, ... bn are the intemidiate matrices form teh tire to the root body

t is teh local tire matrix.

teh for each tore

T = t * b1 * b2 * .. * B

since b1 * b2 * ... bn do no chaneg the can be concatenated and precomputed

so you get

T = t * b * B
t = T * inverse (B) * invese (b)

t is the local matrix of the tire
b in the invese of the bind pose
T is the tire matrix x
B is the car body matrix you get as teh argument in the call back
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: RayCast Vehicle Problem

Postby Stucuk » Fri Mar 12, 2010 2:58 pm

Julio Jerez wrote:I am still asuming we are talking about the Raycast car, if this the case I can see your mistake, in this code

Code: Select all
Tire        := DGRaycastVehicleGetTiresUserData (car, X);
  DGRaycastVehicleGetTireMatrix (car, x, @Matrix[0][0]);
  Tire.Matrix := Matrix;

// this do not look correct, you are applying the tire matrix to a Newton body, and the tire are no bodies.
  NewtonBodySetMatrix(Tire.Body,@Matrix[0][0]);



Raycats car only have one body, in the loop to do not call NewtonBodySetMatrix on each tire, you only call it for the car body.


I added bodies for the tires so that i didn't have to add a proper rendering side to my app. My app renders the Newton Debug Display, so by adding tire bodies and updating there positions i then don't have to create code to generate a visual representation, i just instead need to get all the vertex's directly from Newton and render them each frame. That bit of code doesn't do anything to the car's performance.

Since i created bodies to represent the wheels, there in Global Space, so i shouldn't afaik need to do any calulations on the Matrix returned by DGRaycastVehicleGetTireMatrix as its already in Global Space.

If you run the demo i posted you will see whats happening.

EDIT: To make sure it wasn't the "Tire Bodies" that i created so i could see them, touching the ground and coutner acting the Matrix's rotation i positioned them higher than the vehicle (With the NewtonBodySetMatrix) and it still does the same thing, the Tire Bodies are not effecting it in the slightest.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: RayCast Vehicle Problem

Postby Julio Jerez » Fri Mar 12, 2010 3:17 pm

I just run it an dI see what you mean. I will try to debug it tonigh.
I will also add a BoxRayCast Car to the demos.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: RayCast Vehicle Problem

Postby Stucuk » Mon Mar 15, 2010 5:06 pm

The Car seems to be ignoring(Or countering) the Torque sent to it as the wheels seem to have torque opposite to each other (As in Tire 0's Torque is the exact opposite of Tire 1). When no Torque is applied the values are the same. I modified the joint library so the torque generated (dVector torque ((tire.m_tireAxelPosit - chassisMatrix.m_posit) * tire.m_tireForceAcc);) would be stored in the tire and added the ability to get that info into the app. X in the image below is the torque thats sent to newton. I made the app always unfreeze the car body so it would never goto rest, otherwise the car never gets to the NewtonBodyAddTorque except when it makes contact with the ground.

Image
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: RayCast Vehicle Problem

Postby Julio Jerez » Mon Mar 15, 2010 5:50 pm

I still think your trasform call back is wrong.
It looks to me you are applying the tire matrix to the car body, so the car body always get the matrix of the last tire.

Tonight I will quicklly add a BoxRayCast car that uses a Box and 4 cilinder for tires all in global space.
That will clarify the confusion getting the matrices
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: RayCast Vehicle Problem

Postby Stucuk » Mon Mar 15, 2010 7:17 pm

Julio Jerez wrote:I still think your trasform call back is wrong.
It looks to me you are applying the tire matrix to the car body, so the car body always get the matrix of the last tire.


Nope. Tire.Body isn't the car's body. If it was the car's body then the tires would be at (0,0,0) as they then wouldn't get positioned. I can empty the callback and it does the same thing(The Tire Callback was added so i could see if the Tires were rotating. It was done after the Initial "not being able to move" thing). It is however the wrong thing to do in general as the Tires shouldn't have there own bodies, but for a debug display on a non-moving vehicle that can't have the tires crash into anything, it doesn't harm it.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests

cron