TORCS  1.3.9
The Open Racing Car Simulator
brake.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  file : brake.cpp
4  created : Sun Mar 19 00:05:26 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 SimBrakeConfig(void *hdle, const char *section, tBrake *brake)
22 {
23  tdble diam, area, mu;
24 
25  diam = GfParmGetNum(hdle, section, PRM_BRKDIAM, (char*)NULL, 0.2f);
26  area = GfParmGetNum(hdle, section, PRM_BRKAREA, (char*)NULL, 0.002f);
27  mu = GfParmGetNum(hdle, section, PRM_MU, (char*)NULL, 0.30f);
28  brake->coeff = diam * 0.5f * area * mu;
29 
30  brake->I = GfParmGetNum(hdle, section, PRM_INERTIA, (char*)NULL, 0.13f);
31  brake->radius = diam/2.0f;
32 }
33 
34 
35 void SimBrakeUpdate(tCar *car, tWheel *wheel, tBrake *brake)
36 {
37  brake->Tq = brake->coeff * brake->pressure;
38 
39  const tdble cooling = ((tdble) fabs(car->DynGC.vel.x) * 0.02f + 0.1f) * SimDeltaTime;
40  brake->temp -= cooling;
41  if (brake->temp < 0 ) brake->temp = 0;
42  const tdble heating = (brake->pressure * brake->radius * (tdble) fabs(wheel->spinVel) * 2.5e-8f) * SimDeltaTime;
43  brake->temp += heating;
44  if (brake->temp > 1.0) brake->temp = 1.0;
45 }
46 
47 
49 {
50  void *hdle = car->params;
51 
52  car->brkSyst.rep = GfParmGetNum(hdle, SECT_BRKSYST, PRM_BRKREP, (char*)NULL, 0.5f);
53  car->brkSyst.coeff = GfParmGetNum(hdle, SECT_BRKSYST, PRM_BRKPRESS, (char*)NULL, 1000000);
54  car->brkSyst.repCmdClickValue = GfParmGetNum(hdle, SECT_BRKSYST, PRM_BRKREPCMD_CLICKVALUE, (char*)NULL, 0.0025f);
55  car->brkSyst.repCmdMaxClicks = (int) GfParmGetNum(hdle, SECT_BRKSYST, PRM_BRKREPCMD_MAXCLICKS, (char*)NULL, 20);
56 }
57 
58 
60 {
63  car->brkSyst.rep = v->value;
64  }
65 
66  v = &car->carElt->pitcmd.setup.brakePressure;
68  car->brkSyst.coeff = v->value;
69  }
70 }
71 
72 
74 {
75  tBrakeSyst *brkSyst = &(car->brkSyst);
76  tdble ctrl = car->ctrl->brakeCmd;
77  int brakeRepartitionCmd = car->ctrl->brakeRepartitionCmd;
78 
79  // Check boundaries of allowed adjustment, adjust if out of bounds
80  if (brakeRepartitionCmd > brkSyst->repCmdMaxClicks) {
81  brakeRepartitionCmd = brkSyst->repCmdMaxClicks;
82  } else if (brakeRepartitionCmd < -brkSyst->repCmdMaxClicks) {
83  brakeRepartitionCmd = -brkSyst->repCmdMaxClicks;
84  }
85 
86  // Calculate effective brake repartition considering the driver input, checking boundaries of final repartition
87  tdble repartition = brkSyst->rep + brakeRepartitionCmd*car->brkSyst.repCmdClickValue;
88  if (repartition > 1.0) {
89  repartition = 1.0;
90  } else if (repartition < 0.0) {
91  repartition = 0.0;
92  }
93 
94  ctrl *= brkSyst->coeff;
95  car->wheel[FRNT_RGT].brake.pressure = car->wheel[FRNT_LFT].brake.pressure = ctrl * repartition;
96  car->wheel[REAR_RGT].brake.pressure = car->wheel[REAR_LFT].brake.pressure = ctrl * (1 - repartition);
97 }
#define REAR_LFT
rear left
Definition: car.h:41
void SimBrakeSystemConfig(tCar *car)
Definition: brake.cpp:48
#define FRNT_LFT
front left
Definition: car.h:39
#define FRNT_RGT
front right
Definition: car.h:38
int brakeRepartitionCmd
Brake balance "clicks", positive is to the front.
Definition: car.h:359
void * params
Definition: carstruct.h:39
tDynPt DynGC
Definition: carstruct.h:64
#define PRM_BRKPRESS
Definition: car.h:574
tdble brakeCmd
Brake command [0.0, 1.0].
Definition: car.h:347
#define PRM_BRKDIAM
Definition: car.h:571
tdble pressure
Definition: brake.h:24
#define SECT_BRKSYST
Definition: car.h:498
bool SimAdjustPitCarSetupParam(tCarPitSetupValue *v)
Definition: simu.cpp:491
tCarPitCmd pitcmd
private
Definition: car.h:463
Definition: carstruct.h:35
tCarCtrl * ctrl
Definition: carstruct.h:38
void SimBrakeSystemUpdate(tCar *car)
Definition: brake.cpp:73
void SimBrakeUpdate(tCar *car, tWheel *wheel, tBrake *brake)
Definition: brake.cpp:35
tdble SimDeltaTime
Definition: simu.cpp:35
Section header structure.
Definition: params.cpp:83
tCarPitSetupValue brakePressure
Definition: car.h:394
#define REAR_RGT
rear right
Definition: car.h:40
tBrake brake
Definition: wheel.h:30
Definition: brake.h:22
tCarPitSetupValue brakeRepartition
Definition: car.h:395
tdble coeff
Definition: brake.h:35
Definition: wheel.h:25
#define PRM_BRKREP
Definition: car.h:573
#define PRM_MU
Definition: car.h:531
float tdble
Floating point type used in TORCS.
Definition: tgf.h:48
tdble value
Definition: car.h:375
#define PRM_BRKREPCMD_CLICKVALUE
Definition: car.h:576
tdble x
x coordinate
Definition: tgf.h:131
tCarElt * carElt
Definition: carstruct.h:40
tCarPitSetup setup
Definition: car.h:441
void SimBrakeSystemReConfig(tCar *car)
Definition: brake.cpp:59
tdble coeff
Definition: brake.h:26
tdble Tq
Definition: brake.h:25
tdble spinVel
Definition: wheel.h:43
tBrakeSyst brkSyst
Definition: carstruct.h:48
tdble I
Definition: brake.h:27
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
int repCmdMaxClicks
Definition: brake.h:39
tdble radius
Definition: brake.h:28
tPosd vel
velocity
Definition: tgf.h:145
tdble rep
Definition: brake.h:34
tWheel wheel[4]
Definition: carstruct.h:46
tdble repCmdClickValue
Definition: brake.h:40
#define PRM_BRKREPCMD_MAXCLICKS
Definition: car.h:575
#define PRM_INERTIA
Definition: car.h:525
#define PRM_BRKAREA
Definition: car.h:572
tdble temp
Definition: brake.h:29
void SimBrakeConfig(void *hdle, const char *section, tBrake *brake)
Definition: brake.cpp:21