40 #include "FGLinearActuator.h"
41 #include "math/FGParameterValue.h"
54 CheckInputNodes(1, 1, element);
60 if (ptrSet && ptrSet->IsConstant()) {
61 set = ptrSet->GetValue() >= 0.5;
69 if (ptrReset && ptrReset->IsConstant()) {
70 reset = ptrReset->GetValue() >= 0.5;
78 if (ptrVersus && ptrVersus->IsConstant()) {
79 versus = ptrVersus->GetValue();
87 if (ptrBias && ptrBias->IsConstant()) {
88 bias = ptrBias->GetValue();
95 cout <<
"FGLinearActuator::Run " << InputNodes[0]->GetNameWithSign()
96 <<
" <module> parameter is forced from " << module
97 <<
" value to 1.0 value" << endl;
104 if (hysteresis < 0) {
105 cout <<
"FGLinearActuator::Run " << InputNodes[0]->GetNameWithSign()
106 <<
" <hysteresis> parameter is forced from " << hysteresis
107 <<
" value to 0.0 value" << endl;
115 double denom = 2.00 + dt*lag;
116 ca = dt * lag / denom;
117 cb = (2.00 - dt * lag) / denom;
118 previousLagInput = previousLagOutput = 0.0;
121 cout <<
"FGLinearActuator::Run " << InputNodes[0]->GetNameWithSign()
122 <<
" <lag> parameter is forced from "
123 << lag <<
" value to 0.0 value" << endl;
131 if (rate <= 0 || rate > 1.0) {
132 cout <<
"FGLinearActuator::Run " << InputNodes[0]->GetNameWithSign()
133 <<
" <rate> parameter is forced from " << rate
134 <<
" value to 0.5 value" << endl;
158 if (ptrSet && !ptrSet->IsConstant()) set = ptrSet->GetValue() >= 0.5;
159 if (ptrReset && !ptrReset->IsConstant()) reset = ptrReset->GetValue() >= 0.5;
169 Input = InputNodes[0]->getDoubleValue() - inputLast;
170 double inputDelta = Input - inputMem;
171 if (abs(inputDelta) >= hysteresis) {
172 if (ptrVersus && !ptrVersus->IsConstant()) {
173 versus = ptrVersus->GetValue();
176 }
else if (versus <= -0.5) {
180 if (abs(inputDelta) <= (module * rate)) {
181 if (inputDelta > 0.0) {
183 }
else if (inputDelta < 0.0) {
187 if ((versus == 0) || (versus == direction)) {
189 if (abs(inputDelta) >= (module*rate)) {
195 }
else if ((versus != 0) && (direction != 0) && (versus != direction)) {
196 inputLast += inputDelta;
200 if (ptrBias && !ptrBias->IsConstant()) {
201 bias = ptrBias->GetValue();
203 Output = gain * (bias + inputMem + module*countSpin);
207 double input = Output;
208 Output = ca * (input + previousLagInput) + previousLagOutput * cb;
209 previousLagInput = input;
210 previousLagOutput = Output;
236 void FGLinearActuator::Debug(
int from)
238 if (debug_lvl <= 0)
return;
242 cout <<
" INPUT: " << InputNodes[0]->GetNameWithSign() << endl;
243 cout <<
" inputMem: " << inputMem << endl;
244 cout <<
" bias: " << bias << endl;
245 cout <<
" module: " << module << endl;
246 cout <<
" hysteresis: " << hysteresis << endl;
247 cout <<
" rate: " << rate << endl;
248 cout <<
" versus: " << versus << endl;
249 cout <<
" direction: " << direction << endl;
250 cout <<
" countSpin: " << countSpin << endl;
251 cout <<
" Lag: " << lag << endl;
252 cout <<
" Gain: " << gain << endl;
253 cout <<
" set: " << set << endl;
254 cout <<
" reset: " << reset << endl;
255 for (
auto node: OutputNodes)
256 cout <<
" OUTPUT: " << node->GetName() << endl;
259 if (debug_lvl & 2 ) {
260 if (from == 0) cout <<
"Instantiated: FGLinearActuator" << endl;
261 if (from == 1) cout <<
"Destroyed: FGLinearActuator" << endl;
263 if (debug_lvl & 4 ) {
265 if (debug_lvl & 8 ) {
267 if (debug_lvl & 16) {
269 if (debug_lvl & 64) {