]> git.mxchange.org Git - flightgear.git/blob - FDM/flight.c
c++-ified comments.
[flightgear.git] / FDM / flight.c
1 // flight.c -- a general interface to the various flight models
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 #include <stdio.h>
26
27 #include <Debug/fg_debug.h>
28 #include <Flight/flight.h>
29 #include <Flight/LaRCsim/ls_interface.h>
30 #include <Include/fg_constants.h>
31 #include <Math/fg_geodesy.h>
32
33
34 fgFLIGHT cur_flight_params;
35
36
37 /* Initialize the flight model parameters */
38 int fgFlightModelInit(int model, fgFLIGHT *f, double dt) {
39     double save_alt = 0.0;
40     int result;
41
42     fgPrintf(FG_FLIGHT,FG_INFO,"Initializing flight model\n");
43
44     if ( model == FG_SLEW ) {
45         // fgSlewInit(dt);
46     } else if ( model == FG_LARCSIM ) {
47         /* lets try to avoid really screwing up the LaRCsim model */
48         if ( FG_Altitude < -9000 ) {
49             save_alt = FG_Altitude;
50             FG_Altitude = 0;
51         }
52
53         fgFlight_2_LaRCsim(f);  /* translate FG to LaRCsim structure */
54         fgLaRCsimInit(dt);
55         fgPrintf( FG_FLIGHT, FG_INFO, "FG pos = %.2f\n", FG_Latitude );
56         fgLaRCsim_2_Flight(f);  /* translate LaRCsim back to FG structure */
57
58         /* but lets restore our original bogus altitude when we are done */
59         if ( save_alt < -9000 ) {
60             FG_Altitude = save_alt;
61         }
62     } else {
63         fgPrintf( FG_FLIGHT, FG_WARN,
64                   "Unimplemented flight model == %d\n", model );
65     }
66
67     result = 1;
68
69     return(result);
70 }
71
72
73 /* Run multiloop iterations of the flight model */
74 int fgFlightModelUpdate(int model, fgFLIGHT *f, int multiloop) {
75     double time_step, start_elev, end_elev;
76     int result;
77     // printf("Altitude = %.2f\n", FG_Altitude * 0.3048);
78
79     time_step = (1.0 / DEFAULT_MODEL_HZ) * multiloop;
80     start_elev = FG_Altitude;
81
82     if ( model == FG_SLEW ) {
83         // fgSlewUpdate(f, multiloop);
84     } else if ( model == FG_LARCSIM ) {
85         fgLaRCsimUpdate(f, multiloop);
86     } else {
87         fgPrintf( FG_FLIGHT, FG_WARN,
88                   "Unimplemented flight model == %d\n", model );
89     }
90
91     end_elev = FG_Altitude;
92
93     FG_Climb_Rate = (end_elev - start_elev) / time_step;  /* feet per second */
94
95     result = 1;
96
97     return(result);
98 }
99
100
101 /* Set the altitude (force) */
102 int fgFlightModelSetAltitude(int model, fgFLIGHT *f, double alt_meters) {
103     double sea_level_radius_meters;
104     double lat_geoc;
105     // Set the FG variables first
106     fgGeodToGeoc( FG_Latitude, alt_meters, 
107                   &sea_level_radius_meters, &lat_geoc);
108
109     FG_Altitude = alt_meters * METER_TO_FEET;
110     FG_Radius_to_vehicle = FG_Altitude + 
111         (sea_level_radius_meters * METER_TO_FEET);
112
113     /* additional work needed for some flight models */
114     if ( model == FG_LARCSIM ) {
115         ls_ForceAltitude(FG_Altitude);
116     }
117
118 }
119
120
121 // $Log$
122 // Revision 1.19  1998/09/29 14:57:38  curt
123 // c++-ified comments.
124 //
125 // Revision 1.18  1998/09/29 02:02:40  curt
126 // Added a rate of climb calculation.
127 //
128 // Revision 1.17  1998/08/24 20:09:07  curt
129 // .
130 //
131 // Revision 1.16  1998/08/22  14:49:55  curt
132 // Attempting to iron out seg faults and crashes.
133 // Did some shuffling to fix a initialization order problem between view
134 // position, scenery elevation.
135 //
136 // Revision 1.15  1998/07/30 23:44:36  curt
137 // Beginning to add support for multiple flight models.
138 //
139 // Revision 1.14  1998/07/12 03:08:27  curt
140 // Added fgFlightModelSetAltitude() to force the altitude to something
141 // other than the current altitude.  LaRCsim doesn't let you do this by just
142 // changing FG_Altitude.
143 //
144 // Revision 1.13  1998/04/25 22:06:28  curt
145 // Edited cvs log messages in source files ... bad bad bad!
146 //
147 // Revision 1.12  1998/04/21 16:59:33  curt
148 // Integrated autopilot.
149 // Prepairing for C++ integration.
150 //
151 // Revision 1.11  1998/04/18 04:14:04  curt
152 // Moved fg_debug.c to it's own library.
153 //
154 // Revision 1.10  1998/02/07 15:29:37  curt
155 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
156 // <chotchkiss@namg.us.anritsu.com>
157 //
158 // Revision 1.9  1998/01/27 00:47:53  curt
159 // Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
160 // system and commandline/config file processing code.
161 //
162 // Revision 1.8  1998/01/19 19:27:03  curt
163 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
164 // This should simplify things tremendously.
165 //
166 // Revision 1.7  1998/01/19 18:40:23  curt
167 // Tons of little changes to clean up the code and to remove fatal errors
168 // when building with the c++ compiler.
169 //
170 // Revision 1.6  1998/01/19 18:35:43  curt
171 // Minor tweaks and fixes for cygwin32.
172 //
173 // Revision 1.5  1997/12/30 20:47:37  curt
174 // Integrated new event manager with subsystem initializations.
175 //
176 // Revision 1.4  1997/12/10 22:37:42  curt
177 // Prepended "fg" on the name of all global structures that didn't have it yet.
178 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
179 //
180 // Revision 1.3  1997/08/27 03:30:04  curt
181 // Changed naming scheme of basic shared structures.
182 //
183 // Revision 1.2  1997/05/29 22:39:57  curt
184 // Working on incorporating the LaRCsim flight model.
185 //
186 // Revision 1.1  1997/05/29 02:35:04  curt
187 // Initial revision.
188 //