JSBSim Flight Dynamics Model 1.3.0 (09 Apr 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
FGTransmission.cpp
1/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3 JSBSim
4 Author: Jon S. Berndt
5 Date started: 08/24/00
6 ------------- Copyright (C) 2000 Jon S. Berndt (jon@jsbsim.org) -------------
7
8 Module: FGTransmission.cpp
9 Author: T.Kreitler
10 Date started: 02/05/12
11
12 ------------- Copyright (C) 2012 T. Kreitler (t.kreitler@web.de) -------------
13
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
17 version.
18
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
22 details.
23
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.
27
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.
30
31FUNCTIONAL DESCRIPTION
32--------------------------------------------------------------------------------
33
34HISTORY
35--------------------------------------------------------------------------------
3602/05/12 T.Kreitler Created
37
38%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39INCLUDES
40%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41
42
43#include "FGTransmission.h"
44
45using std::string;
46
47namespace JSBSim {
48
49/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50CLASS IMPLEMENTATION
51%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52
53FGTransmission::FGTransmission(FGFDMExec *exec, int num, double dt) :
54 FreeWheelTransmission(1.0),
55 ThrusterMoment(1.0), EngineMoment(1.0), EngineFriction(0.0),
56 ClutchCtrlNorm(1.0), BrakeCtrlNorm(0.0), MaxBrakePower(0.0),
57 EngineRPM(0.0), ThrusterRPM(0.0)
58{
59 auto PropertyManager = exec->GetPropertyManager();
60 FreeWheelLag = Filter(200.0,dt); // avoid too abrupt changes in transmission
61 BindModel(num, PropertyManager.get());
62}
63
64//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65
68
69//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70
71// basically P = Q*w and Q_Engine + (-Q_Rotor) = J * dw/dt, J = Moment
72//
73void FGTransmission::Calculate(double EnginePower, double ThrusterTorque, double dt) {
74
75 double coupling = 1.0, coupling_sq = 1.0;
76 double fw_mult = 1.0;
77
78 double d_omega = 0.0, engine_d_omega = 0.0, thruster_d_omega = 0.0; // relative changes
79
80 double engine_omega = rpm_to_omega(EngineRPM);
81 double safe_engine_omega = engine_omega < 1e-1 ? 1e-1 : engine_omega;
82 double engine_torque = EnginePower / safe_engine_omega;
83
84 double thruster_omega = rpm_to_omega(ThrusterRPM);
85 double safe_thruster_omega = thruster_omega < 1e-1 ? 1e-1 : thruster_omega;
86
87 engine_torque -= EngineFriction / safe_engine_omega;
88 ThrusterTorque += Constrain(0.0, BrakeCtrlNorm, 1.0) * MaxBrakePower / safe_thruster_omega;
89
90 // would the FWU release ?
91 engine_d_omega = engine_torque/EngineMoment * dt;
92 thruster_d_omega = - ThrusterTorque/ThrusterMoment * dt;
93
94 if ( thruster_omega+thruster_d_omega > engine_omega+engine_d_omega ) {
95 // don't drive the engine
96 FreeWheelTransmission = 0.0;
97 } else {
98 FreeWheelTransmission = 1.0;
99 }
100
101 fw_mult = FreeWheelLag.execute(FreeWheelTransmission);
102 coupling = fw_mult * Constrain(0.0, ClutchCtrlNorm, 1.0);
103
104 if (coupling < 0.999999) { // are the separate calculations needed ?
105 // assume linear transfer
106 engine_d_omega =
107 (engine_torque - ThrusterTorque*coupling)/(ThrusterMoment*coupling + EngineMoment) * dt;
108 thruster_d_omega =
109 (engine_torque*coupling - ThrusterTorque)/(ThrusterMoment + EngineMoment*coupling) * dt;
110
111 EngineRPM += omega_to_rpm(engine_d_omega);
112 ThrusterRPM += omega_to_rpm(thruster_d_omega);
113
114 // simulate transit to static friction
115 coupling_sq = coupling*coupling;
116 EngineRPM = (1.0-coupling_sq) * EngineRPM + coupling_sq * 0.02 * (49.0*EngineRPM + ThrusterRPM);
117 ThrusterRPM = (1.0-coupling_sq) * ThrusterRPM + coupling_sq * 0.02 * (EngineRPM + 49.0*ThrusterRPM);
118
119 // enforce equal rpm
120 if ( fabs(EngineRPM-ThrusterRPM) < 1e-3 ) {
121 EngineRPM = ThrusterRPM = 0.5 * (EngineRPM+ThrusterRPM);
122 }
123 } else {
124 d_omega = (engine_torque - ThrusterTorque)/(ThrusterMoment + EngineMoment) * dt;
125 EngineRPM = ThrusterRPM += omega_to_rpm(d_omega);
126 }
127
128 // nothing will turn backward
129 if (EngineRPM < 0.0 ) EngineRPM = 0.0;
130 if (ThrusterRPM < 0.0 ) ThrusterRPM = 0.0;
131
132}
133
134//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135
136bool FGTransmission::BindModel(int num, FGPropertyManager* PropertyManager)
137{
138 string property_name, base_property_name;
139 base_property_name = CreateIndexedPropertyName("propulsion/engine", num);
140
141 property_name = base_property_name + "/brake-ctrl-norm";
142 PropertyManager->Tie( property_name.c_str(), this,
143 &FGTransmission::GetBrakeCtrlNorm, &FGTransmission::SetBrakeCtrlNorm);
144
145 property_name = base_property_name + "/clutch-ctrl-norm";
146 PropertyManager->Tie( property_name.c_str(), this,
147 &FGTransmission::GetClutchCtrlNorm, &FGTransmission::SetClutchCtrlNorm);
148
149 property_name = base_property_name + "/free-wheel-transmission";
150 PropertyManager->Tie( property_name.c_str(), this,
151 &FGTransmission::GetFreeWheelTransmission);
152
153 return true;
154}
155
156//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157// The bitmasked value choices are as follows:
158// unset: In this case (the default) JSBSim would only print
159// out the normally expected messages, essentially echoing
160// the config files as they are read. If the environment
161// variable is not set, debug_lvl is set to 1 internally
162// 0: This requests JSBSim not to output any messages
163// whatsoever.
164// 1: This value explicity requests the normal JSBSim
165// startup messages
166// 2: This value asks for a message to be printed out when
167// a class is instantiated
168// 4: When this value is set, a message is displayed when a
169// FGModel object executes its Run() method
170// 8: When this value is set, various runtime state variables
171// are printed out periodically
172// 16: When set various parameters are sanity checked and
173// a message is printed out when they go out of bounds
174
175void FGTransmission::Debug(int from)
176{
177 if (debug_lvl <= 0) return;
178
179 if (debug_lvl & 1) { // Standard console startup message output
180 if (from == 0) { // Constructor
181 }
182 }
183 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
184 FGLogging log(LogLevel::DEBUG);
185 if (from == 0) log << "Instantiated: FGTransmission\n";
186 if (from == 1) log << "Destroyed: FGTransmission\n";
187 }
188 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
189 }
190 if (debug_lvl & 8 ) { // Runtime state variables
191 }
192 if (debug_lvl & 16) { // Sanity checking
193 }
194 if (debug_lvl & 64) {
195 if (from == 0) { // Constructor
196 }
197 }
198}
199
200}
Encapsulates the JSBSim simulation executive.
Definition FGFDMExec.h:185
std::shared_ptr< FGPropertyManager > GetPropertyManager(void) const
Returns a pointer to the property manager object.
Definition FGFDMExec.h:422
First order, (low pass / lag) filter.
Definition FGJSBBase.h:127
static constexpr double Constrain(double min, double value, double max)
Constrain a value between a minimum and a maximum value.
Definition FGJSBBase.h:289
FGTransmission(FGFDMExec *exec, int num, double dt)
Constructor for FGTransmission.
~FGTransmission()
Destructor for FGTransmission.
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:71