include/vamos/body/Engine.h

Go to the documentation of this file.
00001 //  Engine.h - an engine for the drivetrain.
00002 //
00003 //  Copyright (C) 2001--2003 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 #ifndef _ENGINE_H_
00022 #define _ENGINE_H_
00023 
00024 #include <vamos/geometry/Conversions.h>
00025 #include <vamos/geometry/Spline.h>
00026 #include <vamos/geometry/Two_Point.h>
00027 #include <vamos/body/Particle.h>
00028 
00029 namespace Vamos_Body
00030 {
00031   //* An engine for the drivetrain.  Although it produces a torque,
00032   // Engine is not derived from Component because the Engine's torque
00033   // is a scalar, not a vector.
00034   class Engine : public Particle
00035   {
00036         // Used to calculate torque in torque_map ().
00037         double m_max_power;
00038 
00039         // Used to calculate torque in torque_map ().
00040         double m_peak_engine_speed;
00041 
00042         // The highest allowed engine speed (rev limit).
00043         double m_engine_speed_limit;
00044 
00045         // The rotational inertia of the engine.
00046         double m_inertia;
00047 
00048         // The fraction of throttle used when idling.
00049         double m_idle_throttle;
00050 
00051         // The rotational speed that the engine is set to when starting.
00052         double m_start_speed;
00053 
00054         // The engine shuts off if the rotational speed goes below this
00055         // value. 
00056         double m_stall_speed;
00057 
00058         // The rate of fuel consumption.
00059         double m_fuel_consumption;
00060 
00061         // The rotational speed of the engine.
00062         double m_rotational_speed;
00063 
00064         double m_last_rotational_speed;
00065 
00066         // The throttle position.
00067         double m_gas;
00068 
00069         // The load on the engine from the clutch.
00070         double m_drag;
00071 
00072         double m_transmission_speed;
00073 
00074         // true if the gas tank is empty, false otherwise.
00075         bool m_out_of_gas;
00076 
00077         // The minimum throttle position.
00078         double m_idle;
00079 
00080         // The current torque produced by the engine.
00081         double m_drive_torque;
00082 
00083         // The impulse calculated in the last call to torque ().
00084         double m_drive_impulse;
00085 
00086         // true if the clutch is fully engaged, false otherwise.
00087         bool m_engaged;
00088         
00089         // Return the torque for a given throttle setting, GAS, and engine
00090         // speed ROTATIONAL_SPEED.
00091         double torque_map (double gas, double rotational_speed);
00092 
00093     Vamos_Geometry::Spline m_torque_curve;
00094 
00095     double m_friction;
00096 
00097 
00098 public:
00099         //** Constructor
00100         // MAX_POWER is in the correct derived units (Watts in SI), 
00101         // PEAK_ENGINE_RPM is in rotations per minute.
00102         Engine (double mass, const Vamos_Geometry::Three_Vector& position, 
00103                         double max_power,
00104                         double peak_engine_rpm,
00105                         double rpm_limit,
00106                         double inertia,
00107                         double idle_throttle,
00108                         double start_rpm,
00109                         double stall_rpm,
00110                         double fuel_consumption);
00111 
00112         void set_torque_curve (const std::vector <Vamos_Geometry::Two_Point>& 
00113                            torque_points);
00114 
00115     void set_friction (double friction) { m_friction = friction; }
00116 
00117         // Handle the input parameters.  GAS is the throttle position.
00118         // TRANSMISSION_SPEED is the rotational speed of the transmission
00119         // side of the clutch.  DRAG is the torque due to friction when
00120         // the clutch is not fully engaged.  ENGAGED is true when the
00121         // clutch is fully engaged, false otherwise.
00122         void input (double gas, double drag, double transmission_speed, 
00123                                 bool engaged);
00124 
00125         void find_forces ();
00126 
00127         // Advance the engine in time by TIME.
00128         void propagate (double time);
00129   
00130         void rewind ();
00131 
00132         // Return the current rotational speed in radians per second.
00133         double rotational_speed () const { return m_rotational_speed; }
00134 
00135         // Return the engine speed where the rev limiter kicks in.
00136         double max_rotational_speed () const { return m_engine_speed_limit; }
00137 
00138         double peak_engine_speed () const { return m_peak_engine_speed; }
00139         
00140         // Return the current torque.
00141         double drive_torque () const { return m_drive_torque; }
00142 
00143         double drive_impulse () const { return m_drive_impulse; }
00144 
00145         double throttle () const { return m_gas; }
00146 
00147         // Return the current rate of fuel consumption. 
00148         double fuel_rate () const 
00149         { return m_fuel_consumption * m_rotational_speed * m_gas; }
00150 
00151         // Tell the engine if we're out of gas.
00152         void out_of_gas (bool out) { m_out_of_gas = out; }
00153 
00154         // Start the engine.
00155         void start () { speed (m_start_speed); }
00156         
00157         // Set the engine speed to SPEED_IN and calculate the resulting
00158         // impulse.
00159         void speed (double speed_in);
00160         
00161         void set_rotational_speed(double newrs) {m_rotational_speed = newrs; m_last_rotational_speed = newrs;}
00162         double drag() {return m_drag;}
00163         void set_drag(double newdrag) {m_drag = newdrag;}
00164         
00165         double max_power() {return m_max_power;}
00166         
00167         double stall_speed() {return m_stall_speed;}
00168   };
00169 }
00170 
00171 #endif // !_ENGINE_H_

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