TORCS  1.3.10
The Open Racing Car Simulator
Loading...
Searching...
No Matches
axle.cpp
Go to the documentation of this file.
1/***************************************************************************
2
3 file : axle.cpp
4 created : Sun Mar 19 00:05:09 CET 2000
5 copyright : (C) 2000-2026 by Eric Espie, Bernhard Wymann
6 email : berniw@bluewin.ch
7
8 ***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
19#include "sim.h"
20
21static const char *AxleSect[2] = {SECT_FRNTAXLE, SECT_REARAXLE};
22
23void SimAxleConfig(tCar *car, int index)
24{
25 void *hdle = car->params;
26 tdble rollCenter;
27
28 tAxle *axle = &(car->axle[index]);
29
30 axle->xpos = GfParmGetNum(hdle, AxleSect[index], PRM_XPOS, (char*)NULL, 0.0f);
31 axle->I = GfParmGetNum(hdle, AxleSect[index], PRM_INERTIA, (char*)NULL, 0.15f);
32 rollCenter = GfParmGetNum(hdle, AxleSect[index], PRM_ROLLCENTER, (char*)NULL, 0.15f);
33 car->wheel[index*2].rollCenter = car->wheel[index*2+1].rollCenter = rollCenter;
34
35 tdble x0 = GfParmGetNum(hdle, AxleSect[index], PRM_SUSPCOURSE, (char*)NULL, 0.0f);
36 SimSuspConfig(hdle, AxleSect[index], &(axle->thirdSusp), 0.0f, x0);
37
38 if (index == 0) {
39 axle->arbSuspSpringK = GfParmGetNum(hdle, SECT_FRNTARB, PRM_SPR, (char*)NULL, 0.0f);
40 } else {
41 axle->arbSuspSpringK = GfParmGetNum(hdle, SECT_REARARB, PRM_SPR, (char*)NULL, 0.0f);
42 }
43
44 car->wheel[index*2].feedBack.I += axle->I / 2.0f;
45 car->wheel[index*2+1].feedBack.I += axle->I / 2.0f;
46}
47
48
49void SimAxleReConfig(tCar *car, int index)
50{
51 tAxle *axle = &(car->axle[index]);
52
53 // Anti rollbar spring
56 axle->arbSuspSpringK = v->value;
57 }
58
59 // Third element
60 v = &car->carElt->pitcmd.setup.thirdX0[index];
62 SimSuspThirdReConfig(car, index, &(axle->thirdSusp), 0.0f, v->value);
63}
64
65
66void SimAxleUpdate(tCar *car, int index)
67{
68 tAxle *axle = &(car->axle[index]);
69 tdble str, stl, vr, vl;
70
71 str = car->wheel[index*2].susp.x;
72 stl = car->wheel[index*2+1].susp.x;
73 vr = car->wheel[index*2].susp.v;
74 vl = car->wheel[index*2+1].susp.v;
75
76 // Anti roll bar
77 tdble farb = axle->arbSuspSpringK * (stl - str);
78
79 // Third element
80 axle->thirdSusp.x = (stl + str)/2.0f;
81 axle->thirdSusp.v = (vl + vr)/2.0f;
83 tdble fthird = 0.0f;
84 if (axle->thirdSusp.x < axle->thirdSusp.spring.xMax && axle->thirdSusp.force > 0.0f) {
85 fthird = axle->thirdSusp.force/2.0f;
86 }
87
88 // right
89 car->wheel[index*2].axleFz = farb + fthird;
90 // left
91 car->wheel[index*2+1].axleFz = -farb + fthird;
92}
93
94
95
static const char * AxleSect[2]
Definition axle.cpp:21
void SimAxleUpdate(tCar *car, int index)
Definition axle.cpp:66
void SimAxleReConfig(tCar *car, int index)
Definition axle.cpp:49
void SimAxleConfig(tCar *car, int index)
Definition axle.cpp:23
#define SECT_REARAXLE
Definition car.h:491
#define PRM_SPR
Definition car.h:557
#define SECT_FRNTAXLE
Definition car.h:480
#define PRM_ROLLCENTER
Definition car.h:610
#define SECT_FRNTARB
Definition car.h:481
#define PRM_INERTIA
Definition car.h:529
#define PRM_XPOS
Definition car.h:568
#define SECT_REARARB
Definition car.h:492
#define PRM_SUSPCOURSE
Definition car.h:558
float tdble
Floating point type used in TORCS.
Definition tgf.h:47
tdble GfParmGetNum(void *handle, const char *path, const char *key, const char *unit, tdble deflt)
Get a numerical parameter from the parameter set handle.
Definition params.cpp:2534
void SimSuspConfig(void *hdle, const char *section, tSuspension *susp, tdble F0, tdble X0)
Definition susp.cpp:140
void SimSuspThirdReConfig(tCar *car, int index, tSuspension *susp, tdble F0, tdble X0)
Definition susp.cpp:218
void SimSuspUpdate(tSuspension *susp)
Definition susp.cpp:122
bool SimAdjustPitCarSetupParam(tCarPitSetupValue *v)
Definition simu.cpp:500
tCarPitCmd pitcmd
private
Definition car.h:465
tdble x
Definition susp.h:52
tdble v
Definition susp.h:53
tdble force
Definition susp.h:55
tSpring spring
Definition susp.h:49
Definition axle.h:28
tSuspension thirdSusp
Definition axle.h:32
tdble xpos
Definition axle.h:29
tdble arbSuspSpringK
Definition axle.h:31
tdble I
Definition axle.h:38
tAxle axle[2]
Definition carstruct.h:45
tWheel wheel[4]
Definition carstruct.h:46
void * params
Definition carstruct.h:39
tCarElt * carElt
Definition carstruct.h:40
tCarPitSetup setup
Definition car.h:443
tCarPitSetupValue thirdX0[2]
Definition car.h:416
tCarPitSetupValue arbspring[2]
Definition car.h:410
tdble value
Definition car.h:377
tdble xMax
Definition susp.h:41
tSuspension susp
Definition wheel.h:29
tDynAxis feedBack
Definition wheel.h:83
tdble axleFz
Definition wheel.h:50
tdble rollCenter
Definition wheel.h:61