Fixes #841, that is cars flipping or flying with the "fixed wheel force" patch. Also added initial code for inerter in the suspension.
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6041 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: c6ba6ae0b85fda5b5fafd0373d8ef8bec15b2c4f Former-commit-id: f76b616080744c62680f64b4ebfb724c7c7afef9
This commit is contained in:
parent
17d5058ddb
commit
bd1d82458f
3 changed files with 24 additions and 13 deletions
|
@ -96,15 +96,16 @@ static tdble springForce(tSuspension *susp)
|
||||||
|
|
||||||
void SimSuspCheckIn(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) {
|
if (susp->x < susp->spring.packers) {
|
||||||
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;
|
susp->x *= susp->spring.bellcrank;
|
||||||
if (susp->x >= susp->spring.xMax) {
|
if (susp->x >= susp->spring.xMax) {
|
||||||
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)
|
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.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.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->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.x0 = susp->spring.bellcrank * X0;
|
||||||
susp->spring.F0 = F0 / susp->spring.bellcrank;
|
susp->spring.F0 = F0 / susp->spring.bellcrank;
|
||||||
|
|
|
@ -48,15 +48,17 @@ typedef struct Suspension
|
||||||
{
|
{
|
||||||
tSpring spring;
|
tSpring spring;
|
||||||
tDamper damper;
|
tDamper damper;
|
||||||
|
tdble inertance;
|
||||||
|
|
||||||
tdble x; /* suspension travel */
|
tdble x; /* suspension travel */
|
||||||
tdble v; /* suspension travel speed */
|
tdble v; /* suspension travel speed */
|
||||||
|
tdble a; /* suspension travel acceleration */
|
||||||
|
|
||||||
tdble force; /* generated force */
|
tdble force; /* generated force */
|
||||||
int state; /* indicate the state of the suspension */
|
int state; /* indicate the state of the suspension */
|
||||||
#define SIM_SUSP_COMP 1 /* the suspension is fully compressed */
|
#define SIM_SUSP_COMP 1 /* the suspension is fully compressed */
|
||||||
#define SIM_SUSP_EXT 2 /* the suspension is fully extended */
|
#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;
|
} tSuspension;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -160,19 +160,29 @@ void SimWheelUpdateRide(tCar *car, int index)
|
||||||
tdble max_extend = wheel->pos.z - Zroad;
|
tdble max_extend = wheel->pos.z - Zroad;
|
||||||
wheel->rideHeight = max_extend;
|
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) {
|
if (max_extend < new_susp_x) {
|
||||||
new_susp_x = max_extend;
|
new_susp_x = max_extend;
|
||||||
wheel->rel_vel = 0.0f;
|
wheel->rel_vel = 0.0f;
|
||||||
} else if (new_susp_x < wheel->susp.spring.packers) {
|
} else if (new_susp_x < wheel->susp.spring.packers) {
|
||||||
wheel->rel_vel = 0.0f;
|
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
|
// verify the suspension travel, beware, wheel->susp.x will be scaled by SimSuspCheckIn
|
||||||
SimSuspCheckIn(&(wheel->susp));
|
SimSuspCheckIn(&(wheel->susp));
|
||||||
wheel->susp.v = (prex - wheel->susp.x) / SimDeltaTime;
|
wheel->susp.v = (prex - wheel->susp.x) / SimDeltaTime;
|
||||||
|
wheel->susp.a = (prev - wheel->susp.v) / SimDeltaTime;
|
||||||
|
|
||||||
// update wheel brake
|
// update wheel brake
|
||||||
SimBrakeUpdate(car, wheel, &(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
|
// VERTICAL STUFF CONSIDERING SMALL PITCH AND ROLL ANGLES
|
||||||
// update suspension force
|
// update suspension force
|
||||||
SimSuspUpdate(&(wheel->susp));
|
SimSuspUpdate(&(wheel->susp));
|
||||||
|
|
||||||
// check suspension state
|
// check suspension state
|
||||||
wheel->state |= wheel->susp.state;
|
wheel->state |= wheel->susp.state;
|
||||||
if ((wheel->state & SIM_SUSP_EXT) == 0) {
|
if ( ((wheel->state & SIM_SUSP_EXT) == 0) && ((wheel->state & SIM_SUSP_INAIR) == 0) ) {
|
||||||
wheel->forces.z = axleFz + wheel->susp.force;
|
wheel->forces.z = axleFz + wheel->susp.force + wheel->axleFz3rd;
|
||||||
if(wheel->susp.force > 0)
|
|
||||||
{wheel->forces.z += wheel->axleFz3rd;}
|
|
||||||
reaction_force = wheel->forces.z;
|
reaction_force = wheel->forces.z;
|
||||||
if (car->features & FEAT_FIXEDWHEELFORCE) {
|
if (car->features & FEAT_FIXEDWHEELFORCE) {
|
||||||
wheel->rel_vel -= SimDeltaTime * wheel->forces.z / wheel->mass;
|
wheel->rel_vel -= SimDeltaTime * wheel->forces.z / wheel->mass;
|
||||||
|
|
Loading…
Reference in a new issue