X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2FUFO.hxx;h=d22832f70d56f25f12eb88ad692566b58eb8ab02;hb=bb2b03c7e392e107aeaf7dbc4eecc59064b28512;hp=0a16d455dc4b8c6fef905500c24e8697374a52dd;hpb=330154263ef80a1c72d57f11aeed56d80096b50f;p=flightgear.git diff --git a/src/FDM/UFO.hxx b/src/FDM/UFO.hxx index 0a16d455d..d22832f70 100644 --- a/src/FDM/UFO.hxx +++ b/src/FDM/UFO.hxx @@ -24,23 +24,45 @@ #ifndef _UFO_HXX #define _UFO_HXX - #include "flight.hxx" class FGUFO: public FGInterface { - double Throttle; - double Aileron; - double Elevator; - double Elevator_Trim; - double Rudder; - SGPropertyNode *Speed_Max; +private: + + class lowpass { + private: + static double _dt; + double _coeff; + double _last; + bool _initialized; + public: + lowpass(double coeff) : _coeff(coeff), _initialized(false) {} + static inline void set_delta(double dt) { _dt = dt; } + double filter(double value) { + if (!_initialized) { + _initialized = true; + return _last = value; + } + double c = _dt / (_coeff + _dt); + return _last = value * c + _last * (1.0 - c); + } + }; + + lowpass *Throttle; + lowpass *Aileron; + lowpass *Elevator; + lowpass *Rudder; + lowpass *Aileron_Trim; + lowpass *Elevator_Trim; + lowpass *Rudder_Trim; + SGPropertyNode_ptr Speed_Max; public: FGUFO( double dt ); ~FGUFO(); - // reset flight params to a specific position + // reset flight params to a specific position void init(); // update position based on inputs, positions, velocities, etc.