TORCS  1.3.9
The Open Racing Car Simulator
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 
21 static const char *AxleSect[2] = {SECT_FRNTAXLE, SECT_REARAXLE};
22 
23 void 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 
49 void SimAxleReConfig(tCar *car, int index)
50 {
51  tAxle *axle = &(car->axle[index]);
52 
53  // Anti rollbar spring
54  tCarPitSetupValue* v = &car->carElt->pitcmd.setup.arbspring[index];
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 
66 void 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;
82  SimSuspUpdate(&axle->thirdSusp);
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 
void * params
Definition: carstruct.h:39
tdble arbSuspSpringK
Definition: axle.h:31
tdble xMax
Definition: susp.h:41
tdble xpos
Definition: axle.h:29
#define SECT_FRNTAXLE
Definition: car.h:476
#define PRM_SUSPCOURSE
Definition: car.h:554
Definition: axle.h:27
tCarPitSetupValue thirdX0[2]
Definition: car.h:414
tdble force
Definition: susp.h:55
bool SimAdjustPitCarSetupParam(tCarPitSetupValue *v)
Definition: simu.cpp:491
tAxle axle[2]
Definition: carstruct.h:45
tCarPitCmd pitcmd
private
Definition: car.h:463
Definition: carstruct.h:35
void SimSuspConfig(void *hdle, const char *section, tSuspension *susp, tdble F0, tdble X0)
Definition: susp.cpp:140
tdble x
Definition: susp.h:52
void SimSuspUpdate(tSuspension *susp)
Definition: susp.cpp:122
void SimAxleReConfig(tCar *car, int index)
Definition: axle.cpp:49
tdble rollCenter
Definition: wheel.h:59
tSuspension susp
Definition: wheel.h:29
#define SECT_REARAXLE
Definition: car.h:487
tCarPitSetupValue arbspring[2]
Definition: car.h:408
tSpring spring
Definition: susp.h:49
float tdble
Floating point type used in TORCS.
Definition: tgf.h:48
void SimSuspThirdReConfig(tCar *car, int index, tSuspension *susp, tdble F0, tdble X0)
Definition: susp.cpp:218
#define SECT_REARARB
Definition: car.h:488
tdble value
Definition: car.h:375
tCarElt * carElt
Definition: carstruct.h:40
void SimAxleUpdate(tCar *car, int index)
Definition: axle.cpp:66
tCarPitSetup setup
Definition: car.h:441
tdble axleFz
Definition: wheel.h:48
tdble I
Definition: axle.h:38
tdble v
Definition: susp.h:53
#define PRM_XPOS
Definition: car.h:564
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:2392
#define PRM_SPR
Definition: car.h:553
tWheel wheel[4]
Definition: carstruct.h:46
#define SECT_FRNTARB
Definition: car.h:477
#define PRM_ROLLCENTER
Definition: car.h:606
tDynAxis feedBack
Definition: wheel.h:81
#define PRM_INERTIA
Definition: car.h:525
tSuspension thirdSusp
Definition: axle.h:32
void SimAxleConfig(tCar *car, int index)
Definition: axle.cpp:23
tdble I
Definition: differential.h:28
static const char * AxleSect[2]
Definition: axle.cpp:21