Re #924: Add SimDifferentialReConfig, SimTransmissionReConfig, SimEngineReConfig, SimSteerReConfig

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6227 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: dfcbc0b6ab7be5d58bf36a6b7e630b5b16bceeb1
Former-commit-id: 983d584576f4ebfd17687eacc808f6386fbac0cf
This commit is contained in:
kakukri 2015-11-16 01:16:59 +00:00
parent e36be8197a
commit 32012d676c
7 changed files with 240 additions and 32 deletions

View file

@ -266,6 +266,15 @@ for(i=0;i<2;i++) {
}
printf("BrakeBal=%g p=%g\n",car->brkSyst.rep,car->brkSyst.coeff);
printf("FWing=%g° Rwing=%g°\n",RAD2DEG(car->wing[0].angle),RAD2DEG(car->wing[1].angle));
for(i=0;i<3;i++) {
printf("DIFF%d typ=%d r=%g\n",i,car->transmission.differential[i].type,car->transmission.differential[i].ratio);
printf(" Tmin=%g Tmax=%g Visc=%g\n",car->transmission.differential[i].dTqMin,car->transmission.differential[i].dTqMax,car->transmission.differential[i].viscosity);
printf(" LockT=%g MaxS=%g CMaxS=%g\n",car->transmission.differential[i].lockInputTq,car->transmission.differential[i].dSlipMax,car->transmission.differential[i].dCoastSlipMax);
}
printf("STEER lock=%g\n",RAD2DEG(car->steer.steerLock));
printf("GEARS: ");
for(i=0; i<MAX_GEARS;i++){printf("%g ",car->transmission.overallRatio[i]);}
printf("\n");
*/
}
@ -347,6 +356,9 @@ SimCarReConfig(tCar *car)
for (i = 0; i < 4; i++) {
SimWheelReConfig(car, i);
}
SimEngineReConfig(car);
SimTransmissionReConfig(car);
SimSteerReConfig(car);
SimBrakeSystemReConfig(car);
for (i = 0; i < 2; i++) {
SimWingReConfig(car, i);

View file

@ -20,21 +20,75 @@
#include "sim.h"
void
SimDifferentialConfig(void *hdle, const char *section, tDifferential *differential)
//SimDifferentialConfig(void *hdle, const char *section, tDifferential *differential)
SimDifferentialConfig(tCar *car, int index)
{
void *hdle = car->params;
const char *type;
const char *section;
switch (index) {
case TRANS_FRONT_DIFF:
section = SECT_FRNTDIFFERENTIAL;
break;
case TRANS_REAR_DIFF:
section = SECT_REARDIFFERENTIAL;
break;
case TRANS_CENTRAL_DIFF:
section = SECT_CENTRALDIFFERENTIAL;
break;
default:
GfLogWarning("No differential indexed %d exists, returning without configuration.", index);
return;
}
tDifferential *differential = &(car->transmission.differential[index]);
tCarSetupItem *setupDRatio = &(car->carElt->setup.differentialRatio[index]);
tCarSetupItem *setupDMinTB = &(car->carElt->setup.differentialMinTqBias[index]);
tCarSetupItem *setupDMaxTB = &(car->carElt->setup.differentialMaxTqBias[index]);
tCarSetupItem *setupDVisc = &(car->carElt->setup.differentialViscosity[index]);
tCarSetupItem *setupDLT = &(car->carElt->setup.differentialLockingTq[index]);
tCarSetupItem *setupDMaxSB = &(car->carElt->setup.differentialMaxSlipBias[index]);
tCarSetupItem *setupDCMaxSB = &(car->carElt->setup.differentialCoastMaxSlipBias[index]);
differential->I = GfParmGetNum(hdle, section, PRM_INERTIA, (char*)NULL, 0.1f);
differential->efficiency = GfParmGetNum(hdle, section, PRM_EFFICIENCY, (char*)NULL, 1.0f);
differential->ratio = GfParmGetNum(hdle, section, PRM_RATIO, (char*)NULL, 1.0f);
//differential->bias is unused as of 2015.11.15.
differential->bias = GfParmGetNum(hdle, section, PRM_BIAS, (char*)NULL, 0.1f);
differential->dTqMin = GfParmGetNum(hdle, section, PRM_MIN_TQ_BIAS, (char*)NULL, 0.05f);
differential->dTqMax = GfParmGetNum(hdle, section, PRM_MAX_TQ_BIAS, (char*)NULL, 0.80f) - differential->dTqMin;
differential->dSlipMax = GfParmGetNum(hdle, section, PRM_MAX_SLIP_BIAS, (char*)NULL, 0.75f);
differential->lockInputTq = GfParmGetNum(hdle, section, PRM_LOCKING_TQ, (char*)NULL, 300.0f);
differential->viscosity = GfParmGetNum(hdle, section, PRM_VISCOSITY_FACTOR, (char*)NULL, 2.0f);
differential->viscomax = 1 - exp(-differential->viscosity);
setupDRatio->desired_value = setupDRatio->min = setupDRatio->max = 1.0f;
GfParmGetNumWithLimits(hdle, section, PRM_RATIO, (char*)NULL, &(setupDRatio->desired_value), &(setupDRatio->min), &(setupDRatio->max));
setupDRatio->changed = TRUE;
setupDRatio->stepsize = 0.1;
setupDMinTB->desired_value = setupDMinTB->min = setupDMinTB->max = 0.05f;
GfParmGetNumWithLimits(hdle, section, PRM_MIN_TQ_BIAS, (char*)NULL, &(setupDMinTB->desired_value), &(setupDMinTB->min), &(setupDMinTB->max));
setupDMinTB->changed = TRUE;
setupDMinTB->stepsize = 0.01;
setupDMaxTB->desired_value = setupDMaxTB->min = setupDMaxTB->max = 0.80f;
GfParmGetNumWithLimits(hdle, section, PRM_MAX_TQ_BIAS, (char*)NULL, &(setupDMaxTB->desired_value), &(setupDMaxTB->min), &(setupDMaxTB->max));
setupDMaxTB->changed = TRUE;
setupDMaxTB->stepsize = 0.01;
setupDVisc->desired_value = setupDVisc->min = setupDVisc->max = 2.0f;
GfParmGetNumWithLimits(hdle, section, PRM_VISCOSITY_FACTOR, (char*)NULL, &(setupDVisc->desired_value), &(setupDVisc->min), &(setupDVisc->max));
setupDVisc->changed = TRUE;
setupDVisc->stepsize = 0.1;
setupDLT->desired_value = setupDLT->min = setupDLT->max = 300.0f;
GfParmGetNumWithLimits(hdle, section, PRM_LOCKING_TQ, (char*)NULL, &(setupDLT->desired_value), &(setupDLT->min), &(setupDLT->max));
setupDLT->changed = TRUE;
setupDLT->stepsize = 10.0f;
setupDMaxSB->desired_value = setupDMaxSB->min = setupDMaxSB->max = 0.75f;
GfParmGetNumWithLimits(hdle, section, PRM_MAX_SLIP_BIAS, (char*)NULL, &(setupDMaxSB->desired_value), &(setupDMaxSB->min), &(setupDMaxSB->max));
setupDMaxSB->changed = TRUE;
setupDMaxSB->stepsize = 0.01f;
setupDCMaxSB->desired_value = setupDCMaxSB->min = setupDCMaxSB->max = setupDMaxSB->desired_value;
GfParmGetNumWithLimits(hdle, section, PRM_COAST_MAX_SLIP_BIAS, (char*)NULL, &(setupDCMaxSB->desired_value), &(setupDCMaxSB->min), &(setupDCMaxSB->max));
setupDCMaxSB->changed = TRUE;
setupDCMaxSB->stepsize = 0.01f;
type = GfParmGetStr(hdle, section, PRM_TYPE, VAL_DIFF_NONE);
if (strcmp(type, VAL_DIFF_LIMITED_SLIP) == 0) {
@ -52,10 +106,8 @@ SimDifferentialConfig(void *hdle, const char *section, tDifferential *differenti
} else {
differential->type = DIFF_NONE;
}
if ( (differential->type == DIFF_15WAY_LSD) || (differential->type == DIFF_ELECTRONIC_LSD) ) {
differential->dCoastSlipMax = GfParmGetNum(hdle, section, PRM_COAST_MAX_SLIP_BIAS, (char*)NULL, differential->dSlipMax);
} else {differential->dCoastSlipMax = differential->dSlipMax;}
car->carElt->setup.differentialType[index] = differential->type;
//TODO: get allowed differential types from xml and store them
if (differential->efficiency > 1.0f) {differential->efficiency = 1.0f;}
if (differential->efficiency < 0.0f) {differential->efficiency = 0.0f;}
@ -65,6 +117,67 @@ SimDifferentialConfig(void *hdle, const char *section, tDifferential *differenti
}
void
SimDifferentialReConfig(tCar *car, int index)
{/* called by SimTransmissionReConfig() in transmission.cpp */
tDifferential *differential = &(car->transmission.differential[index]);
tCarSetupItem *setupDRatio = &(car->carElt->setup.differentialRatio[index]);
tCarSetupItem *setupDMinTB = &(car->carElt->setup.differentialMinTqBias[index]);
tCarSetupItem *setupDMaxTB = &(car->carElt->setup.differentialMaxTqBias[index]);
tCarSetupItem *setupDVisc = &(car->carElt->setup.differentialViscosity[index]);
tCarSetupItem *setupDLT = &(car->carElt->setup.differentialLockingTq[index]);
tCarSetupItem *setupDMaxSB = &(car->carElt->setup.differentialMaxSlipBias[index]);
tCarSetupItem *setupDCMaxSB = &(car->carElt->setup.differentialCoastMaxSlipBias[index]);
//TODO: check if type is available
differential->type = car->carElt->setup.differentialType[index];
if (setupDRatio->changed) {
differential->ratio = MIN(setupDRatio->max, MAX(setupDRatio->min, setupDRatio->desired_value));
setupDRatio->value = differential->ratio;
setupDRatio->changed = FALSE;
}
if (setupDMinTB->changed) {
differential->dTqMin = MIN(setupDMinTB->max, MAX(setupDMinTB->min, setupDMinTB->desired_value));
setupDMinTB->value = differential->dTqMin;
setupDMinTB->changed = FALSE;
}
if (setupDMaxTB->changed) {
differential->dTqMax = MIN(setupDMaxTB->max, MAX(setupDMaxTB->min, setupDMaxTB->desired_value));
setupDMaxTB->value = differential->dTqMax;
setupDMaxTB->changed = FALSE;
}
if (setupDVisc->changed) {
differential->viscosity = MIN(setupDVisc->max, MAX(setupDVisc->min, setupDVisc->desired_value));
setupDVisc->value = differential->viscosity;
setupDVisc->changed = FALSE;
differential->viscomax = 1 - exp(-differential->viscosity);
}
if (setupDLT->changed) {
differential->lockInputTq = MIN(setupDLT->max, MAX(setupDLT->min, setupDLT->desired_value));
setupDLT->value = differential->lockInputTq;
setupDLT->changed = FALSE;
}
if (setupDMaxSB->changed) {
differential->dSlipMax = MIN(setupDMaxSB->max, MAX(setupDMaxSB->min, setupDMaxSB->desired_value));
setupDMaxSB->value = differential->dSlipMax;
setupDMaxSB->changed = FALSE;
}
if (setupDCMaxSB->changed) {
differential->dCoastSlipMax = MIN(setupDCMaxSB->max, MAX(setupDCMaxSB->min, setupDCMaxSB->desired_value));
setupDCMaxSB->changed = FALSE;
}
if ( (differential->type != DIFF_15WAY_LSD) && (differential->type != DIFF_ELECTRONIC_LSD) ) {
differential->dCoastSlipMax = differential->dSlipMax;
}
setupDCMaxSB->value = differential->dCoastSlipMax;
}
static void

View file

@ -28,13 +28,18 @@ SimEngineConfig(tCar *car)
tdble rpmMaxTq = 0;
char idx[64];
tEngineCurveElem *data;
tCarSetupItem *setupRevLimit = &(car->carElt->setup.revsLimiter);
struct tEdesc {
tdble rpm;
tdble tq;
} *edesc;
car->engine.revsLimiter = GfParmGetNum(hdle, SECT_ENGINE, PRM_REVSLIM, (char*)NULL, 800);
setupRevLimit->desired_value = setupRevLimit->min = setupRevLimit->max = 800;
GfParmGetNumWithLimits(hdle, SECT_ENGINE, PRM_REVSLIM, (char*)NULL, &(setupRevLimit->desired_value), &(setupRevLimit->min), &(setupRevLimit->max));
setupRevLimit->changed = TRUE;
setupRevLimit->stepsize = RPM2RADS(100.0);
car->engine.revsLimiter = setupRevLimit->desired_value;
car->carElt->_enginerpmRedLine = car->engine.revsLimiter;
car->engine.revsMax = GfParmGetNum(hdle, SECT_ENGINE, PRM_REVSMAX, (char*)NULL, 1000);
car->carElt->_enginerpmMax = car->engine.revsMax;
@ -123,6 +128,24 @@ SimEngineConfig(tCar *car)
car->engine.revsLimiter = car->engine.revsMax;
GfLogWarning("Revs limiter is bigger than revs maxi.\nIt is set to %g.\n",car->engine.revsLimiter);
}
if (setupRevLimit->max > car->engine.revsMax) {
setupRevLimit->max = car->engine.revsMax;
if (setupRevLimit->min > setupRevLimit->max)
{setupRevLimit->min = setupRevLimit->max;}
}
}
void
SimEngineReConfig(tCar *car)
{/* called by SimCarReConfig in car.cpp */
tCarSetupItem *setupRevLimit = &(car->carElt->setup.revsLimiter);
if (setupRevLimit->changed) {
car->engine.revsLimiter = MIN(setupRevLimit->max, MAX(setupRevLimit->min, setupRevLimit->desired_value));
car->carElt->_enginerpmRedLine = car->engine.revsLimiter;
setupRevLimit->value = car->engine.revsLimiter;
setupRevLimit->changed = FALSE;
}
}
/* Update torque output with engine rpm and accelerator command */

View file

@ -69,6 +69,7 @@ extern void SimUpdateFreeWheels(tCar *car, int axlenb);
extern void SimSteerConfig(tCar *car);
extern void SimSteerReConfig(tCar *car);
extern void SimSteerUpdate(tCar *car);
extern void SimBrakeConfig(void *hdle, const char *section, tBrake *brake);
@ -86,13 +87,16 @@ extern void SimWingUpdate(tCar *car, int index, tSituation *s);
extern void SimCarUpdateWheelPos(tCar *car);
extern void SimTransmissionConfig(tCar *car);
extern void SimTransmissionReConfig(tCar *car);
extern void SimTransmissionUpdate(tCar *car);
extern void SimGearboxUpdate(tCar *car);
extern void SimDifferentialConfig(void *hdle, const char *section, tDifferential *differential);
extern void SimDifferentialConfig(tCar *car, int index);
extern void SimDifferentialReConfig(tCar *car, int index);
extern void SimDifferentialUpdate(tCar *car, tDifferential *differential, int first);
extern void SimEngineConfig(tCar *car);
extern void SimEngineReConfig(tCar *car);
extern void SimEngineUpdateTq(tCar *car);
extern tdble SimEngineUpdateRpm(tCar *car, tdble axleRpm);
extern void SimEngineShutdown(tCar *car);

View file

@ -23,10 +23,27 @@ void
SimSteerConfig(tCar *car)
{
void *hdle = car->params;
tCarSetupItem *setupStLock = &(car->carElt->setup.steerLock);
car->steer.steerLock = GfParmGetNum(hdle, SECT_STEER, PRM_STEERLOCK, (char*)NULL, 0.43f);
setupStLock->desired_value = setupStLock->min = setupStLock->max = 0.43f;
GfParmGetNumWithLimits(hdle, SECT_STEER, PRM_STEERLOCK, (char*)NULL, &(setupStLock->desired_value), &(setupStLock->min), &(setupStLock->max));
setupStLock->changed = TRUE;
setupStLock->stepsize = DEG2RAD(1.0);
car->steer.maxSpeed = GfParmGetNum(hdle, SECT_STEER, PRM_STEERSPD, (char*)NULL, 1.0f);
car->carElt->_steerLock = car->steer.steerLock;
}
void
SimSteerReConfig(tCar *car)
{/* called by SimCarReConfig in car.cpp */
tCarSetupItem *setupStLock = &(car->carElt->setup.steerLock);
if (setupStLock->changed) {
car->steer.steerLock = MIN(setupStLock->max, MAX(setupStLock->min, setupStLock->desired_value));
car->carElt->_steerLock = car->steer.steerLock;
setupStLock->value = car->steer.steerLock;
setupStLock->changed = FALSE;
}
}

View file

@ -32,11 +32,10 @@ SimTransmissionConfig(tCar *car)
const char *transType;
int i, j;
tdble gRatio = 0; // Avoid compiler warning: usage of possibly uninitialized variable
tdble fRatio = 0;
tdble gEff = 0;
//tdble fEff; // Never used
tdble gearI;
char path[256];
tCarSetupItem *setupGear;
//clutchI = GfParmGetNum(hdle, SECT_CLUTCH, PRM_INERTIA, (char*)NULL, 0.12f);
transType = GfParmGetStr(hdle, SECT_DRIVETRAIN, PRM_TYPE, VAL_TRANS_RWD);
@ -58,21 +57,18 @@ SimTransmissionConfig(tCar *car)
trans->differential[TRANS_CENTRAL_DIFF].outAxis[1] = &(trans->differential[TRANS_REAR_DIFF].in);
if (strcmp(VAL_TRANS_RWD, transType) == 0) {
SimDifferentialConfig(hdle, SECT_REARDIFFERENTIAL, &(trans->differential[TRANS_REAR_DIFF]));
SimDifferentialConfig(car, TRANS_REAR_DIFF);
trans->type = TRANS_RWD;
fRatio = trans->differential[TRANS_REAR_DIFF].ratio;
//fEff = trans->differential[TRANS_REAR_DIFF].efficiency;
} else if (strcmp(VAL_TRANS_FWD, transType) == 0) {
SimDifferentialConfig(hdle, SECT_FRNTDIFFERENTIAL, &(trans->differential[TRANS_FRONT_DIFF]));
SimDifferentialConfig(car, TRANS_FRONT_DIFF);
trans->type = TRANS_FWD;
fRatio = trans->differential[TRANS_FRONT_DIFF].ratio;
//fEff = trans->differential[TRANS_FRONT_DIFF].efficiency;
} else if (strcmp(VAL_TRANS_4WD, transType) == 0) {
SimDifferentialConfig(hdle, SECT_FRNTDIFFERENTIAL, &(trans->differential[TRANS_FRONT_DIFF]));
SimDifferentialConfig(hdle, SECT_REARDIFFERENTIAL, &(trans->differential[TRANS_REAR_DIFF]));
SimDifferentialConfig(hdle, SECT_CENTRALDIFFERENTIAL, &(trans->differential[TRANS_CENTRAL_DIFF]));
SimDifferentialConfig(car, TRANS_FRONT_DIFF);
SimDifferentialConfig(car, TRANS_REAR_DIFF);
SimDifferentialConfig(car, TRANS_CENTRAL_DIFF);
trans->type = TRANS_4WD;
fRatio = trans->differential[TRANS_CENTRAL_DIFF].ratio;
//fEff = trans->differential[TRANS_FRONT_DIFF].efficiency * trans->differential[TRANS_CENTRAL_DIFF].efficiency * trans->differential[TRANS_REAR_DIFF].efficiency;
}
@ -83,7 +79,12 @@ SimTransmissionConfig(tCar *car)
sprintf(path, "%s/%s/%s", SECT_GEARBOX, ARR_GEARS, i==0 ? "r" : "n");
else
sprintf(path, "%s/%s/%d", SECT_GEARBOX, ARR_GEARS, i-1);
gRatio = GfParmGetNum(hdle, path, PRM_RATIO, (char*)NULL, 0.0f);
setupGear = &(car->carElt->setup.gearRatio[i]);
setupGear->desired_value = setupGear->min = setupGear->max = 0.0f;
GfParmGetNumWithLimits(hdle, path, PRM_RATIO, (char*)NULL, &(setupGear->desired_value), &(setupGear->min), &(setupGear->max));
setupGear->changed = TRUE;
setupGear->stepsize = 0.01;
gRatio = setupGear->desired_value;
if ((trans->gearbox.gearMax == 0) && (gRatio != 0.0f)) {
trans->gearbox.gearMax = i - 1;
}
@ -93,14 +94,11 @@ SimTransmissionConfig(tCar *car)
trans->gearEff[i] = 1.0f;
continue;
}
carElt->priv.gearRatio[i] = trans->overallRatio[i] = gRatio * fRatio;
gEff = GfParmGetNum(hdle, path, PRM_EFFICIENCY, (char*)NULL, 1.0f);
if (gEff > 1.0f) gEff = 1.0f;
if (gEff < 0.0f) gEff = 0.0f;
gearI = GfParmGetNum(hdle, path, PRM_INERTIA, (char*)NULL, 0.0f);
trans->driveI[i] = (car->engine.I + gearI) * (gRatio * gRatio * fRatio * fRatio);
trans->gearI[i] = GfParmGetNum(hdle, path, PRM_INERTIA, (char*)NULL, 0.0f);
//printf ("drivetrain %d = %f %f\n", i, trans->driveI[i], gearI);
trans->freeI[i] = gearI * (gRatio * gRatio * fRatio * fRatio);
trans->gearEff[i] = gEff;
}
if (gRatio == 0) {
@ -157,6 +155,46 @@ SimTransmissionConfig(tCar *car)
}
void
SimTransmissionReConfig(tCar *car)
{/* called by SimCarReConfig() in car.cpp */
tCarElt *carElt = car->carElt;
tTransmission *trans = &(car->transmission);
int i;
tdble fRatio = 0.0;
tdble gRatio = 0.0;
tCarSetupItem *setupGear;
if (trans->type == TRANS_RWD) {
SimDifferentialReConfig(car, TRANS_REAR_DIFF);
fRatio = trans->differential[TRANS_REAR_DIFF].ratio;
} else if (trans->type == TRANS_FWD) {
SimDifferentialReConfig(car, TRANS_FRONT_DIFF);
fRatio = trans->differential[TRANS_FRONT_DIFF].ratio;
} else if (trans->type == TRANS_4WD) {
SimDifferentialReConfig(car, TRANS_FRONT_DIFF);
SimDifferentialReConfig(car, TRANS_REAR_DIFF);
SimDifferentialReConfig(car, TRANS_CENTRAL_DIFF);
fRatio = trans->differential[TRANS_CENTRAL_DIFF].ratio;
}
for (i = MAX_GEARS - 1; i >= 0; i--) {
setupGear = &(car->carElt->setup.gearRatio[i]);
if (setupGear->changed) {
gRatio = MIN(setupGear->max, MAX(setupGear->min, setupGear->desired_value));
setupGear->value = gRatio;
setupGear->changed = FALSE;
}else {gRatio = setupGear->value;}
if (gRatio == 0.0f) {
carElt->priv.gearRatio[i] = trans->overallRatio[i] = 0;
trans->freeI[i] = trans->driveI[i] = 0;
continue;
}
carElt->priv.gearRatio[i] = trans->overallRatio[i] = gRatio * fRatio;
trans->driveI[i] = (car->engine.I + trans->gearI[i]) * (gRatio * gRatio * fRatio * fRatio);
trans->freeI[i] = trans->gearI[i] * (gRatio * gRatio * fRatio * fRatio);
}
}
void
SimGearboxUpdate(tCar *car)
{

View file

@ -59,6 +59,7 @@ typedef struct
#define TRANS_FWD 1
#define TRANS_4WD 2
tdble overallRatio[MAX_GEARS]; /* including final drive ratio */
tdble gearI[MAX_GEARS]; /* raw gear inertia */
tdble driveI[MAX_GEARS]; /* Inertia (including engine) */
tdble freeI[MAX_GEARS]; /* Inertia when clutch is applied (wheels side) */
tdble gearEff[MAX_GEARS]; /* Gear Efficiency */