1 // turn_indicator.cxx - an electric-powered turn indicator.
2 // Written by David Megginson, started 2003.
4 // This file is in the Public Domain and comes with no warranty.
6 #include "turn_indicator.hxx"
7 #include <Main/fg_props.hxx>
8 #include <Main/util.hxx>
11 // Use a bigger number to be more responsive, or a smaller number
12 // to be more sluggish (the base time is 1.0).
13 #define RESPONSIVENESS 0.25
16 TurnIndicator::TurnIndicator ()
20 TurnIndicator::~TurnIndicator ()
25 TurnIndicator::init ()
27 _roll_rate_node = fgGetNode("/orientation/roll-rate-degps", true);
28 _yaw_rate_node = fgGetNode("/orientation/yaw-rate-degps", true);
29 _electric_current_node =
30 fgGetNode("/systems/electrical/outputs/turn-coordinator", true);
32 fgGetNode("/instrumentation/turn-indicator/indicated-turn-rate", true);
36 TurnIndicator::bind ()
38 fgTie("/instrumentation/turn-indicator/serviceable",
39 &_gyro, &Gyro::is_serviceable, &Gyro::set_serviceable);
40 fgTie("/instrumentation/turn-indicator/spin",
41 &_gyro, &Gyro::get_spin_norm, &Gyro::set_spin_norm);
45 TurnIndicator::unbind ()
47 fgUntie("/instrumentation/turn-indicator/serviceable");
48 fgUntie("/instrumentation/turn-indicator/spin");
52 TurnIndicator::update (double dt)
54 // Get the spin from the gyro
55 _gyro.set_power_norm(_electric_current_node->getDoubleValue()/60.0);
57 double spin = _gyro.get_spin_norm();
59 // Calculate the indicated rate
60 double factor = 1.0 - ((1.0 - spin) * (1.0 - spin) * (1.0 - spin));
61 double rate = ((_roll_rate_node->getDoubleValue() / 20.0) +
62 (_yaw_rate_node->getDoubleValue() / 3.0));
70 // Lag left, based on gyro spin
71 rate = -2.5 + (factor * (rate + 2.5));
72 rate = fgGetLowPass(_last_rate, rate, dt*RESPONSIVENESS);
75 // Publish the indicated rate
76 _rate_out_node->setDoubleValue(rate);
79 // end of turn_indicator.cxx