Demo5 Simple Vehicle AddSingleSuspensionTire Friction Proble

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Demo5 Simple Vehicle AddSingleSuspensionTire Friction Proble

Postby raisins » Tue Aug 04, 2015 11:15 am

Hi, I'm using Ogrenewt for my physics engine and I'm having problem integrating the simplevehicle class to my game. The problem is my jeep/car just keeps on sliding against the surface as if it's in space regardless of its mass, suspensions, etc. I've changed different variables multiple times but it had no effect on the slipperiness of the wheels. I even modified the core newton script so I can directly control the wheels through code but none of it helped. I had to revert all the changes because it didn't solve the problem anyway. Can you help me out please?

I also made different materials for my terrain and the car chasee and applied 2.0 friction to both elements.

Here's a video:


This is my code:
Code: Select all
carMaterial = new OgreNewt::MaterialID(sceneWorld);
terrainMaterial = new OgreNewt::MaterialID(sceneWorld);
mCar = SimpleVehicle::create(&Jeep, sceneManager, sceneWorld);
mCar->getBody0()->setMaterialGroupID(carMaterial);
mCar->getBody0()->setPositionOrientation(Ogre::Vector3(-709, 10, 197), Ogre::Quaternion(Ogre::Quaternion::IDENTITY));
   
worldMaterialPairs = new OgreNewt::MaterialPair(sceneWorld, carMaterial, terrainMaterial);
worldMaterialPairs->setDefaultFriction(1.0f, 0.9f);


I want to stop my vehicle from sliding against the surface.

Thanks.
Last edited by raisins on Tue Aug 04, 2015 12:57 pm, edited 1 time in total.
raisins
 
Posts: 12
Joined: Tue Aug 04, 2015 11:08 am

Re: Demo5 Simple Vehicle AddSingleSuspensionTire Friction Pr

Postby Julio Jerez » Tue Aug 04, 2015 12:19 pm

can you contact him? send him a PM
viewtopic.php?f=14&t=8519
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Demo5 Simple Vehicle AddSingleSuspensionTire Friction Pr

Postby raisins » Tue Aug 04, 2015 4:24 pm

Thanks I sent him a PM. :)

I got rid of this line in CustomDGRayCastCar.cpp on CustomDGRayCastCar::SubmitConstraints function

Code: Select all
   NewtonBodyAddForce (m_body0, &tire.m_tireForceAcc[0]);


I commented it out. The sliding problem subsided but now I don't have suspension on my car.

Image

I know for sure that AddSingleSuspensionTire has something to do with the sliding problem. Because previously when I flip the car it stops sliding, but if I flip it over in normal position, it starts to slide. So the sliding is related to the wheels.

I think I'm on the right path here.
raisins
 
Posts: 12
Joined: Tue Aug 04, 2015 11:08 am

Re: Demo5 Simple Vehicle AddSingleSuspensionTire Friction Pr

Postby raisins » Tue Aug 04, 2015 5:27 pm

I'm also looking at this bit of disabled code (commented out) in the same file, it looks like it has something to do with preventing the car from sliding sideways, the problem is the code doesn't compile, there's a lot of undeclared identifier errors and I don't want to mess up the code, I might end up messing the whole project.

Code: Select all
         // Apply brake, need some little fix here.
         // The fix is need to generate axial force when the brake is apply when the vehicle turn from the steer or on sliding.
         if ( tire.m_breakForce > 1.0e-3f ) {
            _ASSERTE (0);
/*
            // row constrained force is save for later determine the dynamic state of this tire
              tire.m_isBrakingForceIndex = constraintIndex;
            constraintIndex ++;

            frictionCircleMag = tire.m_tireLoad * tire.m_groundFriction;
            if (tire.m_breakForce > frictionCircleMag) {
               tire.m_breakForce = frictionCircleMag;
            }

            //NewtonUserJointAddLinearRow ( m_joint, &tire.m_tireAxelPosit[0], &tire.m_tireAxelPosit[0], &chassisMatrix.m_front.m_x  );
            NewtonUserJointAddLinearRow (m_joint, &tire.m_tireAxelPosit[0], &tire.m_tireAxelPosit[0], &tire.m_longitudinalPin.m_x);
            NewtonUserJointSetRowMaximumFriction( m_joint, tire.m_breakForce);
            NewtonUserJointSetRowMinimumFriction( m_joint, -tire.m_breakForce);

            // there is a longitudinal force that will reduce the lateral force, we need to recalculate the lateral force
            tireForceMag = lateralFrictionForceMag * lateralFrictionForceMag + tire.m_breakForce * tire.m_breakForce;
            if (tireForceMag > (frictionCircleMag * frictionCircleMag)) {
                 lateralFrictionForceMag *= 0.25f * frictionCircleMag / dSqrt (tireForceMag);
            }
*/
         }
