| 1 | // UFO.hxx -- interface to the "UFO" flight model |
| 2 | // |
| 3 | // Written by Curtis Olson, started October 1999. |
| 4 | // Slightly modified from MagicCarpet.hxx by Jonathan Polley, April 2002 |
| 5 | // |
| 6 | // Copyright (C) 1999-2002 Curtis L. Olson - http://www.flightgear.org/~curt |
| 7 | // |
| 8 | // This program is free software; you can redistribute it and/or |
| 9 | // modify it under the terms of the GNU General Public License as |
| 10 | // published by the Free Software Foundation; either version 2 of the |
| 11 | // License, or (at your option) any later version. |
| 12 | // |
| 13 | // This program is distributed in the hope that it will be useful, but |
| 14 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | // General Public License for more details. |
| 17 | // |
| 18 | // You should have received a copy of the GNU General Public License |
| 19 | // along with this program; if not, write to the Free Software |
| 20 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 21 | // |
| 22 | |
| 23 | |
| 24 | #ifndef _UFO_HXX |
| 25 | #define _UFO_HXX |
| 26 | |
| 27 | #include "flight.hxx" |
| 28 | |
| 29 | |
| 30 | class FGUFO : public FGInterface |
| 31 | { |
| 32 | private: |
| 33 | class lowpass |
| 34 | { |
| 35 | private: |
| 36 | static double _dt; |
| 37 | double _coeff; |
| 38 | double _last; |
| 39 | bool _initialized; |
| 40 | |
| 41 | public: |
| 42 | lowpass(double coeff) : _coeff(coeff), _initialized(false) {} |
| 43 | static inline void set_delta(double dt) { _dt = dt; } |
| 44 | double filter(double value) { |
| 45 | if (!_initialized) { |
| 46 | _initialized = true; |
| 47 | return _last = value; |
| 48 | } |
| 49 | double c = _dt / (_coeff + _dt); |
| 50 | return _last = value * c + _last * (1.0 - c); |
| 51 | } |
| 52 | }; |
| 53 | |
| 54 | lowpass *Throttle; |
| 55 | lowpass *Aileron; |
| 56 | lowpass *Elevator; |
| 57 | lowpass *Rudder; |
| 58 | lowpass *Aileron_Trim; |
| 59 | lowpass *Elevator_Trim; |
| 60 | lowpass *Rudder_Trim; |
| 61 | SGPropertyNode_ptr Speed_Max; |
| 62 | |
| 63 | public: |
| 64 | FGUFO( double dt ); |
| 65 | ~FGUFO(); |
| 66 | |
| 67 | // Subsystem API. |
| 68 | void init() override; |
| 69 | void update(double dt) override; |
| 70 | |
| 71 | // Subsystem identification. |
| 72 | static const char* staticSubsystemClassId() { return "ufo"; } |
| 73 | }; |
| 74 | |
| 75 | #endif // _UFO_HXX |