]> git.mxchange.org Git - flightgear.git/blob - src/Controls/controls.cxx
Set default elevator trim to 0 to avoid FPEs and improve transparency
[flightgear.git] / src / Controls / controls.cxx
1 // controls.cxx -- defines a standard interface to all flight sim controls
2 //
3 // Written by Curtis Olson, started May 1997.
4 //
5 // Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #include "controls.hxx"
25
26 #include <simgear/debug/logstream.hxx>
27 #include <Main/fg_props.hxx>
28
29
30 // Constructor
31 FGControls::FGControls() :
32     aileron( 0.0 ),
33     aileron_trim( 0.0 ),
34     elevator( 0.0 ),
35     elevator_trim( 0.0 ),
36     rudder( 0.0 ),
37     rudder_trim( 0.0 ),
38     throttle_idle( true )
39 {
40 }
41
42
43 void FGControls::reset_all()
44 {
45     set_aileron(0.0);
46     set_aileron_trim(0.0);
47     set_elevator(0.0);
48     set_elevator_trim(0.0);
49     set_rudder(0.0);
50     set_rudder_trim(0.0);
51     set_throttle(FGControls::ALL_ENGINES, 0.0);
52     set_starter(FGControls::ALL_ENGINES, false);
53     set_magnetos(FGControls::ALL_ENGINES, 0);
54     throttle_idle = true;
55     gear_down = true;
56 }
57
58
59 // Destructor
60 FGControls::~FGControls() {
61 }
62
63
64 void
65 FGControls::init ()
66 {
67     for ( int engine = 0; engine < MAX_ENGINES; engine++ ) {
68         throttle[engine] = 0.0;
69         mixture[engine] = 1.0;
70         prop_advance[engine] = 1.0;
71         magnetos[engine] = 0;
72         starter[engine] = false;
73     }
74
75     for ( int wheel = 0; wheel < MAX_WHEELS; wheel++ ) {
76         brake[wheel] = 0.0;
77     }
78
79     auto_coordination = fgGetNode("/sim/auto-coordination", true);
80 }
81
82
83 void
84 FGControls::bind ()
85 {
86   fgTie("/controls/aileron", this,
87         &FGControls::get_aileron, &FGControls::set_aileron);
88   fgSetArchivable("/controls/aileron");
89   fgTie("/controls/aileron-trim", this,
90        &FGControls::get_aileron_trim, &FGControls::set_aileron_trim);
91   fgSetArchivable("/controls/aileron-trim");
92   fgTie("/controls/elevator", this,
93        &FGControls::get_elevator, &FGControls::set_elevator);
94   fgSetArchivable("/controls/elevator");
95   fgTie("/controls/elevator-trim", this,
96        &FGControls::get_elevator_trim, &FGControls::set_elevator_trim);
97   fgSetArchivable("/controls/elevator-trim");
98   fgTie("/controls/rudder", this,
99        &FGControls::get_rudder, &FGControls::set_rudder);
100   fgSetArchivable("/controls/rudder");
101   fgTie("/controls/rudder-trim", this,
102        &FGControls::get_rudder_trim, &FGControls::set_rudder_trim);
103   fgSetArchivable("/controls/rudder-trim");
104   fgTie("/controls/flaps", this,
105        &FGControls::get_flaps, &FGControls::set_flaps);
106   fgSetArchivable("/controls/flaps");
107   int index;
108   for (index = 0; index < MAX_ENGINES; index++) {
109     char name[32];
110     sprintf(name, "/controls/throttle[%d]", index);
111     fgTie(name, this, index,
112           &FGControls::get_throttle, &FGControls::set_throttle);
113     fgSetArchivable(name);
114     sprintf(name, "/controls/mixture[%d]", index);
115     fgTie(name, this, index,
116          &FGControls::get_mixture, &FGControls::set_mixture);
117     fgSetArchivable(name);
118     sprintf(name, "/controls/propeller-pitch[%d]", index);
119     fgTie(name, this, index,
120          &FGControls::get_prop_advance, &FGControls::set_prop_advance);
121     fgSetArchivable(name);
122     sprintf(name, "/controls/magnetos[%d]", index);
123     fgTie(name, this, index,
124          &FGControls::get_magnetos, &FGControls::set_magnetos);
125     fgSetArchivable(name);
126     sprintf(name, "/controls/starter[%d]", index);
127     fgTie(name, this, index,
128          &FGControls::get_starter, &FGControls::set_starter);
129     fgSetArchivable(name);
130   }
131   for (index = 0; index < MAX_WHEELS; index++) {
132     char name[32];
133     sprintf(name, "/controls/brakes[%d]", index);
134     fgTie(name, this, index,
135          &FGControls::get_brake, &FGControls::set_brake);
136     fgSetArchivable(name);
137   }
138   fgTie("/controls/gear-down", this,
139         &FGControls::get_gear_down, &FGControls::set_gear_down);
140   fgSetArchivable("/controls/gear-down");
141 }
142
143
144 void
145 FGControls::unbind ()
146 {
147                                 // Tie control properties.
148   fgUntie("/controls/aileron");
149   fgUntie("/controls/aileron-trim");
150   fgUntie("/controls/elevator");
151   fgUntie("/controls/elevator-trim");
152   fgUntie("/controls/rudder");
153   fgUntie("/controls/rudder-trim");
154   fgUntie("/controls/flaps");
155   int index;
156   for (index = 0; index < MAX_ENGINES; index++) {
157     char name[32];
158     sprintf(name, "/controls/throttle[%d]", index);
159     fgUntie(name);
160     sprintf(name, "/controls/mixture[%d]", index);
161     fgUntie(name);
162     sprintf(name, "/controls/propeller-pitch[%d]", index);
163     fgUntie(name);
164     sprintf(name, "/controls/magnetos[%d]", index);
165     fgUntie(name);
166     sprintf(name, "/controls/starter[%d]", index);
167     fgUntie(name);
168   }
169   for (index = 0; index < MAX_WHEELS; index++) {
170     char name[32];
171     sprintf(name, "/controls/brakes[%d]", index);
172     fgUntie(name);
173   }
174   fgUntie("/controls/gear-down");
175 }
176
177
178 void
179 FGControls::update (int dt)
180 {
181 }
182