raisins
 
Posts: 12
Joined: Tue Aug 04, 2015 11:08 am

Re: Demo5 Simple Vehicle AddSingleSuspensionTire Friction Pr

Postby raisins » Wed Aug 05, 2015 2:26 pm

So I decided I could make this work by modifying the submitConstraint fucntion in DGRayCast file. I want to get rid of the x and z movements and leave the y alone to get the spring effect. Getting rid of the x & z means the car won't move anywhere else other than up and down, this also means getting rid of the sliding problem. To move the car I would manipulate the car manually by adding force to the chasee. The problem is I don't know which bits to modify to get rid of the x & ys in the matrix. Here's the code I cleaned up straight from Newton lib's CustomDGRayCastCar.cpp

Code: Select all
void CustomDGRayCastCar::SubmitConstraints (dFloat timestep, int threadIndex){

   // get the vehicle global matrix, and use it in several calculations
   dMatrix bodyMatrix; 
   NewtonBodyGetMatrix (m_body0, &bodyMatrix[0][0]);
   dMatrix chassisMatrix (m_localFrame * bodyMatrix);

   // get the chassis instantaneous linear and angular velocity in the local space of the chassis
   dVector bodyForce;
   dVector bodyOmega;
   dVector bodyVelocity;

   NewtonBodyGetVelocity (m_body0, &bodyVelocity[0]);
   NewtonBodyGetOmega (m_body0, &bodyOmega[0]);

   m_vehicleOnAir = 0;

   for (int i = 0; i < m_tiresCount; i ++) {

      Tire& tire = m_tires[i];
      tire.m_tireIsOnAir = 1;
      tire.m_tireForceAcc = dVector(0.0f, 0.0f, 0.0f, 0.0f);

      // calculate all suspension matrices in global space and tire collision
      dMatrix suspensionMatrix (CalculateSuspensionMatrix (i, 0.0f) * chassisMatrix);

      // calculate the tire collision
      CalculateTireCollision (tire, suspensionMatrix, threadIndex);

      // calculate the linear velocity of the tire at the ground contact
      tire.m_tireAxelPositGlobal = chassisMatrix.TransformVector (tire.m_harpointInJointSpace - m_localFrame.m_up.Scale (tire.m_posit));
      tire.m_tireAxelVelocGlobal = bodyVelocity + bodyOmega * (tire.m_tireAxelPositGlobal - chassisMatrix.m_posit);
      tire.m_lateralPinGlobal = chassisMatrix.RotateVector (tire.m_localAxisInJointSpace);
      tire.m_longitudinalPinGlobal = chassisMatrix.m_up * tire.m_lateralPinGlobal;

      if (tire.m_posit < tire.m_suspensionLenght )  {

         tire.m_tireIsOnAir = 0;
         tire.m_hitBodyPointVelocity = dVector (0.0f, 0.0f, 0.0f, 1.0f);
         if (tire.m_HitBody){
            dMatrix matrix;
            dVector com;
            dVector omega;

            NewtonBodyGetOmega (tire.m_HitBody, &omega[0]);
            NewtonBodyGetMatrix (tire.m_HitBody, &matrix[0][0]);
            NewtonBodyGetCentreOfMass (tire.m_HitBody, &com[0]);
            NewtonBodyGetVelocity (tire.m_HitBody, &tire.m_hitBodyPointVelocity[0]);
            tire.m_hitBodyPointVelocity += (tire.m_contactPoint - matrix.TransformVector (com)) * omega;
         }


         // calculate the relative velocity
         dVector tireHubVeloc (tire.m_tireAxelVelocGlobal - tire.m_hitBodyPointVelocity);
         dFloat suspensionSpeed = - (tireHubVeloc % chassisMatrix.m_up);

         // now calculate the tire load at the contact point
         // Tire suspension distance and hard limit.
         dFloat distance = tire.m_suspensionLenght - tire.m_posit;
         _ASSERTE (distance <= tire.m_suspensionLenght);
         tire.m_tireLoad = - NewtonCalculateSpringDamperAcceleration (timestep, tire.m_springConst, distance, tire.m_springDamper, suspensionSpeed );
         if ( tire.m_tireLoad < 0.0f ) {
            // since the tire is not a body with real mass it can only push the chassis.
            tire.m_tireLoad = 0.0f;
         }

         //this suspension is applying a normalize force to the car chassis, need to scales by the mass of the car
         tire.m_tireLoad *= (m_mass * 0.5f);

         // convert the tire load force magnitude to a torque and force.
         // accumulate the force doe to the suspension spring and damper
         tire.m_tireForceAcc += chassisMatrix.m_up.Scale (tire.m_tireLoad);


         // axle linear speed
         dFloat axelLinearSpeed = tireHubVeloc % chassisMatrix.m_front;

         // calculate the formal longitudinal force the tire apply to the chassis
         dFloat longitudinalForceMag = CalculateLongitudinalForce (i, axelLinearSpeed, tire.m_tireLoad * tire.m_groundFriction);

         // accumulate the longitudinal force
         dVector tireForce (tire.m_longitudinalPinGlobal.Scale (longitudinalForceMag));
         tire.m_tireForceAcc += tireForce;

         // now we apply the combined tire force generated by this tire, to the car chassis
         dVector r (tire.m_tireAxelPositGlobal - chassisMatrix.m_posit);

         // add the toque the tire asserts on the car body (principle of action reaction)
         dVector torque (r * tire.m_tireForceAcc - tire.m_lateralPinGlobal.Scale (tire.m_torque));
         NewtonBodyAddForce (m_body0, &tire.m_tireForceAcc[0]);
         NewtonBodyAddTorque( m_body0, &torque[0] );

      } else {

         // there is a next torque on the tire
         tire.m_torque -= tire.m_angularVelocity * tire.m_Ixx * DG_TIRE_VISCUOS_DAMP;
         tire.m_angularVelocity += tire.m_torque * tire.m_IxxInv * timestep;
         if (m_tires[i].m_breakForce > dFloat (0.1f)) {
            tire.m_angularVelocity = 0.0f;
         }
      }

      // spin the tire by the angular velocity
      tire.m_spinAngle = dMod (tire.m_spinAngle + tire.m_angularVelocity * timestep, 3.14159265f * 2.0f);

      // reset the tire torque
      tire.m_torque = 0.0f;
      tire.m_breakForce = 0.0f; 

   }
}



