/|\ 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
How to calculate the correct amount of friction
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
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]
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