From 1a5bbec83be8797f8570e5d4b1df4ce553786273 Mon Sep 17 00:00:00 2001 From: andy Date: Sun, 27 May 2007 20:19:15 +0000 Subject: [PATCH] Maik: add ROTORELTARGET and ROTORENGINEMAXRELTORQUE input axes --- src/FDM/YASim/ControlMap.cpp | 9 +++++++-- src/FDM/YASim/ControlMap.hpp | 2 +- src/FDM/YASim/FGFDM.cpp | 3 +++ src/FDM/YASim/Rotor.cpp | 38 ++++++++++++++++++++++++++++-------- src/FDM/YASim/Rotor.hpp | 2 ++ 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/FDM/YASim/ControlMap.cpp b/src/FDM/YASim/ControlMap.cpp index 1b9de6834..f68a1be8f 100644 --- a/src/FDM/YASim/ControlMap.cpp +++ b/src/FDM/YASim/ControlMap.cpp @@ -211,8 +211,13 @@ void ControlMap::applyControls(float dt) case COLLECTIVE: ((Rotor*)obj)->setCollective(lval); break; case CYCLICAIL: ((Rotor*)obj)->setCyclicail(lval,rval); break; case CYCLICELE: ((Rotor*)obj)->setCyclicele(lval,rval); break; - case ROTORBRAKE: ((Rotorgear*)obj)->setRotorBrake(lval); break; - case ROTORENGINEON: ((Rotorgear*)obj)->setEngineOn((int)lval); break; + case ROTORBRAKE: ((Rotorgear*)obj)->setRotorBrake(lval); break; + case ROTORENGINEON: + ((Rotorgear*)obj)->setEngineOn((int)lval); break; + case ROTORENGINEMAXRELTORQUE: + ((Rotorgear*)obj)->setRotorEngineMaxRelTorque(lval); break; + case ROTORELTARGET: + ((Rotorgear*)obj)->setRotorRelTarget(lval); break; case REVERSE_THRUST: ((Jet*)obj)->setReverse(lval != 0); break; case BOOST: ((PistonEngine*)((Thruster*)obj)->getEngine())->setBoost(lval); diff --git a/src/FDM/YASim/ControlMap.hpp b/src/FDM/YASim/ControlMap.hpp index aadef7a21..05d2cbb67 100644 --- a/src/FDM/YASim/ControlMap.hpp +++ b/src/FDM/YASim/ControlMap.hpp @@ -15,7 +15,7 @@ public: INCIDENCE, FLAP0, FLAP1, SLAT, SPOILER, VECTOR, BOOST, CASTERING, PROPPITCH, PROPFEATHER, COLLECTIVE, CYCLICAIL, CYCLICELE, ROTORENGINEON, - ROTORBRAKE, + ROTORBRAKE, ROTORENGINEMAXRELTORQUE, ROTORELTARGET, REVERSE_THRUST, WASTEGATE, WINCHRELSPEED, HITCHOPEN, PLACEWINCH, FINDAITOW}; diff --git a/src/FDM/YASim/FGFDM.cpp b/src/FDM/YASim/FGFDM.cpp index 641232c14..c3c00bcdf 100644 --- a/src/FDM/YASim/FGFDM.cpp +++ b/src/FDM/YASim/FGFDM.cpp @@ -949,6 +949,9 @@ int FGFDM::parseOutput(const char* name) if(eq(name, "CYCLICELE")) return ControlMap::CYCLICELE; if(eq(name, "ROTORGEARENGINEON")) return ControlMap::ROTORENGINEON; if(eq(name, "ROTORBRAKE")) return ControlMap::ROTORBRAKE; + if(eq(name, "ROTORENGINEMAXRELTORQUE")) + return ControlMap::ROTORENGINEMAXRELTORQUE; + if(eq(name, "ROTORELTARGET")) return ControlMap::ROTORELTARGET; if(eq(name, "REVERSE_THRUST")) return ControlMap::REVERSE_THRUST; if(eq(name, "WASTEGATE")) return ControlMap::WASTEGATE; if(eq(name, "WINCHRELSPEED")) return ControlMap::WINCHRELSPEED; diff --git a/src/FDM/YASim/Rotor.cpp b/src/FDM/YASim/Rotor.cpp index 717cbb110..0e59f6610 100644 --- a/src/FDM/YASim/Rotor.cpp +++ b/src/FDM/YASim/Rotor.cpp @@ -184,6 +184,13 @@ void Rotor::inititeration(float dt,float omegarel,float ddt_omegarel,float *rot) Math::mul3(Math::sin(_roll),side,help); Math::add3(_normal_with_yaw_roll,help,_normal_with_yaw_roll); + + //update balance + if ((_balance1*_balance2 < 0.97) && (_balance1>-1)) + { + _balance1-=(0.97-_balance1*_balance2)*(0.97-_balance1*_balance2)*0.00001; + if (_balance1<-1) _balance1=-1; + } } float Rotor::calcStall(float incidence,float speed) @@ -247,11 +254,11 @@ int Rotor::getValueforFGSet(int j,char *text,float *f) if (j==0) { sprintf(text,"/rotors/%s/cone-deg", _name); - *f=( ((Rotorpart*)getRotorpart(0))->getrealAlpha() + *f=(_balance1>-1)?( ((Rotorpart*)getRotorpart(0))->getrealAlpha() +((Rotorpart*)getRotorpart(1*(_number_of_parts>>2)))->getrealAlpha() +((Rotorpart*)getRotorpart(2*(_number_of_parts>>2)))->getrealAlpha() +((Rotorpart*)getRotorpart(3*(_number_of_parts>>2)))->getrealAlpha() - )/4*180/pi; + )/4*180/pi:0; } else if (j==1) @@ -260,7 +267,7 @@ int Rotor::getValueforFGSet(int j,char *text,float *f) _roll = ( ((Rotorpart*)getRotorpart(0))->getrealAlpha() -((Rotorpart*)getRotorpart(2*(_number_of_parts>>2)))->getrealAlpha() )/2*(_ccw?-1:1); - *f=_roll *180/pi; + *f=(_balance1>-1)?_roll *180/pi:0; } else if (j==2) @@ -269,7 +276,7 @@ int Rotor::getValueforFGSet(int j,char *text,float *f) _yaw=( ((Rotorpart*)getRotorpart(1*(_number_of_parts>>2)))->getrealAlpha() -((Rotorpart*)getRotorpart(3*(_number_of_parts>>2)))->getrealAlpha() )/2; - *f=_yaw*180/pi; + *f=(_balance1>-1)?_yaw*180/pi:0; } else if (j==3) @@ -350,6 +357,16 @@ void Rotorgear::setEngineOn(int value) _engineon=value; } +void Rotorgear::setRotorEngineMaxRelTorque(float lval) +{ + fgGetNode("/rotors/gear/max-rel-torque", true)->setDoubleValue(lval); +} + +void Rotorgear::setRotorRelTarget(float lval) +{ + fgGetNode("/rotors/gear/target-rel-rpm", true)->setDoubleValue(lval); +} + void Rotor::setAlpha0(float f) { _alpha0=f; @@ -1358,13 +1375,16 @@ 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->getDoubleValue("target-rel-rpm",1); if (_engineon) { - max_torque_of_engine=_max_power_engine; - float df=1-omegarel; + float max_rel_torque=node->getDoubleValue("max-rel-torque",1); + 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_torque_of_engine = df * _max_power_engine*max_rel_torque; } total_torque*=-1; _ddt_omegarel=0; @@ -1391,7 +1411,7 @@ void Rotorgear::calcForces(float* torqueOut) //change the rotation of the rotors if ((max_torque_of_enginetotal_torque)&&(omegarel<1)) + ||((max_torque_of_engine>total_torque)&&(omegarelcompile(); } + fgGetNode("/rotors/gear/target-rel-rpm", true)->setDoubleValue(1); + fgGetNode("/rotors/gear/max-rel-torque", true)->setDoubleValue(1); } void Rotorgear::getDownWash(float *pos, float * v_heli, float *downwash) diff --git a/src/FDM/YASim/Rotor.hpp b/src/FDM/YASim/Rotor.hpp index 1cc3b38f3..1b31df0ab 100644 --- a/src/FDM/YASim/Rotor.hpp +++ b/src/FDM/YASim/Rotor.hpp @@ -243,6 +243,8 @@ public: void setEngineOn(int value); int getEngineon(); void setRotorBrake(float lval); + void setRotorEngineMaxRelTorque(float lval); + void setRotorRelTarget(float lval); float getYasimDragFactor() { return _yasimdragfactor;} float getYasimLiftFactor() { return _yasimliftfactor;} float getMaxPowerEngine() { return _max_power_engine;}