[go: up one dir, main page]

Menu

[8286ad]: / body / Drivetrain.cpp  Maximize  Restore  History

Download this file

101 lines (89 with data), 3.4 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
 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
// Drivetrain.cc - manages the engine, clutch, transmission and differential.
//
// Copyright (C) 2001--2002 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 "Drivetrain.hpp"
#include <cassert>
using namespace Vamos_Body;
Drivetrain::Drivetrain(Engine *engine, Clutch *clutch, Transmission *transmission,
Differential *differential)
: mp_engine(engine),
mp_clutch(clutch),
mp_transmission(transmission),
mp_differential(differential)
{
assert(mp_engine && mp_clutch && mp_transmission && mp_differential);
}
void Drivetrain::input(double gas, double clutch, double left_wheel_speed, double right_wheel_speed)
{
m_gas = gas;
mp_clutch->position(clutch);
double shaft_speed = mp_differential->get_driveshaft_speed(left_wheel_speed, right_wheel_speed);
mp_transmission->set_driveshaft_speed(shaft_speed);
if (m_auto_neutral && mp_engine->rotational_speed() == 0.0 && !mp_engine->is_out_of_gas())
{
mp_transmission->shift(0);
mp_engine->start();
}
}
void Drivetrain::propagate(double time)
{
// Find the drag due to friction in the clutch if the clutch is not fully engaged, and
// the torque on the driveshaft.
double drag = 0.0;
double torque = 0.0;
double clutch_speed = 0.0;
bool engaged = mp_transmission->get_gear() != 0 && mp_clutch->engaged();
if (engaged)
{
// If the clutch is fully engaged, the engine speed is forced to match the
// transmission speed. There is no clutch drag.
clutch_speed = mp_transmission->get_clutch_speed();
torque = mp_transmission->get_torque(mp_engine->drive_torque());
}
else if (mp_transmission->get_gear() != 0)
{
// Find the drag due to friction in the clutch. As a side-effect, the value
// of Clutch::engaged() is set.
drag = mp_clutch->drag(mp_engine->rotational_speed(), mp_transmission->get_clutch_speed());
// Find out how much torque we get from the drivetrain.
torque = mp_transmission->get_torque(drag);
}
mp_engine->input(m_gas, drag, clutch_speed, engaged);
// Apply the torque to the differential.
mp_differential->find_wheel_torques(torque);
mp_engine->propagate(time);
}
void Drivetrain::reset()
{
mp_clutch->position(0.0);
mp_transmission->shift(0);
}
double Drivetrain::torque(Vamos_Geometry::Direction side) const
{
switch (side)
{
case Vamos_Geometry::LEFT:
return mp_differential->left_wheel_torque();
case Vamos_Geometry::RIGHT:
return mp_differential->right_wheel_torque();
default:
assert(false);
break;
}
return 0.0;
}