diff --git a/src/modules/simu/simuv4/susp.cpp b/src/modules/simu/simuv4/susp.cpp index 8c2e51d41..03164bd05 100644 --- a/src/modules/simu/simuv4/susp.cpp +++ b/src/modules/simu/simuv4/susp.cpp @@ -96,15 +96,16 @@ static tdble springForce(tSuspension *susp) void SimSuspCheckIn(tSuspension *susp) { - susp->state = 0; + /*susp->state = 0;*/ + /* note: susp->state is reset in SimWheelUpdateRide in wheel.cpp */ if (susp->x < susp->spring.packers) { susp->x = susp->spring.packers; - susp->state = SIM_SUSP_COMP; + susp->state |= SIM_SUSP_COMP; } susp->x *= susp->spring.bellcrank; if (susp->x >= susp->spring.xMax) { susp->x = susp->spring.xMax; - susp->state = SIM_SUSP_EXT; + susp->state |= SIM_SUSP_EXT; } } @@ -113,7 +114,7 @@ void SimSuspCheckIn(tSuspension *susp) void SimSuspUpdate(tSuspension *susp) { - susp->force = (springForce(susp) + damperForce(susp)) * susp->spring.bellcrank; + susp->force = (springForce(susp) + damperForce(susp) + susp->inertance * susp->a) * susp->spring.bellcrank; } @@ -136,6 +137,7 @@ void SimSuspConfig(void *hdle, const char *section, tSuspension *susp, tdble F0, susp->damper.rebound.C2 = GfParmGetNum(hdle, section, PRM_FASTREBOUND, (char*)NULL, 0.0f); susp->damper.bump.v1 = GfParmGetNum(hdle, section, PRM_BUMPLVEL, (char*)NULL, 0.5f); susp->damper.rebound.v1 = GfParmGetNum(hdle, section, PRM_REBOUNDLVEL, (char*)NULL, 0.5f); + susp->inertance = 0.0; susp->spring.x0 = susp->spring.bellcrank * X0; susp->spring.F0 = F0 / susp->spring.bellcrank; diff --git a/src/modules/simu/simuv4/susp.h b/src/modules/simu/simuv4/susp.h index 4f3abb1aa..e81bfffd2 100644 --- a/src/modules/simu/simuv4/susp.h +++ b/src/modules/simu/simuv4/susp.h @@ -48,15 +48,17 @@ typedef struct Suspension { tSpring spring; tDamper damper; + tdble inertance; tdble x; /* suspension travel */ tdble v; /* suspension travel speed */ + tdble a; /* suspension travel acceleration */ tdble force; /* generated force */ int state; /* indicate the state of the suspension */ #define SIM_SUSP_COMP 1 /* the suspension is fully compressed */ #define SIM_SUSP_EXT 2 /* the suspension is fully extended */ - +#define SIM_SUSP_INAIR 4 /* the suspension is in the air, can be combined with the other states */ } tSuspension; diff --git a/src/modules/simu/simuv4/wheel.cpp b/src/modules/simu/simuv4/wheel.cpp index 91d98bfe3..a87d118bc 100644 --- a/src/modules/simu/simuv4/wheel.cpp +++ b/src/modules/simu/simuv4/wheel.cpp @@ -160,19 +160,29 @@ void SimWheelUpdateRide(tCar *car, int index) tdble max_extend = wheel->pos.z - Zroad; wheel->rideHeight = max_extend; + if (car->features & FEAT_FIXEDWHEELFORCE) { + if (max_extend > new_susp_x + 0.01) { + wheel->susp.state = SIM_SUSP_INAIR; + } else {wheel->susp.state = 0;} + } else { + wheel->susp.state = 0; + } + if (max_extend < new_susp_x) { new_susp_x = max_extend; wheel->rel_vel = 0.0f; } else if (new_susp_x < wheel->susp.spring.packers) { wheel->rel_vel = 0.0f; } - - tdble prex = wheel->susp.x; - wheel->susp.x = new_susp_x; + tdble prex = wheel->susp.x; + tdble prev = wheel->susp.v; + wheel->susp.x = new_susp_x; + // verify the suspension travel, beware, wheel->susp.x will be scaled by SimSuspCheckIn SimSuspCheckIn(&(wheel->susp)); wheel->susp.v = (prex - wheel->susp.x) / SimDeltaTime; + wheel->susp.a = (prev - wheel->susp.v) / SimDeltaTime; // update wheel brake SimBrakeUpdate(car, wheel, &(wheel->brake)); @@ -210,13 +220,10 @@ void SimWheelUpdateForce(tCar *car, int index) // VERTICAL STUFF CONSIDERING SMALL PITCH AND ROLL ANGLES // update suspension force SimSuspUpdate(&(wheel->susp)); - // check suspension state wheel->state |= wheel->susp.state; - if ((wheel->state & SIM_SUSP_EXT) == 0) { - wheel->forces.z = axleFz + wheel->susp.force; - if(wheel->susp.force > 0) - {wheel->forces.z += wheel->axleFz3rd;} + if ( ((wheel->state & SIM_SUSP_EXT) == 0) && ((wheel->state & SIM_SUSP_INAIR) == 0) ) { + wheel->forces.z = axleFz + wheel->susp.force + wheel->axleFz3rd; reaction_force = wheel->forces.z; if (car->features & FEAT_FIXEDWHEELFORCE) { wheel->rel_vel -= SimDeltaTime * wheel->forces.z / wheel->mass;