Can you help me pin point which bits to edit please? I just need to set the X & Y to 0 and that should work.

Thanks.
raisins
 
Posts: 12
Joined: Tue Aug 04, 2015 11:08 am

Re: Demo5 Simple Vehicle AddSingleSuspensionTire Friction Pr

Postby Julio Jerez » Wed Aug 05, 2015 2:58 pm

The problem is that in DGRayCast is very old, I do not even thonk David is using any more, he
is using the latest Newton Ogre Newton and I think he made his own DGRayCast tah seem vey cool
https://www.youtube.com/watch?v=PLXBh85PL7E
what do you just use that version?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Demo5 Simple Vehicle AddSingleSuspensionTire Friction Pr

Postby Dave Gravel » Mon Aug 10, 2015 4:22 pm

I use a multibody custom joint in my demo, it's not a raycast vehicle.
I don't have get the time to test DGRayCast again, I need to update my code for try this one.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://orionx3d.sytes.net
https://www.facebook.com/dave.gravel1
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 801
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Demo5 Simple Vehicle AddSingleSuspensionTire Friction Pr

Postby raisins » Mon Aug 10, 2015 7:29 pm

I found a working example of a simple 4 wheel vehicle in MogreNewt. It's not raycast but it works.

I have some problems with it though. I tried integrating it to my class with this:
Code: Select all
   
   //INIT CAR
   Ogre::Real mass = 300.0f;
   Ogre::Vector3 inertia, offset;
   int tireCount = 0;
   coreVehicle* carWhole;

   //CREATE CHASEE ENTITY
   Ogre::Entity* carChaseeEntity = sceneManager->createEntity(carConfig->vehicleChaseeMesh);
   Ogre::SceneNode* carChaseeNode = sceneManager->getRootSceneNode()->createChildSceneNode("car", Ogre::Vector3(0, 55, 0));
                  carChaseeNode->attachObject(carChaseeEntity);

   //GET TIRE STRUCT
   CAR_CONFIG::TIRE* carTireGeo = &carConfig->front_right;

   //CREATE CHASEE/CAR COLLISION
   OgreNewt::ConvexCollisionPtr col(new OgreNewt::CollisionPrimitives::ConvexHull(sceneWorld, carChaseeEntity, 0));
                           col->calculateInertialMatrix(inertia, offset);
   
   //CREATE CHASEE/CAR RIGID BODY
   OgreNewt::Body* carChasee = new OgreNewt::Body(sceneWorld, col);
               carChasee->attachNode(carChaseeNode);
               carChasee->setMassMatrix(mass, mass * inertia);
               carChasee->setCenterOfMass(offset);
               carChasee->setAutoSleep(false);
               carChasee->setCustomForceAndTorqueCallback<coreVehicle>(&coreVehicle::vehicleForceCallback, carWhole);
   
   //FINALIZE CAR
   carWhole = new coreVehicle(carChasee, 4);

   //CREATE AND ATTACH TIRES
   for(int i = 0; i < 4; i++){

      Ogre::Real tireMass = 10.0f;
      Ogre::Vector3 tireInertia, tireOffset;

      Ogre::Vector3 posit(carTireGeo[i].m_posit[0],
                     carTireGeo[i].m_posit[1],
                     carTireGeo[i].m_posit[2]);

      Ogre::Quaternion rotation(carTireGeo[i].m_rotation[0],
                           carTireGeo[i].m_rotation[1],
                           carTireGeo[i].m_rotation[2],
                           carTireGeo[i].m_rotation[3]);
      
      Ogre::Entity* carTireEntity = sceneManager->createEntity("Car Entity" + Ogre::StringConverter::toString(tireCount++),
                                                   carTireGeo[i].vehicleTireMesh);

      Ogre::Node* carTireHarpointAttachement = carChaseeNode->createChild();

      Ogre::SceneNode* carTireNode = (Ogre::SceneNode*)carTireHarpointAttachement->createChild(posit, rotation);
                     carTireNode->attachObject(carTireEntity);
      
      OgreNewt::ConvexCollisionPtr tireCol(new OgreNewt::CollisionPrimitives::ConvexHull(sceneWorld, carChaseeEntity, 0));
                              tireCol->calculateInertialMatrix(tireInertia, tireOffset);

      OgreNewt::Body* tireBody = new OgreNewt::Body(sceneWorld, tireCol);
                  tireBody->setMassMatrix(tireMass, tireInertia * tireMass);
                  tireBody->setCenterOfMass(tireOffset);
                  tireBody->setStandardForceCallback();
                  tireBody->attachNode(carTireNode);
                  tireBody->setPositionOrientation(posit, rotation);

      OgreNewt::Joint* wheelHinge = new OgreNewt::Hinge(tireBody, carChasee, posit, Ogre::Vector3::UNIT_X);
   
   }
               
   return carWhole;


