How to calculate the correct amount of friction

Started by
2 comments, last by Fusi0n 20 years, 6 months ago
hi, recently ive been playing about trying to model the dynamics of a car (you can see how far i got on my last attempt here: www.cloudfusion.com/rbd.exe (needs glut32.dll, base rbd code by Olli)). that example is fully 3d, only movement is only in 2d. if you have a play with the demo you will see that the amount of friction generated by the spinning wheels isnt enough to accelerate the car at the desired rate (the wheels spin whilst on the ground too much). i have dumped the method i used to generate the friction in the demo and have read the physics of racing series many many times, and it looks more plausible (the author makes a good attempt at explaining how things work out on a higher level). however, the author does not go (as far as i can tell) into how to find out the magnitude of the friction force generated by the wheel. first off, let me explain how i interpret how to apply friction to a car from a wheel contact. before we can do anything we need the location of the contact point (the wheel touching the ground). we need the velocity of the car at the point of contact, which we will call cV. we also need the orientation of the wheel relative to the car (for simplicity: a normal vector pointing in the direction the wheel is facing) which we will call wO; we then need the torque being applied to the the wheel from the engine, which we call eT. at this point we need to find the velocity of the wheel at the point of contact. to find this we take eT and divide it by the distance of the contact point to the center of mass, to get the amount of force the wheel is exerting on the ground at the contact point, in the direction of the velocity of the wheel. we then use this force to find the amount of friction the ground applies to the wheel, which we then use to find out the new velocity of the wheel, wV. we then add cV and wV to get the net velocity of the point of contact (remember the wheel is spinning forward, so wV will be pointing backwards along the wheel normal, wO). and now, using the net velocity of the point of contact we can work out the friction the wheel is generating, using the contact points net velocity, the amount of force on the wheel from the suspension and the coefficient of adhesion (or static friction). once we have the friction we apply it directly to the car at the relative point of contact to make the car move. this is where i come unstuck. in the phors series, the author talks about clamping the friction forces a wheel can take, and the maximum acceleration a wheel can undergo. the maximum force a wheel can take (i guess this means create on the ground) is f <= uW where f is the force, u is the adhesion constant and W is the force acting on the wheel from the suspension. the maximum acceleration a tire can undergo is a <= uG, where u is the adhesion constant and G is the acceleration of gravity. i have no idea where to apply these constraints to the system. when applying the torque to the wheel, do we put a limit on the force that causes the wheel to accelerate (keeping the a <= uG constraint)? when finding out the friction generated from the net velocity, the adhesion constant and the suspension force, is it here we cap the friction force to uW? should i infact figure out the friction using the torque directly? what happens when no torque is being applied to the wheel? how can this system result in wheel spin? surely wheel spin is when the force the wheel generates is more than the force needed to move the car, or less? aarggh! :o to illustrate and explain what i mean a little better, here are a few ascci art diagrams:


      /|\ cV
  _____|__________
       |          |
       |        /\_
       |       /   \
              /    /
             /    /
            / .  /|
           / /  / |
          / /  /  |
          \/  /   |
          / \/    |
        |/ wV
         ¯
Fig.1 cV is the car velocity, wV is the wheel velocity (after having already applied the torque force to the acceleration, and to the velocity)


      /|\ cV
  _____|__________
       |          |
       |        /\_
       |       /   \
              /    /
          nV /    /
         ___/_.  /|
        |  / /  / |
        | / /  /  |
     cV | \/  /   |
        | / \/    |
        |/ wV

Fig.2 we work out nV, the net velocity of the point of contact using cV and wV


      /|\ cV
  _____|__________
       |          |
       |        /\_
       |       /   \
              /    /
             /    /
        /___/_.__/___________\
        \nV/    / |         F/
          /    /  |
          \_  /   |
            \/    |

Fig.3 using nV we figure out the amount of friction to apply to the car at the contact point (this is the force that makes the car move)
 
