Re: Patch for wheel spin velocity traction
David Savinkoff <[email protected]> Thu, 12 Nov 2015 20:42:43 -0700 (MST)
| Newsgroups | gmane.games.torcs.general |
|---|---|
| Message-ID | <1106379470.24296778.1447386163973.JavaMail.zimbra@mailid.telus.net> |
----- David Savinkoff wrote: > ----- 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 > > > > > > > > > On 06/16/2015 01:16 AM, David Savinkoff wrote: > > > > Hi, > > > > . . . . . . . > > > > Hi Bernhard, > > > > After some time I returned to the TORCS traction issue and spent > > some time and thought on the matter. > > > > Here is a new patch that supersedes the previous, and is to be > > applied to the torcs-1.3.6 source code. Please see. > > > > The traction formula is actually very straightforward. > > Excellent performance and Nobody else has it either. Ha HA > > > > Sincerely, > > David Savinkoff > > > > ps. > > > > To others that compile TORCS: > > You will like this one. > > Hi Bernhard, > > Here is a massive improvement related to skid energy. > > Sincerely, > David Savinkoff Even better. ------------------------------------------------------------------------------ _______________________________________________ Torcs-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/torcs-users
wheel.cpp.2015nov12.diff
(text/x-patch, 2.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-11-12 17:46:45.783751982 -0800
@@ -174,12 +174,12 @@
{
tWheel *wheel = &(car->wheel[index]);
tdble axleFz = wheel->axleFz;
- tdble vt, v, v2, wrl; // wheel related velocity
+ tdble vt, vn, v, v2, slip_magnitude, wrl; // wheel related velocity
tdble Fn, Ft;
tdble waz;
tdble CosA, SinA;
tdble s, sa, sx, sy; // slip vector
- tdble stmp, F, Bx;
+ tdble F, Bx;
tdble mu;
wheel->state = 0;
@@ -215,6 +215,7 @@
// tangent velocity.
vt = wheel->bodyVel.x * CosA + wheel->bodyVel.y * SinA;
+ vn = wheel->bodyVel.y * CosA - wheel->bodyVel.x * SinA;
v2 = wheel->bodyVel.x * wheel->bodyVel.x + wheel->bodyVel.y * wheel->bodyVel.y;
v = sqrt(v2);
@@ -227,34 +228,31 @@
NORM_PI_PI(sa);
wrl = wheel->spinVel * wheel->radius;
+
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);
- sy = sin(sa);
+ // Normalize the friction circle to get normalized vector components (sx, sy) while
+ // braking (vt), accelerating (wrl), or wheel counter spin (vt - wrl) for any angle.
+ slip_magnitude = 0.000001f + sqrt( MAX(MAX((vn*vn+vt*vt), (vn*vn+wrl*wrl)), (vn*vn+(vt - wrl)*(vt - wrl))) );
+ sx = (vt - wrl) / slip_magnitude;
+ sy = vn / slip_magnitude;
}
- Ft = 0.0f;
- Fn = 0.0f;
s = sqrt(sx*sx+sy*sy);
{
// calculate _skid and _reaction for sound.
- if (v < 2.0f) {
+ if ((v < 2.0f) || (zforce < 0.0002f)) {
car->carElt->_skid[index] = 0.0f;
} else {
- car->carElt->_skid[index] = MIN(1.0f, (s*zforce*0.0002f));
+ car->carElt->_skid[index] = 2.0*s*s; // skid energy :: F*d :: v*v :: s*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));
@@ -264,11 +262,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);