]> git.mxchange.org Git - flightgear.git/blob - LaRCsim/ls_interface.c
Removed some printf()'s.
[flightgear.git] / LaRCsim / ls_interface.c
1 /**************************************************************************
2  * ls_interface.c -- the FG interface to the LaRCsim routines
3  *                   This is a heavily modified version of LaRCsim.c
4  *                   As a result there is much old baggage left in this file.
5  *
6  * Originally Written 921230 by Bruce Jackson
7  * Modified by Curtis Olson, started May 1997.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of the
12  * License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  * $Id$
24  * (Log is kept at end of this file)
25  **************************************************************************/
26
27 /* Original headers follow: */
28
29 /***************************************************************************
30
31         TITLE:          LaRCsim.c
32         
33 ----------------------------------------------------------------------------
34
35         FUNCTION:       Top level routine for LaRCSIM.  Includes
36                         global variable declarations.
37
38 ----------------------------------------------------------------------------
39
40         MODULE STATUS:  Developmental
41
42 ----------------------------------------------------------------------------
43
44         GENEALOGY:      Written 921230 by Bruce Jackson
45
46 ----------------------------------------------------------------------------
47
48         DESIGNED BY:    EBJ
49         
50         CODED BY:       EBJ
51         
52         MAINTAINED BY:  EBJ
53
54 ----------------------------------------------------------------------------
55
56         MODIFICATION HISTORY:
57         
58         DATE    PURPOSE                                         BY
59
60         930111  Added "progname" variable to keep name of invoking command.
61                                                                         EBJ
62         931012  Removed altitude < 0. test to support gear development. EBJ
63         931214  Added various pressures (Impact, Dynamic, Static, etc.) EBJ
64         931215  Adopted new generic variable structure.                 EBJ
65         931218  Added command line options decoding.                    EBJ
66         940110  Changed file type of matrix file to ".m"                EBJ
67         940513  Renamed this routine "LaRCsim.c" from "ls_main.c"       EBJ
68         940513  Added time_stamp routine,  t_stamp.                     EBJ
69         950225  Added options flag, 'i', to set I/O output rate.        EBJ
70         950306  Added calls to ls_get_settings() and ls_put_settings()  EBJ
71         950314  Options flag 'i' now reads IC file; 'o' is output rate  EBJ
72         950406  Many changes: added definition of default value macros;
73                 removed local variables term_update_hz, model_dt, endtime,
74                 substituted sim_control_ globals for these; removed
75                 initialization of sim_control_.tape_channels; moved optarg
76                 to generic extern; added mod_end_time & mod_buf_size flags
77                 and temporary buffer_time and data_rate locals to
78                 ls_checkopts(); added additional command line switches '-s'
79                 and '-b'; made psuedo-mandatory file names for data output
80                 switches; considerable rewrite of logic for setting data
81                 buffer length and interleave parameters; updated '-h' help
82                 output message; added protection logic to calculations of
83                 these parameters; added check of return value on first call
84                 to ls_cockpit() so <esc> abort works from initial pause
85                 state; added call to ls_unsync() immediately following
86                 first ls_sync() call, if paused (to avoid alarm clock
87                 timeout); moved call to ls_record() into non-paused
88                 multiloop path (was filling buffer with identical data
89                 during pause); put check of paused flag before calling sync
90                 routine ls_pause(); and added call to exit() on termination.
91
92
93 $Header$
94 $Original log: LaRCsim.c,v $
95  * Revision 1.4.1.7  1995/04/07  01:04:37  bjax
96  * Many changes made to support storage of sim options from run to run,
97  * as well as restructuring storage buffer sizing and some loop logic
98  * changes. See the modification log for details.
99  *
100  * Revision 1.4.1.6  1995/03/29  16:12:09  bjax
101  * Added argument to -o switch; changed run loop to pass dt=0
102  * if in paused mode. EBj
103  *
104  * Revision 1.4.1.5  1995/03/15  12:30:20  bjax
105  * Set paused flag to non-zero by default; moved 'i' I/O rate flag
106  * switch to 'o'; made 'i' an initial conditions file switch; added
107  * null string to ls_get_settings() call so that default settings
108  * file will be read. EBJ
109  *
110  * Revision 1.4.1.4  1995/03/08  12:31:34  bjax
111  * Added userid retrieval and proper termination of time & date strings.
112  *
113  * Revision 1.4.1.3  1995/03/08  12:00:21  bjax
114  * Moved setting of default options to ls_setdefopts from
115  * ls_checkopts; rearranged order of ls_get_settings() call
116  * to between ls_setdefopts and ls_checkopts, so command
117  * line options will override settings file options.
118  * EBJ
119  *
120  * Revision 1.4.1.2  1995/03/06  18:48:49  bjax
121  * Added calles to ls_get_settings() and ls_put_settings(); added
122  * passing of dt and init flags in ls_model(). EBJ
123  *
124  * Revision 1.4.1.1  1995/03/03  02:23:08  bjax
125  * Beta version for LaRCsim, version 1.4
126  *
127  * Revision 1.3.2.7  1995/02/27  20:00:21  bjax
128  * Rebuilt LaRCsim
129  *
130  * Revision 1.3.2.6  1995/02/25  16:52:31  bjax
131  * Added 'i' option to set I/O iteration rate. EBJ
132  *
133  * Revision 1.3.2.5  1995/02/06  19:33:15  bjax
134  * Rebuilt LaRCsim
135  *
136  * Revision 1.3.2.4  1995/02/06  19:30:30  bjax
137  * Oops, should really compile these before checking in. Fixed capitailzation of
138  * Initialize in ls_loop parameter.
139  *
140  * Revision 1.3.2.3  1995/02/06  19:25:44  bjax
141  * Moved main simulation loop into subroutine ls_loop. EBJ
142  *
143  * Revision 1.3.2.2  1994/05/20  21:46:45  bjax
144  * A little better logic on checking for option arguments.
145  *
146  * Revision 1.3.2.1  1994/05/20  19:29:51  bjax
147  * Added options arguments to command line.
148  *
149  * Revision 1.3.1.16  1994/05/17  15:08:45  bjax
150  * Corrected so that full name to directyr and file is saved
151  * in new global variable "fullname"; this allows symbol table
152  * to be extracted when in another default directory.
153  *
154  * Revision 1.3.1.15  1994/05/17  14:50:24  bjax
155  * Rebuilt LaRCsim
156  *
157  * Revision 1.3.1.14  1994/05/17  14:50:23  bjax
158  * Rebuilt LaRCsim
159  *
160  * Revision 1.3.1.13  1994/05/17  14:50:21  bjax
161  * Rebuilt LaRCsim
162  *
163  * Revision 1.3.1.12  1994/05/17  14:50:20  bjax
164  * Rebuilt LaRCsim
165  *
166  * Revision 1.3.1.11  1994/05/17  13:56:24  bjax
167  * Rebuilt LaRCsim
168  *
169  * Revision 1.3.1.10  1994/05/17  13:23:03  bjax
170  * Rebuilt LaRCsim
171  *
172  * Revision 1.3.1.9  1994/05/17  13:20:03  bjax
173  * Rebuilt LaRCsim
174  *
175  * Revision 1.3.1.8  1994/05/17  13:19:23  bjax
176  * Rebuilt LaRCsim
177  *
178  * Revision 1.3.1.7  1994/05/17  13:18:29  bjax
179  * Rebuilt LaRCsim
180  *
181  * Revision 1.3.1.6  1994/05/17  13:16:30  bjax
182  * Rebuilt LaRCsim
183  *
184  * Revision 1.3.1.5  1994/05/17  13:03:44  bjax
185  * Rebuilt LaRCsim
186  *
187  * Revision 1.3.1.4  1994/05/17  13:03:38  bjax
188  * Rebuilt LaRCsim
189  *
190  * Revision 1.3.1.3  1994/05/17  12:49:08  bjax
191  * Rebuilt LaRCsim
192  *
193  * Revision 1.3.1.2  1994/05/17  12:48:45  bjax
194  * *** empty log message ***
195  *
196  * Revision 1.3.1.1  1994/05/13  20:39:17  bjax
197  * Top of 1.3 branch.
198  *
199  * Revision 1.2  1994/05/13  19:51:50  bjax
200  * Skip rev
201  *
202
203 ----------------------------------------------------------------------------
204
205         REFERENCES:
206
207 ----------------------------------------------------------------------------
208
209         CALLED BY:
210
211 ----------------------------------------------------------------------------
212
213         CALLS TO:
214
215 ----------------------------------------------------------------------------
216
217         INPUTS:
218
219 ----------------------------------------------------------------------------
220
221         OUTPUTS:
222
223 --------------------------------------------------------------------------*/
224
225 #include <sys/types.h>
226 /* #include <sys/stat.h> */
227 #include <stdlib.h>
228 #include <stdio.h>
229 #include <math.h>
230 #include <time.h>
231
232 #include "ls_types.h"
233 #include "ls_constants.h"
234 #include "ls_generic.h"
235 #include "ls_sim_control.h"
236 #include "ls_cockpit.h"
237 #include "ls_interface.h"
238 #include "ls_step.h"
239 #include "ls_accel.h"
240 #include "ls_aux.h"
241 #include "ls_model.h"
242 #include "ls_init.h"
243 #include <Flight/flight.h>
244 #include <Aircraft/aircraft.h>
245 #include <Autopilot/autopilot.h>
246 #include <Debug/fg_debug.h>
247
248
249 /* global variable declarations */
250
251 /* TAPE         *Tape; */
252 GENERIC         generic_;
253 SIM_CONTROL     sim_control_;
254 COCKPIT         cockpit_;
255
256 SCALAR          Simtime;
257
258 #define DEFAULT_TERM_UPDATE_HZ 20
259 #define DEFAULT_MODEL_HZ 120
260 #define DEFAULT_END_TIME 3600.
261 #define DEFAULT_SAVE_SPACING 8
262 #define DEFAULT_WRITE_SPACING 1
263 #define MAX_FILE_NAME_LENGTH 80
264
265 /* global variables */
266
267 char    *progname;
268 char    *fullname;
269
270 /* file variables - default simulation settings */
271
272 static double model_dt;
273 static double speedup;
274 static char  asc1name[MAX_FILE_NAME_LENGTH] = "run.asc1";
275 static char  tabname[MAX_FILE_NAME_LENGTH]  = "run.dat";
276 static char  fltname[MAX_FILE_NAME_LENGTH]  = "run.flt";
277 static char  matname[MAX_FILE_NAME_LENGTH]  = "run.m";
278
279
280
281 void ls_stamp( void ) {
282     char rcsid[] = "$Id$";
283     char revid[] = "$Revision$";
284     char dateid[] = "$Date$";
285     struct tm *nowtime;
286     time_t nowtime_t;
287     long date;
288     
289     /* report version of LaRCsim*/
290     printf("\nLaRCsim %s, %s\n\n", revid, dateid); 
291     
292     nowtime_t = time( 0 );
293     nowtime = localtime( &nowtime_t ); /* set fields to correct time values */
294     date = (nowtime->tm_year)*10000 
295          + (nowtime->tm_mon + 1)*100
296          + (nowtime->tm_mday);
297     sprintf(sim_control_.date_string, "%06d\0", date);
298     sprintf(sim_control_.time_stamp, "%02d:%02d:%02d\0", 
299         nowtime->tm_hour, nowtime->tm_min, nowtime->tm_sec);
300 #ifdef COMPILE_THIS_CODE_THIS_USELESS_CODE
301     cuserid( sim_control_.userid );     /* set up user id */
302 #endif /* COMPILE_THIS_CODE_THIS_USELESS_CODE */
303     return;
304 }
305
306 void ls_setdefopts( void ) {
307     /* set default values for most options */
308
309     sim_control_.debug = 0;             /* change to non-zero if in dbx! */
310     sim_control_.vision = 0;
311     sim_control_.write_av = 0;          /* write Agile-Vu '.flt' file */
312     sim_control_.write_mat = 0;         /* write matrix-x/matlab script */
313     sim_control_.write_tab = 0;         /* write tab delim. history file */
314     sim_control_.write_asc1 = 0;        /* write GetData file */
315     sim_control_.save_spacing = DEFAULT_SAVE_SPACING;   
316                                         /* interpolation on recording */
317     sim_control_.write_spacing = DEFAULT_WRITE_SPACING; 
318                                         /* interpolation on output */
319     sim_control_.end_time = DEFAULT_END_TIME;
320     sim_control_.model_hz = DEFAULT_MODEL_HZ;
321     sim_control_.term_update_hz = DEFAULT_TERM_UPDATE_HZ;
322     sim_control_.time_slices = (long int)(DEFAULT_END_TIME * DEFAULT_MODEL_HZ / 
323         DEFAULT_SAVE_SPACING);
324     sim_control_.paused = 0;
325
326     speedup = 1.0;
327 }
328
329
330 /* return result codes from ls_checkopts */
331
332 #define OPT_OK 0
333 #define OPT_ERR 1
334
335 #ifdef COMPILE_THIS_CODE_THIS_USELESS_CODE
336
337 extern char *optarg;
338 extern int optind;
339
340 int ls_checkopts(argc, argv)    /* check and set options flags */
341   int argc;
342   char *argv[];
343   {
344     int c;
345     int opt_err = 0;
346     int mod_end_time = 0;
347     int mod_buf_size = 0;
348     float buffer_time, data_rate;
349
350     /* set default values */
351
352     buffer_time = sim_control_.time_slices * sim_control_.save_spacing / 
353         sim_control_.model_hz;
354     data_rate   = sim_control_.model_hz / sim_control_.save_spacing;
355
356     while ((c = getopt(argc, argv, "Aa:b:de:f:hi:kmo:r:s:t:x:")) != EOF)
357         switch (c) {
358             case 'A':
359                 if (sim_control_.sim_type == GLmouse)
360                   {
361                     fprintf(stderr, "Cannot specify both keyboard (k) and ACES (A) cockpits option\n");
362                     fprintf(stderr, "Keyboard operation assumed.\n");
363                     break;
364                   }
365                 sim_control_.sim_type = cockpit;
366                 break;
367             case 'a':
368                 sim_control_.write_av = 1;
369                 if (optarg != NULL)
370                 if (*optarg != '-') 
371                     strncpy(fltname, optarg, MAX_FILE_NAME_LENGTH);
372                 else
373                     optind--;
374                 break;
375             case 'b':   
376                 buffer_time = atof(optarg);
377                 if (buffer_time <= 0.) opt_err = -1;
378                 mod_buf_size++;
379                 break;
380             case 'd':
381                 sim_control_.debug = 1;
382                 break;
383             case 'e':
384                 sim_control_.end_time = atof(optarg);
385                 mod_end_time++;
386                 break;
387             case 'f':
388                 sim_control_.model_hz = atof(optarg);
389                 break;
390             case 'h': 
391                 opt_err = 1;
392                 break;
393             case 'i':
394                 /* ls_get_settings( optarg ); */
395                 break;
396             case 'k':
397                 sim_control_.sim_type = GLmouse;
398                 break;
399             case 'm':
400                 sim_control_.vision = 1;
401                 break;
402             case 'o': 
403                 sim_control_.term_update_hz = atof(optarg);
404                 if (sim_control_.term_update_hz <= 0.) opt_err = 1;
405                 break;
406             case 'r':
407                 sim_control_.write_mat = 1;
408                 if (optarg != NULL)
409                 if (*optarg != '-') 
410                     strncpy(matname, optarg, MAX_FILE_NAME_LENGTH);
411                 else
412                     optind--;
413                 break;
414             case 's':
415                 data_rate = atof(optarg);
416                 if (data_rate <= 0.) opt_err = -1;
417                 break;
418             case 't':
419                 sim_control_.write_tab = 1;
420                 if (optarg != NULL)
421                 if (*optarg != '-') 
422                     strncpy(tabname, optarg, MAX_FILE_NAME_LENGTH);
423                 else
424                     optind--;
425                 break;
426             case 'x':
427                 sim_control_.write_asc1 = 1;
428                 if (optarg != NULL)
429                 if (*optarg != '-') 
430                     strncpy(asc1name, optarg, MAX_FILE_NAME_LENGTH);
431                 else
432                     optind--;
433                 break;
434             default:
435                 opt_err = 1;
436             
437         }
438
439     if (opt_err)
440       {
441         fprintf(stderr, "Usage: %s [-options]\n", progname);
442         fprintf(stderr, "\n");
443         fprintf(stderr, "  where [-options] is zero or more of the following:\n");
444         fprintf(stderr, "\n");
445         fprintf(stderr, "  [A|k]           Run mode: [A]CES cockpit   [default]\n");
446         fprintf(stderr, "                         or [k]eyboard\n");
447         fprintf(stderr, "\n");
448         fprintf(stderr, "  [i <filename>]  [i]nitial conditions filename\n");
449         fprintf(stderr, "\n");
450         fprintf(stderr, "  [f <value>]     Iteration rate [f]requency, Hz (default is %5.2f Hz)\n", 
451                                                 sim_control_.model_hz);
452         fprintf(stderr, "\n");
453         fprintf(stderr, "  [o <value>]     Display [o]utput frequency, Hz (default is %5.2f Hz)\n", 
454                                                 sim_control_.term_update_hz);
455         fprintf(stderr, "\n");
456         fprintf(stderr, "  [s <value>]     Data storage frequency, Hz (default is %5.2f Hz)\n",
457                                                 data_rate);
458         fprintf(stderr, "\n");
459         fprintf(stderr, "  [e <value>]     [e]nd time in seconds (default %5.1f seconds)\n", 
460                                                 sim_control_.end_time);
461         fprintf(stderr, "\n");
462         fprintf(stderr, "  [b <value>]     circular time history storage [b]uffer size, in seconds \n");
463         fprintf(stderr, "                  (default %5.1f seconds) (normally same as end time)\n", 
464                                                 sim_control_.time_slices*sim_control_.save_spacing/
465                                                         sim_control_.model_hz);
466         fprintf(stderr, "\n");
467         fprintf(stderr, "  [atxr [<filename>]] Output: [a]gile-vu  (default name: %s )\n", fltname);
468         fprintf(stderr, "                       and/or [t]ab delimited ( '' name: %s )\n", tabname);
469         fprintf(stderr, "                       and/or [x]plot     (default name: %s)\n", asc1name);
470         fprintf(stderr, "                       and/or mat[r]ix script ( '' name: %s   )\n", matname);
471         fprintf(stderr, "\n");
472         return OPT_ERR;
473       }
474
475 /* calculate additional controls */
476
477     sim_control_.save_spacing = (int) (0.5 + sim_control_.model_hz / data_rate);
478     if (sim_control_.save_spacing < 1) sim_control_.save_spacing = 1;
479
480     sim_control_.time_slices = buffer_time * sim_control_.model_hz / 
481         sim_control_.save_spacing;
482     if (sim_control_.time_slices < 2) sim_control_.time_slices = 2;
483          
484     return OPT_OK;
485   }
486 #endif /* COMPILE_THIS_CODE_THIS_USELESS_CODE */
487
488
489 void ls_loop( SCALAR dt, int initialize ) {
490     /* printf ("  In ls_loop()\n"); */
491     ls_step( dt, initialize );
492     /* if (sim_control_.sim_type == cockpit ) ls_ACES();  */
493     ls_aux();
494     ls_model( dt, initialize );
495     ls_accel();
496 }
497
498
499
500 int ls_cockpit( void ) {
501     fgCONTROLS *c;
502
503     sim_control_.paused = 0;
504
505     c = current_aircraft.controls;
506
507     Lat_control = FG_Aileron;
508     Long_control = FG_Elevator;
509     Long_trim = FG_Elev_Trim;
510     Rudder_pedal = FG_Rudder;
511     Throttle_pct = FG_Throttle[0];
512
513     /* printf("Mach = %.2f  ", Mach_number);
514     printf("%.4f,%.4f,%.2f  ", Latitude, Longitude, Altitude);
515     printf("%.2f,%.2f,%.2f\n", Phi, Theta, Psi); */
516
517     return( 0 );
518 }
519
520
521 /* Initialize the LaRCsim flight model, dt is the time increment for
522    each subsequent iteration through the EOM */
523 int fgLaRCsimInit(double dt) {
524     model_dt = dt;
525
526     ls_setdefopts();            /* set default options */
527         
528     ls_stamp();   /* ID stamp; record time and date of run */
529
530     if (speedup == 0.0) {
531         fprintf(stderr, "%s: Cannot run with speedup of 0.\n", progname);
532         return 1;
533     }
534
535     /* printf("LS pre Init pos = %.2f\n", Latitude); */
536
537     ls_init();
538
539     /* printf("LS post Init pos = %.2f\n", Latitude); */
540
541     if (speedup > 0) {
542         /* Initialize (get) cockpit (controls) settings */
543         ls_cockpit();
544     }
545
546     return(1);
547 }
548
549
550 /* Run an iteration of the EOM (equations of motion) */
551 int fgLaRCsimUpdate(fgFLIGHT *f, int multiloop) {
552     int i;
553
554     if (speedup > 0) {
555         ls_cockpit();
556     }
557
558     for ( i = 0; i < multiloop; i++ ) {
559         //Insertion by Jeff Goeke-Smith for Autopilot.
560         
561         // run Autopilot system
562         // fgPrintf( FG_ALL, FG_BULK, "Attempting autopilot run\n");
563                       
564         fgAPRun();
565         // translate FG to LaRCsim structure
566         fgFlight_2_LaRCsim(f);
567         // printf("FG_Altitude = %.2f\n", FG_Altitude * 0.3048);
568         // printf("Altitude = %.2f\n", Altitude * 0.3048);
569         // printf("Radius to Vehicle = %.2f\n", Radius_to_vehicle * 0.3048);
570
571         // end of insertion 
572         
573         ls_loop( model_dt, 0);
574
575         // printf("%d FG_Altitude = %.2f\n", i, FG_Altitude * 0.3048);
576         // printf("%d Altitude = %.2f\n", i, Altitude * 0.3048);
577
578         // translate LaRCsim back to FG structure so that the
579         // autopilot (and the rest of the sim can use the updated
580         // values
581         fgLaRCsim_2_Flight(f);
582     }
583
584     return(1);
585 }
586
587
588 /* Convert from the fgFLIGHT struct to the LaRCsim generic_ struct */
589 int fgFlight_2_LaRCsim (fgFLIGHT *f) {
590     Mass =      FG_Mass;
591     I_xx =      FG_I_xx;
592     I_yy =      FG_I_yy;
593     I_zz =      FG_I_zz;
594     I_xz =      FG_I_xz;
595     Dx_pilot =  FG_Dx_pilot;
596     Dy_pilot =  FG_Dy_pilot;
597     Dz_pilot =  FG_Dz_pilot;
598     Dx_cg =     FG_Dx_cg;
599     Dy_cg =     FG_Dy_cg;
600     Dz_cg =     FG_Dz_cg;
601     F_X =       FG_F_X;
602     F_Y =       FG_F_Y;
603     F_Z =       FG_F_Z;
604     F_north =   FG_F_north;
605     F_east =    FG_F_east;
606     F_down =    FG_F_down;
607     F_X_aero =  FG_F_X_aero;
608     F_Y_aero =  FG_F_Y_aero;
609     F_Z_aero =  FG_F_Z_aero;
610     F_X_engine =        FG_F_X_engine;
611     F_Y_engine =        FG_F_Y_engine;
612     F_Z_engine =        FG_F_Z_engine;
613     F_X_gear =  FG_F_X_gear;
614     F_Y_gear =  FG_F_Y_gear;
615     F_Z_gear =  FG_F_Z_gear;
616     M_l_rp =    FG_M_l_rp;
617     M_m_rp =    FG_M_m_rp;
618     M_n_rp =    FG_M_n_rp;
619     M_l_cg =    FG_M_l_cg;
620     M_m_cg =    FG_M_m_cg;
621     M_n_cg =    FG_M_n_cg;
622     M_l_aero =  FG_M_l_aero;
623     M_m_aero =  FG_M_m_aero;
624     M_n_aero =  FG_M_n_aero;
625     M_l_engine =        FG_M_l_engine;
626     M_m_engine =        FG_M_m_engine;
627     M_n_engine =        FG_M_n_engine;
628     M_l_gear =  FG_M_l_gear;
629     M_m_gear =  FG_M_m_gear;
630     M_n_gear =  FG_M_n_gear;
631     V_dot_north =       FG_V_dot_north;
632     V_dot_east =        FG_V_dot_east;
633     V_dot_down =        FG_V_dot_down;
634     U_dot_body =        FG_U_dot_body;
635     V_dot_body =        FG_V_dot_body;
636     W_dot_body =        FG_W_dot_body;
637     A_X_cg =    FG_A_X_cg;
638     A_Y_cg =    FG_A_Y_cg;
639     A_Z_cg =    FG_A_Z_cg;
640     A_X_pilot = FG_A_X_pilot;
641     A_Y_pilot = FG_A_Y_pilot;
642     A_Z_pilot = FG_A_Z_pilot;
643     N_X_cg =    FG_N_X_cg;
644     N_Y_cg =    FG_N_Y_cg;
645     N_Z_cg =    FG_N_Z_cg;
646     N_X_pilot = FG_N_X_pilot;
647     N_Y_pilot = FG_N_Y_pilot;
648     N_Z_pilot = FG_N_Z_pilot;
649     P_dot_body =        FG_P_dot_body;
650     Q_dot_body =        FG_Q_dot_body;
651     R_dot_body =        FG_R_dot_body;
652     V_north =   FG_V_north;
653     V_east =    FG_V_east;
654     V_down =    FG_V_down;
655     V_north_rel_ground =        FG_V_north_rel_ground;
656     V_east_rel_ground = FG_V_east_rel_ground;
657     V_down_rel_ground = FG_V_down_rel_ground;
658     V_north_airmass =   FG_V_north_airmass;
659     V_east_airmass =    FG_V_east_airmass;
660     V_down_airmass =    FG_V_down_airmass;
661     V_north_rel_airmass =       FG_V_north_rel_airmass;
662     V_east_rel_airmass =        FG_V_east_rel_airmass;
663     V_down_rel_airmass =        FG_V_down_rel_airmass;
664     U_gust =    FG_U_gust;
665     V_gust =    FG_V_gust;
666     W_gust =    FG_W_gust;
667     U_body =    FG_U_body;
668     V_body =    FG_V_body;
669     W_body =    FG_W_body;
670     V_rel_wind =        FG_V_rel_wind;
671     V_true_kts =        FG_V_true_kts;
672     V_rel_ground =      FG_V_rel_ground;
673     V_inertial =        FG_V_inertial;
674     V_ground_speed =    FG_V_ground_speed;
675     V_equiv =   FG_V_equiv;
676     V_equiv_kts =       FG_V_equiv_kts;
677     V_calibrated =      FG_V_calibrated;
678     V_calibrated_kts =  FG_V_calibrated_kts;
679     P_body =    FG_P_body;
680     Q_body =    FG_Q_body;
681     R_body =    FG_R_body;
682     P_local =   FG_P_local;
683     Q_local =   FG_Q_local;
684     R_local =   FG_R_local;
685     P_total =   FG_P_total;
686     Q_total =   FG_Q_total;
687     R_total =   FG_R_total;
688     Phi_dot =   FG_Phi_dot;
689     Theta_dot = FG_Theta_dot;
690     Psi_dot =   FG_Psi_dot;
691     Latitude_dot =      FG_Latitude_dot;
692     Longitude_dot =     FG_Longitude_dot;
693     Radius_dot =        FG_Radius_dot;
694     Lat_geocentric =    FG_Lat_geocentric;
695     Lon_geocentric =    FG_Lon_geocentric;
696     Radius_to_vehicle = FG_Radius_to_vehicle;
697     Latitude =  FG_Latitude;
698     Longitude = FG_Longitude;
699     Altitude =  FG_Altitude;
700     Phi =       FG_Phi;
701     Theta =     FG_Theta;
702     Psi =       FG_Psi;
703     T_local_to_body_11 =        FG_T_local_to_body_11;
704     T_local_to_body_12 =        FG_T_local_to_body_12;
705     T_local_to_body_13 =        FG_T_local_to_body_13;
706     T_local_to_body_21 =        FG_T_local_to_body_21;
707     T_local_to_body_22 =        FG_T_local_to_body_22;
708     T_local_to_body_23 =        FG_T_local_to_body_23;
709     T_local_to_body_31 =        FG_T_local_to_body_31;
710     T_local_to_body_32 =        FG_T_local_to_body_32;
711     T_local_to_body_33 =        FG_T_local_to_body_33;
712     Gravity =   FG_Gravity;
713     Centrifugal_relief =        FG_Centrifugal_relief;
714     Alpha =     FG_Alpha;
715     Beta =      FG_Beta;
716     Alpha_dot = FG_Alpha_dot;
717     Beta_dot =  FG_Beta_dot;
718     Cos_alpha = FG_Cos_alpha;
719     Sin_alpha = FG_Sin_alpha;
720     Cos_beta =  FG_Cos_beta;
721     Sin_beta =  FG_Sin_beta;
722     Cos_phi =   FG_Cos_phi;
723     Sin_phi =   FG_Sin_phi;
724     Cos_theta = FG_Cos_theta;
725     Sin_theta = FG_Sin_theta;
726     Cos_psi =   FG_Cos_psi;
727     Sin_psi =   FG_Sin_psi;
728     Gamma_vert_rad =    FG_Gamma_vert_rad;
729     Gamma_horiz_rad =   FG_Gamma_horiz_rad;
730     Sigma =     FG_Sigma;
731     Density =   FG_Density;
732     V_sound =   FG_V_sound;
733     Mach_number =       FG_Mach_number;
734     Static_pressure =   FG_Static_pressure;
735     Total_pressure =    FG_Total_pressure;
736     Impact_pressure =   FG_Impact_pressure;
737     Dynamic_pressure =  FG_Dynamic_pressure;
738     Static_temperature =        FG_Static_temperature;
739     Total_temperature = FG_Total_temperature;
740     Sea_level_radius =  FG_Sea_level_radius;
741     Earth_position_angle =      FG_Earth_position_angle;
742     Runway_altitude =   FG_Runway_altitude;
743     Runway_latitude =   FG_Runway_latitude;
744     Runway_longitude =  FG_Runway_longitude;
745     Runway_heading =    FG_Runway_heading;
746     Radius_to_rwy =     FG_Radius_to_rwy;
747     D_cg_north_of_rwy = FG_D_cg_north_of_rwy;
748     D_cg_east_of_rwy =  FG_D_cg_east_of_rwy;
749     D_cg_above_rwy =    FG_D_cg_above_rwy;
750     X_cg_rwy =  FG_X_cg_rwy;
751     Y_cg_rwy =  FG_Y_cg_rwy;
752     H_cg_rwy =  FG_H_cg_rwy;
753     D_pilot_north_of_rwy =      FG_D_pilot_north_of_rwy;
754     D_pilot_east_of_rwy =       FG_D_pilot_east_of_rwy;
755     D_pilot_above_rwy = FG_D_pilot_above_rwy;
756     X_pilot_rwy =       FG_X_pilot_rwy;
757     Y_pilot_rwy =       FG_Y_pilot_rwy;
758     H_pilot_rwy =       FG_H_pilot_rwy;
759
760     return( 0 );
761 }
762
763
764 /* Convert from the LaRCsim generic_ struct to the fgFLIGHT struct */
765 int fgLaRCsim_2_Flight (fgFLIGHT *f) {
766     FG_Mass =   Mass;
767     FG_I_xx =   I_xx;
768     FG_I_yy =   I_yy;
769     FG_I_zz =   I_zz;
770     FG_I_xz =   I_xz;
771     FG_Dx_pilot =       Dx_pilot;
772     FG_Dy_pilot =       Dy_pilot;
773     FG_Dz_pilot =       Dz_pilot;
774     FG_Dx_cg =  Dx_cg;
775     FG_Dy_cg =  Dy_cg;
776     FG_Dz_cg =  Dz_cg;
777     FG_F_X =    F_X;
778     FG_F_Y =    F_Y;
779     FG_F_Z =    F_Z;
780     FG_F_north =        F_north;
781     FG_F_east = F_east;
782     FG_F_down = F_down;
783     FG_F_X_aero =       F_X_aero;
784     FG_F_Y_aero =       F_Y_aero;
785     FG_F_Z_aero =       F_Z_aero;
786     FG_F_X_engine =     F_X_engine;
787     FG_F_Y_engine =     F_Y_engine;
788     FG_F_Z_engine =     F_Z_engine;
789     FG_F_X_gear =       F_X_gear;
790     FG_F_Y_gear =       F_Y_gear;
791     FG_F_Z_gear =       F_Z_gear;
792     FG_M_l_rp = M_l_rp;
793     FG_M_m_rp = M_m_rp;
794     FG_M_n_rp = M_n_rp;
795     FG_M_l_cg = M_l_cg;
796     FG_M_m_cg = M_m_cg;
797     FG_M_n_cg = M_n_cg;
798     FG_M_l_aero =       M_l_aero;
799     FG_M_m_aero =       M_m_aero;
800     FG_M_n_aero =       M_n_aero;
801     FG_M_l_engine =     M_l_engine;
802     FG_M_m_engine =     M_m_engine;
803     FG_M_n_engine =     M_n_engine;
804     FG_M_l_gear =       M_l_gear;
805     FG_M_m_gear =       M_m_gear;
806     FG_M_n_gear =       M_n_gear;
807     FG_V_dot_north =    V_dot_north;
808     FG_V_dot_east =     V_dot_east;
809     FG_V_dot_down =     V_dot_down;
810     FG_U_dot_body =     U_dot_body;
811     FG_V_dot_body =     V_dot_body;
812     FG_W_dot_body =     W_dot_body;
813     FG_A_X_cg = A_X_cg;
814     FG_A_Y_cg = A_Y_cg;
815     FG_A_Z_cg = A_Z_cg;
816     FG_A_X_pilot =      A_X_pilot;
817     FG_A_Y_pilot =      A_Y_pilot;
818     FG_A_Z_pilot =      A_Z_pilot;
819     FG_N_X_cg = N_X_cg;
820     FG_N_Y_cg = N_Y_cg;
821     FG_N_Z_cg = N_Z_cg;
822     FG_N_X_pilot =      N_X_pilot;
823     FG_N_Y_pilot =      N_Y_pilot;
824     FG_N_Z_pilot =      N_Z_pilot;
825     FG_P_dot_body =     P_dot_body;
826     FG_Q_dot_body =     Q_dot_body;
827     FG_R_dot_body =     R_dot_body;
828     FG_V_north =        V_north;
829     FG_V_east = V_east;
830     FG_V_down = V_down;
831     FG_V_north_rel_ground =     V_north_rel_ground;
832     FG_V_east_rel_ground =      V_east_rel_ground;
833     FG_V_down_rel_ground =      V_down_rel_ground;
834     FG_V_north_airmass =        V_north_airmass;
835     FG_V_east_airmass = V_east_airmass;
836     FG_V_down_airmass = V_down_airmass;
837     FG_V_north_rel_airmass =    V_north_rel_airmass;
838     FG_V_east_rel_airmass =     V_east_rel_airmass;
839     FG_V_down_rel_airmass =     V_down_rel_airmass;
840     FG_U_gust = U_gust;
841     FG_V_gust = V_gust;
842     FG_W_gust = W_gust;
843     FG_U_body = U_body;
844     FG_V_body = V_body;
845     FG_W_body = W_body;
846     FG_V_rel_wind =     V_rel_wind;
847     FG_V_true_kts =     V_true_kts;
848     FG_V_rel_ground =   V_rel_ground;
849     FG_V_inertial =     V_inertial;
850     FG_V_ground_speed = V_ground_speed;
851     FG_V_equiv =        V_equiv;
852     FG_V_equiv_kts =    V_equiv_kts;
853     FG_V_calibrated =   V_calibrated;
854     FG_V_calibrated_kts =       V_calibrated_kts;
855     FG_P_body = P_body;
856     FG_Q_body = Q_body;
857     FG_R_body = R_body;
858     FG_P_local =        P_local;
859     FG_Q_local =        Q_local;
860     FG_R_local =        R_local;
861     FG_P_total =        P_total;
862     FG_Q_total =        Q_total;
863     FG_R_total =        R_total;
864     FG_Phi_dot =        Phi_dot;
865     FG_Theta_dot =      Theta_dot;
866     FG_Psi_dot =        Psi_dot;
867     FG_Latitude_dot =   Latitude_dot;
868     FG_Longitude_dot =  Longitude_dot;
869     FG_Radius_dot =     Radius_dot;
870     FG_Lat_geocentric = Lat_geocentric;
871     FG_Lon_geocentric = Lon_geocentric;
872     FG_Radius_to_vehicle =      Radius_to_vehicle;
873     FG_Latitude =       Latitude;
874     FG_Longitude =      Longitude;
875     FG_Altitude =       Altitude;
876     FG_Phi =    Phi;
877     FG_Theta =  Theta;
878     FG_Psi =    Psi;
879     FG_T_local_to_body_11 =     T_local_to_body_11;
880     FG_T_local_to_body_12 =     T_local_to_body_12;
881     FG_T_local_to_body_13 =     T_local_to_body_13;
882     FG_T_local_to_body_21 =     T_local_to_body_21;
883     FG_T_local_to_body_22 =     T_local_to_body_22;
884     FG_T_local_to_body_23 =     T_local_to_body_23;
885     FG_T_local_to_body_31 =     T_local_to_body_31;
886     FG_T_local_to_body_32 =     T_local_to_body_32;
887     FG_T_local_to_body_33 =     T_local_to_body_33;
888     FG_Gravity =        Gravity;
889     FG_Centrifugal_relief =     Centrifugal_relief;
890     FG_Alpha =  Alpha;
891     FG_Beta =   Beta;
892     FG_Alpha_dot =      Alpha_dot;
893     FG_Beta_dot =       Beta_dot;
894     FG_Cos_alpha =      Cos_alpha;
895     FG_Sin_alpha =      Sin_alpha;
896     FG_Cos_beta =       Cos_beta;
897     FG_Sin_beta =       Sin_beta;
898     FG_Cos_phi =        Cos_phi;
899     FG_Sin_phi =        Sin_phi;
900     FG_Cos_theta =      Cos_theta;
901     FG_Sin_theta =      Sin_theta;
902     FG_Cos_psi =        Cos_psi;
903     FG_Sin_psi =        Sin_psi;
904     FG_Gamma_vert_rad = Gamma_vert_rad;
905     FG_Gamma_horiz_rad =        Gamma_horiz_rad;
906     FG_Sigma =  Sigma;
907     FG_Density =        Density;
908     FG_V_sound =        V_sound;
909     FG_Mach_number =    Mach_number;
910     FG_Static_pressure =        Static_pressure;
911     FG_Total_pressure = Total_pressure;
912     FG_Impact_pressure =        Impact_pressure;
913     FG_Dynamic_pressure =       Dynamic_pressure;
914     FG_Static_temperature =     Static_temperature;
915     FG_Total_temperature =      Total_temperature;
916     FG_Sea_level_radius =       Sea_level_radius;
917     FG_Earth_position_angle =   Earth_position_angle;
918     FG_Runway_altitude =        Runway_altitude;
919     FG_Runway_latitude =        Runway_latitude;
920     FG_Runway_longitude =       Runway_longitude;
921     FG_Runway_heading = Runway_heading;
922     FG_Radius_to_rwy =  Radius_to_rwy;
923     FG_D_cg_north_of_rwy =      D_cg_north_of_rwy;
924     FG_D_cg_east_of_rwy =       D_cg_east_of_rwy;
925     FG_D_cg_above_rwy = D_cg_above_rwy;
926     FG_X_cg_rwy =       X_cg_rwy;
927     FG_Y_cg_rwy =       Y_cg_rwy;
928     FG_H_cg_rwy =       H_cg_rwy;
929     FG_D_pilot_north_of_rwy =   D_pilot_north_of_rwy;
930     FG_D_pilot_east_of_rwy =    D_pilot_east_of_rwy;
931     FG_D_pilot_above_rwy =      D_pilot_above_rwy;
932     FG_X_pilot_rwy =    X_pilot_rwy;
933     FG_Y_pilot_rwy =    Y_pilot_rwy;
934     FG_H_pilot_rwy =    H_pilot_rwy;
935
936     return ( 0 );
937 }
938
939
940 /* Set the altitude (force) */
941 int ls_ForceAltitude(double alt_feet) {
942     Altitude = alt_feet;
943     ls_geod_to_geoc( Latitude, Altitude, &Sea_level_radius, &Lat_geocentric);
944     Radius_to_vehicle = Altitude + Sea_level_radius;
945 }
946
947
948 /* Flight Gear Modification Log
949  *
950  * $Log$
951  * Revision 1.20  1998/07/12 03:11:03  curt
952  * Removed some printf()'s.
953  * Fixed the autopilot integration so it should be able to update it's control
954  *   positions every time the internal flight model loop is run, and not just
955  *   once per rendered frame.
956  * Added a routine to do the necessary stuff to force an arbitrary altitude
957  *   change.
958  * Gave the Navion engine just a tad more power.
959  *
960  * Revision 1.19  1998/05/11 18:17:28  curt
961  * Output message tweaking.
962  *
963  * Revision 1.18  1998/04/21 16:59:38  curt
964  * Integrated autopilot.
965  * Prepairing for C++ integration.
966  *
967  * Revision 1.17  1998/02/23 19:07:58  curt
968  * Incorporated Durk's Astro/ tweaks.  Includes unifying the sun position
969  * calculation code between sun display, and other FG sections that use this
970  * for things like lighting.
971  *
972  * Revision 1.16  1998/02/07 15:29:38  curt
973  * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
974  * <chotchkiss@namg.us.anritsu.com>
975  *
976  * Revision 1.15  1998/01/22 22:03:47  curt
977  * Removed #include <sys/stat.h>
978  *
979  * Revision 1.14  1998/01/19 19:27:04  curt
980  * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
981  * This should simplify things tremendously.
982  *
983  * Revision 1.13  1998/01/19 18:40:26  curt
984  * Tons of little changes to clean up the code and to remove fatal errors
985  * when building with the c++ compiler.
986  *
987  * Revision 1.12  1998/01/06 01:20:16  curt
988  * Tweaks to help building with MSVC++
989  *
990  * Revision 1.11  1998/01/05 22:19:26  curt
991  * #ifdef'd out some unused code that was problematic for MSVC++ to compile.
992  *
993  * Revision 1.10  1997/12/10 22:37:43  curt
994  * Prepended "fg" on the name of all global structures that didn't have it yet.
995  * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
996  *
997  * Revision 1.9  1997/08/27 03:30:08  curt
998  * Changed naming scheme of basic shared structures.
999  *
1000  * Revision 1.8  1997/06/21 17:12:50  curt
1001  * Capitalized subdirectory names.
1002  *
1003  * Revision 1.7  1997/05/31 19:16:28  curt
1004  * Elevator trim added.
1005  *
1006  * Revision 1.6  1997/05/31 04:13:53  curt
1007  * WE CAN NOW FLY!!!
1008  *
1009  * Continuing work on the LaRCsim flight model integration.
1010  * Added some MSFS-like keyboard input handling.
1011  *
1012  * Revision 1.5  1997/05/30 23:26:25  curt
1013  * Added elevator/aileron controls.
1014  *
1015  * Revision 1.4  1997/05/30 19:30:15  curt
1016  * The LaRCsim flight model is starting to look like it is working.
1017  *
1018  * Revision 1.3  1997/05/30 03:54:12  curt
1019  * Made a bit more progress towards integrating the LaRCsim flight model.
1020  *
1021  * Revision 1.2  1997/05/29 22:39:59  curt
1022  * Working on incorporating the LaRCsim flight model.
1023  *
1024  * Revision 1.1  1997/05/29 00:09:57  curt
1025  * Initial Flight Gear revision.
1026  *
1027  */