| 1 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 | |
| 3 | Header: FGActuator.h |
| 4 | Author: Jon Berndt |
| 5 | Date started: 21 February 2007 |
| 6 | |
| 7 | ------------- Copyright (C) 2006 Jon S. Berndt ([email protected]) ------------- |
| 8 | |
| 9 | This program is free software; you can redistribute it and/or modify it under |
| 10 | the terms of the GNU Lesser General Public License as published by the Free |
| 11 | Software Foundation; either version 2 of the License, or (at your option) any |
| 12 | later version. |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 16 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
| 17 | details. |
| 18 | |
| 19 | You should have received a copy of the GNU Lesser General Public License along |
| 20 | with this program; if not, write to the Free Software Foundation, Inc., 59 |
| 21 | Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | |
| 23 | Further information about the GNU Lesser General Public License can also be |
| 24 | found on the world wide web at http://www.gnu.org. |
| 25 | |
| 26 | HISTORY |
| 27 | -------------------------------------------------------------------------------- |
| 28 | |
| 29 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 30 | SENTRY |
| 31 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 32 | |
| 33 | #ifndef FGACTUATOR_H |
| 34 | #define FGACTUATOR_H |
| 35 | |
| 36 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 37 | INCLUDES |
| 38 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 39 | |
| 40 | #include "FGFCSComponent.h" |
| 41 | |
| 42 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 43 | FORWARD DECLARATIONS |
| 44 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 45 | |
| 46 | namespace JSBSim { |
| 47 | |
| 48 | class FGFCS; |
| 49 | |
| 50 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 51 | CLASS DOCUMENTATION |
| 52 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 53 | |
| 54 | /** Encapsulates an Actuator component for the flight control system. |
| 55 | The actuator can be modeled as a "perfect actuator", with the Output |
| 56 | being set directly to the input. The actuator can be made more "real" |
| 57 | by specifying any/all of the following additional effects that can be |
| 58 | applied to the actuator. In order of application to the input signal, |
| 59 | these are: |
| 60 | |
| 61 | - System lag (input lag, really) |
| 62 | - Rate limiting |
| 63 | - Deadband |
| 64 | - Hysteresis (mechanical hysteresis) |
| 65 | - Bias (mechanical bias) |
| 66 | - Position limiting ("hard stops") |
| 67 | |
| 68 | There are also several malfunctions that can be applied to the actuator |
| 69 | by setting a property to true or false (or 1 or 0). |
| 70 | |
| 71 | Rate limits can be specified either as a single number or property. If a |
| 72 | single <rate_limit> is supplied (with no "sense" attribute) then the |
| 73 | actuator is rate limited at +/- the specified rate limit. If the |
| 74 | <rate_limit> element is supplied with a "sense" attribute of either |
| 75 | "incr[easing]" or "decr[easing]" then the actuator is limited to the |
| 76 | provided numeric or property value) exactly as provided. |
| 77 | |
| 78 | Lag filter's numerical integration assumes that the lag parameter is |
| 79 | constant. So a continuously varying parameter via a property will introduce |
| 80 | a non negligible error that will accumulate as the simulation progresses. |
| 81 | |
| 82 | Syntax: |
| 83 | |
| 84 | @code |
| 85 | <actuator name="name"> |
| 86 | <input> {[-]property} </input> |
| 87 | <lag> {property name | value} </lag> |
| 88 | [<rate_limit> {property name | value} </rate_limit>] |
| 89 | [<rate_limit sense="incr"> {property name | value} </rate_limit> |
| 90 | <rate_limit sense="decr"> {property name | value} </rate_limit>] |
| 91 | <bias> number </bias> |
| 92 | <deadband_width> number </deadband_width> |
| 93 | <hysteresis_width> number </hysteresis_width> |
| 94 | [<clipto> |
| 95 | <min> {property name | value} </min> |
| 96 | <max> {property name | value} </max> |
| 97 | </clipto>] |
| 98 | [<output> {property} </output>] |
| 99 | </actuator> |
| 100 | @endcode |
| 101 | |
| 102 | Example: |
| 103 | |
| 104 | @code |
| 105 | <actuator name="fcs/gimbal_pitch_position_radians"> |
| 106 | <input> fcs/gimbal_pitch_command </input> |
| 107 | <lag> 60 </lag> |
| 108 | <rate_limit> 0.085 </rate_limit> <!-- 0.085 radians/sec --> |
| 109 | <bias> 0.002 </bias> |
| 110 | <deadband_width> 0.002 </deadband_width> |
| 111 | <hysteresis_width> 0.05 </hysteresis_width> |
| 112 | <clipto> <!-- +/- 0.17 radians --> |
| 113 | <min> -0.17 </min> |
| 114 | <max> 0.17 </max> |
| 115 | </clipto> |
| 116 | </actuator> |
| 117 | @endcode |
| 118 | |
| 119 | @author Jon S. Berndt |
| 120 | @version $Revision: 1.20 $ |
| 121 | */ |
| 122 | |
| 123 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 124 | CLASS DECLARATION |
| 125 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 126 | |
| 127 | class FGActuator : public FGFCSComponent |
| 128 | { |
| 129 | public: |
| 130 | /// Constructor |
| 131 | FGActuator(FGFCS* fcs, Element* element); |
| 132 | /// Destructor |
| 133 | ~FGActuator(); |
| 134 | |
| 135 | /** This function processes the input. |
| 136 | It calls private functions if needed to perform the hysteresis, lag, |
| 137 | limiting, etc. functions. */ |
| 138 | bool Run (void) override; |
| 139 | void ResetPastStates(void) override; |
| 140 | |
| 141 | // these may need to have the bool argument replaced with a double |
| 142 | /** This function fails the actuator to zero. The motion to zero |
| 143 | will flow through the lag, hysteresis, and rate limiting |
| 144 | functions if those are activated. */ |
| 145 | void SetFailZero(bool set) {fail_zero = set;} |
| 146 | void SetFailHardover(bool set) {fail_hardover = set;} |
| 147 | void SetFailStuck(bool set) {fail_stuck = set;} |
| 148 | |
| 149 | bool GetFailZero(void) const {return fail_zero;} |
| 150 | bool GetFailHardover(void) const {return fail_hardover;} |
| 151 | bool GetFailStuck(void) const {return fail_stuck;} |
| 152 | bool IsSaturated(void) const {return saturated;} |
| 153 | |
| 154 | private: |
| 155 | //double span; |
| 156 | double bias; |
| 157 | FGParameter* rate_limit_incr; |
| 158 | FGParameter* rate_limit_decr; |
| 159 | double hysteresis_width; |
| 160 | double deadband_width; |
| 161 | FGParameter* lag; |
| 162 | double lagVal; |
| 163 | double ca; // lag filter coefficient "a" |
| 164 | double cb; // lag filter coefficient "b" |
| 165 | double PreviousOutput; |
| 166 | double PreviousHystOutput; |
| 167 | double PreviousRateLimOutput; |
| 168 | double PreviousLagInput; |
| 169 | double PreviousLagOutput; |
| 170 | bool fail_zero; |
| 171 | bool fail_hardover; |
| 172 | bool fail_stuck; |
| 173 | bool initialized; |
| 174 | bool saturated; |
| 175 | |
| 176 | void Hysteresis(void); |
| 177 | void Lag(void); |
| 178 | void RateLimit(void); |
| 179 | void Deadband(void); |
| 180 | void Bias(void); |
| 181 | |
| 182 | void bind(Element* el) override; |
| 183 | |
| 184 | void InitializeLagCoefficients(); |
| 185 | |
| 186 | void Debug(int from) override; |
| 187 | }; |
| 188 | } |
| 189 | #endif |