| 1 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 | |
| 3 | Header: FGLinearActuator.h |
| 4 | Author: Adriano Bassignana |
| 5 | Date started: 2019-01-02 |
| 6 | |
| 7 | ------------- Copyright (C) 2019 A. Bassignana ------------- |
| 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 FGLINEARACTUATOR_H |
| 34 | #define FGLINEARACTUATOR_H |
| 35 | |
| 36 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 37 | INCLUDES |
| 38 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 39 | |
| 40 | #include "FGFCSComponent.h" |
| 41 | |
| 42 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 43 | FORWARD DECLARATIONS |
| 44 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 45 | |
| 46 | namespace JSBSim { |
| 47 | |
| 48 | class Element; |
| 49 | |
| 50 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 51 | CLASS DOCUMENTATION |
| 52 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 53 | |
| 54 | /** Models a flight control system summing component. |
| 55 | |
| 56 | Linear actuators typically operate by conversion of rotary motion into |
| 57 | linear motion. The linear_actuator component is described in the Wikipedia |
| 58 | link: https://en.wikipedia.org/wiki/Linear_actuator. |
| 59 | |
| 60 | Linear actuators converts a rotation into a linear movement or a multiturn |
| 61 | rotation. For the conversion it is necessary to declare a module that is |
| 62 | defined by the difference of the maximum and minimum value Input. |
| 63 | |
| 64 | List of parameters: |
| 65 | - input: Value to be transformed |
| 66 | - Output: Output value following the following rule it is the result of |
| 67 | gain * (bias + Input + module*countSpin) |
| 68 | - CountSpin is the number of complete rotations calculated by this device |
| 69 | - gain: Apply a multiplication coefficient to the output value, the default |
| 70 | value is 1.0 |
| 71 | - bias: Value that is added to the input value |
| 72 | - module: Difference between the maximum and minimum value of Input. Default |
| 73 | is 1.0. |
| 74 | - hysteresis: Defines the sensitivity of the actuator according to the |
| 75 | input. |
| 76 | |
| 77 | For example, if the actuator has a module of 360 and if the hysteresis is |
| 78 | 5.0, the actuator, with gain = 1, will output a value equal to: 5, 10...355, |
| 79 | 360, 365, 370 etc. This parameter allows to simulate stepper motors. The |
| 80 | default value is 0.1 It is not advisable to have this parameter too small |
| 81 | (less than 0.1) as it could make the CPU load heavier. |
| 82 | |
| 83 | - versus: Direction of rotation if fixed. The versus allows to obtain a |
| 84 | mechanism similar to the tick of a clock. The default value |
| 85 | is 0. |
| 86 | |
| 87 | If the value is zero, the verse is automatically obtained according to |
| 88 | variation of the input data. |
| 89 | |
| 90 | If set to a value > 0.5 the verse is increasing, i.e. the output changes |
| 91 | only if the Input value is greater than the previous one. |
| 92 | |
| 93 | If set to a value < -0.5 the output is changed only if the next value is |
| 94 | lower than the previous one. |
| 95 | |
| 96 | With this parameter allows to easily obtain a "step counter". |
| 97 | - rate: To define when the rotation is complete, the differential criterion |
| 98 | is used. |
| 99 | |
| 100 | For example, if the rotation is clockwise and the module is 360, the |
| 101 | revolution will be complete when the input value changes from 360 to 0. |
| 102 | |
| 103 | When this happens a counter increases the output of the value of the module. |
| 104 | As a way the system keeps track of the number of rotations. Rate defines the |
| 105 | sensitivity of the system. |
| 106 | |
| 107 | If a difficulty in determining the rotation is observed during the tests, |
| 108 | this parameter must be modified with a positive value not exceeding 1. |
| 109 | The default value is 0.3 |
| 110 | |
| 111 | - set: If the absolute value is greater or equal 0.5, the output changes |
| 112 | according to the input. |
| 113 | |
| 114 | If its value is lower 0.5, the output remains constant (the system stores |
| 115 | the data). The use of this parameter allows to simulate the behavior of a |
| 116 | servomechanism that is blocked, for example due to a power failure. |
| 117 | |
| 118 | - Reset: if the absolute value is greater or equal 0.5, the output returns |
| 119 | to zero and reset internal data. |
| 120 | - lag: Activate a lag filter on exit if the value is greater 0.0 the lag is |
| 121 | active. |
| 122 | |
| 123 | Be very careful to use the lag filter in case you use two or more |
| 124 | "linear_actuator" in cascade; it may happen that the smoothing effect due to |
| 125 | the lag in the output value can mislead the rotation determination |
| 126 | system. The effect is similar to that of a loose coupling of a rack and |
| 127 | pinion. Therefore, with these types of coupling, place lag only at the last |
| 128 | stage. |
| 129 | |
| 130 | @code |
| 131 | <linear_actuator name="{string}"> |
| 132 | <input> {property name} </input> |
| 133 | <bias> {property name | value} </bias> |
| 134 | <module> {value} </module> |
| 135 | <hysteresis> {value} </hysteresis> |
| 136 | <rate> {value} </rate> |
| 137 | <versus> {property name | value} </versus> |
| 138 | <gain> {value} </gain> |
| 139 | <set> {property name | value} </set> |
| 140 | <reset> {property name | value} </reset> |
| 141 | <lag> {value} </lag> |
| 142 | <output> {property name} </output> |
| 143 | </linear_actuator> |
| 144 | @endcode |
| 145 | |
| 146 | Mechanical counter: |
| 147 | |
| 148 | It is the typical mechanism used to count the kilometers traveled by a car, |
| 149 | for example the value of the digit changes quickly at the beginning of the |
| 150 | km. Module 10 indicates that the count goes from 0 to 9 after one complete |
| 151 | revolution. |
| 152 | |
| 153 | @code |
| 154 | |
| 155 | <linear_actuator name="systems/gauges/PHI/indicator/digit3AW"> |
| 156 | <input>systems/gauges/PHI/indicator/digit3A</input> |
| 157 | <module>10</module> |
| 158 | <rate>0.2</rate> |
| 159 | <lag>8.0</lag> |
| 160 | </linear_actuator> |
| 161 | |
| 162 | @endcode |
| 163 | |
| 164 | The gyrocompass from a rotation with a value from 0 to 259 degrees. When it |
| 165 | returns to zero, if it is made more realistic by means of an actuator, there |
| 166 | is a jump of the disk which performs a complete rotation of 360 °. By |
| 167 | activating a linear actuator followed by an actuator it is possible to obtain |
| 168 | a very realistic result. |
| 169 | |
| 170 | @code |
| 171 | |
| 172 | <linear_actuator name="gyrocompass-magnetic-deg-linear"> |
| 173 | <input>gyrocompass-magnetic-deg</input> |
| 174 | <module>360</module> |
| 175 | </linear_actuator> |
| 176 | |
| 177 | <actuator name="gyrocompass-magnetic-deg-linear-actuator"> |
| 178 | <input>gyrocompass-magnetic-deg-linear</input> |
| 179 | <lag>2.0</lag> |
| 180 | <rate_limit>100</rate_limit> |
| 181 | <bias>0.1</bias> |
| 182 | <deadband_width>1</deadband_width> |
| 183 | <hysteresis_width>0.5</hysteresis_width> |
| 184 | </actuator> |
| 185 | |
| 186 | @endcode |
| 187 | |
| 188 | Count steps with memory: |
| 189 | |
| 190 | If you use a button or switch to advance a mechanism, we can build a step |
| 191 | counter. In this case the module is 1 and the rate 1. The verse is positive |
| 192 | (increasing). A pulse counter (for example the count of the switched-on |
| 193 | states of a switch with values 1 and 0), the module must be 1 in that each |
| 194 | step must advance its value by one unit. The verse is "1" because it has to |
| 195 | accept only increasing values (as in a clock escapement). The gain is 0.5 |
| 196 | because, in similitude to an escapement of a clock, the gear makes two steps |
| 197 | for a complete rotation of the pendulum. |
| 198 | |
| 199 | @code |
| 200 | |
| 201 | <linear_actuator name="systems/gauges/PHI/doppler/switch-increase-summer"> |
| 202 | <input>systems/gauges/PHI/doppler/switch-increase</input> |
| 203 | <module>1</module> |
| 204 | <rate>1</rate> |
| 205 | <versus>1</versus> |
| 206 | <gain>0.5</gain> |
| 207 | <lag>0.0</lag> |
| 208 | <reset>systems/gauges/PHI/doppler/test_reset_off</reset> |
| 209 | </linear_actuator> |
| 210 | |
| 211 | @endcode |
| 212 | |
| 213 | @author Adriano Bassignana |
| 214 | */ |
| 215 | |
| 216 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 217 | CLASS DECLARATION |
| 218 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 219 | |
| 220 | class FGLinearActuator : public FGFCSComponent |
| 221 | { |
| 222 | public: |
| 223 | /** Constructor. |
| 224 | @param fcs a pointer to the parent FGFCS object. |
| 225 | @param element a pointer to the configuration file node. */ |
| 226 | FGLinearActuator(FGFCS* fcs, Element* element); |
| 227 | /// Destructor |
| 228 | ~FGLinearActuator(); |
| 229 | |
| 230 | /// The execution method for this FCS component. |
| 231 | bool Run(void) override; |
| 232 | |
| 233 | private: |
| 234 | FGParameter_ptr ptrSet; |
| 235 | bool set = true; |
| 236 | FGParameter_ptr ptrReset; |
| 237 | bool reset = false; |
| 238 | int direction = 0; |
| 239 | int countSpin = 0; |
| 240 | int versus = 0; |
| 241 | FGParameter_ptr ptrVersus; |
| 242 | double bias = 0.0; |
| 243 | FGParameter_ptr ptrBias; |
| 244 | double inputLast = 0.0; |
| 245 | double inputMem = 0.0; |
| 246 | double module = 1.0; |
| 247 | double hysteresis = 0.1; |
| 248 | double input = 1.0; |
| 249 | double rate = 0.3; |
| 250 | double gain = 1.0; |
| 251 | double lag = 0.0; |
| 252 | double previousLagInput; |
| 253 | double previousLagOutput; |
| 254 | double ca; // lag filter coefficient "a" |
| 255 | double cb; // lag filter coefficient "b" |
| 256 | |
| 257 | void Debug(int from) override; |
| 258 | }; |
| 259 | } |
| 260 | #endif |