Re: Patch for wheel spin velocity traction
David Savinkoff <[email protected]> Sun, 16 Aug 2015 14:53:16 -0600 (MDT)
| Newsgroups | gmane.games.torcs.general |
|---|---|
| Message-ID | <1779358877.6006865.1439758396125.JavaMail.zimbra@mailid.telus.net> |
Hi, Here's a followup patch to my last patch (last patch included). Apply wheel.cpp.diff then apply wheel.cpp.followup.diff wheel.cpp.followup.diff avoids a divide by zero situation in a smoother and more specific manner that before. This fixes a loose steering linkage artifact that was caused by setting Ft and Fn forces to zero with an if() statement. I have tested this patch with the previous patch for realistic driving on different cars, rookie --> pro settings, on different tracks, at deliberately slower public speed and racing speed. torcs-1.3.6 plus these two patches clear up all of my current objective driving annoyances. Try the patch to discover that any of your objective driving annoyances are gone. Swerve the car to break traction in a high speed S turn, work the steering, work the throttle, work the drift, then drift though the S turn onto the straightaway... feels like downhill skiing. Perhaps TORCS could have excellent wet pavement and slick ice. TORCS is really realistic now, the proof is in the code. Sincerely, David Savinkoff ----- David Savinkoff wrote: > ----- Bernhard Wymann wrote: > > Hi David > > > > Thank you, I will have a look into this for a later version (1.4.0), I > > plan as well to study the acual SAE papers and fetching a recent edition > > of Pacejka's book. > > > > Kind regards > > > > Bernhard > > > > Thank you very much. I am excited about the potential that > TORCS has. If you, or anyone, has patches or observations > related to TORCS physics... I'll certainly be listening. > > > > > On 06/16/2015 01:16 AM, David Savinkoff wrote: > > > Hi, > > > > > > This patch is the same as the previous, and has further fixes. > > > Apply this patch to clean sources (not with my previous patches). > > > This patch is an injection of natural physics, and an improvement. > > > > > > *** > > > In hunk 1: > > > > > > stmp is removed because this line of code in hunk 3 > > > is not needed anymore: > > > stmp = MIN(s, 1.5f); > > > > > > *** > > > In hunk 2: > > > > > > wrl calculation is corrected. wrl is the speed of the > > > spinning wheel (in the direction the wheel is pointed). > > > However, the wheel is sliding sideways due to the > > > slip angle. Thus, the 'vector component' of wrl must > > > derived from the slip angle. > > > > > > else if () code is factored out. > > > > > > Correct percent slip calculation for ALL conditions: > > > sx = (vt - wrl) / (0.000001f + MAX(fabs(vt) , fabs(wrl)) ); > > > if (fabs(sx) > 1.0) sx /= fabs(sx); > > > > > > The reason for this correction is because it is not > > > physically possible to have more than 100 percent slip > > > (The old code is correct 'only' under braking conditions). > > > > > > *** > > > In hunk 3: > > > > > > if ((v < 2.0f) || (zforce == 0.0f)) > > > replaces > > > if (v < 2.0f) > > > because skid marks are otherwise present in the air with this patch. > > > > > > > > > car->carElt->_skid[index] = s; > > > because s is correct, and never exceeds 1.0f (100% slip). > > > > > > removed: > > > stmp = MIN(s, 1.5f); > > > > > > Magic formula uses 's' instead of 'stmp' > > > > > > > > > > > > Sincerely, > > > David Savinkoff > > > > > > ----- David Savinkoff wrote: > > >> Hi, > > >> > > >> I found the shocking truth that I independently derived > > >> a formula for tire friction. The formula is: > > >> > > >> sx = (vt - wrl) / (MAX(fabs(vt) , fabs(wrl)) ) > > >> > > >> Please read page 2 of this authoritive paper: > > >> http://bsesrv214.bse.vt.edu/Hop/Papers/Tire-Road%20Friction%20Coefficient.pdf > > >> > > >> TORCS and Speed Dreams need fixin' > > >> > > >> Sincerely, > > >> David Savinkoff > > >> > > >> > > >> ----- David Savinkoff wrote: > > >>> ----- Bernhard Wymann wrote: > > >>>> Hi David > > >>>> > > >>>> It makes in my opinion no sense in respect to the tire model, the slip > > >>>> definition looks consistent as is for me > > >>> > > >>> I cannot make an argument here because I am not absolutely certain how > > >>> the tire model interacts with 'sx = (vt - wrl) / fabs(vt)' > > >>> > > >>>> > > >>>> (in your analysis there is a little glitch, vt is not the car velocity, > > >>>> it is the wheel specific velocity, all wheels have usually at least > > >>>> slightly different velocities). > > >>>> > > >>> > > >>> I may have not have expressed myself properly when I said 'car velocity' > > >>> I envisioned a single wheel in contact with the road where 'vt' is the > > >>> velocity in the direction the wheel is pointed... and where 'wrl' is the > > >>> wheel spin velocity (can only be in the direction the wheel is pointed). > > >>> > > >>>> > > >>>> The proposed change would cause a discontinuity which would usually > > >>>> lower the grip. > > >>>> > > >>> > > >>> 'sx = (vt - wrl) / ( 0.000001f + MAX(fabs(vt) , fabs(wrl)) )' has an > > >>> inflection point where the wheel is actuated to slip by > > >>> deceleration, or slip by acceleration. > > >>> The discontinuity is caused by the 'act' of braking or accelerating. > > >>> > > >>> I believe 'sx' may need three different functions to include: > > >>> 1) braking > > >>> 2) accelerating > > >>> 3) wheels rotating backwards to the direction of travel. > > >>> The formula for 'sx' is my best so far, and it seems to work ok. > > >>> > > >>> I visualize vt and wrl as two parallel lines showing their respective > > >>> lengths. Where vt - wrl is the length part that differs. eg. > > >>> _________________________ > > >>> _____________________________________ > > >>> > > >>> The formula for 'sx' suggests that one wants to determine a 'normalized' > > >>> slip value given vt, wrl, and vt-wrl. Note that the slip happens in > > >>> several different situations. > > >>> > > >>>> I think a better solution for drifting is to adjust the parameters of > > >>>> the tire model > > >>> > > >>> I just tried different tire pressures (other than the default 40 psi). > > >>> I will comment on this list when I come across interesting things. > > >>> > > >>> *** > > >>> Please actually try my latest patch traction2.diff on different cars > > >>> and tracks. Drive aggressively (off-track also) or ride with Olethros 6. > > >>> *** > > >>> > > >>>> , differential and suspension. If you don't mind to edit > > >>>> the XML you can adjust as well the engine braking coefficient (instead > > >>>> of adapting your accelerator control in your mind;-) ). > > >>>> > > >>>> Other opinions? > > >>>> > > >>> > > >>> Others on the list... Your opinions please. > > >>> > > >>> Sincerely, > > >>> David Savinkoff > > >>> ------------------------------------------------------------------------------ _______________________________________________ Torcs-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/torcs-users
wheel.cpp.followup.diff
(text/x-patch, 744 B)
--- torcs-1.3.6/src/modules/simu/simuv2/wheel.cpp 2015-06-15 12:56:55.856144909 -0700
+++ torcs-1.3.6/src/modules/simu/simuv2/wheel.cpp 2015-08-15 13:28:11.000000000 -0700
@@ -236,8 +236,6 @@
sy = sin(sa);
}
- Ft = 0.0f;
- Fn = 0.0f;
s = sqrt(sx*sx+sy*sy);
{
@@ -261,11 +259,10 @@
wheel->rollRes = zforce * wheel->trkPos.seg->surface->kRollRes;
car->carElt->priv.wheel[index].rollRes = wheel->rollRes;
- if (s > 0.000001f) {
- // wheel axis based
- Ft -= F * sx / s;
- Fn -= F * sy / s;
- }
+ // wheel axis based
+ s = -0.000001f - s; // make Ft, Fn and s negative with stable divide by zero avoidance.
+ Ft = F * sx/s;
+ Fn = F * sy/s;
RELAXATION2(Fn, wheel->preFn, 50.0f);
RELAXATION2(Ft, wheel->preFt, 50.0f);
wheel.cpp.diff
(text/x-patch, 1.7 KB)
--- torcs-1.3.6/src/modules/simu/simuv2/wheel.cpp 2013-08-29 06:01:32.000000000 -0700
+++ torcs-1.3.6/src/modules/simu/simuv2/wheel.cpp 2015-06-15 12:56:55.856144909 -0700
@@ -179,7 +179,7 @@
tdble waz;
tdble CosA, SinA;
tdble s, sa, sx, sy; // slip vector
- tdble stmp, F, Bx;
+ tdble F, Bx;
tdble mu;
wheel->state = 0;
@@ -226,14 +226,13 @@
}
NORM_PI_PI(sa);
- wrl = wheel->spinVel * wheel->radius;
+ wrl = wheel->spinVel * wheel->radius * fabs(cos(sa)); // wheel can slide sideways due to slip angle
+
if ((wheel->state & SIM_WH_ONAIR) != 0) {
sx = sy = 0.0f;
- } else if (v < 0.000001f) {
- sx = wrl;
- sy = 0.0f;
} else {
- sx = (vt - wrl) / fabs(vt);
+ sx = (vt - wrl) / (0.000001f + MAX(fabs(vt) , fabs(wrl)) ); // slip factor for wheel spin and wheel skid
+ if (fabs(sx) > 1.0) sx /= fabs(sx); // slip factor = 1.0 for all else (eg. forward wheel spin while sliding backwards)
sy = sin(sa);
}
@@ -243,18 +242,16 @@
{
// calculate _skid and _reaction for sound.
- if (v < 2.0f) {
+ if ((v < 2.0f) || (zforce == 0.0f)) {
car->carElt->_skid[index] = 0.0f;
} else {
- car->carElt->_skid[index] = MIN(1.0f, (s*zforce*0.0002f));
+ car->carElt->_skid[index] = s;
}
}
- stmp = MIN(s, 1.5f);
-
// MAGIC FORMULA
- Bx = wheel->mfB * stmp;
- F = sin(wheel->mfC * atan(Bx * (1.0f - wheel->mfE) + wheel->mfE * atan(Bx))) * (1.0f + stmp * simSkidFactor[car->carElt->_skillLevel]);
+ Bx = wheel->mfB * s;
+ F = sin(wheel->mfC * atan(Bx * (1.0f - wheel->mfE) + wheel->mfE * atan(Bx))) * (1.0f + s * simSkidFactor[car->carElt->_skillLevel]);
// load sensitivity
mu = wheel->mu * (wheel->lfMin + (wheel->lfMax - wheel->lfMin) * exp(wheel->lfK * zforce / wheel->opLoad));