src/vamos/body/Drivetrain.cc

Go to the documentation of this file.
00001 //  Drivetrain.cc - manages the engine, clutch, transmission and differential.
00002 //
00003 //  Copyright (C) 2001--2002 Sam Varner
00004 //
00005 //  This file is part of Vamos Automotive Simulator.
00006 //
00007 //  This program is free software; you can redistribute it and/or modify
00008 //  it under the terms of the GNU General Public License as published by
00009 //  the Free Software Foundation; either version 2 of the License, or
00010 //  (at your option) any later version.
00011 //
00012 //  This program is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU General Public License for more details.
00016 //
00017 //  You should have received a copy of the GNU General Public License
00018 //  along with this program; if not, write to the Free Software
00019 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021 #include <vamos/body/Drivetrain.h>
00022 
00023 #include <cassert>
00024 
00025 //* Class Drivetrain
00026 
00027 //** Constructor
00028 Vamos_Body::
00029 Drivetrain::Drivetrain (Engine* engine,
00030                                                 Clutch* clutch,
00031                                                 Transmission* transmission,
00032                                                 Differential* differential) 
00033   : mp_engine (engine),
00034         mp_clutch (clutch),
00035         mp_transmission (transmission),
00036         mp_differential (differential),
00037         m_gas (0.0)
00038 {
00039 }
00040 
00041 //** Destructor
00042 Vamos_Body::
00043 Drivetrain::~Drivetrain ()
00044 {
00045   delete mp_engine;
00046   delete mp_clutch;
00047   delete mp_transmission;
00048   delete mp_differential;
00049 }
00050 
00051 // Process the input parameters.
00052 void Vamos_Body::
00053 Drivetrain::input (double gas, double clutch, 
00054                                    double left_wheel_speed, double right_wheel_speed)
00055 {
00056   m_gas = gas;
00057   mp_clutch->position (clutch);
00058   
00059   double shaft_speed = mp_differential->
00060         get_driveshaft_speed (left_wheel_speed, right_wheel_speed);
00061   mp_transmission->set_driveshaft_speed (shaft_speed);
00062         
00063         /*if (m_auto_neutral &&
00064      (mp_engine->rotational_speed () == 0.0))
00065     {
00066       mp_transmission->shift (0);
00067       mp_engine->start ();
00068     }*/
00069 }
00070 
00071 void Vamos_Body::
00072 Drivetrain::find_forces ()
00073 {
00074   // Find the drag due to friction in the clutch if the clutch is not
00075   // fully engaged, and the torque on the driveshaft.
00076   double drag = 0.0;
00077   double torque = 0.0;
00078   if (mp_transmission->gear () != 0)
00079         {
00080           // Find the drag due to friction in the clutch.  As a
00081           // side-effect, the value of Clutch::engaged() is set.
00082           drag = mp_clutch->drag (mp_engine->rotational_speed (), 
00083                                                         mp_transmission->clutch_speed ());
00084 
00085           if (mp_clutch->engaged ())
00086                 {
00087                   // If the clutch is fully engaged, the engine speed is forced to
00088                   // match the transmission speed.  There is no clutch drag.
00089                   mp_engine->input (m_gas, 0.0, mp_transmission->clutch_speed (), 
00090                                                         true);
00091                   torque = mp_transmission->torque (mp_engine->drive_torque ());
00092                 }
00093           else
00094                 {
00095                   // Find out how much torque we get from the drivetrain.
00096                   torque = mp_transmission->torque (drag);
00097                   // Update the Engine
00098                   mp_engine->input (m_gas, drag, 0.0, false);
00099                 }
00100         }
00101   else
00102         {
00103           // We're in neutral.  Just update the engine.
00104           mp_engine->input (m_gas, drag, 0.0, false);
00105         }
00106 
00107   // Apply the torque to the differential.
00108   mp_differential->find_wheel_torques (torque);
00109   mp_engine->find_forces ();
00110 }
00111 
00112 // Advance the drivetrain in time by TIME.
00113 void Vamos_Body::
00114 Drivetrain::propagate (double time)
00115 {
00116   mp_engine->propagate (time);
00117 }
00118 
00119 void Vamos_Body::
00120 Drivetrain::rewind ()
00121 {
00122   mp_engine->rewind ();
00123 }
00124 
00125 void Vamos_Body::
00126 Drivetrain::reset ()
00127 {
00128   mp_clutch->position (0.0);
00129   mp_transmission->shift (0);
00130 }
00131 
00132 double Vamos_Body::
00133 Drivetrain::torque (Vamos_Geometry::Side side) const
00134 {
00135   switch (side)
00136         {
00137         case Vamos_Geometry::LEFT:
00138           return mp_differential->left_wheel_torque ();
00139           break;
00140         case Vamos_Geometry::RIGHT:
00141           return mp_differential->right_wheel_torque ();
00142           break;
00143         default:
00144           assert (false);
00145         }
00146   return 0.0;
00147 }

Generated on Thu Oct 19 04:05:55 2006 by  doxygen 1.4.6