1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 ------------- Copyright (C) 2000 Jon S. Berndt (jon@jsbsim.org) -------------
8 Module: FGTransmission.cpp
10 Date started: 02/05/12
12 ------------- Copyright (C) 2012 T. Kreitler (t.kreitler@web.de) -------------
14 This program is free software; you can redistribute it and/or modify it under
15 the terms of the GNU Lesser General Public License as published by the Free Software
16 Foundation; either version 2 of the License, or (at your option) any later
19 This program is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
24 You should have received a copy of the GNU Lesser General Public License along with
25 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
26 Place - Suite 330, Boston, MA 02111-1307, USA.
28 Further information about the GNU Lesser General Public License can also be found on
29 the world wide web at http://www.gnu.org.
31 FUNCTIONAL DESCRIPTION
32 --------------------------------------------------------------------------------
35 --------------------------------------------------------------------------------
36 02/05/12 T.Kreitler Created
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43 #include "FGTransmission.h"
51 static const char *IdSrc = "$Id: FGTransmission.cpp,v 1.2 2013/11/15 22:43:03 bcoconni Exp $";
52 static const char *IdHdr = ID_TRANSMISSION;
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58 FGTransmission::FGTransmission(FGFDMExec *exec, int num, double dt) :
59 FreeWheelTransmission(1.0),
60 ThrusterMoment(1.0), EngineMoment(1.0), EngineFriction(0.0),
61 ClutchCtrlNorm(1.0), BrakeCtrlNorm(0.0), MaxBrakePower(0.0),
62 EngineRPM(0.0), ThrusterRPM(0.0)
64 PropertyManager = exec->GetPropertyManager();
65 FreeWheelLag = Filter(200.0,dt); // avoid too abrupt changes in transmission
69 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 FGTransmission::~FGTransmission(){
74 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 // basically P = Q*w and Q_Engine + (-Q_Rotor) = J * dw/dt, J = Moment
78 void FGTransmission::Calculate(double EnginePower, double ThrusterTorque, double dt) {
80 double coupling = 1.0, coupling_sq = 1.0;
83 double d_omega = 0.0, engine_d_omega = 0.0, thruster_d_omega = 0.0; // relative changes
85 double engine_omega = rpm_to_omega(EngineRPM);
86 double safe_engine_omega = engine_omega < 1e-1 ? 1e-1 : engine_omega;
87 double engine_torque = EnginePower / safe_engine_omega;
89 double thruster_omega = rpm_to_omega(ThrusterRPM);
90 double safe_thruster_omega = thruster_omega < 1e-1 ? 1e-1 : thruster_omega;
92 engine_torque -= EngineFriction / safe_engine_omega;
93 ThrusterTorque += Constrain(0.0, BrakeCtrlNorm, 1.0) * MaxBrakePower / safe_thruster_omega;
95 // would the FWU release ?
96 engine_d_omega = engine_torque/EngineMoment * dt;
97 thruster_d_omega = - ThrusterTorque/ThrusterMoment * dt;
99 if ( thruster_omega+thruster_d_omega > engine_omega+engine_d_omega ) {
100 // don't drive the engine
101 FreeWheelTransmission = 0.0;
103 FreeWheelTransmission = 1.0;
106 fw_mult = FreeWheelLag.execute(FreeWheelTransmission);
107 coupling = fw_mult * Constrain(0.0, ClutchCtrlNorm, 1.0);
109 if (coupling < 0.999999) { // are the separate calculations needed ?
110 // assume linear transfer
112 (engine_torque - ThrusterTorque*coupling)/(ThrusterMoment*coupling + EngineMoment) * dt;
114 (engine_torque*coupling - ThrusterTorque)/(ThrusterMoment + EngineMoment*coupling) * dt;
116 EngineRPM += omega_to_rpm(engine_d_omega);
117 ThrusterRPM += omega_to_rpm(thruster_d_omega);
119 // simulate transit to static friction
120 coupling_sq = coupling*coupling;
121 EngineRPM = (1.0-coupling_sq) * EngineRPM + coupling_sq * 0.02 * (49.0*EngineRPM + ThrusterRPM);
122 ThrusterRPM = (1.0-coupling_sq) * ThrusterRPM + coupling_sq * 0.02 * (EngineRPM + 49.0*ThrusterRPM);
125 if ( fabs(EngineRPM-ThrusterRPM) < 1e-3 ) {
126 EngineRPM = ThrusterRPM = 0.5 * (EngineRPM+ThrusterRPM);
129 d_omega = (engine_torque - ThrusterTorque)/(ThrusterMoment + EngineMoment) * dt;
130 EngineRPM = ThrusterRPM += omega_to_rpm(d_omega);
133 // nothing will turn backward
134 if (EngineRPM < 0.0 ) EngineRPM = 0.0;
135 if (ThrusterRPM < 0.0 ) ThrusterRPM = 0.0;
139 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 bool FGTransmission::BindModel(int num)
143 string property_name, base_property_name;
144 base_property_name = CreateIndexedPropertyName("propulsion/engine", num);
146 property_name = base_property_name + "/brake-ctrl-norm";
147 PropertyManager->Tie( property_name.c_str(), this,
148 &FGTransmission::GetBrakeCtrlNorm, &FGTransmission::SetBrakeCtrlNorm);
150 property_name = base_property_name + "/clutch-ctrl-norm";
151 PropertyManager->Tie( property_name.c_str(), this,
152 &FGTransmission::GetClutchCtrlNorm, &FGTransmission::SetClutchCtrlNorm);
154 property_name = base_property_name + "/free-wheel-transmission";
155 PropertyManager->Tie( property_name.c_str(), this,
156 &FGTransmission::GetFreeWheelTransmission);
161 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162 // The bitmasked value choices are as follows:
163 // unset: In this case (the default) JSBSim would only print
164 // out the normally expected messages, essentially echoing
165 // the config files as they are read. If the environment
166 // variable is not set, debug_lvl is set to 1 internally
167 // 0: This requests JSBSim not to output any messages
169 // 1: This value explicity requests the normal JSBSim
171 // 2: This value asks for a message to be printed out when
172 // a class is instantiated
173 // 4: When this value is set, a message is displayed when a
174 // FGModel object executes its Run() method
175 // 8: When this value is set, various runtime state variables
176 // are printed out periodically
177 // 16: When set various parameters are sanity checked and
178 // a message is printed out when they go out of bounds
180 void FGTransmission::Debug(int from)
182 if (debug_lvl <= 0) return;
184 if (debug_lvl & 1) { // Standard console startup message output
185 if (from == 0) { // Constructor
188 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
189 if (from == 0) cout << "Instantiated: FGTransmission" << endl;
190 if (from == 1) cout << "Destroyed: FGTransmission" << endl;
192 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
194 if (debug_lvl & 8 ) { // Runtime state variables
196 if (debug_lvl & 16) { // Sanity checking
198 if (debug_lvl & 64) {
199 if (from == 0) { // Constructor
200 cout << IdSrc << endl;
201 cout << IdHdr << endl;