| 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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_geodesy.h" |
| 235 | #include "ls_generic.h" |
| 236 | #include "ls_sim_control.h" |
| 237 | #include "ls_cockpit.h" |
| 238 | #include "ls_interface.h" |
| 239 | #include "ls_step.h" |
| 240 | #include "ls_accel.h" |
| 241 | #include "ls_aux.h" |
| 242 | #include "ls_model.h" |
| 243 | #include "ls_init.h" |
| 244 | |
| 245 | // #include <Flight/flight.h> |
| 246 | // #include <Aircraft/aircraft.h> |
| 247 | // #include <Debug/fg_debug.h> |
| 248 | |
| 249 | |
| 250 | /* global variable declarations */ |
| 251 | |
| 252 | /* TAPE *Tape; */ |
| 253 | GENERIC generic_; |
| 254 | SIM_CONTROL sim_control_; |
| 255 | COCKPIT cockpit_; |
| 256 | |
| 257 | SCALAR Simtime; |
| 258 | |
| 259 | #define DEFAULT_TERM_UPDATE_HZ 20 |
| 260 | #define DEFAULT_MODEL_HZ 120 |
| 261 | #define DEFAULT_END_TIME 3600. |
| 262 | #define DEFAULT_SAVE_SPACING 8 |
| 263 | #define DEFAULT_WRITE_SPACING 1 |
| 264 | #define MAX_FILE_NAME_LENGTH 80 |
| 265 | |
| 266 | /* global variables */ |
| 267 | |
| 268 | char *progname; |
| 269 | char *fullname; |
| 270 | |
| 271 | /* file variables - default simulation settings */ |
| 272 | |
| 273 | static double model_dt; |
| 274 | static double speedup; |
| 275 | |
| 276 | |
| 277 | |
| 278 | void ls_stamp( void ) { |
| 279 | // char rcsid[] = "$Id$"; |
| 280 | char revid[] = "$Revision$"; |
| 281 | char dateid[] = "$Date$"; |
| 282 | struct tm *nowtime; |
| 283 | time_t nowtime_t; |
| 284 | long date; |
| 285 | |
| 286 | /* report version of LaRCsim*/ |
| 287 | printf("\nLaRCsim %s, %s\n\n", revid, dateid); |
| 288 | |
| 289 | nowtime_t = time( 0 ); |
| 290 | nowtime = localtime( &nowtime_t ); /* set fields to correct time values */ |
| 291 | date = (nowtime->tm_year % 100)*10000 |
| 292 | + (nowtime->tm_mon + 1)*100 |
| 293 | + (nowtime->tm_mday); |
| 294 | snprintf(sim_control_.date_string, sizeof(sim_control_.date_string), "%06ld", date); |
| 295 | snprintf(sim_control_.time_stamp, sizeof(sim_control_.time_stamp), "%02d:%02d:%02d", |
| 296 | nowtime->tm_hour, nowtime->tm_min, nowtime->tm_sec); |
| 297 | #ifdef COMPILE_THIS_CODE_THIS_USELESS_CODE |
| 298 | cuserid( sim_control_.userid ); /* set up user id */ |
| 299 | #endif /* COMPILE_THIS_CODE_THIS_USELESS_CODE */ |
| 300 | return; |
| 301 | } |
| 302 | |
| 303 | void ls_setdefopts( void ) { |
| 304 | /* set default values for most options */ |
| 305 | |
| 306 | sim_control_.debug = 0; /* change to non-zero if in dbx! */ |
| 307 | sim_control_.vision = 0; |
| 308 | sim_control_.write_av = 0; /* write Agile-Vu '.flt' file */ |
| 309 | sim_control_.write_mat = 0; /* write matrix-x/matlab script */ |
| 310 | sim_control_.write_tab = 0; /* write tab delim. history file */ |
| 311 | sim_control_.write_asc1 = 0; /* write GetData file */ |
| 312 | sim_control_.save_spacing = DEFAULT_SAVE_SPACING; |
| 313 | /* interpolation on recording */ |
| 314 | sim_control_.write_spacing = DEFAULT_WRITE_SPACING; |
| 315 | /* interpolation on output */ |
| 316 | sim_control_.end_time = DEFAULT_END_TIME; |
| 317 | sim_control_.model_hz = DEFAULT_MODEL_HZ; |
| 318 | sim_control_.term_update_hz = DEFAULT_TERM_UPDATE_HZ; |
| 319 | sim_control_.time_slices = (long int)(DEFAULT_END_TIME * DEFAULT_MODEL_HZ / |
| 320 | DEFAULT_SAVE_SPACING); |
| 321 | sim_control_.paused = 0; |
| 322 | |
| 323 | speedup = 1.0; |
| 324 | } |
| 325 | |
| 326 | |
| 327 | /* return result codes from ls_checkopts */ |
| 328 | |
| 329 | #define OPT_OK 0 |
| 330 | #define OPT_ERR 1 |
| 331 | |
| 332 | #ifdef COMPILE_THIS_CODE_THIS_USELESS_CODE |
| 333 | |
| 334 | extern char *optarg; |
| 335 | extern int optind; |
| 336 | |
| 337 | int ls_checkopts(argc, argv) /* check and set options flags */ |
| 338 | int argc; |
| 339 | char *argv[]; |
| 340 | { |
| 341 | int c; |
| 342 | int opt_err = 0; |
| 343 | int mod_end_time = 0; |
| 344 | int mod_buf_size = 0; |
| 345 | float buffer_time, data_rate; |
| 346 | char asc1name[MAX_FILE_NAME_LENGTH] = "run.asc1"; |
| 347 | char tabname[MAX_FILE_NAME_LENGTH] = "run.dat"; |
| 348 | char fltname[MAX_FILE_NAME_LENGTH] = "run.flt"; |
| 349 | char matname[MAX_FILE_NAME_LENGTH] = "run.m"; |
| 350 | |
| 351 | /* set default values */ |
| 352 | |
| 353 | buffer_time = sim_control_.time_slices * sim_control_.save_spacing / |
| 354 | sim_control_.model_hz; |
| 355 | data_rate = sim_control_.model_hz / sim_control_.save_spacing; |
| 356 | |
| 357 | while ((c = getopt(argc, argv, "Aa:b:de:f:hi:kmo:r:s:t:x:")) != EOF) |
| 358 | switch (c) { |
| 359 | case 'A': |
| 360 | if (sim_control_.sim_type == GLmouse) |
| 361 | { |
| 362 | fprintf(stderr, "Cannot specify both keyboard (k) and ACES (A) cockpits option\n"); |
| 363 | fprintf(stderr, "Keyboard operation assumed.\n"); |
| 364 | break; |
| 365 | } |
| 366 | sim_control_.sim_type = cockpit; |
| 367 | break; |
| 368 | case 'a': |
| 369 | sim_control_.write_av = 1; |
| 370 | if (optarg != NULL) |
| 371 | if (*optarg != '-') |
| 372 | strncpy(fltname, optarg, MAX_FILE_NAME_LENGTH); |
| 373 | else |
| 374 | optind--; |
| 375 | break; |
| 376 | case 'b': |
| 377 | buffer_time = atof(optarg); |
| 378 | if (buffer_time <= 0.) opt_err = -1; |
| 379 | mod_buf_size++; |
| 380 | break; |
| 381 | case 'd': |
| 382 | sim_control_.debug = 1; |
| 383 | break; |
| 384 | case 'e': |
| 385 | sim_control_.end_time = atof(optarg); |
| 386 | mod_end_time++; |
| 387 | break; |
| 388 | case 'f': |
| 389 | sim_control_.model_hz = atof(optarg); |
| 390 | break; |
| 391 | case 'h': |
| 392 | opt_err = 1; |
| 393 | break; |
| 394 | case 'i': |
| 395 | /* ls_get_settings( optarg ); */ |
| 396 | break; |
| 397 | case 'k': |
| 398 | sim_control_.sim_type = GLmouse; |
| 399 | break; |
| 400 | case 'm': |
| 401 | sim_control_.vision = 1; |
| 402 | break; |
| 403 | case 'o': |
| 404 | sim_control_.term_update_hz = atof(optarg); |
| 405 | if (sim_control_.term_update_hz <= 0.) opt_err = 1; |
| 406 | break; |
| 407 | case 'r': |
| 408 | sim_control_.write_mat = 1; |
| 409 | if (optarg != NULL) |
| 410 | if (*optarg != '-') |
| 411 | strncpy(matname, optarg, MAX_FILE_NAME_LENGTH); |
| 412 | else |
| 413 | optind--; |
| 414 | break; |
| 415 | case 's': |
| 416 | data_rate = atof(optarg); |
| 417 | if (data_rate <= 0.) opt_err = -1; |
| 418 | break; |
| 419 | case 't': |
| 420 | sim_control_.write_tab = 1; |
| 421 | if (optarg != NULL) |
| 422 | if (*optarg != '-') |
| 423 | strncpy(tabname, optarg, MAX_FILE_NAME_LENGTH); |
| 424 | else |
| 425 | optind--; |
| 426 | break; |
| 427 | case 'x': |
| 428 | sim_control_.write_asc1 = 1; |
| 429 | if (optarg != NULL) |
| 430 | if (*optarg != '-') |
| 431 | strncpy(asc1name, optarg, MAX_FILE_NAME_LENGTH); |
| 432 | else |
| 433 | optind--; |
| 434 | break; |
| 435 | default: |
| 436 | opt_err = 1; |
| 437 | |
| 438 | } |
| 439 | |
| 440 | if (opt_err) |
| 441 | { |
| 442 | fprintf(stderr, "Usage: %s [-options]\n", progname); |
| 443 | fprintf(stderr, "\n"); |
| 444 | fprintf(stderr, " where [-options] is zero or more of the following:\n"); |
| 445 | fprintf(stderr, "\n"); |
| 446 | fprintf(stderr, " [A|k] Run mode: [A]CES cockpit [default]\n"); |
| 447 | fprintf(stderr, " or [k]eyboard\n"); |
| 448 | fprintf(stderr, "\n"); |
| 449 | fprintf(stderr, " [i <filename>] [i]nitial conditions filename\n"); |
| 450 | fprintf(stderr, "\n"); |
| 451 | fprintf(stderr, " [f <value>] Iteration rate [f]requency, Hz (default is %5.2f Hz)\n", |
| 452 | sim_control_.model_hz); |
| 453 | fprintf(stderr, "\n"); |
| 454 | fprintf(stderr, " [o <value>] Display [o]utput frequency, Hz (default is %5.2f Hz)\n", |
| 455 | sim_control_.term_update_hz); |
| 456 | fprintf(stderr, "\n"); |
| 457 | fprintf(stderr, " [s <value>] Data storage frequency, Hz (default is %5.2f Hz)\n", |
| 458 | data_rate); |
| 459 | fprintf(stderr, "\n"); |
| 460 | fprintf(stderr, " [e <value>] [e]nd time in seconds (default %5.1f seconds)\n", |
| 461 | sim_control_.end_time); |
| 462 | fprintf(stderr, "\n"); |
| 463 | fprintf(stderr, " [b <value>] circular time history storage [b]uffer size, in seconds \n"); |
| 464 | fprintf(stderr, " (default %5.1f seconds) (normally same as end time)\n", |
| 465 | sim_control_.time_slices*sim_control_.save_spacing/ |
| 466 | sim_control_.model_hz); |
| 467 | fprintf(stderr, "\n"); |
| 468 | fprintf(stderr, " [atxr [<filename>]] Output: [a]gile-vu (default name: %s )\n", fltname); |
| 469 | fprintf(stderr, " and/or [t]ab delimited ( '' name: %s )\n", tabname); |
| 470 | fprintf(stderr, " and/or [x]plot (default name: %s)\n", asc1name); |
| 471 | fprintf(stderr, " and/or mat[r]ix script ( '' name: %s )\n", matname); |
| 472 | fprintf(stderr, "\n"); |
| 473 | return OPT_ERR; |
| 474 | } |
| 475 | |
| 476 | /* calculate additional controls */ |
| 477 | |
| 478 | sim_control_.save_spacing = (int) (0.5 + sim_control_.model_hz / data_rate); |
| 479 | if (sim_control_.save_spacing < 1) sim_control_.save_spacing = 1; |
| 480 | |
| 481 | sim_control_.time_slices = buffer_time * sim_control_.model_hz / |
| 482 | sim_control_.save_spacing; |
| 483 | if (sim_control_.time_slices < 2) sim_control_.time_slices = 2; |
| 484 | |
| 485 | return OPT_OK; |
| 486 | } |
| 487 | #endif /* COMPILE_THIS_CODE_THIS_USELESS_CODE */ |
| 488 | |
| 489 | void ls_set_model_dt(double dt) { |
| 490 | model_dt = dt; |
| 491 | } |
| 492 | |
| 493 | void ls_loop( SCALAR dt, int initialize ) { |
| 494 | /* printf (" In ls_loop()\n"); */ |
| 495 | ls_step( dt, initialize ); |
| 496 | /* if (sim_control_.sim_type == cockpit ) ls_ACES(); */ |
| 497 | ls_aux(); |
| 498 | ls_model( dt, initialize ); |
| 499 | ls_accel(); |
| 500 | } |
| 501 | |
| 502 | |
| 503 | |
| 504 | int ls_cockpit( void ) { |
| 505 | // fgCONTROLS *c; |
| 506 | |
| 507 | sim_control_.paused = 0; |
| 508 | |
| 509 | // c = current_aircraft.controls; |
| 510 | |
| 511 | // Lat_control = FG_Aileron; |
| 512 | // Long_control = FG_Elevator; |
| 513 | // Long_trim = FG_Elev_Trim; |
| 514 | // Rudder_pedal = FG_Rudder; |
| 515 | // Throttle_pct = FG_Throttle[0]; |
| 516 | |
| 517 | /* printf("Mach = %.2f ", Mach_number); |
| 518 | printf("%.4f,%.4f,%.2f ", Latitude, Longitude, Altitude); |
| 519 | printf("%.2f,%.2f,%.2f\n", Phi, Theta, Psi); */ |
| 520 | |
| 521 | return( 0 ); |
| 522 | } |
| 523 | |
| 524 | |
| 525 | /* Initialize the LaRCsim flight model, dt is the time increment for |
| 526 | each subsequent iteration through the EOM */ |
| 527 | int ls_toplevel_init(double dt, char * aircraft) { |
| 528 | model_dt = dt; |
| 529 | |
| 530 | ls_setdefopts(); /* set default options */ |
| 531 | |
| 532 | ls_stamp(); /* ID stamp; record time and date of run */ |
| 533 | |
| 534 | if (speedup == 0.0) { |
| 535 | fprintf(stderr, "%s: Cannot run with speedup of 0.\n", progname); |
| 536 | return 1; |
| 537 | } |
| 538 | |
| 539 | /* printf("LS pre Init pos = %.2f\n", Latitude); */ |
| 540 | |
| 541 | ls_init(aircraft); |
| 542 | |
| 543 | /* printf("LS post Init pos = %.2f\n", Latitude); */ |
| 544 | |
| 545 | if (speedup > 0) { |
| 546 | /* Initialize (get) cockpit (controls) settings */ |
| 547 | ls_cockpit(); |
| 548 | } |
| 549 | |
| 550 | return(1); |
| 551 | } |
| 552 | |
| 553 | |
| 554 | /* Run an iteration of the EOM (equations of motion) */ |
| 555 | int ls_update(int multiloop) { |
| 556 | int i; |
| 557 | |
| 558 | if (speedup > 0) { |
| 559 | ls_cockpit(); |
| 560 | } |
| 561 | |
| 562 | for ( i = 0; i < multiloop; i++ ) { |
| 563 | ls_loop( model_dt, 0); |
| 564 | } |
| 565 | |
| 566 | return 1; |
| 567 | } |
| 568 | |
| 569 | |
| 570 | /* Set the altitude (force) */ |
| 571 | int ls_ForceAltitude(double alt_feet) { |
| 572 | Altitude = alt_feet; |
| 573 | ls_geod_to_geoc( Latitude, Altitude, &Sea_level_radius, &Lat_geocentric); |
| 574 | Radius_to_vehicle = Altitude + Sea_level_radius; |
| 575 | |
| 576 | return 0; |
| 577 | } |
| 578 | |
| 579 | |
| 580 | /* Flight Gear Modification Log |
| 581 | * |
| 582 | * $Log$ |
| 583 | * Revision 1.3 2007/03/01 17:53:24 mfranz |
| 584 | * Hans Ulrich NIEDERMANN: |
| 585 | * |
| 586 | * """ |
| 587 | * Fix Y2K bug triggering string overflow |
| 588 | * |
| 589 | * sim_control_.date_string is a char[7], so it can contain "yymmdd" and |
| 590 | * the terminating '\0'. However, nowtime->tm_year is 107 for the year 2007, |
| 591 | * so you'll end up with a 7 digit number and the string written to |
| 592 | * sim_control_.date_string is longer than sim_control_.date_string is. |
| 593 | * Ouch! |
| 594 | * """ |
| 595 | * |
| 596 | * mf: ... and sim_control_.date_string isn't even used. |
| 597 | * |
| 598 | * Revision 1.2 2006-02-21 17:45:03 mfranz |
| 599 | * new FSF address (see http://www.gnu.org/licenses/gpl.html) |
| 600 | * |
| 601 | * Revision 1.1.1.1 2002-09-10 01:14:02 curt |
| 602 | * Initial revision of FlightGear-0.9.0 |
| 603 | * |
| 604 | * Revision 1.6 2002/01/30 15:17:27 david |
| 605 | * Fixes from Cameron Moore: |
| 606 | * |
| 607 | * I've attached 3 diffs against files in FlightGear to fix some printf |
| 608 | * format strings. The changes are pretty straight forward. Let me know |
| 609 | * if you have any questions. (BTW, I'm using gcc 2.95.4) |
| 610 | * |
| 611 | * Revision 1.5 2001/05/21 18:44:59 curt |
| 612 | * Tile pager tweaks. |
| 613 | * MSVC++ tweaks. |
| 614 | * |
| 615 | * Revision 1.4 2001/03/24 05:03:12 curt |
| 616 | * SG-ified logstream. |
| 617 | * |
| 618 | * Revision 1.3 2000/10/23 22:34:54 curt |
| 619 | * I tested: |
| 620 | * LaRCsim c172 on-ground and in-air starts, reset: all work |
| 621 | * UIUC Cessna172 on-ground and in-air starts work as expected, reset |
| 622 | * results in an aircraft that is upside down but does not crash FG. I |
| 623 | * don't know what it was like before, so it may well be no change. |
| 624 | * JSBSim c172 and X15 in-air starts work fine, resets now work (and are |
| 625 | * trimmed), on-ground starts do not -- the c172 ends up on its back. I |
| 626 | * suspect this is no worse than before. |
| 627 | * |
| 628 | * I did not test: |
| 629 | * Balloon (the weather code returns nan's for the atmosphere data --this |
| 630 | * is in the weather module and apparently is a linux only bug) |
| 631 | * ADA (don't know how) |
| 632 | * MagicCarpet (needs work yet) |
| 633 | * External (don't know how) |
| 634 | * |
| 635 | * known to be broken: |
| 636 | * LaRCsim c172 on-ground starts with a negative terrain altitude (this |
| 637 | * happens at KPAO when the scenery is not present). The FDM inits to |
| 638 | * about 50 feet AGL and the model falls to the ground. It does stay |
| 639 | * upright, however, and seems to be fine once it settles out, FWIW. |
| 640 | * |
| 641 | * To do: |
| 642 | * --implement set_Model on the bus |
| 643 | * --bring Christian's weather data into JSBSim |
| 644 | * -- add default method to bus for updating things like the sin and cos of |
| 645 | * latitude (for Balloon, MagicCarpet) |
| 646 | * -- lots of cleanup |
| 647 | * |
| 648 | * The files: |
| 649 | * src/FDM/flight.cxx |
| 650 | * src/FDM/flight.hxx |
| 651 | * -- all data members now declared protected instead of private. |
| 652 | * -- eliminated all but a small set of 'setters', no change to getters. |
| 653 | * -- that small set is declared virtual, the default implementation |
| 654 | * provided preserves the old behavior |
| 655 | * -- all of the vector data members are now initialized. |
| 656 | * -- added busdump() method -- SG_LOG's all the bus data when called, |
| 657 | * useful for diagnostics. |
| 658 | * |
| 659 | * src/FDM/ADA.cxx |
| 660 | * -- bus data members now directly assigned to |
| 661 | * |
| 662 | * src/FDM/Balloon.cxx |
| 663 | * -- bus data members now directly assigned to |
| 664 | * -- changed V_equiv_kts to V_calibrated_kts |
| 665 | * |
| 666 | * src/FDM/JSBSim.cxx |
| 667 | * src/FDM/JSBSim.hxx |
| 668 | * -- bus data members now directly assigned to |
| 669 | * -- implemented the FGInterface virtual setters with JSBSim specific |
| 670 | * logic |
| 671 | * -- changed the static FDMExec to a dynamic fdmex (needed so that the |
| 672 | * JSBSim object can be deleted when a model change is called for) |
| 673 | * -- implemented constructor and destructor, moved some of the logic |
| 674 | * formerly in init() to constructor |
| 675 | * -- added logic to bring up FGEngInterface objects and set the RPM and |
| 676 | * throttle values. |
| 677 | * |
| 678 | * src/FDM/LaRCsim.cxx |
| 679 | * src/FDM/LaRCsim.hxx |
| 680 | * -- bus data members now directly assigned to |
| 681 | * -- implemented the FGInterface virtual setters with LaRCsim specific |
| 682 | * logic, uses LaRCsimIC |
| 683 | * -- implemented constructor and destructor, moved some of the logic |
| 684 | * formerly in init() to constructor |
| 685 | * -- moved default inertias to here from fg_init.cxx |
| 686 | * -- eliminated the climb rate calculation. The equivalent, climb_rate = |
| 687 | * -1*vdown, is now in copy_from_LaRCsim(). |
| 688 | * |
| 689 | * src/FDM/LaRCsimIC.cxx |
| 690 | * src/FDM/LaRCsimIC.hxx |
| 691 | * -- similar to FGInitialCondition, this class has all the logic needed to |
| 692 | * turn data like Vc and Mach into the more fundamental quantities LaRCsim |
| 693 | * needs to initialize. |
| 694 | * -- put it in src/FDM since it is a class |
| 695 | * |
| 696 | * src/FDM/MagicCarpet.cxx |
| 697 | * -- bus data members now directly assigned to |
| 698 | * |
| 699 | * src/FDM/Makefile.am |
| 700 | * -- adds LaRCsimIC.hxx and cxx |
| 701 | * |
| 702 | * src/FDM/JSBSim/FGAtmosphere.h |
| 703 | * src/FDM/JSBSim/FGDefs.h |
| 704 | * src/FDM/JSBSim/FGInitialCondition.cpp |
| 705 | * src/FDM/JSBSim/FGInitialCondition.h |
| 706 | * src/FDM/JSBSim/JSBSim.cpp |
| 707 | * -- changes to accomodate the new bus |
| 708 | * |
| 709 | * src/FDM/LaRCsim/atmos_62.h |
| 710 | * src/FDM/LaRCsim/ls_geodesy.h |
| 711 | * -- surrounded prototypes with #ifdef __cplusplus ... #endif , functions |
| 712 | * here are needed in LaRCsimIC |
| 713 | * |
| 714 | * src/FDM/LaRCsim/c172_main.c |
| 715 | * src/FDM/LaRCsim/cherokee_aero.c |
| 716 | * src/FDM/LaRCsim/ls_aux.c |
| 717 | * src/FDM/LaRCsim/ls_constants.h |
| 718 | * src/FDM/LaRCsim/ls_geodesy.c |
| 719 | * src/FDM/LaRCsim/ls_geodesy.h |
| 720 | * src/FDM/LaRCsim/ls_step.c |
| 721 | * src/FDM/UIUCModel/uiuc_betaprobe.cpp |
| 722 | * -- changed PI to LS_PI, eliminates preprocessor naming conflict with |
| 723 | * weather module |
| 724 | * |
| 725 | * src/FDM/LaRCsim/ls_interface.c |
| 726 | * src/FDM/LaRCsim/ls_interface.h |
| 727 | * -- added function ls_set_model_dt() |
| 728 | * |
| 729 | * src/Main/bfi.cxx |
| 730 | * -- eliminated calls that set the NED speeds to body components. They |
| 731 | * are no longer needed and confuse the new bus. |
| 732 | * |
| 733 | * src/Main/fg_init.cxx |
| 734 | * -- eliminated calls that just brought the bus data up-to-date (e.g. |
| 735 | * set_sin_cos_latitude). or set default values. The bus now handles the |
| 736 | * defaults and updates itself when the setters are called (for LaRCsim and |
| 737 | * JSBSim). A default method for doing this needs to be added to the bus. |
| 738 | * -- added fgVelocityInit() to set the speed the user asked for. Both |
| 739 | * JSBSim and LaRCsim can now be initialized using any of: |
| 740 | * vc,mach, NED components, UVW components. |
| 741 | * |
| 742 | * src/Main/main.cxx |
| 743 | * --eliminated call to fgFDMSetGroundElevation, this data is now 'pulled' |
| 744 | * onto the bus every update() |
| 745 | * |
| 746 | * src/Main/options.cxx |
| 747 | * src/Main/options.hxx |
| 748 | * -- added enum to keep track of the speed requested by the user |
| 749 | * -- eliminated calls to set NED velocity properties to body speeds, they |
| 750 | * are no longer needed. |
| 751 | * -- added options for the NED components. |
| 752 | * |
| 753 | * src/Network/garmin.cxx |
| 754 | * src/Network/nmea.cxx |
| 755 | * --eliminated calls that just brought the bus data up-to-date (e.g. |
| 756 | * set_sin_cos_latitude). The bus now updates itself when the setters are |
| 757 | * called (for LaRCsim and JSBSim). A default method for doing this needs |
| 758 | * to be added to the bus. |
| 759 | * -- changed set_V_equiv_kts to set_V_calibrated_kts. set_V_equiv_kts no |
| 760 | * longer exists ( get_V_equiv_kts still does, though) |
| 761 | * |
| 762 | * src/WeatherCM/FGLocalWeatherDatabase.cpp |
| 763 | * -- commented out the code to put the weather data on the bus, a |
| 764 | * different scheme for this is needed. |
| 765 | * |
| 766 | * Revision 1.2 2000/04/10 18:09:41 curt |
| 767 | * David Megginson made a few (mostly minor) mods to the LaRCsim files, and |
| 768 | * it's now possible to choose the LaRCsim model at runtime, as in |
| 769 | * |
| 770 | * fgfs --aircraft=c172 |
| 771 | * |
| 772 | * or |
| 773 | * |
| 774 | * fgfs --aircraft=uiuc --aircraft-dir=Aircraft-uiuc/Boeing747 |
| 775 | * |
| 776 | * I did this so that I could play with the UIUC stuff without losing |
| 777 | * Tony's C172 with its flaps, etc. I did my best to respect the design |
| 778 | * of the LaRCsim code by staying in C, making only minimal changes, and |
| 779 | * not introducing any dependencies on the rest of FlightGear. The |
| 780 | * modified files are attached. |
| 781 | * |
| 782 | * Revision 1.1.1.1 1999/06/17 18:07:33 curt |
| 783 | * Start of 0.7.x branch |
| 784 | * |
| 785 | * Revision 1.2 1999/04/27 19:28:04 curt |
| 786 | * Changes for the MacOS port contributed by Darrell Walisser. |
| 787 | * |
| 788 | * Revision 1.1.1.1 1999/04/05 21:32:45 curt |
| 789 | * Start of 0.6.x branch. |
| 790 | * |
| 791 | * Revision 1.25 1999/01/19 20:57:02 curt |
| 792 | * MacOS portability changes contributed by "Robert Puyol" <[email protected]> |
| 793 | * |
| 794 | * Revision 1.24 1998/12/14 13:27:47 curt |
| 795 | * Removed some old, outdated, no longer needed code. |
| 796 | * |
| 797 | * Revision 1.23 1998/10/16 23:27:44 curt |
| 798 | * C++-ifying. |
| 799 | * |
| 800 | * Revision 1.22 1998/09/29 02:02:59 curt |
| 801 | * Added a brake + autopilot mods. |
| 802 | * |
| 803 | * Revision 1.21 1998/08/22 14:49:56 curt |
| 804 | * Attempting to iron out seg faults and crashes. |
| 805 | * Did some shuffling to fix a initialization order problem between view |
| 806 | * position, scenery elevation. |
| 807 | * |
| 808 | * Revision 1.20 1998/07/12 03:11:03 curt |
| 809 | * Removed some printf()'s. |
| 810 | * Fixed the autopilot integration so it should be able to update it's control |
| 811 | * positions every time the internal flight model loop is run, and not just |
| 812 | * once per rendered frame. |
| 813 | * Added a routine to do the necessary stuff to force an arbitrary altitude |
| 814 | * change. |
| 815 | * Gave the Navion engine just a tad more power. |
| 816 | * |
| 817 | * Revision 1.19 1998/05/11 18:17:28 curt |
| 818 | * Output message tweaking. |
| 819 | * |
| 820 | * Revision 1.18 1998/04/21 16:59:38 curt |
| 821 | * Integrated autopilot. |
| 822 | * Prepairing for C++ integration. |
| 823 | * |
| 824 | * Revision 1.17 1998/02/23 19:07:58 curt |
| 825 | * Incorporated Durk's Astro/ tweaks. Includes unifying the sun position |
| 826 | * calculation code between sun display, and other FG sections that use this |
| 827 | * for things like lighting. |
| 828 | * |
| 829 | * Revision 1.16 1998/02/07 15:29:38 curt |
| 830 | * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss |
| 831 | * <[email protected]> |
| 832 | * |
| 833 | * Revision 1.15 1998/01/22 22:03:47 curt |
| 834 | * Removed #include <sys/stat.h> |
| 835 | * |
| 836 | * Revision 1.14 1998/01/19 19:27:04 curt |
| 837 | * Merged in make system changes from Bob Kuehne <[email protected]> |
| 838 | * This should simplify things tremendously. |
| 839 | * |
| 840 | * Revision 1.13 1998/01/19 18:40:26 curt |
| 841 | * Tons of little changes to clean up the code and to remove fatal errors |
| 842 | * when building with the c++ compiler. |
| 843 | * |
| 844 | * Revision 1.12 1998/01/06 01:20:16 curt |
| 845 | * Tweaks to help building with MSVC++ |
| 846 | * |
| 847 | * Revision 1.11 1998/01/05 22:19:26 curt |
| 848 | * #ifdef'd out some unused code that was problematic for MSVC++ to compile. |
| 849 | * |
| 850 | * Revision 1.10 1997/12/10 22:37:43 curt |
| 851 | * Prepended "fg" on the name of all global structures that didn't have it yet. |
| 852 | * i.e. "struct WEATHER {}" became "struct fgWEATHER {}" |
| 853 | * |
| 854 | * Revision 1.9 1997/08/27 03:30:08 curt |
| 855 | * Changed naming scheme of basic shared structures. |
| 856 | * |
| 857 | * Revision 1.8 1997/06/21 17:12:50 curt |
| 858 | * Capitalized subdirectory names. |
| 859 | * |
| 860 | * Revision 1.7 1997/05/31 19:16:28 curt |
| 861 | * Elevator trim added. |
| 862 | * |
| 863 | * Revision 1.6 1997/05/31 04:13:53 curt |
| 864 | * WE CAN NOW FLY!!! |
| 865 | * |
| 866 | * Continuing work on the LaRCsim flight model integration. |
| 867 | * Added some MSFS-like keyboard input handling. |
| 868 | * |
| 869 | * Revision 1.5 1997/05/30 23:26:25 curt |
| 870 | * Added elevator/aileron controls. |
| 871 | * |
| 872 | * Revision 1.4 1997/05/30 19:30:15 curt |
| 873 | * The LaRCsim flight model is starting to look like it is working. |
| 874 | * |
| 875 | * Revision 1.3 1997/05/30 03:54:12 curt |
| 876 | * Made a bit more progress towards integrating the LaRCsim flight model. |
| 877 | * |
| 878 | * Revision 1.2 1997/05/29 22:39:59 curt |
| 879 | * Working on incorporating the LaRCsim flight model. |
| 880 | * |
| 881 | * Revision 1.1 1997/05/29 00:09:57 curt |
| 882 | * Initial Flight Gear revision. |
| 883 | * |
| 884 | */ |