1 /***************************************************************************
5 ----------------------------------------------------------------------------
7 FUNCTION: Initializes simulation
9 ----------------------------------------------------------------------------
11 MODULE STATUS: incomplete
13 ----------------------------------------------------------------------------
15 GENEALOGY: Written 921230 by Bruce Jackson
17 ----------------------------------------------------------------------------
25 ----------------------------------------------------------------------------
31 950314 Added get_set, put_set, and init routines. EBJ
37 Revision 1.4 1998/01/19 18:40:26 curt
38 Tons of little changes to clean up the code and to remove fatal errors
39 when building with the c++ compiler.
41 Revision 1.3 1998/01/05 22:19:25 curt
42 #ifdef'd out some unused code that was problematic for MSVC++ to compile.
44 Revision 1.2 1997/05/29 22:39:58 curt
45 Working on incorporating the LaRCsim flight model.
47 Revision 1.1 1997/05/29 00:09:57 curt
48 Initial Flight Gear revision.
50 * Revision 1.4 1995/03/15 12:15:23 bjax
51 * Added ls_init_get_set() and ls_init_put_set() and ls_init_init()
54 * Revision 1.3 1994/01/11 19:09:44 bjax
55 * Fixed header includes.
57 * Revision 1.2 1992/12/30 14:04:53 bjax
58 * Added call to ls_step(0, 1).
60 * Revision 1.1 92/12/30 14:02:19 bjax
63 * Revision 1.1 92/12/30 13:21:21 bjax
66 * Revision 1.3 93/12/31 10:34:11 bjax
67 * Added $Log marker as well.
70 ----------------------------------------------------------------------------
74 ----------------------------------------------------------------------------
78 ----------------------------------------------------------------------------
82 ----------------------------------------------------------------------------
86 ----------------------------------------------------------------------------
90 --------------------------------------------------------------------------*/
91 static char rcsid[] = "$Id$";
99 #include "navion_init.h"
102 #include "ls_generic.h"
104 #define MAX_NUMBER_OF_CONTINUOUS_STATES 100
105 #define MAX_NUMBER_OF_DISCRETE_STATES 20
107 #define NIL_POINTER 0L
109 #define FACILITY_NAME_STRING "init"
110 #define CURRENT_VERSION 10
125 extern SCALAR Simtime;
127 /* static int Symbols_loaded = 0; */
128 static int Number_of_Continuous_States = 0;
129 static int Number_of_Discrete_States = 0;
130 static cont_state_rec Continuous_States[ MAX_NUMBER_OF_CONTINUOUS_STATES ];
131 static disc_state_rec Discrete_States[ MAX_NUMBER_OF_DISCRETE_STATES ];
134 void ls_init_init( void ) {
138 if (Number_of_Continuous_States == 0)
140 Number_of_Continuous_States = HARDWIRED;
142 for (i=0;i<HARDWIRED;i++)
143 strcpy( Continuous_States[i].Symbol.Mod_Name, "*" );
145 strcpy( Continuous_States[ 0].Symbol.Par_Name,
146 "generic_.geodetic_position_v[0]");
147 strcpy( Continuous_States[ 1].Symbol.Par_Name,
148 "generic_.geodetic_position_v[1]");
149 strcpy( Continuous_States[ 2].Symbol.Par_Name,
150 "generic_.geodetic_position_v[2]");
151 strcpy( Continuous_States[ 3].Symbol.Par_Name,
152 "generic_.v_local_v[0]");
153 strcpy( Continuous_States[ 4].Symbol.Par_Name,
154 "generic_.v_local_v[1]");
155 strcpy( Continuous_States[ 5].Symbol.Par_Name,
156 "generic_.v_local_v[2]");
157 strcpy( Continuous_States[ 6].Symbol.Par_Name,
158 "generic_.euler_angles_v[0]");
159 strcpy( Continuous_States[ 7].Symbol.Par_Name,
160 "generic_.euler_angles_v[1]");
161 strcpy( Continuous_States[ 8].Symbol.Par_Name,
162 "generic_.euler_angles_v[2]");
163 strcpy( Continuous_States[ 9].Symbol.Par_Name,
164 "generic_.omega_body_v[0]");
165 strcpy( Continuous_States[10].Symbol.Par_Name,
166 "generic_.omega_body_v[1]");
167 strcpy( Continuous_States[11].Symbol.Par_Name,
168 "generic_.omega_body_v[2]");
169 strcpy( Continuous_States[12].Symbol.Par_Name,
170 "generic_.earth_position_angle");
173 /* commented out by CLO
174 for (i=0;i<Number_of_Continuous_States;i++)
176 (void) ls_get_sym_val( &Continuous_States[i].Symbol, &error );
177 if (error) Continuous_States[i].Symbol.Addr = NIL_POINTER;
180 for (i=0;i<Number_of_Discrete_States;i++)
182 (void) ls_get_sym_val( &Discrete_States[i].Symbol, &error );
183 if (error) Discrete_States[i].Symbol.Addr = NIL_POINTER;
188 void ls_init( void ) {
193 printf("LS in init() pos = %.2f\n", Latitude);
197 printf("LS after init_init() pos = %.2f\n", Latitude);
198 /* move the states to proper values */
200 /* commented out by CLO
201 for(i=0;i<Number_of_Continuous_States;i++)
202 if (Continuous_States[i].Symbol.Addr)
203 ls_set_sym_val( &Continuous_States[i].Symbol,
204 Continuous_States[i].value );
206 for(i=0;i<Number_of_Discrete_States;i++)
207 if (Discrete_States[i].Symbol.Addr)
208 ls_set_sym_val( &Discrete_States[i].Symbol,
209 (double) Discrete_States[i].value );
214 printf("LS after model_init() pos = %.2f\n", Latitude);
218 printf("LS after ls_step() pos = %.2f\n", Latitude);
222 #ifdef COMPILE_THIS_CODE_THIS_USELESS_CODE
224 char *ls_init_get_set(char *buffer, char *eob)
225 /* This routine parses the settings file for "init" entries. */
228 static char *fac_name = FACILITY_NAME_STRING;
231 int n, ver, i, error, abrt;
233 enum {cont_states_header, cont_states, disc_states_header, disc_states, done } looking_for;
236 looking_for = cont_states_header;
238 n = sscanf(buffer, "%s", line);
239 if (n == 0) return 0L;
240 if (strncasecmp( fac_name, line, strlen(fac_name) )) return 0L;
242 bufptr = strtok( buffer+strlen(fac_name)+1, "\n");
243 if (bufptr == 0) return 0L;
245 sscanf( bufptr, "%d", &ver );
246 if (ver != CURRENT_VERSION) return 0L;
250 while( !abrt && (eob > bufptr))
252 bufptr = strtok( 0L, "\n");
253 if (bufptr == 0) return 0L;
254 if (strncasecmp( bufptr, "end", 3) == 0) break;
256 sscanf( bufptr, "%s", line );
257 if (line[0] != '#') /* ignore comments */
261 case cont_states_header:
263 if (strncasecmp( line, "continuous_states", 17) == 0)
265 n = sscanf( bufptr, "%s%d", line,
266 &Number_of_Continuous_States );
267 if (n != 2) abrt = 1;
268 looking_for = cont_states;
275 n = sscanf( bufptr, "%s%s%le",
276 Continuous_States[i].Symbol.Mod_Name,
277 Continuous_States[i].Symbol.Par_Name,
278 &Continuous_States[i].value );
279 if (n != 3) abrt = 1;
280 Continuous_States[i].Symbol.Addr = NIL_POINTER;
282 if (i >= Number_of_Continuous_States)
283 looking_for = disc_states_header;
286 case disc_states_header:
288 if (strncasecmp( line, "discrete_states", 15) == 0)
290 n = sscanf( bufptr, "%s%d", line,
291 &Number_of_Discrete_States );
292 if (n != 2) abrt = 1;
293 looking_for = disc_states;
300 n = sscanf( bufptr, "%s%s%ld",
301 Discrete_States[i].Symbol.Mod_Name,
302 Discrete_States[i].Symbol.Par_Name,
303 &Discrete_States[i].value );
304 if (n != 3) abrt = 1;
305 Discrete_States[i].Symbol.Addr = NIL_POINTER;
307 if (i >= Number_of_Discrete_States) looking_for = done;
318 Symbols_loaded = !abrt;
322 #endif /* COMPILE_THIS_CODE_THIS_USELESS_CODE */
325 void ls_init_put_set( FILE *fp )
331 fprintf(fp, "#============================== %s\n", FACILITY_NAME_STRING);
333 fprintf(fp, FACILITY_NAME_STRING);
335 fprintf(fp, "%04d\n", CURRENT_VERSION);
336 fprintf(fp, " continuous_states: %d\n", Number_of_Continuous_States);
337 fprintf(fp, "# module parameter value\n");
338 for (i=0; i<Number_of_Continuous_States; i++)
339 fprintf(fp, " %s\t%s\t%E\n",
340 Continuous_States[i].Symbol.Mod_Name,
341 Continuous_States[i].Symbol.Par_Name,
342 Continuous_States[i].value );
344 fprintf(fp, " discrete_states: %d\n", Number_of_Discrete_States);
345 fprintf(fp, "# module parameter value\n");
346 for (i=0;i<Number_of_Discrete_States;i++)
347 fprintf(fp, " %s\t%s\t%ld\n",
348 Discrete_States[i].Symbol.Mod_Name,
349 Discrete_States[i].Symbol.Par_Name,
350 Discrete_States[i].value );
351 fprintf(fp, "end\n");
355 void ls_save_current_as_ic( void ) {
356 /* Save current states as initial conditions */
360 /* commented out by CLO
361 for(i=0;i<Number_of_Continuous_States;i++)
362 if (Continuous_States[i].Symbol.Addr)
363 Continuous_States[i].value =
364 ls_get_sym_val( &Continuous_States[i].Symbol, &error );
366 for(i=0;i<Number_of_Discrete_States;i++)
367 if (Discrete_States[i].Symbol.Addr)
368 Discrete_States[i].value = (long)
369 ls_get_sym_val( &Discrete_States[i].Symbol, &error );