TORCS  1.3.10
The Open Racing Car Simulator
Loading...
Searching...
No Matches
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
21void 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
35void 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);
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
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}
void SimBrakeConfig(void *hdle, const char *section, tBrake *brake)
Definition brake.cpp:21
void SimBrakeSystemConfig(tCar *car)
Definition brake.cpp:48
void SimBrakeUpdate(tCar *car, tWheel *wheel, tBrake *brake)
Definition brake.cpp:35
void SimBrakeSystemUpdate(tCar *car)
Definition brake.cpp:73
void SimBrakeSystemReConfig(tCar *car)
Definition brake.cpp:59
#define PRM_BRKAREA
Definition car.h:576
#define PRM_BRKREPCMD_MAXCLICKS
Definition car.h:579
#define FRNT_RGT
front right
Definition car.h:38
#define PRM_MU
Definition car.h:535
#define PRM_BRKREPCMD_CLICKVALUE
Definition car.h:580
#define PRM_BRKREP
Definition car.h:577
#define REAR_RGT
rear right
Definition car.h:40
#define PRM_BRKDIAM
Definition car.h:575
#define REAR_LFT
rear left
Definition car.h:41
#define SECT_BRKSYST
Definition car.h:502
#define FRNT_LFT
front left
Definition car.h:39
#define PRM_INERTIA
Definition car.h:529
#define PRM_BRKPRESS
Definition car.h:578
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
tdble SimDeltaTime
Definition simu.cpp:35
bool SimAdjustPitCarSetupParam(tCarPitSetupValue *v)
Definition simu.cpp:500
tCarPitCmd pitcmd
private
Definition car.h:465
Section header structure.
Definition params.cpp:83
Definition brake.h:23
tdble Tq
Definition brake.h:25
tdble pressure
Definition brake.h:24
tdble radius
Definition brake.h:28
tdble coeff
Definition brake.h:26
tdble I
Definition brake.h:27
tdble temp
Definition brake.h:29
int repCmdMaxClicks
Definition brake.h:39
tdble coeff
Definition brake.h:35
tdble repCmdClickValue
Definition brake.h:40
tdble rep
Definition brake.h:34
int brakeRepartitionCmd
Brake balance "clicks", positive is to the front.
Definition car.h:361
tdble brakeCmd
Brake command [0.0, 1.0].
Definition car.h:349
tWheel wheel[4]
Definition carstruct.h:46
tBrakeSyst brkSyst
Definition carstruct.h:48
void * params
Definition carstruct.h:39
tCarElt * carElt
Definition carstruct.h:40
tDynPt DynGC
Definition carstruct.h:64
tCarCtrl * ctrl
Definition carstruct.h:38
tCarPitSetup setup
Definition car.h:443
tCarPitSetupValue brakePressure
Definition car.h:396
tCarPitSetupValue brakeRepartition
Definition car.h:397
tdble value
Definition car.h:377
tPosd vel
velocity
Definition tgf.h:144
tdble x
x coordinate
Definition tgf.h:130
Definition wheel.h:26
tBrake brake
Definition wheel.h:30
tdble spinVel
Definition wheel.h:45