I got this: Image

Nevermind the guy on the back. That's just dummy animated model.
raisins
 
Posts: 12
Joined: Tue Aug 04, 2015 11:08 am

Re: Demo5 Simple Vehicle AddSingleSuspensionTire Friction Pr

Postby raisins » Mon Aug 10, 2015 9:09 pm

nearly there, except the collision mdoel is off the mark.

Image
raisins
 
Posts: 12
Joined: Tue Aug 04, 2015 11:08 am

Re: Demo5 Simple Vehicle AddSingleSuspensionTire Friction Pr

Postby raisins » Wed Aug 12, 2015 10:26 am

Question: is it normal for my vehicle to slide off the surface? There's no force acting on the chasee and the wheels. No force other than the gravity.
raisins
 
Posts: 12
Joined: Tue Aug 04, 2015 11:08 am

Re: Demo5 Simple Vehicle AddSingleSuspensionTire Friction Pr

Postby Julio Jerez » Wed Aug 12, 2015 11:21 am

no that is no normal. unless it is a high pitch slope.
what version of Newton are you using?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Demo5 Simple Vehicle AddSingleSuspensionTire Friction Pr

Postby raisins » Wed Aug 12, 2015 11:29 am

I'm using Newton 2.33. It looks like the vehicle class is disabled in it because OgreNewt::Vehicle comes up with errors at compile time such as:

