/*************************************************************************** TITLE: ls_init.c ---------------------------------------------------------------------------- FUNCTION: Initializes simulation ---------------------------------------------------------------------------- MODULE STATUS: incomplete ---------------------------------------------------------------------------- GENEALOGY: Written 921230 by Bruce Jackson ---------------------------------------------------------------------------- DESIGNED BY: EBJ CODED BY: EBJ MAINTAINED BY: EBJ ---------------------------------------------------------------------------- MODIFICATION HISTORY: DATE PURPOSE BY 950314 Added get_set, put_set, and init routines. EBJ CURRENT RCS HEADER: $Header$ $Log$ Revision 1.2 2003/07/25 17:53:35 mselig UIUC code initilization mods to tidy things up a bit. Revision 1.1.1.1 2002/09/10 01:14:02 curt Initial revision of FlightGear-0.9.0 Revision 1.3 2000/05/24 04:10:01 curt MSVC5 portability changes contributed by Bruce Finney. Revision 1.2 2000/04/10 18:09:41 curt David Megginson made a few (mostly minor) mods to the LaRCsim files, and it's now possible to choose the LaRCsim model at runtime, as in fgfs --aircraft=c172 or fgfs --aircraft=uiuc --aircraft-dir=Aircraft-uiuc/Boeing747 I did this so that I could play with the UIUC stuff without losing Tony's C172 with its flaps, etc. I did my best to respect the design of the LaRCsim code by staying in C, making only minimal changes, and not introducing any dependencies on the rest of FlightGear. The modified files are attached. Revision 1.1.1.1 1999/06/17 18:07:34 curt Start of 0.7.x branch Revision 1.1.1.1 1999/04/05 21:32:45 curt Start of 0.6.x branch. Revision 1.5 1998/07/12 03:11:03 curt Removed some printf()'s. Fixed the autopilot integration so it should be able to update it's control positions every time the internal flight model loop is run, and not just once per rendered frame. Added a routine to do the necessary stuff to force an arbitrary altitude change. Gave the Navion engine just a tad more power. Revision 1.4 1998/01/19 18:40:26 curt Tons of little changes to clean up the code and to remove fatal errors when building with the c++ compiler. Revision 1.3 1998/01/05 22:19:25 curt #ifdef'd out some unused code that was problematic for MSVC++ to compile. Revision 1.2 1997/05/29 22:39:58 curt Working on incorporating the LaRCsim flight model. Revision 1.1 1997/05/29 00:09:57 curt Initial Flight Gear revision. * Revision 1.4 1995/03/15 12:15:23 bjax * Added ls_init_get_set() and ls_init_put_set() and ls_init_init() * routines. EBJ * * Revision 1.3 1994/01/11 19:09:44 bjax * Fixed header includes. * * Revision 1.2 1992/12/30 14:04:53 bjax * Added call to ls_step(0, 1). * * Revision 1.1 92/12/30 14:02:19 bjax * Initial revision * * Revision 1.1 92/12/30 13:21:21 bjax * Initial revision * * Revision 1.3 93/12/31 10:34:11 bjax * Added $Log marker as well. * ---------------------------------------------------------------------------- REFERENCES: ---------------------------------------------------------------------------- CALLED BY: ---------------------------------------------------------------------------- CALLS TO: ---------------------------------------------------------------------------- INPUTS: ---------------------------------------------------------------------------- OUTPUTS: --------------------------------------------------------------------------*/ // static char rcsid[] = "$Id$"; #include #include #include "ls_types.h" #include "ls_sym.h" #include "ls_step.h" #include "ls_init.h" #include "navion_init.h" #include "ls_model.h" /* temp */ #include "ls_generic.h" #define MAX_NUMBER_OF_CONTINUOUS_STATES 100 #define MAX_NUMBER_OF_DISCRETE_STATES 20 #define HARDWIRED 13 #define NIL_POINTER 0L #define FACILITY_NAME_STRING "init" #define CURRENT_VERSION 10 void cherokee_init( void ); void c172_init( void ); void basic_init( void ); typedef struct { symbol_rec Symbol; double value; } cont_state_rec; typedef struct { symbol_rec Symbol; long value; } disc_state_rec; extern SCALAR Simtime; /* static int Symbols_loaded = 0; */ static int Number_of_Continuous_States = 0; static int Number_of_Discrete_States = 0; static cont_state_rec Continuous_States[ MAX_NUMBER_OF_CONTINUOUS_STATES ]; static disc_state_rec Discrete_States[ MAX_NUMBER_OF_DISCRETE_STATES ]; void ls_init_init( void ) { int i; /* int error; */ if (Number_of_Continuous_States == 0) { Number_of_Continuous_States = HARDWIRED; for (i=0;i bufptr)) { bufptr = strtok( 0L, "\n"); if (bufptr == 0) return 0L; if (strncasecmp( bufptr, "end", 3) == 0) break; sscanf( bufptr, "%s", line ); if (line[0] != '#') /* ignore comments */ { switch (looking_for) { case cont_states_header: { if (strncasecmp( line, "continuous_states", 17) == 0) { n = sscanf( bufptr, "%s%d", line, &Number_of_Continuous_States ); if (n != 2) abrt = 1; looking_for = cont_states; i = 0; } break; } case cont_states: { n = sscanf( bufptr, "%s%s%le", Continuous_States[i].Symbol.Mod_Name, Continuous_States[i].Symbol.Par_Name, &Continuous_States[i].value ); if (n != 3) abrt = 1; Continuous_States[i].Symbol.Addr = NIL_POINTER; i++; if (i >= Number_of_Continuous_States) looking_for = disc_states_header; break; } case disc_states_header: { if (strncasecmp( line, "discrete_states", 15) == 0) { n = sscanf( bufptr, "%s%d", line, &Number_of_Discrete_States ); if (n != 2) abrt = 1; looking_for = disc_states; i = 0; } break; } case disc_states: { n = sscanf( bufptr, "%s%s%ld", Discrete_States[i].Symbol.Mod_Name, Discrete_States[i].Symbol.Par_Name, &Discrete_States[i].value ); if (n != 3) abrt = 1; Discrete_States[i].Symbol.Addr = NIL_POINTER; i++; if (i >= Number_of_Discrete_States) looking_for = done; } case done: { break; } } } } Symbols_loaded = !abrt; return bufptr; } #endif /* COMPILE_THIS_CODE_THIS_USELESS_CODE */ void ls_init_put_set( FILE *fp ) { int i; if (fp==0) return; fprintf(fp, "\n"); fprintf(fp, "#============================== %s\n", FACILITY_NAME_STRING); fprintf(fp, "\n"); fprintf(fp, FACILITY_NAME_STRING); fprintf(fp, "\n"); fprintf(fp, "%04d\n", CURRENT_VERSION); fprintf(fp, " continuous_states: %d\n", Number_of_Continuous_States); fprintf(fp, "# module parameter value\n"); for (i=0; i