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