error C3861: 'NewtonVehicleTireIsAirBorne': identifier not found

This is a snippet of a group of errors (not all) that comes up at compile time:
Code: Select all
1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(77) : error C3861: 'NewtonVehicleTireIsAirBorne': identifier not found
1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(80) : error C3861: 'NewtonVehicleTireLostSideGrip': identifier not found
1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(83) : error C3861: 'NewtonVehicleTireLostTraction': identifier not found
1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(86) : error C3861: 'NewtonVehicleGetTireOmega': identifier not found
1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(89) : error C3861: 'NewtonVehicleGetTireNormalLoad': identifier not found
1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(92) : error C3861: 'NewtonVehicleGetTireSteerAngle': identifier not found
1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(95) : error C3861: 'NewtonVehicleGetTireLateralSpeed': identifier not found
1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(98) : error C3861: 'NewtonVehicleGetTireLongitudinalSpeed': identifier not found
1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(104) : error C3861: 'NewtonVehicleSetTireTorque': identifier not found
1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(107) : error C3861: 'NewtonVehicleSetTireSteerAngle': identifier not found
1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(110) : error C3861: 'NewtonVehicleTireCalculateMaxBrakeAcceleration': identifier not found
1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(113) : error C3861: 'NewtonVehicleTireSetBrakeAcceleration': identifier not found
1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(116) : error C3861: 'NewtonVehicleSetTireMaxSideSleepSpeed': identifier not found
1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(119) : error C3861: 'NewtonVehicleSetTireSideSleepCoeficient': identifier not found
1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(122) : error C3861: 'NewtonVehicleSetTireMaxLongitudinalSlideSpeed': identifier not found
1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(125) : error C3861: 'NewtonVehicleSetTireLongitudinalSlideCoeficient': identifier not found
1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(179) : error C3861: 'NewtonVehicleReset': identifier not found


Apparently the errors can be fixed by downgrading to Newton 1.53. But I'm afraid it might cause set backs on my OgreNewt codes.
raisins
 
Posts: 12
Joined: Tue Aug 04, 2015 11:08 am

Re: Demo5 Simple Vehicle AddSingleSuspensionTire Friction Pr

Postby Julio Jerez » Wed Aug 12, 2015 8:13 pm

the problem is that you have a version of the engine that is so old no one has it the latest newton has a nice cool vehicle. but since no one maintain the Newton Ogre wrapper you are stocked with an old version.

I tried once to make an Ogre Wrapper but the people over Ogre do not want anything to with Newton, or with me particularly, they prefer libraries that the think will give the more notoriety
any one who dare to say anything positive about newton get bat mouse and scorned out of the forum.so I decide to focus my attention on other projects.

if you want here is a Ogre wrapper the use Newton 3.13 which gas a nice vehicle, you can try that
but you will have to make some change on your side.
https://code.google.com/p/ogrenewton
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Demo5 Simple Vehicle AddSingleSuspensionTire Friction Pr

Postby raisins » Wed Aug 12, 2015 8:25 pm

Thank you, I'll check it out. Despite what everyone says I think OgreNewt & Newton are very flexible compared to PhysX & Bullet (I haven't tried Ode yet). NxOgre has a faulty player controller and the tutorials aren't exactly 1:1 copy of the tutorials provided by PhysX. Bullet doesn't even compile.

Thanks again, I'll check out the latest version.
raisins
 
Posts: 12
Joined: Tue Aug 04, 2015 11:08 am

Re: Demo5 Simple Vehicle AddSingleSuspensionTire Friction Pr

Postby Julio Jerez » Wed Aug 12, 2015 8:40 pm

That later version is more flexible and it works more like Ogre that the original OgreNewton.
It be eassy for you to get it to go because it will be like working in Ogre.

It also do a few things that the original did not like frame interpolations.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests