43 #include "FGTransmission.h" 51 IDENT(IdSrc,
"$Id: FGTransmission.cpp,v 1.4 2014/01/13 10:46:10 ehofman Exp $");
52 IDENT(IdHdr,ID_TRANSMISSION);
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)
65 FreeWheelLag =
Filter(200.0,dt);
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;
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;
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 ) {
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) {
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);
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);
134 if (EngineRPM < 0.0 ) EngineRPM = 0.0;
135 if (ThrusterRPM < 0.0 ) ThrusterRPM = 0.0;
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);
180 void FGTransmission::Debug(
int from)
182 if (debug_lvl <= 0)
return;
188 if (debug_lvl & 2 ) {
189 if (from == 0) cout <<
"Instantiated: FGTransmission" << endl;
190 if (from == 1) cout <<
"Destroyed: FGTransmission" << endl;
192 if (debug_lvl & 4 ) {
194 if (debug_lvl & 8 ) {
196 if (debug_lvl & 16) {
198 if (debug_lvl & 64) {
200 cout << IdSrc << endl;
201 cout << IdHdr << endl;
static double Constrain(double min, double value, double max)
Constrain a value between a minimum and a maximum value.
FGPropertyManager * GetPropertyManager(void)
Returns a pointer to the property manager object.
FGTransmission(FGFDMExec *exec, int num, double dt)
Constructor for FGTransmission.
First order, (low pass / lag) filter.
void Tie(const std::string &name, bool *pointer, bool useDefault=true)
Tie a property to an external bool variable.
Encapsulates the JSBSim simulation executive.
~FGTransmission()
Destructor for FGTransmission.