/
carclutch.h
148 lines (126 loc) · 4.38 KB
/
carclutch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/************************************************************************/
/* */
/* This file is part of VDrift. */
/* */
/* VDrift is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation, either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* VDrift is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with VDrift. If not, see <http://www.gnu.org/licenses/>. */
/* */
/************************************************************************/
#ifndef _CARCLUTCH_H
#define _CARCLUTCH_H
#include "LinearMath/btScalar.h"
#include "joeserialize.h"
#include "macros.h"
#include <iostream>
class CARCLUTCH
{
friend class joeserialize::Serializer;
private:
//constants (not actually declared as const because they can be changed after object creation)
btScalar sliding_friction; ///< torque on the clutch is found by dividing the clutch pressure by the value in the area tag and multiplying by the radius and sliding (friction) parameters
btScalar radius; ///< torque on the clutch is found by dividing the clutch pressure by the value in the area tag and multiplying by the radius and sliding (friction) parameters
btScalar area; ///< torque on the clutch is found by dividing the clutch pressure by the value in the area tag and multiplying by the radius and sliding (friction) parameters
btScalar max_pressure; ///< maximum allowed pressure on the plates
//variables
btScalar clutch_position;
bool locked;
//for info only
btScalar last_torque;
btScalar engine_speed;
btScalar drive_speed;
public:
//default constructor makes an S2000-like car
CARCLUTCH() :
sliding_friction(0.27),
radius(0.15),
area(0.75),
max_pressure(11079.26),
clutch_position(0),
locked(false),
last_torque(0),
engine_speed(0),
drive_speed(0)
{}
void DebugPrint(std::ostream & out) const
{
out << "---Clutch---" << "\n";
out << "Clutch position: " << clutch_position << "\n";
out << "Locked: " << locked << "\n";
out << "Torque: " << last_torque << "\n";
out << "Engine speed: " << engine_speed << "\n";
out << "Drive speed: " << drive_speed << "\n";
}
void SetSlidingFriction ( const btScalar& value )
{
sliding_friction = value;
}
void SetRadius ( const btScalar& value )
{
radius = value;
}
void SetArea ( const btScalar& value )
{
area = value;
}
void SetMaxPressure ( const btScalar& value )
{
max_pressure = value;
}
///set the clutch engagement, where 1.0 is fully engaged
void SetClutch ( const btScalar& value )
{
clutch_position = value;
}
btScalar GetClutch() const
{
return clutch_position;
}
btScalar GetTorque(btScalar n_engine_speed, btScalar n_drive_speed)
{
engine_speed = n_engine_speed;
drive_speed = n_drive_speed;
btScalar new_speed_diff = drive_speed - engine_speed;
locked = true;
btScalar torque_capacity = sliding_friction * max_pressure * area * radius; // constant
btScalar max_torque = clutch_position * torque_capacity;
btScalar friction_torque = max_torque * new_speed_diff; // highly viscous coupling (locked clutch)
if (friction_torque > max_torque) // slipping clutch
{
friction_torque = max_torque;
locked = false;
}
else if (friction_torque < -max_torque)
{
friction_torque = -max_torque;
locked = false;
}
btScalar torque = friction_torque;
last_torque = torque;
return torque;
}
bool IsLocked() const
{
return locked;
}
btScalar GetLastTorque() const
{
return last_torque;
}
bool Serialize(joeserialize::Serializer & s)
{
_SERIALIZE_(s, clutch_position);
_SERIALIZE_(s, locked);
return true;
}
};
#endif