1 // ============================================================================= 2 // PROJECT CHRONO - http://projectchrono.org 3 // 4 // Copyright (c) 2014 projectchrono.org 5 // All rights reserved. 6 // 7 // Use of this source code is governed by a BSD-style license that can be found 8 // in the LICENSE file at the top level of the distribution and at 9 // http://projectchrono.org/license-chrono.txt. 10 // 11 // ============================================================================= 12 // Authors: Radu Serban, Justin Madsen 13 // ============================================================================= 14 // 15 // Base class for a vehicle powertrain. 16 // 17 // ============================================================================= 18 19 #ifndef CH_POWERTRAIN_H 20 #define CH_POWERTRAIN_H 21 22 #include <vector> 23 24 #include "chrono/core/ChVector.h" 25 #include "chrono/physics/ChBody.h" 26 #include "chrono/physics/ChShaft.h" 27 28 #include "chrono_vehicle/ChApiVehicle.h" 29 #include "chrono_vehicle/ChChassis.h" 30 #include "chrono_vehicle/ChDriveline.h" 31 32 namespace chrono { 33 namespace vehicle { 34 35 /// @addtogroup vehicle_powertrain 36 /// @{ 37 38 /// Base class for a powertrain system. 39 class CH_VEHICLE_API ChPowertrain : public ChPart { 40 public: 41 /// Driving modes. 42 enum class DriveMode { 43 FORWARD, ///< vehicle moving forward 44 NEUTRAL, ///< vehicle in neutral 45 REVERSE ///< vehicle moving backward 46 }; 47 48 /// Transmission mode. 49 enum class TransmissionMode { 50 AUTOMATIC, ///< automatic transmission 51 MANUAL ///< manual (manumatic) transmission 52 }; 53 ~ChPowertrain()54 virtual ~ChPowertrain() {} 55 56 /// Return the current engine speed. 57 virtual double GetMotorSpeed() const = 0; 58 59 /// Return the current engine torque. 60 virtual double GetMotorTorque() const = 0; 61 62 /// Return the value of slippage in the torque converter. 63 virtual double GetTorqueConverterSlippage() const = 0; 64 65 /// Return the input torque to the torque converter. 66 virtual double GetTorqueConverterInputTorque() const = 0; 67 68 /// Return the output torque from the torque converter. 69 virtual double GetTorqueConverterOutputTorque() const = 0; 70 71 /// Return the torque converter output shaft speed. 72 virtual double GetTorqueConverterOutputSpeed() const = 0; 73 74 /// Return the current transmission gear. 75 /// A return value of 0 indicates reverse; a positive value indicates a forward gear. GetCurrentTransmissionGear()76 int GetCurrentTransmissionGear() const { return m_current_gear; } 77 78 /// Return the output torque from the powertrain. 79 /// This is the torque that is passed to a vehicle system, thus providing the 80 /// interface between the powertrain and vehicle co-simulation modules. 81 virtual double GetOutputTorque() const = 0; 82 83 /// Set the drive mode. 84 void SetDriveMode(DriveMode mode); 85 86 /// Return the current drive mode. GetDriveMode()87 DriveMode GetDriveMode() const { return m_drive_mode; } 88 89 /// Set the transmission mode (automatic or manual). 90 /// Note that a derived powertrain class may ignore this is the selected mode is not supported. SetTransmissionMode(TransmissionMode mode)91 void SetTransmissionMode(TransmissionMode mode) { m_transmission_mode = mode; } 92 93 /// Get the current transmission mode. GetTransmissionMode()94 TransmissionMode GetTransmissionMode() const { return m_transmission_mode; } 95 96 /// Shift up. 97 void ShiftUp(); 98 99 /// Shift down. 100 void ShiftDown(); 101 102 protected: 103 ChPowertrain(const std::string& name); 104 105 /// Initialize this powertrain system by attaching it to an existing vehicle chassis. 106 /// A derived class override must first call this base class version. 107 virtual void Initialize(std::shared_ptr<ChChassis> chassis); 108 109 /// Set the transmission gear ratios (one or more forward gear ratios and a single reverse gear ratio). 110 virtual void SetGearRatios(std::vector<double>& fwd, double& rev) = 0; 111 112 /// Perform any action required on a gear shift (the new gear and gear ratio are available). OnGearShift()113 virtual void OnGearShift() {} 114 115 /// Perform any action required on placing the transmission in neutral. OnNeutralShift()116 virtual void OnNeutralShift() {} 117 118 /// Synchronize the state of this powertrain system at the current time. 119 /// The powertrain system is provided the current driver throttle input, a value in the range [0,1]. 120 virtual void Synchronize(double time, ///< [in] current time 121 double throttle, ///< [in] current throttle input [0,1] 122 double shaft_speed ///< [in] driveshaft speed 123 ) = 0; 124 125 /// Advance the state of this powertrain system by the specified time step. Advance(double step)126 virtual void Advance(double step) {} 127 128 /// Shift to the specified gear. 129 /// Note that reverse gear is index 0 and forward gears are index > 0. 130 void SetGear(int gear); 131 132 TransmissionMode m_transmission_mode; ///< transmission mode (automatic or manual) 133 DriveMode m_drive_mode; ///< drive mode (neutral, forward, or reverse) 134 std::shared_ptr<ChDriveline> m_driveline; ///< associated driveline subsystem 135 136 std::vector<double> m_gear_ratios; ///< gear ratios (0: reverse, 1+: forward) 137 int m_current_gear; ///< current transmission gear (0: reverse, 1+: forward) 138 double m_current_gear_ratio; ///< current gear ratio (positive for forward, negative for reverse) 139 140 friend class ChWheeledVehicle; 141 friend class ChTrackedVehicle; 142 }; 143 144 /// @} vehicle_powertrain 145 146 } // end namespace vehicle 147 } // end namespace chrono 148 149 #endif 150