Vehicle Problem

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Vehicle Problem

Postby mikeman42 » Sun Jun 14, 2009 6:55 am

This is the first time I've tried the vehicle utilities, and I have some problems.

The code is this(it's a C# wrapper but you get the point):

Code: Select all
           size = new Vec3(0.3f, 0.15f, 0.7f);
           
            IntPtr boxColl = Newton.CreateBox(newtonWorld, size.x, size.y, size.z);
            body = Newton.CreateBody(newtonWorld, boxColl);
            Newton.BodySetForceAndTorqueCallback(body, FT);
            Newton.BodySetMassMatrix(body, 1000, 1000, 1000, 1000);

                Matrix4 matrix;
                float pin[]={1,0,0};
   float up[]={0,-1,0};
   NewtonJoint* v=NewtonConstraintCreateVehicle((NewtonWorld*)world.ToPointer(),up,(NewtonBody*)body.ToPointer());

 
                matrix.posit=Vec3(-0.1,-0.3,0.2);//left front
   NewtonVehicleAddTire(v,matrix,pin,100.0,0.05,radius,0.1,0.1,0.6,NULL,0);           

                matrix.posit=Vec3(0.1,-0.3,0.2);//right front
   NewtonVehicleAddTire(v,matrix,pin,100.0,0.05,radius,0.1,0.1,0.6,NULL,1);           

                matrix.posit=Vec3(0.1,-0.3,-0.2);//right back
   NewtonVehicleAddTire(v,matrix,pin,100.0,0.05,radius,0.1,0.1,0.6,NULL,2);           

                matrix.posit=Vec3(-0.1,-0.3,-0.2);//left back
   NewtonVehicleAddTire(v,matrix,pin,100.0,0.05,radius,0.1,0.1,0.6,NULL,3);           


All the vehicle code is this(no callbacks). After that I just let the body to fall into the ground. Now, very strange things happen, I render the tyres, and they look like they're not attached to the body at all. From what I can tell, the bounce off the ground, go above the vehicle, then fall down and 'sit' just above the vehicle. And so on. Very strange. Is there something I'm missing, something I should add to this code to get normal behaviour? Thank you.
mikeman42
 
Posts: 19
Joined: Tue May 01, 2007 6:08 pm

Re: Vehicle Problem

Postby Julio Jerez » Sun Jun 14, 2009 9:20 am

Ib in no enoght to just creat eteh car and add the tire, you also must set and special trasform call back that set teh visual position and teh teh tire position.
if you look at the demos theye is a very trivial one

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_tireOffsetMatrix * carMatrix) ;
         rootMatrixInv = rootMatrixInv.Inverse();
         count = car->GetTiresCount();

         // for each tire get the global matrix postion, 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
            if (tireAnim->m_animation) {
               dFloat param;
               param = (1.0f - car->GetParametricPosition(i));

               if (param > 1.0f) {
                  param = 1.0f;
               }
               if (param < 0.0f) {
                  param = 0.0f;
               }

               tireAnim->m_animation->GeneratePose (param);
               tireAnim->m_animation->UpdatePose();
            }

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

            if (DebugDisplayOn()) {
               // if debug display show the contact and tire collsion 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);
            }
         }
      }
   }



you will need implement a similar funtion in c# and assigne it to teh body
Set the debug code that show the collisions shape and contact point , it will tell you what is going on.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Vehicle Problem

Postby mikeman42 » Sun Jun 14, 2009 9:27 am

Yes, of course I have function that set the transforms, I didn't mention that.

Turns out I was using low values for spring and shock, I used the formulas in the sample and it stabilized. However, I still can't get smooth motion, from what I can tell I use the same values as the sample for gravity,mass,suspensions and such, however the wheels get 'stuck' and the vehicle just bounces around like crazy and flips over. And the way it appears to move, it almost seems like the wheels are...cubes. I don't know how else to describe it. No matter how much I tweak I can't get it to work.

I don't know, could please anyone write down the very MINIMUM steps that it takes so you get a working vehicle? The sample has too many things and I can't know which one I'm missing. Thanks in advance.
mikeman42
 
Posts: 19
Joined: Tue May 01, 2007 6:08 pm

