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);
52 TurnIndicator::bind ()
54 std::ostringstream temp;
57 branch = "/instrumentation/" + _name + "[" + temp.str() + "]";
59 fgTie((branch + "/serviceable").c_str(),
60 &_gyro, &Gyro::is_serviceable, &Gyro::set_serviceable);
61 fgTie((branch + "/spin").c_str(),
62 &_gyro, &Gyro::get_spin_norm, &Gyro::set_spin_norm);
66 TurnIndicator::unbind ()
68 std::ostringstream temp;
71 branch = "/instrumentation/" + _name + "[" + temp.str() + "]";
73 fgUntie((branch + "/serviceable").c_str());
74 fgUntie((branch + "/serviceable").c_str());
78 TurnIndicator::update (double dt)
80 // Get the spin from the gyro
81 double power = _electric_current_node->getDoubleValue() / 12.0;
82 _gyro.set_power_norm(power);
84 double spin = _gyro.get_spin_norm();
86 // Calculate the indicated rate
87 double factor = 1.0 - ((1.0 - spin) * (1.0 - spin) * (1.0 - spin));
88 double rate = ((_roll_rate_node->getDoubleValue() / 20.0) +
89 (_yaw_rate_node->getDoubleValue() / 3.0));
97 // Lag left, based on gyro spin
98 rate = -2.5 + (factor * (rate + 2.5));
99 rate = fgGetLowPass(_last_rate, rate, dt*RESPONSIVENESS);
102 // Publish the indicated rate
103 _rate_out_node->setDoubleValue(rate);
106 // end of turn_indicator.cxx