|
From: <fli...@li...> - 2026-05-18 07:50:06
|
unknown user pushed a commit to branch next
in repository flightgear.
The following commit(s) were added to refs/heads/next by this push:
new 7f0d77359 Edit turn_indicator.cxx
7f0d77359 is described below
SF URL: http://sourceforge.net/p/flightgear/flightgear/ci/7f0d773599501c1ecf64749a775c71acf1a18d81/
Commit: 7f0d773599501c1ecf64749a775c71acf1a18d81
Author: Mariusz Matuszek
Committer: James Turner
AuthorDate: Mon May 18 09:49:56 2026 +0200
Edit turn_indicator.cxx
---
src/Instrumentation/turn_indicator.cxx | 57 ++++++++++++++++++++++++----------
src/Instrumentation/turn_indicator.hxx | 16 ++++++----
2 files changed, 50 insertions(+), 23 deletions(-)
diff --git a/src/Instrumentation/turn_indicator.cxx b/src/Instrumentation/turn_indicator.cxx
index 9aacede77..665966512 100644
--- a/src/Instrumentation/turn_indicator.cxx
+++ b/src/Instrumentation/turn_indicator.cxx
@@ -33,9 +33,12 @@ TurnIndicator::TurnIndicator ( SGPropertyNode *node) :
setDefaultPowerSupplyPath("/systems/electrical/outputs/turn-coordinator");
}
+ _max_out_degsec = node->getDoubleValue("max-indicated-degsec", 6.0);
+
SGPropertyNode* gyro_cfg = node->getChild("gyro", 0, true);
_gyro_spin_up = gyro_cfg->getDoubleValue("spin-up-sec", 4.0);
_gyro_spin_down = gyro_cfg->getDoubleValue("spin-down-sec", 180.0);
+ _gyro_spin_valid_from = gyro_cfg->getDoubleValue("gyro-spin-valid-norm", 0.93);
readConfig(node, "turn-indicator");
}
@@ -53,14 +56,18 @@ TurnIndicator::init ()
_roll_rate_node = fgGetNode("/orientation/roll-rate-degps", true);
_yaw_rate_node = fgGetNode("/orientation/yaw-rate-degps", true);
_rate_out_node = node->getChild("indicated-turn-rate", 0, true);
- _spin_node = node->getChild("spin", 0, true);
+ _is_valid_node = node->getChild("is-valid", 0, true);
SGPropertyNode* gyro_node = node->getChild("gyro", 0, true);
+ _spin_node = gyro_node->getChild("spin", 0.0, true);
_gyro_spin_up_node = gyro_node->getChild("spin-up-sec", 0, true);
_gyro_spin_down_node = gyro_node->getChild("spin-down-sec", 0, true);
+ _gyro_spin_valid_from_node = gyro_node->getChild("gyro-spin-valid-norm", 0, true);
if (!_gyro_spin_up_node->hasValue())
_gyro_spin_up_node->setDoubleValue(_gyro_spin_up);
if (!_gyro_spin_down_node->hasValue())
_gyro_spin_down_node->setDoubleValue(_gyro_spin_down);
+ if (!_gyro_spin_valid_from_node->hasValue())
+ _gyro_spin_valid_from_node->setDoubleValue(_gyro_spin_valid_from);
initServicePowerProperties(node);
@@ -77,7 +84,7 @@ TurnIndicator::reinit ()
void
TurnIndicator::update (double dt)
{
- // Get the spin from the gyro
+ // Get the spin from the gyro
_gyro.set_power_norm(isServiceableAndPowered());
_gyro.set_spin_up(_gyro_spin_up_node->getDoubleValue());
_gyro.set_spin_down(_gyro_spin_down_node->getDoubleValue());
@@ -86,24 +93,40 @@ TurnIndicator::update (double dt)
double spin = _gyro.get_spin_norm();
_spin_node->setDoubleValue( spin );
- // Calculate the indicated rate
- double factor = 1.0 - ((1.0 - spin) * (1.0 - spin) * (1.0 - spin));
- double rate = ((_roll_rate_node->getDoubleValue() / 20.0) +
- (_yaw_rate_node->getDoubleValue() / 3.0));
+ //Set 'indication is valid'
+ _is_valid_node->setBoolValue(spin >= _gyro_spin_valid_from_node->getDoubleValue());
+
+ // Calculate gyro responsiveness
+ double gyro_responsiveness_factor = 1.0 - pow((1.0 - spin), 3);
+
+ // Calculate the indicated turn rate
+ const double instrument_yaw_sensitivity = 1.0; // TODO: make it configurable?
+ const double instrument_roll_sensitivity = 0.15; // TODO: make it configurable?
+
+ double yaw_rate = instrument_yaw_sensitivity * _yaw_rate_node->getDoubleValue();
+ double roll_rate = instrument_roll_sensitivity * _roll_rate_node->getDoubleValue();
+
+ // Get sign of the dominant vector
+ double sign = (fabs(roll_rate) > fabs(yaw_rate) ? roll_rate : yaw_rate);
+
+ // Add vectors (always perpendicular)
+ double indicated_turn_rate = sqrt(
+ pow(gyro_responsiveness_factor * yaw_rate, 2) +
+ pow(gyro_responsiveness_factor * roll_rate, 2));
+
+ indicated_turn_rate = std::copysign(indicated_turn_rate, sign);
+
+ // Clamp the output
+ indicated_turn_rate = std::clamp(indicated_turn_rate, -_max_out_degsec, _max_out_degsec);
- // Clamp the rate
- if (rate < -2.5)
- rate = -2.5;
- else if (rate > 2.5)
- rate = 2.5;
+ // Lag left, based on gyro spin
+ indicated_turn_rate = indicated_turn_rate - (1.0 - gyro_responsiveness_factor) * _max_out_degsec;
- // Lag left, based on gyro spin
- rate = -2.5 + (factor * (rate + 2.5));
- rate = fgGetLowPass(_last_rate, rate, dt*RESPONSIVENESS);
- _last_rate = rate;
+ // Dampen instrument response
+ indicated_turn_rate = fgGetLowPass(_last_rate, indicated_turn_rate, dt * RESPONSIVENESS);
- // Publish the indicated rate
- _rate_out_node->setDoubleValue(rate);
+ _last_rate = indicated_turn_rate;
+ _rate_out_node->setDoubleValue(indicated_turn_rate);
}
// end of turn_indicator.cxx
diff --git a/src/Instrumentation/turn_indicator.hxx b/src/Instrumentation/turn_indicator.hxx
index 0f502f61c..9ba250e20 100644
--- a/src/Instrumentation/turn_indicator.hxx
+++ b/src/Instrumentation/turn_indicator.hxx
@@ -22,7 +22,7 @@
* Input properties:
*
* /instrumentation/"name"/serviceable
- * /instrumentation/"name"/spin
+ * /instrumentation/"name"/gyro/spin
* /orientation/roll-rate-degps
* /orientation/yaw-rate-degps
* /systems/electrical/outputs/turn-coordinator (see below)
@@ -30,6 +30,7 @@
* Output properties:
*
* /instrumentation/"name"/indicated-turn-rate
+ * /instrumentation/"name"/is-valid
*
* Configuration:
*
@@ -40,8 +41,10 @@
* supply path (not used when power-supply is set)
* power-supply
* minimum-supply-volts
- * gyro-spin-up-sec If given, seconds to spin up until power-norm (from 0->100%)
- * gyro-spin-down-sec If given, seconds the gyro will loose spin without power (from 100%->0)
+ * gyro-spin-up-sec If given, seconds to spin up until power-norm (from 0->100%). Defaults to 4s
+ * gyro-spin-down-sec If given, seconds the gyro will loose spin without power (from 100%->0). Defaults to 180s
+ * gyro-spin-valid-norm If given, 'is-valid' turns to 'true' from this norm. gyro rotation value. Defaults to 0.93
+ *
*
* Notes on the power supply path:
*
@@ -72,10 +75,11 @@ public:
private:
Gyro _gyro;
double _last_rate;
- double _gyro_spin_up, _gyro_spin_down;
+ double _max_out_degsec;
+ double _gyro_spin_up, _gyro_spin_down, _gyro_spin_valid_from;
SGPropertyNode_ptr _roll_rate_node;
SGPropertyNode_ptr _yaw_rate_node;
- SGPropertyNode_ptr _rate_out_node;
- SGPropertyNode_ptr _spin_node, _gyro_spin_up_node, _gyro_spin_down_node;
+ SGPropertyNode_ptr _rate_out_node, _is_valid_node;
+ SGPropertyNode_ptr _spin_node, _gyro_spin_up_node, _gyro_spin_down_node, _gyro_spin_valid_from_node;
};
|