]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/YASim/Rotor.cpp
latest updates from JSBSim
[flightgear.git] / src / FDM / YASim / Rotor.cpp
index ebda4875e1e01d9bbdd1a8c1cebf35d8cc5f709f..2a93a4457f4be5e9468ddad21d4784c31f455a4d 100644 (file)
@@ -8,10 +8,10 @@
 #include "Ground.hpp"
 #include "Rotor.hpp"
 
-#include STL_IOSTREAM
-#include STL_IOMANIP
+#include <iostream>
+#include <iomanip>
 
-SG_USING_STD(setprecision);
+using std::setprecision;
 
 #ifdef TEST_DEBUG
 #include <stdio.h>
@@ -150,6 +150,7 @@ Rotor::Rotor()
     _max_tilt_yaw=0;
     _max_tilt_pitch=0;
     _max_tilt_roll=0;
+    _downwash_factor=1;
 }
 
 Rotor::~Rotor()
@@ -375,14 +376,12 @@ void Rotorgear::setEngineOn(int value)
 
 void Rotorgear::setRotorEngineMaxRelTorque(float lval)
 {
-    SGPropertyNode * node = fgGetNode("/rotors/gear/max-rel-torque", true);
-    if (node) node->setDoubleValue(lval);
+    _max_rel_torque=lval;
 }
 
 void Rotorgear::setRotorRelTarget(float lval)
 {
-    SGPropertyNode * node = fgGetNode("/rotors/gear/target-rel-rpm", true);
-    if (node) node->setDoubleValue(lval);
+    _target_rel_rpm=lval;
 }
 
 void Rotor::setAlpha0(float f)
@@ -654,6 +653,11 @@ void Rotor::setRelLenHinge(float value)
     _rel_len_hinge=value;
 }
 
+void Rotor::setDownwashFactor(float value)
+{
+    _downwash_factor=value;
+}
+
 void Rotor::setAlphaoutput(int i, const char *text)
 {
     strncpy(_alphaoutput[i],text,255);
@@ -695,7 +699,7 @@ void Rotor::setGlobalGround(double *global_ground, float* global_vel)
     for(i=0; i<4; i++) _global_ground[i] = global_ground[i];
 }
 
-void Rotor::setParameter(char *parametername, float value)
+void Rotor::setParameter(const char *parametername, float value)
 {
 #define p(a,b) if (strcmp(parametername,#a)==0) _##a = (value * (b)); else
     p(translift_ve,1)
@@ -787,6 +791,12 @@ void Rotor::setCyclicail(float lval,float rval)
     _cyclicail=-(_mincyclicail+(lval+1)/2*(_maxcyclicail-_mincyclicail));
 }
 
+void Rotor::setRotorBalance(float lval)
+{
+    lval = Math::clamp(lval, -1, 1);
+    _balance2 = lval;
+}
+
 void Rotor::getPosition(float* out)
 {
     int i;
@@ -808,7 +818,7 @@ void Rotor::calcLiftFactor(float* v, float rho, State *s)
     _f_ge=1+_diameter/_ground_effect_altitude*_ground_effect_constant;
 
     // Now calculate translational lift
-    float v_vert = Math::dot3(v,_normal);
+    // float v_vert = Math::dot3(v,_normal);
     float help[3];
     Math::cross3(v,_normal,help);
     float v_horiz = Math::mag3(help);
@@ -819,6 +829,7 @@ void Rotor::calcLiftFactor(float* v, float rho, State *s)
 
     //store the gravity direction
     Glue::geodUp(s->pos, _grav_direction);
+    s->velGlobalToLocal(_grav_direction, _grav_direction);
 }
 
 void Rotor::findGroundEffectAltitude(Ground * ground_cb,State *s)
@@ -1021,7 +1032,7 @@ void Rotor::getDownWash(float *pos, float *v_heli, float *downwash)
     //at dist = rotor radius it is assumed to be 1/e * v1 + (1-1/e)* v2
 
     float v = g * v1 + (1-g) * v2;
-    Math::mul3(-v,_normal_with_yaw_roll,downwash);
+    Math::mul3(-v*_downwash_factor,_normal_with_yaw_roll,downwash);
     //the downwash is calculated in the opposite direction of the normal
 }
 
@@ -1170,7 +1181,7 @@ void Rotor::compile()
         * _diameter * _rel_blade_center * _rel_blade_center /(0.5*0.5);
     float speed=_rotor_rpm/60*_diameter*_rel_blade_center*pi;
     float lentocenter=_diameter*_rel_blade_center*0.5;
