]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/propulsion/FGRotor.cpp
Merge branch 'next' into comm-subsystem
[flightgear.git] / src / FDM / JSBSim / models / propulsion / FGRotor.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGRotor.cpp
4  Author:       Jon S. Berndt
5  Date started: 08/24/00
6  Purpose:      Encapsulates the rotor object
7
8  ------------- Copyright (C) 2000  Jon S. Berndt (jon@jsbsim.org) -------------
9
10  This program is free software; you can redistribute it and/or modify it under
11  the terms of the GNU Lesser General Public License as published by the Free Software
12  Foundation; either version 2 of the License, or (at your option) any later
13  version.
14
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
18  details.
19
20  You should have received a copy of the GNU Lesser General Public License along with
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  Place - Suite 330, Boston, MA  02111-1307, USA.
23
24  Further information about the GNU Lesser General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
29
30 HISTORY
31 --------------------------------------------------------------------------------
32 08/24/00  JSB  Created
33 01/01/10  T.Kreitler test implementation
34 11/15/10  T.Kreitler treated flow solver bug, flow and torque calculations 
35                      simplified, tiploss influence removed from flapping angles
36 01/10/11  T.Kreitler changed to single rotor model
37 03/06/11  T.Kreitler added brake, clutch, and experimental free-wheeling-unit,
38                      reasonable estimate for inflowlag
39
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 INCLUDES
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43
44 #include <iostream>
45 #include <sstream>
46
47 #include "FGRotor.h"
48 #include "input_output/FGXMLElement.h"
49 #include "models/FGMassBalance.h"
50 #include "models/FGPropulsion.h" // to get the GearRatio from a linked rotor
51
52 using std::cerr;
53 using std::endl;
54 using std::ostringstream;
55 using std::cout;
56
57 namespace JSBSim {
58
59 static const char *IdSrc = "$Id: FGRotor.cpp,v 1.18 2011/10/15 21:30:28 jentron Exp $";
60 static const char *IdHdr = ID_ROTOR;
61
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 MISC
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65
66 static inline double sqr(double x) { return x*x; }
67
68 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 CLASS IMPLEMENTATION
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
71
72
73 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74
75 // Note: The FGTransmission class is currently carried 'pick-a-pack' by
76 // FGRotor.
77
78 FGTransmission::FGTransmission(FGFDMExec *exec, int num) :
79   FreeWheelTransmission(1.0),
80   ThrusterMoment(1.0), EngineMoment(1.0), EngineFriction(0.0),
81   ClutchCtrlNorm(1.0), BrakeCtrlNorm(0.0), MaxBrakePower(0.0),
82   EngineRPM(0.0), ThrusterRPM(0.0)
83 {
84   double dt;
85   PropertyManager = exec->GetPropertyManager();
86   dt = exec->GetDeltaT();
87
88   // avoid too abrupt changes in transmission
89   FreeWheelLag = Filter(200.0,dt);
90   BindModel(num);
91 }
92
93 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94
95 FGTransmission::~FGTransmission(){
96 }
97
98 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99
100 // basically P = Q*w and Q_Engine + (-Q_Rotor) = J * dw/dt, J = Moment
101 //
102 void FGTransmission::Calculate(double EnginePower, double ThrusterTorque, double dt) {
103
104   double coupling = 1.0, coupling_sq = 1.0;
105   double fw_mult = 1.0;
106
107   double d_omega = 0.0, engine_d_omega = 0.0, thruster_d_omega = 0.0; // relative changes
108
109   double engine_omega = rpm_to_omega(EngineRPM);
110   double safe_engine_omega = engine_omega < 1e-1 ? 1e-1 : engine_omega;
111   double engine_torque = EnginePower / safe_engine_omega;
112
113   double thruster_omega = rpm_to_omega(ThrusterRPM);
114   double safe_thruster_omega = thruster_omega < 1e-1 ? 1e-1 : thruster_omega;
115
116   engine_torque  -= EngineFriction / safe_engine_omega;
117   ThrusterTorque += Constrain(0.0, BrakeCtrlNorm, 1.0) * MaxBrakePower / safe_thruster_omega;
118
119   // would the FWU release ?
120   engine_d_omega = engine_torque/EngineMoment * dt;
121   thruster_d_omega =  - ThrusterTorque/ThrusterMoment * dt;
122
123   if ( thruster_omega+thruster_d_omega > engine_omega+engine_d_omega ) {
124     // don't drive the engine
125     FreeWheelTransmission = 0.0;
126   } else {
127     FreeWheelTransmission = 1.0;
128   }
129
130   fw_mult = FreeWheelLag.execute(FreeWheelTransmission);
131   coupling = fw_mult * Constrain(0.0, ClutchCtrlNorm, 1.0);
132
133   if (coupling < 0.999999) { // are the separate calculations needed ?
134     // assume linear transfer 
135     engine_d_omega   =
136        (engine_torque - ThrusterTorque*coupling)/(ThrusterMoment*coupling + EngineMoment) * dt;
137     thruster_d_omega = 
138        (engine_torque*coupling - ThrusterTorque)/(ThrusterMoment + EngineMoment*coupling) * dt;
139
140     EngineRPM += omega_to_rpm(engine_d_omega);
141     ThrusterRPM += omega_to_rpm(thruster_d_omega);
142
143     // simulate friction in clutch
144     coupling_sq = coupling*coupling;
145     EngineRPM   = (1.0-coupling_sq) * EngineRPM    + coupling_sq * 0.02 * (49.0*EngineRPM + ThrusterRPM);
146     ThrusterRPM = (1.0-coupling_sq) * ThrusterRPM  + coupling_sq * 0.02 * (EngineRPM + 49.0*ThrusterRPM);
147
148     // enforce equal rpm
149     if ( fabs(EngineRPM-ThrusterRPM) < 1e-3 ) {
150       EngineRPM = ThrusterRPM = 0.5 * (EngineRPM+ThrusterRPM);
151     }
152   } else {
153     d_omega = (engine_torque - ThrusterTorque)/(ThrusterMoment + EngineMoment) * dt;
154     EngineRPM = ThrusterRPM += omega_to_rpm(d_omega);
155   }
156
157   // nothing will turn backward
158   if (EngineRPM < 0.0 ) EngineRPM = 0.0;
159   if (ThrusterRPM < 0.0 ) ThrusterRPM = 0.0;
160
161 }
162
163 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164
165 bool FGTransmission::BindModel(int num)
166 {
167   string property_name, base_property_name;
168   base_property_name = CreateIndexedPropertyName("propulsion/engine", num);
169
170   property_name = base_property_name + "/brake-ctrl-norm";
171   PropertyManager->Tie( property_name.c_str(), this, &FGTransmission::GetBrakeCtrl, &FGTransmission::SetBrakeCtrl);
172   property_name = base_property_name + "/free-wheel-transmission";
173   PropertyManager->Tie( property_name.c_str(), this, &FGTransmission::GetFreeWheelTransmission);
174
175   return true;
176 }
177
178
179
180 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181
182 // Constructor
183
184 FGRotor::FGRotor(FGFDMExec *exec, Element* rotor_element, int num)
185   : FGThruster(exec, rotor_element, num),
186     rho(0.002356),                                  // environment
187     Radius(0.0), BladeNum(0),                       // configuration parameters
188     Sense(1.0), NominalRPM(0.0), MinimalRPM(0.0), MaximalRPM(0.0), 
189     ExternalRPM(0), RPMdefinition(0), ExtRPMsource(NULL), SourceGearRatio(1.0),
190     BladeChord(0.0), LiftCurveSlope(0.0), BladeTwist(0.0), HingeOffset(0.0),
191     BladeFlappingMoment(0.0), BladeMassMoment(0.0), PolarMoment(0.0),
192     InflowLag(0.0), TipLossB(0.0),
193     GroundEffectExp(0.0), GroundEffectShift(0.0),
194     LockNumberByRho(0.0), Solidity(0.0),            // derived parameters
195     RPM(0.0), Omega(0.0),                           // dynamic values
196     beta_orient(0.0),
197     a0(0.0), a_1(0.0), b_1(0.0), a_dw(0.0),
198     a1s(0.0), b1s(0.0),
199     H_drag(0.0), J_side(0.0), Torque(0.0), C_T(0.0),
200     lambda(-0.001), mu(0.0), nu(0.001), v_induced(0.0),
201     theta_downwash(0.0), phi_downwash(0.0),
202     ControlMap(eMainCtrl),                          // control
203     CollectiveCtrl(0.0), LateralCtrl(0.0), LongitudinalCtrl(0.0),
204     Transmission(NULL),                             // interaction with engine
205     EngineRPM(0.0), MaxBrakePower(0.0), GearLoss(0.0), GearMoment(0.0)
206 {
207   FGColumnVector3 location(0.0, 0.0, 0.0), orientation(0.0, 0.0, 0.0);
208   Element *thruster_element;
209
210   // initialise/set remaining variables
211   SetTransformType(FGForce::tCustom);
212   PropertyManager = exec->GetPropertyManager();
213   Type = ttRotor;
214   GearRatio = 1.0;
215
216   dt = exec->GetDeltaT();
217   for (int i=0; i<5; i++) R[i] = 0.0;
218   for (int i=0; i<5; i++) B[i] = 0.0;
219
220   // get positions 
221   thruster_element = rotor_element->GetParent()->FindElement("sense");
222   if (thruster_element) {
223     double s = thruster_element->GetDataAsNumber();
224     if (s < -0.1) {
225       Sense = -1.0; // 'CW' as seen from above
226     } else if (s < 0.1) {
227       Sense = 0.0;  // 'coaxial'
228     } else {
229       Sense = 1.0; // 'CCW' as seen from above
230     }
231   }
232
233   thruster_element = rotor_element->GetParent()->FindElement("location");
234   if (thruster_element) {
235     location = thruster_element->FindElementTripletConvertTo("IN");
236   } else {
237     cerr << "No thruster location found." << endl;
238   }
239
240   thruster_element = rotor_element->GetParent()->FindElement("orient");
241   if (thruster_element) {
242     orientation = thruster_element->FindElementTripletConvertTo("RAD");
243   } else {
244     cerr << "No thruster orientation found." << endl;
245   }
246
247   SetLocation(location);
248   SetAnglesToBody(orientation);
249   InvTransform = Transform().Transposed();
250
251   // wire controls
252   ControlMap = eMainCtrl;
253   if (rotor_element->FindElement("controlmap")) {
254     string cm = rotor_element->FindElementValue("controlmap");
255     cm = to_upper(cm);
256     if (cm == "TAIL") {
257       ControlMap = eTailCtrl;
258     } else if (cm == "TANDEM") {
259       ControlMap = eTandemCtrl;
260     } else {
261       cerr << "# found unknown controlmap: '" << cm << "' using main rotor config."  << endl;
262     }
263   }
264
265   // ExternalRPM -- is the RPM dictated ?
266   if (rotor_element->FindElement("ExternalRPM")) {
267     ExternalRPM = 1;
268     SourceGearRatio = 1.0;
269     RPMdefinition = (int) rotor_element->FindElementValueAsNumber("ExternalRPM");
270     int rdef = RPMdefinition;
271     if (RPMdefinition>=0) {
272       // avoid ourself and (still) unknown engines.
273       if (!exec->GetPropulsion()->GetEngine(RPMdefinition) || RPMdefinition==num) {
274         RPMdefinition = -1;
275       } else {
276         FGThruster *tr = exec->GetPropulsion()->GetEngine(RPMdefinition)->GetThruster();
277         SourceGearRatio = tr->GetGearRatio();
278         // cout << "# got sources' GearRatio: " << SourceGearRatio << endl;
279       }
280     }
281     if (RPMdefinition != rdef) {
282       cerr << "# discarded given RPM source (" << rdef << ") and switched to external control (-1)." << endl;
283     }
284   }
285
286   // configure the rotor parameters
287   Configure(rotor_element);
288
289   // configure the transmission parameters
290   if (!ExternalRPM) {
291     Transmission = new FGTransmission(exec, num);
292
293     Transmission->SetMaxBrakePower(MaxBrakePower);
294
295     if (rotor_element->FindElement("gearloss")) {
296       GearLoss = rotor_element->FindElementValueAsNumberConvertTo("gearloss","HP");
297       GearLoss *= hptoftlbssec;
298     }
299
300     if (GearLoss<1e-6) { // TODO, allow 0 ?
301       double ehp = 0.5 * BladeNum*BladeChord*Radius*Radius; // guess engine power
302       //cout << "# guessed engine power: " << ehp << endl;
303       GearLoss = 0.0025 * ehp * hptoftlbssec;
304     }
305     Transmission->SetEngineFriction(GearLoss);
306
307     // The MOI sensed behind the gear ( MOI_engine*sqr(GearRatio) ).
308     if (rotor_element->FindElement("gearmoment")) {
309       GearMoment = rotor_element->FindElementValueAsNumberConvertTo("gearmoment","SLUG*FT2");
310     }
311
312     if (GearMoment<1e-2) { // TODO, need better check for lower limit
313       GearMoment = 0.1*PolarMoment;
314     }
315     Transmission->SetEngineMoment(GearMoment);
316
317     Transmission->SetThrusterMoment(PolarMoment);
318   }
319
320   // shaft representation - a rather simple transform, 
321   // but using a matrix is safer.
322   TboToHsr.InitMatrix(   0.0, 0.0, 1.0,
323                          0.0, 1.0, 0.0,
324                         -1.0, 0.0, 0.0  );
325   HsrToTbo  =  TboToHsr.Transposed();
326
327   // smooth out jumps in hagl reported, otherwise the ground effect
328   // calculation would cause jumps too. 1Hz seems sufficient.
329   damp_hagl = Filter(1.0, dt);
330
331   // enable import-export
332   BindModel();
333
334   Debug(0);
335
336 }  // Constructor
337
338 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
339
340 FGRotor::~FGRotor(){
341   if (Transmission) delete Transmission;
342   Debug(1);
343 }
344
345
346 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
347
348 // 5in1: value-fetch-convert-default-return function 
349
350 double FGRotor::ConfigValueConv( Element* el, const string& ename, double default_val, 
351                                   const string& unit, bool tell)
352 {
353
354   Element *e = NULL;
355   double val = default_val;
356
357   string pname = "*No parent element*";
358
359   if (el) {
360     e = el->FindElement(ename);
361     pname = el->GetName();
362   }
363
364   if (e) {
365     if (unit.empty()) {
366       val = e->GetDataAsNumber();
367     } else {
368       val = el->FindElementValueAsNumberConvertTo(ename,unit);
369     }
370   } else {
371     if (tell) {
372       cerr << pname << ": missing element '" << ename <<
373                        "' using estimated value: " << default_val << endl;
374     }
375   }
376
377   return val;
378 }
379
380 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
381
382 double FGRotor::ConfigValue(Element* el, const string& ename, double default_val, bool tell)
383 {
384   return ConfigValueConv(el, ename, default_val, "", tell);
385 }
386
387 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
388
389 // 1. read configuration and try to fill holes, ymmv
390 // 2. calculate derived parameters
391 void FGRotor::Configure(Element* rotor_element)
392 {
393
394   double estimate;
395   const bool yell   = true;
396   const bool silent = false;
397
398
399   Radius = 0.5 * ConfigValueConv(rotor_element, "diameter", 42.0, "FT", yell); 
400   Radius = Constrain(1e-3, Radius, 1e9);
401   
402   BladeNum = (int) ConfigValue(rotor_element, "numblades", 3 , yell);
403   
404   GearRatio = ConfigValue(rotor_element, "gearratio", 1.0, yell);
405
406   // make sure that v_tip (omega*r) is below 0.7mach ~ 750ft/s
407   estimate = (750.0/Radius)/(2.0*M_PI) * 60.0;  // 7160/Radius
408   NominalRPM = ConfigValue(rotor_element, "nominalrpm", estimate, yell);
409   NominalRPM = Constrain(2.0, NominalRPM, 1e9);
410
411   MinimalRPM = ConfigValue(rotor_element, "minrpm", 1.0);
412   MinimalRPM = Constrain(1.0, MinimalRPM, NominalRPM - 1.0);
413
414   MaximalRPM = ConfigValue(rotor_element, "maxrpm", 2.0*NominalRPM);
415   MaximalRPM = Constrain(NominalRPM, MaximalRPM, 1e9);
416
417   estimate = Constrain(0.07, 2.0/Radius , 0.14); // guess solidity
418   estimate = estimate * M_PI*Radius/BladeNum;
419   BladeChord = ConfigValueConv(rotor_element, "chord", estimate, "FT", yell);
420
421   LiftCurveSlope = ConfigValue(rotor_element, "liftcurveslope", 6.0); // "1/RAD"
422   BladeTwist = ConfigValueConv(rotor_element, "twist", -0.17, "RAD");
423
424   HingeOffset = ConfigValueConv(rotor_element, "hingeoffset", 0.05 * Radius, "FT" );
425
426   estimate = sqr(BladeChord) * sqr(Radius - HingeOffset) * 0.57;
427   BladeFlappingMoment = ConfigValueConv(rotor_element, "flappingmoment", estimate, "SLUG*FT2");   
428   BladeFlappingMoment = Constrain(1.0e-6, BladeFlappingMoment, 1e9);
429
430   // guess mass from moment of a thin stick, and multiply by the blades cg distance
431   estimate = ( 3.0 * BladeFlappingMoment / sqr(Radius) ) * (0.45 * Radius) ;
432   BladeMassMoment = ConfigValue(rotor_element, "massmoment", estimate); // unit is slug-ft
433   BladeMassMoment = Constrain(0.001, BladeMassMoment, 1e9);
434
435   estimate = 1.1 * BladeFlappingMoment * BladeNum;
436   PolarMoment = ConfigValueConv(rotor_element, "polarmoment", estimate, "SLUG*FT2");
437   PolarMoment = Constrain(1e-6, PolarMoment, 1e9);
438
439   // "inflowlag" is treated further down.
440
441   TipLossB = ConfigValue(rotor_element, "tiplossfactor", 1.0, silent);
442
443   estimate = 0.01 * PolarMoment ; // guesses for huey, bo105 20-30hp
444   MaxBrakePower  = ConfigValueConv(rotor_element, "maxbrakepower", estimate, "HP");
445   MaxBrakePower *= hptoftlbssec;
446
447   // ground effect
448   if (rotor_element->FindElement("cgroundeffect")) {
449     double cge,gee;
450     cge = rotor_element->FindElementValueAsNumber("cgroundeffect");
451     cge = Constrain(1e-9, cge, 1.0);
452     gee = 1.0 / ( 2.0*Radius * cge );
453     cerr << "# *** 'cgroundeffect' is defunct." << endl;
454     cerr << "# *** use 'groundeffectexp' with: " << gee << endl;
455   }
456
457   GroundEffectExp = ConfigValue(rotor_element, "groundeffectexp", 0.0);
458   GroundEffectShift = ConfigValueConv(rotor_element, "groundeffectshift", 0.0, "FT");
459
460   // precalc often used powers
461   R[0]=1.0; R[1]=Radius;   R[2]=R[1]*R[1]; R[3]=R[2]*R[1]; R[4]=R[3]*R[1];
462   B[0]=1.0; B[1]=TipLossB; B[2]=B[1]*B[1]; B[3]=B[2]*B[1]; B[4]=B[3]*B[1];
463
464   // derived parameters
465   LockNumberByRho = LiftCurveSlope * BladeChord * R[4] / BladeFlappingMoment;
466   Solidity = BladeNum * BladeChord / (M_PI * Radius);
467
468   // estimate inflow lag, see /GE49/ eqn(1)
469   double omega_tmp = (NominalRPM/60.0)*2.0*M_PI;
470   estimate = 16.0/(LockNumberByRho*rho * omega_tmp ); // 16/(gamma*Omega)
471   // printf("# Est. InflowLag: %f\n", estimate);
472   InflowLag = ConfigValue(rotor_element, "inflowlag", estimate, yell);
473   InflowLag = Constrain(1.0e-6, InflowLag, 2.0);
474
475   return;
476 } // Configure
477
478 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
479
480 // calculate control-axes components of total airspeed at the hub.
481 // sets rotor orientation angle (beta) as side effect. /SH79/ eqn(19-22)
482
483 FGColumnVector3 FGRotor::hub_vel_body2ca( const FGColumnVector3 &uvw, 
484                                                  const FGColumnVector3 &pqr,
485                                                  double a_ic, double b_ic)
486 {
487   FGColumnVector3  v_r, v_shaft, v_w;
488   FGColumnVector3 pos;
489
490   pos = fdmex->GetMassBalance()->StructuralToBody(GetActingLocation());
491
492   v_r = uvw + pqr*pos;
493   v_shaft = TboToHsr * InvTransform * v_r;
494
495   beta_orient = atan2(v_shaft(eV),v_shaft(eU));
496
497   v_w(eU) = v_shaft(eU)*cos(beta_orient) + v_shaft(eV)*sin(beta_orient);
498   v_w(eV) = 0.0;
499   v_w(eW) = v_shaft(eW) - b_ic*v_shaft(eU) - a_ic*v_shaft(eV);
500
501   return v_w;
502 }
503
504 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
505
506 // express fuselage angular velocity in control axes /SH79/ eqn(30,31)
507
508 FGColumnVector3 FGRotor::fus_angvel_body2ca( const FGColumnVector3 &pqr)
509 {
510   FGColumnVector3 av_s_fus, av_w_fus;    
511
512   // for comparison:
513   // av_s_fus = BodyToShaft * pqr; /SH79/ 
514   // BodyToShaft = TboToHsr * InvTransform
515   av_s_fus = TboToHsr * InvTransform * pqr;
516
517   av_w_fus(eP)=   av_s_fus(eP)*cos(beta_orient) + av_s_fus(eQ)*sin(beta_orient);
518   av_w_fus(eQ)= - av_s_fus(eP)*sin(beta_orient) + av_s_fus(eQ)*cos(beta_orient);
519   av_w_fus(eR)=   av_s_fus(eR);
520
521   return av_w_fus;
522 }
523
524
525 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
526
527 // The calculation is a bit tricky because thrust depends on induced velocity,
528 // and vice versa.
529 //
530 // The flow_scale parameter (ranging from 0.5-1.0) is used to approximate a
531 // reduction of inflow if the helicopter is close to the ground, yielding to
532 // higher thrust, see /TA77/ eqn(10a).
533
534 void FGRotor::calc_flow_and_thrust( double theta_0, double Uw, double Ww, 
535                                     double flow_scale)
536 {
537
538   double ct_over_sigma = 0.0;
539   double c0, ct_l, ct_t0, ct_t1;
540   double mu2;
541
542   mu = Uw/(Omega*Radius); // /SH79/ eqn(24)
543   if (mu > 0.7) mu = 0.7;
544   mu2 = sqr(mu);
545   
546   ct_t0 = (1.0/3.0*B[3] + 1.0/2.0 * TipLossB*mu2 - 4.0/(9.0*M_PI) * mu*mu2 ) * theta_0;
547   ct_t1 = (1.0/4.0*B[4] + 1.0/4.0 * B[2]*mu2) * BladeTwist;
548
549   ct_l  = (1.0/2.0*B[2] + 1.0/4.0 * mu2) * lambda; // first time
550
551   c0 = (LiftCurveSlope/2.0)*(ct_l + ct_t0 + ct_t1) * Solidity;
552   c0 = c0 / ( 2.0 * sqrt( sqr(mu) + sqr(lambda) ) + 1e-15);
553
554   // replacement for /SH79/ eqn(26).
555   // ref: dnu/dt = 1/tau ( Ct / (2*sqrt(mu^2+lambda^2))  -  nu )
556   // taking mu and lambda constant, this integrates to
557
558   nu  = flow_scale * ((nu - c0) * exp(-dt/InflowLag) + c0);
559
560   // now from nu to lambda, C_T, and Thrust
561
562   lambda = Ww/(Omega*Radius) - nu; // /SH79/ eqn(25)
563
564   ct_l  = (1.0/2.0*B[2] + 1.0/4.0 * mu2) * lambda;
565
566   ct_over_sigma = (LiftCurveSlope/2.0)*(ct_l + ct_t0 + ct_t1); // /SH79/ eqn(27)
567
568   Thrust = BladeNum*BladeChord*Radius*rho*sqr(Omega*Radius) * ct_over_sigma;
569
570   C_T = ct_over_sigma * Solidity;
571   v_induced = nu * (Omega*Radius);
572
573 }
574
575
576 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
577
578 // The coning angle doesn't apply for teetering rotors, but calculating
579 // doesn't hurt. /SH79/ eqn(29)
580
581 void FGRotor::calc_coning_angle(double theta_0)
582 {
583   double lock_gamma = LockNumberByRho * rho;
584
585   double a0_l  = (1.0/6.0  + 0.04 * mu*mu*mu) * lambda;
586   double a0_t0 = (1.0/8.0  + 1.0/8.0  * mu*mu) * theta_0;
587   double a0_t1 = (1.0/10.0 + 1.0/12.0 * mu*mu) * BladeTwist;
588   a0 = lock_gamma * ( a0_l + a0_t0 + a0_t1);
589   return;
590 }
591
592 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
593
594 // Flapping angles relative to control axes /SH79/ eqn(32)
595
596 void FGRotor::calc_flapping_angles(double theta_0, const FGColumnVector3 &pqr_fus_w)
597 {
598   double lock_gamma = LockNumberByRho * rho;
599
600
601   double mu2_2 = sqr(mu)/2.0;
602   double t075 = theta_0 + 0.75 * BladeTwist;  // common approximation for rectangular blades
603   
604   a_1 = 1.0/(1.0 - mu2_2) * (
605                                  (2.0*lambda + (8.0/3.0)*t075)*mu
606                                + pqr_fus_w(eP)/Omega
607                                - 16.0 * pqr_fus_w(eQ)/(lock_gamma*Omega)
608                              );
609
610   b_1 = 1.0/(1.0 + mu2_2) * (
611                                  (4.0/3.0)*mu*a0
612                                - pqr_fus_w(eQ)/Omega
613                                - 16.0 * pqr_fus_w(eP)/(lock_gamma*Omega)
614                              );
615
616   // used in  force calc
617   a_dw = 1.0/(1.0 - mu2_2) * (
618                                  (2.0*lambda + (8.0/3.0)*t075)*mu
619                                - 24.0 * pqr_fus_w(eQ)/(lock_gamma*Omega)
620                                  * ( 1.0 - ( 0.29 * t075 / (C_T/Solidity) ) )
621                              );
622
623   return;
624 }
625
626 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
627
628 // /SH79/ eqn(38,39)
629
630 void FGRotor::calc_drag_and_side_forces(double theta_0)
631 {
632   double cy_over_sigma;
633   double t075 = theta_0 + 0.75 * BladeTwist;
634
635   H_drag = Thrust * a_dw;
636
637   cy_over_sigma = (
638                       0.75*b_1*lambda - 1.5*a0*mu*lambda + 0.25*a_1*b_1*mu
639                     - a0*a_1*sqr(mu) + (1.0/6.0)*a0*a_1
640                     - (0.75*mu*a0 - (1.0/3.0)*b_1 - 0.5*sqr(mu)*b_1)*t075
641                   );
642   cy_over_sigma *= LiftCurveSlope/2.0;
643
644   J_side = BladeNum * BladeChord * Radius * rho * sqr(Omega*Radius) * cy_over_sigma;
645
646   return;
647 }
648
649 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
650
651 // Simplified version of /SH79/ eqn(36). Uses an estimate for blade drag
652 // (a new config parameter to come...).
653 // From "Bramwell's Helicopter Dynamics", second edition, eqn(3.43) and (3.44)
654
655 void FGRotor::calc_torque(double theta_0)
656 {
657   // estimate blade drag
658   double delta_dr = 0.009 + 0.3*sqr(6.0*C_T/(LiftCurveSlope*Solidity));
659
660   Torque = rho * BladeNum * BladeChord * delta_dr * sqr(Omega*Radius) * R[2] * 
661            (1.0+4.5*sqr(mu))/8.0
662                      - (Thrust*lambda + H_drag*mu)*Radius;
663
664   return;
665 }
666
667 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
668
669 // transform rotor forces from control axes to shaft axes, and express
670 // in body axes /SH79/ eqn(40,41)
671
672 FGColumnVector3 FGRotor::body_forces(double a_ic, double b_ic)
673 {
674   FGColumnVector3 F_s(
675         - H_drag*cos(beta_orient) - J_side*sin(beta_orient) + Thrust*b_ic,
676         - H_drag*sin(beta_orient) + J_side*cos(beta_orient) + Thrust*a_ic,
677         - Thrust);    
678
679   return HsrToTbo * F_s;
680 }
681
682 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
683
684 // calculates the additional moments due to hinge offset and handles 
685 // torque and sense
686
687 FGColumnVector3 FGRotor::body_moments(double a_ic, double b_ic)
688 {
689   FGColumnVector3 M_s, M_hub, M_h;
690   double mf;
691
692   // cyclic flapping relative to shaft axes /SH79/ eqn(43)
693   a1s = a_1*cos(beta_orient) + b_1*sin(beta_orient) - b_ic;
694   b1s = b_1*cos(beta_orient) - a_1*sin(beta_orient) + a_ic;
695
696   mf = 0.5 * HingeOffset * BladeNum * Omega*Omega * BladeMassMoment;
697
698   M_s(eL) = mf*b1s;
699   M_s(eM) = mf*a1s;
700   M_s(eN) = Torque * Sense ;
701
702   return HsrToTbo * M_s;
703 }
704
705 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
706
707 void FGRotor::CalcRotorState(void)
708 {
709   double A_IC;       // lateral (roll) control in radians
710   double B_IC;       // longitudinal (pitch) control in radians
711   double theta_col;  // rotor collective pitch in radians
712
713   FGColumnVector3 vHub_ca, avFus_ca;
714
715   double filtered_hagl = 0.0;
716   double ge_factor = 1.0;
717
718   // fetch needed values from environment
719   rho = in.Density; // slugs/ft^3.
720   double h_agl_ft = in.H_agl;
721   // update InvTransform, the rotor orientation could have been altered
722   InvTransform = Transform().Transposed();
723
724   // handle RPM requirements, calc omega.
725   if (ExternalRPM && ExtRPMsource) {
726     RPM = ExtRPMsource->getDoubleValue() * ( SourceGearRatio / GearRatio );
727   }
728
729   // MinimalRPM is always >= 1. MaximalRPM is always >= NominalRPM
730   RPM = Constrain(MinimalRPM, RPM, MaximalRPM);
731
732   Omega = (RPM/60.0)*2.0*M_PI;
733
734   // set control inputs
735   A_IC      = LateralCtrl;
736   B_IC      = LongitudinalCtrl;
737   theta_col = CollectiveCtrl;
738
739   // ground effect
740   if (GroundEffectExp > 1e-5) {
741     if (h_agl_ft<0.0) h_agl_ft = 0.0; // clamp
742     filtered_hagl = damp_hagl.execute(h_agl_ft) + GroundEffectShift;
743     // actual/nominal factor avoids absurd scales at startup
744     ge_factor -= exp(-filtered_hagl*GroundEffectExp) * (RPM / NominalRPM);
745     if (ge_factor<0.5) ge_factor=0.5; // clamp
746   }
747
748   // all set, start calculations
749
750   vHub_ca  = hub_vel_body2ca(in.AeroUVW, in.AeroPQR, A_IC, B_IC);
751
752   avFus_ca = fus_angvel_body2ca(in.AeroPQR);
753
754   calc_flow_and_thrust(theta_col, vHub_ca(eU), vHub_ca(eW), ge_factor);
755
756   calc_coning_angle(theta_col);
757
758   calc_flapping_angles(theta_col, avFus_ca);
759
760   calc_drag_and_side_forces(theta_col);
761
762   calc_torque(theta_col);
763
764   // Fixme: only valid for a 'decent' rotor
765   theta_downwash = atan2( -in.AeroUVW(eU), v_induced - in.AeroUVW(eW));
766   phi_downwash   = atan2(  in.AeroUVW(eV), v_induced - in.AeroUVW(eW));
767
768   vFn = body_forces(A_IC, B_IC);
769   vMn = Transform() * body_moments(A_IC, B_IC); 
770
771 }
772
773 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
774
775 double FGRotor::Calculate(double EnginePower)
776 {
777
778   CalcRotorState();
779
780   if (! ExternalRPM) {
781     Transmission->SetClutchCtrlNorm(ClutchCtrlNorm);
782
783     // the RPM values are handled inside Transmission
784     Transmission->Calculate(EnginePower, Torque, in.TotalDeltaT);
785
786     EngineRPM = Transmission->GetEngineRPM() * GearRatio;
787     RPM = Transmission->GetThrusterRPM();
788   } else {
789     EngineRPM = RPM * GearRatio;
790   }
791
792   RPM = Constrain(MinimalRPM, RPM, MaximalRPM); // trim again
793
794   return Thrust;
795 }
796
797
798 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
799
800
801 bool FGRotor::BindModel(void)
802 {
803   string property_name, base_property_name;
804   base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNum);
805
806   property_name = base_property_name + "/rotor-rpm";
807   PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetRPM );
808
809   property_name = base_property_name + "/engine-rpm";
810   PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetEngineRPM );
811
812   property_name = base_property_name + "/rotor-thrust-lbs"; // might be redundant - check!
813   PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetThrust );
814
815   property_name = base_property_name + "/a0-rad";
816   PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetA0 );
817
818   property_name = base_property_name + "/a1-rad";
819   PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetA1 );
820
821   property_name = base_property_name + "/b1-rad";
822   PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetB1 );
823
824   property_name = base_property_name + "/inflow-ratio";
825   PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetLambda );
826
827   property_name = base_property_name + "/advance-ratio";
828   PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetMu );
829
830   property_name = base_property_name + "/induced-inflow-ratio";
831   PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetNu );
832
833   property_name = base_property_name + "/vi-fps";
834   PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetVi );
835
836   property_name = base_property_name + "/thrust-coefficient";
837   PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetCT );
838
839   property_name = base_property_name + "/torque-lbsft";
840   PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetTorque );
841
842   property_name = base_property_name + "/theta-downwash-rad";
843   PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetThetaDW );
844
845   property_name = base_property_name + "/phi-downwash-rad";
846   PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetPhiDW );
847
848   switch (ControlMap) {
849     case eTailCtrl:
850       property_name = base_property_name + "/antitorque-ctrl-rad";
851       PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetCollectiveCtrl, &FGRotor::SetCollectiveCtrl);
852       break;
853     case eTandemCtrl:
854       property_name = base_property_name + "/tail-collective-ctrl-rad";
855       PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetCollectiveCtrl, &FGRotor::SetCollectiveCtrl);
856       property_name = base_property_name + "/lateral-ctrl-rad";
857       PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetLateralCtrl, &FGRotor::SetLateralCtrl);
858       property_name = base_property_name + "/longitudinal-ctrl-rad";
859       PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetLongitudinalCtrl, &FGRotor::SetLongitudinalCtrl);
860       break;
861     default: // eMainCtrl
862       property_name = base_property_name + "/collective-ctrl-rad";
863       PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetCollectiveCtrl, &FGRotor::SetCollectiveCtrl);
864       property_name = base_property_name + "/lateral-ctrl-rad";
865       PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetLateralCtrl, &FGRotor::SetLateralCtrl);
866       property_name = base_property_name + "/longitudinal-ctrl-rad";
867       PropertyManager->Tie( property_name.c_str(), this, &FGRotor::GetLongitudinalCtrl, &FGRotor::SetLongitudinalCtrl);
868   }
869
870   if (ExternalRPM) {
871     if (RPMdefinition == -1) {
872       property_name = base_property_name + "/x-rpm-dict";
873       ExtRPMsource = PropertyManager->GetNode(property_name, true);
874     } else if (RPMdefinition >= 0 && RPMdefinition != EngineNum) {
875       string ipn = CreateIndexedPropertyName("propulsion/engine", RPMdefinition);
876       property_name = ipn + "/rotor-rpm";
877       ExtRPMsource = PropertyManager->GetNode(property_name, false);
878       if (! ExtRPMsource) {
879         cerr << "# Warning: Engine number " << EngineNum << "." << endl;
880         cerr << "# No 'rotor-rpm' property found for engine " << RPMdefinition << "." << endl;
881         cerr << "# Please check order of engine definitons."  << endl;
882       }
883     } else {
884       cerr << "# Engine number " << EngineNum;
885       cerr << ", given ExternalRPM value '" << RPMdefinition << "' unhandled."  << endl;
886     }
887   }
888
889   return true;
890 }
891
892 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
893
894 string FGRotor::GetThrusterLabels(int id, string delimeter)
895 {
896
897   ostringstream buf;
898
899   buf << Name << " RPM (engine " << id << ")";
900
901   return buf.str();
902
903 }
904
905 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
906
907 string FGRotor::GetThrusterValues(int id, string delimeter)
908 {
909
910   ostringstream buf;
911
912   buf << RPM;
913
914   return buf.str();
915
916 }
917
918 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
919 //    The bitmasked value choices are as follows:
920 //    unset: In this case (the default) JSBSim would only print
921 //       out the normally expected messages, essentially echoing
922 //       the config files as they are read. If the environment
923 //       variable is not set, debug_lvl is set to 1 internally
924 //    0: This requests JSBSim not to output any messages
925 //       whatsoever.
926 //    1: This value explicity requests the normal JSBSim
927 //       startup messages
928 //    2: This value asks for a message to be printed out when
929 //       a class is instantiated
930 //    4: When this value is set, a message is displayed when a
931 //       FGModel object executes its Run() method
932 //    8: When this value is set, various runtime state variables
933 //       are printed out periodically
934 //    16: When set various parameters are sanity checked and
935 //       a message is printed out when they go out of bounds
936
937 void FGRotor::Debug(int from)
938 {
939   string ControlMapName;
940
941   if (debug_lvl <= 0) return;
942
943   if (debug_lvl & 1) { // Standard console startup message output
944     if (from == 0) { // Constructor
945       cout << "\n    Rotor Name: " << Name << endl;
946       cout << "      Diameter = " << 2.0 * Radius << " ft." << endl;
947       cout << "      Number of Blades = " << BladeNum << endl;
948       cout << "      Gear Ratio = " << GearRatio << endl;
949       cout << "      Sense = " << Sense << endl;
950       cout << "      Nominal RPM = " << NominalRPM << endl;
951       cout << "      Minimal RPM = " << MinimalRPM << endl;
952       cout << "      Maximal RPM = " << MaximalRPM << endl;
953
954       if (ExternalRPM) {
955         if (RPMdefinition == -1) {
956           cout << "      RPM is controlled externally" << endl;
957         } else {
958           cout << "      RPM source set to thruster " << RPMdefinition << endl;
959         }
960       }
961
962       cout << "      Blade Chord = " << BladeChord << endl;
963       cout << "      Lift Curve Slope = " << LiftCurveSlope << endl;
964       cout << "      Blade Twist = " << BladeTwist << endl;
965       cout << "      Hinge Offset = " << HingeOffset << endl;
966       cout << "      Blade Flapping Moment = " << BladeFlappingMoment << endl;
967       cout << "      Blade Mass Moment = " << BladeMassMoment << endl;
968       cout << "      Polar Moment = " << PolarMoment << endl;
969       cout << "      Inflow Lag = " << InflowLag << endl;
970       cout << "      Tip Loss = " << TipLossB << endl;
971       cout << "      Lock Number = " << LockNumberByRho * 0.002356 << " (SL)" << endl;
972       cout << "      Solidity = " << Solidity << endl;
973       cout << "      Max Brake Power = " << MaxBrakePower/hptoftlbssec << " HP" << endl;
974       cout << "      Gear Loss = " << GearLoss/hptoftlbssec << " HP" << endl;
975       cout << "      Gear Moment = " << GearMoment << endl;
976
977       switch (ControlMap) {
978         case eTailCtrl:    ControlMapName = "Tail Rotor";   break;
979         case eTandemCtrl:  ControlMapName = "Tandem Rotor"; break;
980         default:           ControlMapName = "Main Rotor";
981       }
982       cout << "      Control Mapping = " << ControlMapName << endl;
983
984     }
985   }
986   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
987     if (from == 0) cout << "Instantiated: FGRotor" << endl;
988     if (from == 1) cout << "Destroyed:    FGRotor" << endl;
989   }
990   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
991   }
992   if (debug_lvl & 8 ) { // Runtime state variables
993   }
994   if (debug_lvl & 16) { // Sanity checking
995   }
996   if (debug_lvl & 64) {
997     if (from == 0) { // Constructor
998       cout << IdSrc << endl;
999       cout << IdHdr << endl;
1000     }
1001   }
1002
1003 }
1004
1005
1006 } // namespace JSBSim 
1007