]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGControls.h
Updates from the Jon and Tony show.
[flightgear.git] / src / FDM / JSBSim / FGControls.h
1 // controls.hxx -- 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 // (Log is kept at end of this file)
23
24
25 #ifndef _CONTROLS_HXX
26 #define _CONTROLS_HXX
27
28
29 #ifndef __cplusplus                                                          
30 # error This library requires C++
31 #endif                                   
32
33 // Define a structure containing the control parameters
34
35 class FGControls {
36
37 public:
38
39     static const int ALL_ENGINES = -1;
40     static const int MAX_ENGINES = 10;
41
42     static const int ALL_WHEELS = -1;
43     static const int MAX_WHEELS = 3;
44
45 private:
46
47     double aileron;
48     double elevator;
49     double elevator_trim;
50     double rudder;
51     double throttle[MAX_ENGINES];
52     double brake[MAX_WHEELS];
53
54 public:
55
56     FGControls();
57     ~FGControls();
58
59     // Query functions
60     inline double get_aileron() const { return aileron; }
61     inline double get_elevator() const { return elevator; }
62     inline double get_elevator_trim() const { return elevator_trim; }
63     inline double get_rudder() const { return rudder; }
64     inline double get_throttle(int engine) const { return throttle[engine]; }
65     inline double get_brake(int wheel) const { return brake[wheel]; }
66
67     // Update functions
68     inline void set_aileron( double pos ) {
69         aileron = pos;
70         if ( aileron < -1.0 ) aileron = -1.0;
71         if ( aileron >  1.0 ) aileron =  1.0;
72     }
73     inline void move_aileron( double amt ) {
74         aileron += amt;
75         if ( aileron < -1.0 ) aileron = -1.0;
76         if ( aileron >  1.0 ) aileron =  1.0;
77     }
78     inline void set_elevator( double pos ) {
79         elevator = pos;
80         if ( elevator < -1.0 ) elevator = -1.0;
81         if ( elevator >  1.0 ) elevator =  1.0;
82     }
83     inline void move_elevator( double amt ) {
84         elevator += amt;
85         if ( elevator < -1.0 ) elevator = -1.0;
86         if ( elevator >  1.0 ) elevator =  1.0;
87     }
88     inline void set_elevator_trim( double pos ) {
89         elevator_trim = pos;
90         if ( elevator_trim < -1.0 ) elevator_trim = -1.0;
91         if ( elevator_trim >  1.0 ) elevator_trim =  1.0;
92     }
93     inline void move_elevator_trim( double amt ) {
94         elevator_trim += amt;
95         if ( elevator_trim < -1.0 ) elevator_trim = -1.0;
96         if ( elevator_trim >  1.0 ) elevator_trim =  1.0;
97     }
98     inline void set_rudder( double pos ) {
99         rudder = pos;
100         if ( rudder < -1.0 ) rudder = -1.0;
101         if ( rudder >  1.0 ) rudder =  1.0;
102     }
103     inline void move_rudder( double amt ) {
104         rudder += amt;
105         if ( rudder < -1.0 ) rudder = -1.0;
106         if ( rudder >  1.0 ) rudder =  1.0;
107     }
108     inline void set_throttle( int engine, double pos ) {
109         if ( engine == ALL_ENGINES ) {
110             for ( int i = 0; i < MAX_ENGINES; i++ ) {
111                 throttle[i] = pos;
112                 if ( throttle[i] < 0.0 ) throttle[i] = 0.0;
113                 if ( throttle[i] >  1.0 ) throttle[i] =  1.0;
114             }
115         } else {
116             if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
117                 throttle[engine] = pos;
118                 if ( throttle[engine] < 0.0 ) throttle[engine] = 0.0;
119                 if ( throttle[engine] >  1.0 ) throttle[engine] =  1.0;
120             }
121         }
122     }
123     inline void move_throttle( int engine, double amt ) {
124         if ( engine == ALL_ENGINES ) {
125             for ( int i = 0; i < MAX_ENGINES; i++ ) {
126                 throttle[i] += amt;
127                 if ( throttle[i] < 0.0 ) throttle[i] = 0.0;
128                 if ( throttle[i] >  1.0 ) throttle[i] =  1.0;
129             }
130         } else {
131             if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
132                 throttle[engine] += amt;
133                 if ( throttle[engine] < 0.0 ) throttle[engine] = 0.0;
134                 if ( throttle[engine] >  1.0 ) throttle[engine] =  1.0;
135             }
136         }
137     }
138     inline void set_brake( int wheel, double pos ) {
139         if ( wheel == ALL_WHEELS ) {
140             for ( int i = 0; i < MAX_WHEELS; i++ ) {
141                 brake[i] = pos;
142                 if ( brake[i] < 0.0 ) brake[i] = 0.0;
143                 if ( brake[i] >  1.0 ) brake[i] =  1.0;
144             }
145         } else {
146             if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
147                 brake[wheel] = pos;
148                 if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0;
149                 if ( brake[wheel] >  1.0 ) brake[wheel] =  1.0;
150             }
151         }
152     }
153     inline void move_brake( int wheel, double amt ) {
154         if ( wheel == ALL_WHEELS ) {
155             for ( int i = 0; i < MAX_WHEELS; i++ ) {
156                 brake[i] += amt;
157                 if ( brake[i] < 0.0 ) brake[i] = 0.0;
158                 if ( brake[i] >  1.0 ) brake[i] =  1.0;
159             }
160         } else {
161             if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
162                 brake[wheel] += amt;
163                 if ( brake[wheel] < 0.0 ) brake[wheel] = 0.0;
164                 if ( brake[wheel] >  1.0 ) brake[wheel] =  1.0;
165             }
166         }
167     }
168 };
169
170
171 extern FGControls controls;
172
173
174 #endif // _CONTROLS_HXX
175
176
177 // $Log$
178 // Revision 1.9  2000/05/16 19:35:11  curt
179 // Updates from the Jon and Tony show.
180 //
181 // Tony submitted:
182 //
183 // JSBsim:
184 // Added trimming routine, it is longitudinal & in-air only at this point
185 // Added support for taking wind & weather data from external source
186 // Added support for flaps.
187 // Added independently settable pitch trim
188 // Added alphamin and max to config file, stall modeling and warning to
189 // follow
190 //
191 // c172.cfg:
192 // Flaps!
193 // Adjusted Cmo, model should be speed stable now
194 //
195 // FG:
196 // Hooked up Christian's weather code, should be using it soon.
197 // Hooked up the trimming routine.  Note that the X-15 will not trim.
198 //   This is not a model or trimming routine deficiency, just the
199 //   nature of the X-15
200 // The trimming routine sets the pitch trim and and throttle at startup.
201 // The throttle is set using Norman's code for the autothrottle so the
202 // autothrottle is on by default.  --notrim will turn it off.
203 // Added --vc, --mach, and --notrim switches
204 //       (vc is airspeed in knots)
205 // uBody, vBody, and wBody are still supported, last one entered
206 // on the command line counts, i.e. you can set vc or mach or u,v,
207 // and w but any combination will be ignored.
208 //
209 // Revision 1.5  2000/05/12 22:45:35  jsb
210 // Removed extraneous namespace identifiers and header files
211 //
212 // Revision 1.4  2000/04/26 10:55:57  jsb
213 // Made changes as required by Curt to install JSBSim into FGFS
214 //
215 // Revision 1.7  2000/04/24 21:49:07  curt
216 // Updated JSBsim code.
217 //
218 // Revision 1.3  2000/04/15 13:16:54  jsb
219 // In good shape, now, changes to Coefficient and aircraft, mostly, with new commands added and inputs and outputs separated.
220 //
221 // Revision 1.6  1999/09/07 21:15:45  curt
222 // Updates to get engine working.
223 //
224 // Revision 1.1  1999/02/13 01:12:03  curt
225 // Initial Revision.
226 //
227 // Revision 1.3  1998/12/05 16:13:13  curt
228 // Renamed class fgCONTROLS to class FGControls.
229 //
230 // Revision 1.2  1998/10/25 14:08:42  curt
231 // Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
232 //
233 // Revision 1.1  1998/10/18 01:51:07  curt
234 // c++-ifying ...
235 //
236 // Revision 1.17  1998/09/29 14:57:00  curt
237 // c++-ified some comments.
238 //
239 // Revision 1.16  1998/09/29 02:01:32  curt
240 // Added a brake.
241 //
242 // Revision 1.15  1998/04/25 22:06:27  curt
243 // Edited cvs log messages in source files ... bad bad bad!
244 //
245 // Revision 1.14  1998/04/22 13:26:19  curt
246 // C++ - ifing the code a bit.
247 //
248 // Revision 1.13  1998/04/21 17:02:35  curt
249 // Prepairing for C++ integration.
250 //
251 // Revision 1.12  1998/02/09 22:56:48  curt
252 // Removed "depend" files from cvs control.  Other minor make tweaks.
253 //
254 // Revision 1.11  1998/02/07 15:29:36  curt
255 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
256 // <chotchkiss@namg.us.anritsu.com>
257 //
258 // Revision 1.10  1998/01/27 00:47:52  curt
259 // Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
260 // system and commandline/config file processing code.
261 //
262 // Revision 1.9  1998/01/22 02:59:31  curt
263 // Changed #ifdef FILE_H to #ifdef _FILE_H
264 //
265 // Revision 1.8  1998/01/19 18:40:22  curt
266 // Tons of little changes to clean up the code and to remove fatal errors
267 // when building with the c++ compiler.
268 //
269 // Revision 1.7  1997/12/15 23:54:36  curt
270 // Add xgl wrappers for debugging.
271 // Generate terrain normals on the fly.
272 //
273 // Revision 1.6  1997/12/10 22:37:41  curt
274 // Prepended "fg" on the name of all global structures that didn't have it yet.
275 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
276 //
277 // Revision 1.5  1997/08/27 03:30:02  curt
278 // Changed naming scheme of basic shared structures.
279 //
280 // Revision 1.4  1997/07/23 21:52:18  curt
281 // Put comments around the text after an #endif for increased portability.
282 //
283 // Revision 1.3  1997/05/31 19:16:27  curt
284 // Elevator trim added.
285 //
286 // Revision 1.2  1997/05/23 15:40:33  curt
287 // Added GNU copyright headers.
288 //
289 // Revision 1.1  1997/05/16 15:59:48  curt
290 // Initial revision.
291 //