TORCS  1.3.9
The Open Racing Car Simulator
steer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  file : steer.cpp
4  created : Sun Mar 19 00:08:20 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 void SimSteerConfig(tCar *car)
22 {
23  void *hdle = car->params;
24 
25  car->steer.steerLock = GfParmGetNum(hdle, SECT_STEER, PRM_STEERLOCK, (char*)NULL, 0.43f);
26  car->steer.maxSpeed = GfParmGetNum(hdle, SECT_STEER, PRM_STEERSPD, (char*)NULL, 1.0f);
27  car->carElt->_steerLock = car->steer.steerLock;
28 }
29 
30 
32 {
33  tCarPitSetupValue* steerLock = &car->carElt->pitcmd.setup.steerLock;
34  if (SimAdjustPitCarSetupParam(steerLock)) {
35  car->steer.steerLock = steerLock->value;
36  car->carElt->_steerLock = steerLock->value;
37  }
38 }
39 
40 void
42 {
43  tdble steer, steer2;
44  tdble stdelta;
45  tdble tanSteer;
46 
47  /* input control */
48  steer = car->ctrl->steer;
49  steer *= car->steer.steerLock;
50  stdelta = steer - car->steer.steer;
51 
52  if (((tdble) fabs(stdelta) / SimDeltaTime) > car->steer.maxSpeed) {
53  steer = SIGN(stdelta) * car->steer.maxSpeed * SimDeltaTime + car->steer.steer;
54  }
55 
56  car->steer.steer = steer;
57  tanSteer = (tdble) fabs(tan(steer));
58  steer2 = (tdble) atan2((car->wheelbase * tanSteer) , (car->wheelbase - tanSteer * car->wheeltrack));
59 
60  if (steer > 0) {
61  car->wheel[FRNT_RGT].steer = steer2;
62  car->wheel[FRNT_LFT].steer = steer;
63  } else {
64  car->wheel[FRNT_RGT].steer = steer;
65  car->wheel[FRNT_LFT].steer = -steer2;
66  }
67 }
tdble wheeltrack
Definition: carstruct.h:79
#define FRNT_LFT
front left
Definition: car.h:39
#define FRNT_RGT
front right
Definition: car.h:38
void * params
Definition: carstruct.h:39
tdble wheelbase
Definition: carstruct.h:78
tdble steer
Definition: wheel.h:54
bool SimAdjustPitCarSetupParam(tCarPitSetupValue *v)
Definition: simu.cpp:491
tCarPitCmd pitcmd
private
Definition: car.h:463
#define SIGN(x)
Sign of the expression.
Definition: tgf.h:78
Definition: carstruct.h:35
tCarCtrl * ctrl
Definition: carstruct.h:38
tdble SimDeltaTime
Definition: simu.cpp:35
void SimSteerReConfig(tCar *car)
Definition: steer.cpp:31
void SimSteerUpdate(tCar *car)
Definition: steer.cpp:41
tCarPitSetupValue steerLock
Definition: car.h:385
tSteer steer
Definition: carstruct.h:47
tdble steer
Steer command [-1.0, 1.0].
Definition: car.h:345
float tdble
Floating point type used in TORCS.
Definition: tgf.h:48
void SimSteerConfig(tCar *car)
Definition: steer.cpp:21
#define PRM_STEERSPD
Definition: car.h:569
tdble value
Definition: car.h:375
tCarElt * carElt
Definition: carstruct.h:40
tCarPitSetup setup
Definition: car.h:441
#define PRM_STEERLOCK
Definition: car.h:568
#define SECT_STEER
Definition: car.h:497
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
tdble steer
Definition: steer.h:27
tWheel wheel[4]
Definition: carstruct.h:46
tdble steerLock
Definition: steer.h:25
tdble maxSpeed
Definition: steer.h:26