-    float lentoforceattac=_diameter*_rel_len_hinge*0.5;
+    // float lentoforceattac=_diameter*_rel_len_hinge*0.5;
     float zentforce=rotorpartmass*speed*speed/lentocenter;
     float pitchaforce=_force_at_pitch_a/_number_of_parts*.453*9.81;
     // was pounds of force, now N, devided by _number_of_parts
@@ -1185,8 +1196,8 @@ void Rotor::compile()
 
     float relamp=(omega*omega/(2*_delta*Math::sqrt(sqr(omega0*omega0-omega*omega)
         +4*_delta*_delta*omega*omega)))*_cyclic_factor;
-    float relamp_theoretical=(omega*omega/(2*delta_theoretical*Math::sqrt(sqr(omega0*omega0-omega*omega)
-        +4*delta_theoretical*delta_theoretical*omega*omega)))*_cyclic_factor;
+    //float relamp_theoretical=(omega*omega/(2*delta_theoretical*Math::sqrt(sqr(omega0*omega0-omega*omega)
+    //    +4*delta_theoretical*delta_theoretical*omega*omega)))*_cyclic_factor;
     _phi=Math::acos(_rel_len_hinge);
     _phi-=Math::atan(_delta3);
     if (!_no_torque)
@@ -1517,16 +1528,14 @@ void Rotorgear::calcForces(float* torqueOut)
             total_torque+=r->getTorque()*omegan;
         }
         float max_torque_of_engine=0;
-        SGPropertyNode * node=fgGetNode("/rotors/gear", true);
-        float target_rel_rpm=(node==0?1:node->getDoubleValue("target-rel-rpm",1));
+        // SGPropertyNode * node=fgGetNode("/rotors/gear", true);
         if (_engineon)
         {
-            float max_rel_torque=(node==0?1:node->getDoubleValue("max-rel-torque",1));
-            max_torque_of_engine=_max_power_engine*max_rel_torque;
-            float df=target_rel_rpm-omegarel;
+            max_torque_of_engine=_max_power_engine*_max_rel_torque;
+            float df=_target_rel_rpm-omegarel;
             df/=_engine_prop_factor;
             df = Math::clamp(df, 0, 1);
-            max_torque_of_engine = df * _max_power_engine*max_rel_torque;
+            max_torque_of_engine = df * _max_power_engine*_max_rel_torque;
         }
         total_torque*=-1;
         _ddt_omegarel=0;
@@ -1553,7 +1562,7 @@ void Rotorgear::calcForces(float* torqueOut)
 
         //change the rotation of the rotors 
         if ((max_torque_of_engine<total_torque) //decreasing rotation
-            ||((max_torque_of_engine>total_torque)&&(omegarel<target_rel_rpm))
+            ||((max_torque_of_engine>total_torque)&&(omegarel<_target_rel_rpm))
             //increasing rotation due to engine
             ||(total_torque<0) ) //increasing rotation due to autorotation
         {
@@ -1590,7 +1599,7 @@ void Rotorgear::calcForces(float* torqueOut)
             for(j=0; j<_rotors.size(); j++) {
                 Rotor* r = (Rotor*)_rotors.get(j);
                 for(i=0; i<r->_rotorparts.size(); i++) {
-                    float torque_scalar=0;
+                    // float torque_scalar=0;
                     Rotorpart* rp = (Rotorpart*)r->_rotorparts.get(i);
                     float torque[3];
                     rp->getAccelTorque(_ddt_omegarel,torque);
@@ -1610,15 +1619,11 @@ void Rotorgear::addRotor(Rotor* rotor)
 
 void Rotorgear::compile()
 {
-    float wgt = 0;
+    // float wgt = 0;
     for(int j=0; j<_rotors.size(); j++) {
         Rotor* r = (Rotor*)_rotors.get(j);
         r->compile();
     }
-    SGPropertyNode * node = fgGetNode("/rotors/gear/target-rel-rpm", true);
-    if (node) node->setDoubleValue(1);
-    node =fgGetNode("/rotors/gear/max-rel-torque", true);
-    if (node) node->setDoubleValue(1);
 }
 
 void Rotorgear::getDownWash(float *pos, float * v_heli, float *downwash)
@@ -1670,6 +1675,8 @@ Rotorgear::Rotorgear()
     _ddt_omegarel=0;
     _engine_accel_limit=0.05f;
     _total_torque_on_engine=0;
+    _target_rel_rpm=1;
+    _max_rel_torque=1;
 }
 
 Rotorgear::~Rotorgear()