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 TurnIndicator::TurnIndicator ()
15 TurnIndicator::~TurnIndicator ()
20 TurnIndicator::init ()
22 _roll_rate_node = fgGetNode("/orientation/roll-rate-degps", true);
23 _yaw_rate_node = fgGetNode("/orientation/yaw-rate-degps", true);
24 _electric_current_node =
25 fgGetNode("/systems/electrical/outputs/turn-coordinator", true);
27 fgGetNode("/instrumentation/turn-indicator/indicated-turn-rate", true);
31 TurnIndicator::bind ()
33 fgTie("/instrumentation/turn-indicator/serviceable",
34 &_gyro, &Gyro::is_serviceable, &Gyro::set_serviceable);
35 fgTie("/instrumentation/turn-indicator/spin",
36 &_gyro, &Gyro::get_spin_norm, &Gyro::set_spin_norm);
40 TurnIndicator::unbind ()
42 fgUntie("/instrumentation/turn-indicator/serviceable");
43 fgUntie("/instrumentation/turn-indicator/spin");
47 TurnIndicator::update (double dt)
49 // Get the spin from the gyro
50 _gyro.set_power_norm(_electric_current_node->getDoubleValue()/60.0);
52 double spin = _gyro.get_spin_norm();
54 // Calculate the indicated rate
55 double factor = 1.0 - ((1.0 - spin) * (1.0 - spin) * (1.0 - spin));
56 double rate = ((_roll_rate_node->getDoubleValue() / 20.0) +
57 (_yaw_rate_node->getDoubleValue() / 3.0));
65 // Lag left, based on gyro spin
66 rate = -2.5 + (factor * (rate + 2.5));
68 // Add a lag, based on gyro spin
69 rate = fgGetLowPass(_last_rate, rate, dt/factor);
72 // Publish the indicated rate
73 _rate_out_node->setDoubleValue(rate);
76 // end of turn_indicator.cxx