[go: up one dir, main page]

Menu

[2d94f2]: / body / Clutch.cpp  Maximize  Restore  History

Download this file

59 lines (52 with data), 2.0 kB

 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
// A clutch for the drivetrain.
//
// Copyright (C) 2001-2019 Sam Varner
//
// This file is part of Vamos Automotive Simulator.
//
// Vamos 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.
//
// Vamos 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 Vamos. If not, see <http://www.gnu.org/licenses/>.
#include "Clutch.hpp"
#include <cmath>
namespace
{
/// The locking threshold. The clutch is fully engaged when engine speed transmission
/// speeds < m_threshold * normal force.
const double m_threshold = 0.01;
} // namespace
Vamos_Body::Clutch::Clutch(double sliding, double radius, double area, double max_pressure)
: m_sliding_friction(sliding),
m_radius(radius),
m_area(area),
m_max_pressure(max_pressure)
{
}
double Vamos_Body::Clutch::drag(double engine_speed, double drive_speed)
{
double normal = m_pressure * m_area;
if (std::abs(engine_speed - drive_speed) < m_threshold * normal)
{
// Setting m_engaged to true will cause the drivetrain to ignore the return value
// and act as though the clutch is fully engaged.
m_engaged = true;
return 0.0;
}
double force = m_sliding_friction * normal * (engine_speed > drive_speed ? 1.0 : -1.0);
// The pressure is considered to be concentrated at m_radius from the center.
return force * m_radius;
}
void Vamos_Body::Clutch::position(double factor)
{
m_engaged = factor > 0.99;
m_pressure = (m_engaged ? 1.0 : factor) * m_max_pressure;
}