i''m going to keep cracking on at this, but at the moment i cant see a way around this, can anyone enlighten me as to what i do and how i do it? thanks for your time reading this post, its a bit long i know :F fusi0n "We are what we repeatedly do. Excellence, then, is not an act, but a habit." - Aristotle
http://fusi.basscut.net"We are what we repeatedly do. Excellence, then, is not an act, but a habit." - Aristotle
Advertisement
hmm, just read the response Geoff the Medio gave to the thread titled "friction force". very good explanation. using the information Geoff divulged, i can fill in some of the blanks to the questions i asked earlier, but im still a bit muddled.

in order to get the velocity of the wheel at the contact point we must integrate the torque to acceleration and then velocity (which i assume is done in the previous frame).

the maximum friction force a wheel can generate is uW. if a wheels torque is higher than this threshold, the wheel spins on the surface. if its less the wheel stays stuck.

if the relative velocity of the contact point in respect to the ground is greater than 0 (+epsilon) the wheel spins, if its 0 (or
when i say the wheel sticks i mean the friction force a wheel generates acts completely in the direction of the wheel.

so, having chewed on that, heres some code i just came up with im my head, dunno if it works, or if its right or what, ill get it working later. however, you can see how i want to do things by looking at the code:

void CWheel::CalculateFriction(){	Vector vFriction = Vector::BLANK;	Vector vFrictionNormal = Vector::BLANK;	float fAdhesionConstant = 0.9f;	float fFriction = Torques / Size.y;	float fMaxFriction = m_vSuspensionForce * fAdhesionConstant;	Vector vNetVelocity = m_pChassis->GetVelocityAt(m_vContactPoint) + m_vWheelVelocity;	Clamp(vNetVelocity.y, 0.0f, 0.0f);			if(fFriction > fMaxFriction || vNetVelocity > gEpsilon){		if(fFriction > fMaxFriction){			m_bOverMaxForce = true;			}		m_bSliding = true;		}	else{		m_bOverMaxForce = false;		m_bSliding = false;			}			if(m_bSliding){		vFrictionNormal = -vNetVelocity;		// apply friction in -vNetVelocity;		}	else{		vFrictionNormal = GetViewDirection();	// apply friction in direction of wheel		}	vFrictionNormal.Normalise();	if(m_bOverMaxForce){				vFriction = vFrictionNormal * fMaxFriction;		}	else{		vFriction = vFrictionNormal * fFriction;		}		m_pChassis->AddForce(m_vContactPoint, vFriction);	IntegrateWheel(p_fDeltaTime, vFriction);	// integrate torque -> acceleration -> velocity	} 


Integrate wheel uses all the torque force to generate the velocity. when we are sliding we apply the force in the direction of net velocity, and when we are stuck we apply the force in the direction of the wheel.

i cant quite figure it out in my head but im hoping with a normal setup (car mass ~750kg, wheel mass 35kg, adhesion coefficient ~1.0), the acceleration and resulting velocity of the wheel from a reasonable torque should not cause the relative velocity of the contact point to be greater than epsilon in most cases.

if the torque were to be increased to it overcomes uW, the net velocity of the contact point would have a large enough component in the direction of the wheel to affect the force and therefore the rotation of the car.

i dunno, im rambling what do you peeps think?

fusi0n

"We are what we repeatedly do. Excellence, then, is not an act, but a habit." - Aristotle
http://fusi.basscut.net"We are what we repeatedly do. Excellence, then, is not an act, but a habit." - Aristotle
quote:must integrate the torque to acceleration and then velocity

One does not integrate torque to acceleration. Rather, it is converted to angular acceleration or to force(s). I think you knew that, but just making sure...
quote:
Vector vNetVelocity = m_pChassis->GetVelocityAt(m_vContactPoint) + m_vWheelVelocity;Clamp(vNetVelocity.y, 0.0f, 0.0f);    

How does your chassis have different velocities at different points? I'd think you'd do something more like:
 Vector vNetVelocity = m_pChassis->GetVelocity() + m_vWheelVelocity + CrossProd(m_vWheelAngVelocity, (m_vContactPoint - m_vWheelHubPoint) ;    

which would give you the velocity of the chassis, plus the (vertical?) velocity of the wheel hub, plus the rotational velocity of the wheel at the contact point. The rotational velocity at the contact point is determed using a cross product of the velocity vector of the wheel and the vector from the axis of rotation of the wheel to the contact point. (note: I might have the order of vectors in the crossproduct mixed up... but you can check that and fix easily)


You might not want to restrict the velocity of the wheel to flat in this case... if it isn't in the plane of the driving surface, then you probably aren't getting any friction, as the wheel is coming off the pavement. You could put a small wheel height and vertical velocity combined limit such that small bumps or wheel height integration errors don't cause the wheel to jump off the pavement for friction purposes too often, but if the wheel really does come off the surface, you probly shouldn't add friction.


Your big if structure to determine which friction force to use looks like it would work, but seems needlessly verbose. (I may write too much text, but I try to keep my code lean).


If your engine torque too easily overcomes the static friction, then your car is overpowered. It's not too rare for this to happen... haven't you ever, or seen someone, spin the tires on their vehicle when gassing to fast/hard?

[edited by - Geoff the Medio on October 3, 2003 5:01:23 PM]

hi Geoff

quote:One does not integrate torque to acceleration. Rather, it is converted to angular acceleration or to force(s). I think you knew that, but just making sure...


hehe yea i know, i use the term sloppily

quote:How does your chassis have different velocities at different points?


i must take into account rotational velocity about the center of mass, which results in different velocities at different points on the chassis of course this probably doesnt contribute very much to the output, but i do like attention to detail

quote:The rotational velocity at the contact point is determed using a cross product of the velocity vector of the wheel and the vector from the axis of rotation of the wheel to the contact point.


thanks for confirming, thats how i worked it in the end

quote:You might not want to restrict the velocity of the wheel to flat in this case... if it isn''t in the plane of the driving surface, then you probably aren''t getting any friction, as the wheel is coming off the pavement. You could put a small wheel height and vertical velocity combined limit such that small bumps or wheel height integration errors don''t cause the wheel to jump off the pavement for friction purposes too often, but if the wheel really does come off the surface, you probly shouldn''t add friction.


hehe yea, ur absolutely right, already catered for by the physics engine. each contact has a normal and is solved independantly of other contacts. basically i assume there is always friction with any contact. at the end i''d like to be able to drive over a heightmap (like everyone else ).

quote:Your big if structure to determine which friction force to use looks like it would work, but seems needlessly verbose. (I may write too much text, but I try to keep my code lean).


hehe yea just the way my mind works i do like to stretch my code out when im still working on it, makes it easier to read fast and process logically, once i know its bug free ill optamize it down

quote:If your engine torque too easily overcomes the static friction, then your car is overpowered. It''s not too rare for this to happen... haven''t you ever, or seen someone, spin the tires on their vehicle when gassing to fast/hard?


yup thats what its doin in the app, although in the app the suspension is a flakey and really needs fixing :<

ive been looking at the pacejka magic formula in the last few days and it looks promising, but it also feels like a bit of a fudge :/ im not sure whether i should spend time implementing the pacejka solution instead of working with my current system.i notice the pacejka is referenced in ode, and is also used in many race sims - is it really that accurate? of course i dont absolute ''realistic'' handling, just something that feels and acts like you would expect. would pacejka be overkill in this situation :? what do you think?

thanks for the reply Geoff, much appreciated

fusi0n

"We are what we repeatedly do. Excellence, then, is not an act, but a habit." - Aristotle
http://fusi.basscut.net"We are what we repeatedly do. Excellence, then, is not an act, but a habit." - Aristotle

This topic is closed to new replies.

Advertisement