]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/attitude_indicator.cxx
Set the initial log-level back to info
[flightgear.git] / src / Instrumentation / attitude_indicator.cxx
1 // attitude_indicator.cxx - a vacuum-powered attitude indicator.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain and comes with no warranty.
5
6 // TODO:
7 // - tumble
8 // - better spin-up
9
10 #include "attitude_indicator.hxx"
11 #include <Main/fg_props.hxx>
12
13
14 AttitudeIndicator::AttitudeIndicator ()
15 {
16 }
17
18 AttitudeIndicator::~AttitudeIndicator ()
19 {
20 }
21
22 void
23 AttitudeIndicator::init ()
24 {
25                                 // TODO: allow index of pump and AI
26                                 // to be configured.
27     _pitch_in_node = fgGetNode("/orientation/pitch-deg", true);
28     _roll_in_node = fgGetNode("/orientation/roll-deg", true);
29     _suction_node = fgGetNode("/systems/vacuum[0]/suction-inhg", true);
30     _pitch_out_node =
31         fgGetNode("/instrumentation/attitude-indicator/indicated-pitch-deg",
32                   true);
33     _roll_out_node =
34         fgGetNode("/instrumentation/attitude-indicator/indicated-roll-deg",
35                   true);
36 }
37
38 void
39 AttitudeIndicator::bind ()
40 {
41     fgTie("/instrumentation/attitude-indicator/serviceable",
42           &_gyro, &Gyro::is_serviceable, &Gyro::set_serviceable);
43     fgTie("/instrumentation/attitude-indicator/spin",
44           &_gyro, &Gyro::get_spin_norm, &Gyro::set_spin_norm);
45 }
46
47 void
48 AttitudeIndicator::unbind ()
49 {
50     fgUntie("/instrumentation/attitude-indicator/serviceable");
51     fgUntie("/instrumentation/attitude-indicator/spin");
52 }
53
54 void
55 AttitudeIndicator::update (double dt)
56 {
57                                 // Get the spin from the gyro
58     _gyro.set_power_norm(_suction_node->getDoubleValue()/5.0);
59     _gyro.update(dt);
60     double spin = _gyro.get_spin_norm();
61
62                                 // Next, calculate the indicated roll
63                                 // and pitch, introducing errors.
64     double factor = 1.0 - ((1.0 - spin) * (1.0 - spin) * (1.0 - spin));
65     double roll = _roll_in_node->getDoubleValue();
66     double pitch = _pitch_in_node->getDoubleValue();
67     roll = 35 + (factor * (roll - 35));
68     pitch = 15 + (factor * (pitch - 15));
69
70     _roll_out_node->setDoubleValue(roll);
71     _pitch_out_node->setDoubleValue(pitch);
72 }
73
74 // end of attitude_indicator.cxx