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