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.
10 #include <simgear/compiler.h>
15 #include "turn_indicator.hxx"
16 #include <Main/fg_props.hxx>
17 #include <Main/util.hxx>
21 // Use a bigger number to be more responsive, or a smaller number
22 // to be more sluggish.
23 #define RESPONSIVENESS 0.5
26 TurnIndicator::TurnIndicator ( SGPropertyNode *node) :
28 _name(node->getStringValue("name", "turn-indicator")),
29 _num(node->getIntValue("number", 0))
33 TurnIndicator::~TurnIndicator ()
38 TurnIndicator::init ()
41 branch = "/instrumentation/" + _name;
43 SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
44 _roll_rate_node = fgGetNode("/orientation/roll-rate-degps", true);
45 _yaw_rate_node = fgGetNode("/orientation/yaw-rate-degps", true);
46 _electric_current_node =
47 fgGetNode("/systems/electrical/outputs/turn-coordinator", true);
48 _rate_out_node = node->getChild("indicated-turn-rate", 0, true);
54 TurnIndicator::reinit ()
61 TurnIndicator::bind ()
63 std::ostringstream temp;
66 branch = "/instrumentation/" + _name + "[" + temp.str() + "]";
68 fgTie((branch + "/serviceable").c_str(),
69 &_gyro, &Gyro::is_serviceable, &Gyro::set_serviceable);
70 fgTie((branch + "/spin").c_str(),
71 &_gyro, &Gyro::get_spin_norm, &Gyro::set_spin_norm);
75 TurnIndicator::unbind ()
77 std::ostringstream temp;
80 branch = "/instrumentation/" + _name + "[" + temp.str() + "]";
82 fgUntie((branch + "/serviceable").c_str());
83 fgUntie((branch + "/serviceable").c_str());
87 TurnIndicator::update (double dt)
89 // Get the spin from the gyro
90 double power = _electric_current_node->getDoubleValue() / 12.0;
91 _gyro.set_power_norm(power);
93 double spin = _gyro.get_spin_norm();
95 // Calculate the indicated rate
96 double factor = 1.0 - ((1.0 - spin) * (1.0 - spin) * (1.0 - spin));
97 double rate = ((_roll_rate_node->getDoubleValue() / 20.0) +
98 (_yaw_rate_node->getDoubleValue() / 3.0));
106 // Lag left, based on gyro spin
107 rate = -2.5 + (factor * (rate + 2.5));
108 rate = fgGetLowPass(_last_rate, rate, dt*RESPONSIVENESS);
111 // Publish the indicated rate
112 _rate_out_node->setDoubleValue(rate);
115 // end of turn_indicator.cxx