Re: Vehicle Problem

Postby Julio Jerez » Sun Jun 14, 2009 9:46 am

way a minute you are using 1.53
Code: Select all
    Matrix4 matrix;
    float pin[]={1,0,0};
   float up[]={0,-1,0};
   NewtonJoint* v=NewtonConstraintCreateVehicle((NewtonWorld*)world.ToPointer(),up,(NewtonBody*)body.ToPointer());

the above code are the funtions from 1.53, you need to use SDK 2.01

The car code is simpler, the joint is open source, and there are two car models you can implemnet, one is ray cast car whish in the demo, and we are making the Multi body car which is the same one in 1.53
with bug fixes and some optimizations.
this time is implemented as a custom joint you can see how everything is done.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Vehicle Problem

Postby mikeman42 » Sun Jun 14, 2009 10:05 am

Hm...the sample demo in 1.53 works fine though...so whatever problems I'm having is my own fault and won't be magically fixed if I switch versions, right? I'd like to see what's wrong first before I upgrade.

An update: I used to have pin=(1,0,0)...when I changed it to pin=(0,0,1), the wheels behave way more normal...there's still some bouncing around though and most importantly I get random crashes inside NewtonUpdate()...
mikeman42
 
Posts: 19
Joined: Tue May 01, 2007 6:08 pm

Re: Vehicle Problem

Postby Julio Jerez » Sun Jun 14, 2009 10:09 am

Trusth me, porting the wraper to 2.01 is the way to go,
at least download the SDK and play the demo the car demo is the default demo. Ther is no install you just unzip and play the demo.

The car is much more robust and polished in Newton 2 than is is in newton 1.53
All the bouncing is gone, and it can be set across a much wider set of values and still being stable.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Vehicle Problem

Postby mikeman42 » Sun Jun 14, 2009 10:41 am

Okay I downloaded it...quick question so I don't waste too much time on this and see if it actually fixes the problem:

I opened the solution file with VS, and tried to build the NewtonDemos myself....however it's not possible out of the box, I get many linker errors(like dRollMatrix or DGRaycastCar missing). Do I need to add some libraries and update any directories(indlude/lib) so it can compile?
mikeman42
 
Posts: 19
Joined: Tue May 01, 2007 6:08 pm

Re: Vehicle Problem

Postby Julio Jerez » Sun Jun 14, 2009 11:02 am

not the project shuold build out of the box, it sould be absolutly perfect just open teh .sln project
I have tryed in othe computers and I have it seems to work

also you you can just play the executable that is already compiled.
I woudl paly the exe first, them you can see waht I mean abput teh car.

the project is a VS2008 you soudh not have any problem opening and building it.
There is also a 2003 project in case you do not have VS 2008.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Vehicle Problem

Postby Julio Jerez » Sun Jun 14, 2009 11:20 am

these are the steps

Right click on file NewtonWin-2.01.rar and select unpack here.
It will decompress the SDK in a file NewtonWin-2.01
To test the demo, go to C:\NewtonWin-2.01\samples\bin\x32
And double click on NewtonDemos.exe
The demos will start playing

For building the project:

go to: C:\NewtonWin-2.01\samples\sdkDemos
double click on NewtonDemos_2003.sln or NewtonDemos_2009.sln
Visual studio will open the complete project,
Click rebuild solution,
The project should build with zero warning and zero errors.
Hit F5 key and the demo should play.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Vehicle Problem

Postby Julio Jerez » Sun Jun 14, 2009 12:35 pm

here is a demo of the same car joint on 1.53 implemneted as Cistom joint in 2.01

This demo was provided by David Gravel, and I fix the last edge bug, ote htah tah it is teh same demo of hix with a DLL with a Bug fixd
http://www.newtondynamics.com/downloads/atv_demo.rar

and here is the Raycasr an dComvex Cast car.
http://www.newtondynamics.com/downloads ... le_B19.rar

those demo show the level of stability and performance you can expect from newton 2.01 SDK as opposed to 1.53 where cars are hard to tune and can no possible yeild the same performance

Daved is will make a Mutibody car demo that will be in next 2.02
but if you port you C# wraper by them you will have both car models.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron