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.
13 #define RESPONSIVENESS 0.5
16 TurnIndicator::TurnIndicator ( SGPropertyNode *node) :
18 name("turn-indicator"),
22 for ( i = 0; i < node->nChildren(); ++i ) {
23 SGPropertyNode *child = node->getChild(i);
24 string cname = child->getName();
25 string cval = child->getStringValue();
26 if ( cname == "name" ) {
28 } else if ( cname == "number" ) {
29 num = child->getIntValue();
31 SG_LOG( SG_INSTR, SG_WARN, "Error in turn-indicator config logic" );
32 if ( name.length() ) {
33 SG_LOG( SG_INSTR, SG_WARN, "Section = " << name );
39 TurnIndicator::TurnIndicator () :
44 TurnIndicator::~TurnIndicator ()
49 TurnIndicator::init ()
52 branch = "/instrumentation/" + name;
54 SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
55 _roll_rate_node = fgGetNode("/orientation/roll-rate-degps", true);
56 _yaw_rate_node = fgGetNode("/orientation/yaw-rate-degps", true);
57 _electric_current_node =
58 fgGetNode("/systems/electrical/outputs/turn-coordinator", true);
59 _rate_out_node = node->getChild("indicated-turn-rate", 0, true);
63 TurnIndicator::bind ()
66 branch = "/instrumentation/" + name + "/serviceable";
68 &_gyro, &Gyro::is_serviceable, &Gyro::set_serviceable);
69 branch = "/instrumentation/" + name + "/spin";
71 &_gyro, &Gyro::get_spin_norm, &Gyro::set_spin_norm);
75 TurnIndicator::unbind ()
78 branch = "/instrumentation/" + name + "/serviceable";
79 fgUntie(branch.c_str());
80 branch = "/instrumentation/" + name + "/spin";
81 fgUntie(branch.c_str());
85 TurnIndicator::update (double dt)
87 // Get the spin from the gyro
88 _gyro.set_power_norm(_electric_current_node->getDoubleValue()/60.0);
90 double spin = _gyro.get_spin_norm();
92 // Calculate the indicated rate
93 double factor = 1.0 - ((1.0 - spin) * (1.0 - spin) * (1.0 - spin));
94 double rate = ((_roll_rate_node->getDoubleValue() / 20.0) +
95 (_yaw_rate_node->getDoubleValue() / 3.0));
103 // Lag left, based on gyro spin
104 rate = -2.5 + (factor * (rate + 2.5));
105 rate = fgGetLowPass(_last_rate, rate, dt*RESPONSIVENESS);
108 // Publish the indicated rate
109 _rate_out_node->setDoubleValue(rate);
112 // end of turn_indicator.cxx