X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2FYASim%2FRotor.cpp;h=2a93a4457f4be5e9468ddad21d4784c31f455a4d;hb=d66903e9ad63b91182ccc25d9bb82f18f8dd98b6;hp=bdc3aa62ca13e7a2dd063e4f0e6a7e72db32cf67;hpb=d0550441bb16858591b1817580657d8ee1d47313;p=flightgear.git diff --git a/src/FDM/YASim/Rotor.cpp b/src/FDM/YASim/Rotor.cpp index bdc3aa62c..2a93a4457 100644 --- a/src/FDM/YASim/Rotor.cpp +++ b/src/FDM/YASim/Rotor.cpp @@ -8,10 +8,10 @@ #include "Ground.hpp" #include "Rotor.hpp" -#include STL_IOSTREAM -#include STL_IOMANIP +#include +#include -SG_USING_STD(setprecision); +using std::setprecision; #ifdef TEST_DEBUG #include @@ -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,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; @@ -803,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); @@ -814,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) @@ -1016,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 } @@ -1029,10 +1045,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]; @@ -1156,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 @@ -1171,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) @@ -1213,7 +1238,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(); @@ -1502,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; @@ -1538,7 +1562,7 @@ void Rotorgear::calcForces(float* torqueOut) //change the rotation of the rotors if ((max_torque_of_enginetotal_torque)&&(omegareltotal_torque)&&(omegarel<_target_rel_rpm)) //increasing rotation due to engine ||(total_torque<0) ) //increasing rotation due to autorotation { @@ -1575,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_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); @@ -1595,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) @@ -1655,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()