]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/YASim/Rotor.cpp
Port over remaining Point3D usage to the more type and unit safe SG* classes.
[flightgear.git] / src / FDM / YASim / Rotor.cpp
index bdc3aa62ca13e7a2dd063e4f0e6a7e72db32cf67..5eb2c33fcc62d08808cd38f30172a44aa2ba2f07 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>
@@ -141,12 +141,16 @@ Rotor::Rotor()
     _tilt_yaw=0;
     _tilt_roll=0;
     _tilt_pitch=0;
+    _old_tilt_roll=0;
+    _old_tilt_pitch=0;
+    _old_tilt_yaw=0;
     _min_tilt_yaw=0;
     _min_tilt_pitch=0;
     _min_tilt_roll=0;
     _max_tilt_yaw=0;
     _max_tilt_pitch=0;
     _max_tilt_roll=0;
+    _downwash_factor=1;
 }
 
 Rotor::~Rotor()
@@ -174,14 +178,16 @@ void Rotor::inititeration(float dt,float omegarel,float ddt_omegarel,float *rot)
     _omega=_omegan*_omegarel; 
     _ddt_omega=_omegan*ddt_omegarel;
     int i;
-    updateDirectionsAndPositions();
+    float drot[3];
+    updateDirectionsAndPositions(drot);
+    Math::add3(rot,drot,drot);
     for(i=0; i<_rotorparts.size(); i++) {
         float s = Math::sin(float(2*pi*i/_number_of_parts+(_phi-pi/2.)*(_ccw?1:-1)));
         float c = Math::cos(float(2*pi*i/_number_of_parts+(_phi-pi/2.)*(_ccw?1:-1)));
         Rotorpart* r = (Rotorpart*)_rotorparts.get(i);
         r->setOmega(_omega);
         r->setDdtOmega(_ddt_omega);
-        r->inititeration(dt,rot);
+        r->inititeration(dt,drot);
         r->setCyclic(_cyclicail*c+_cyclicele*s);
     }
 
@@ -370,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)
@@ -649,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);
@@ -690,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)
@@ -782,6 +791,13 @@ 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);
+    int i;
+    _balance2 = lval;
+}
+
 void Rotor::getPosition(float* out)
 {
     int i;
@@ -814,6 +830,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)
@@ -1016,7 +1033,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
 }
 
@@ -1029,10 +1046,19 @@ void Rotor::euler2orient(float roll, float pitch, float hdg, float* out)
 }
 
 
-void Rotor::updateDirectionsAndPositions()
+void Rotor::updateDirectionsAndPositions(float *rot)
 {
     if (!_directions_and_postions_dirty)
+    {
+        rot[0]=rot[1]=rot[2]=0;
         return;
+    }
+    rot[0]=_old_tilt_roll-_tilt_roll;
+    rot[1]=_old_tilt_pitch-_tilt_pitch;
+    rot[2]=_old_tilt_yaw-_tilt_yaw;
+    _old_tilt_roll=_tilt_roll;
+    _old_tilt_pitch=_tilt_pitch;
+    _old_tilt_yaw=_tilt_yaw;
     float orient[9];
     euler2orient(_tilt_roll, _tilt_pitch, _tilt_yaw, orient);
     float forward[3];
@@ -1213,7 +1239,8 @@ void Rotor::compile()
             rps[(i-_number_of_parts/4+_number_of_parts)%_number_of_parts],
             rps[(i+_number_of_parts/4)%_number_of_parts]);
     }
-    updateDirectionsAndPositions();
+    float drot[3];
+    updateDirectionsAndPositions(drot);
     for (i=0;i<_number_of_parts;i++)
     {
         rps[i]->setCompiled();
@@ -1503,15 +1530,13 @@ void Rotorgear::calcForces(float* torqueOut)
         }
         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));
         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;
@@ -1538,7 +1563,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
         {
@@ -1600,10 +1625,6 @@ void Rotorgear::compile()
         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)
@@ -1655,6 +1676,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()