1 /*
2 			  SAR Flight Model
3 
4 	Flight dynamics model employing a new `simple' dimensional
5 	recursive approach to flight dynamics.
6 
7  */
8 
9 #ifndef SFM_H
10 #define SFM_H
11 
12 #include "sfmtypes.h"
13 #include "sfmmodel.h"
14 
15 
16 /*
17  *	Unit cycle constant, in milliseconds. This value determines
18  *	what SFM considers a `unit cycle'.
19  */
20 #define SFMCycleUnitsMS		1000
21 #define SFMCycleUnitsUS		(SFMCycleUnitsMS * 1000)
22 
23 
24 /*
25  *	Default gravity in (meters per cycle^2).
26  */
27 #define SFMDefaultGravity	9.8
28 
29 
30 
31 /*
32  *	Core structure:
33  */
34 typedef struct {
35 
36 
37 	/* Timings for current management */
38 	SFMTime		lapsed_time;		/* In milliseconds */
39 	double		time_compensation;	/* Coefficient */
40 	double		time_compression;	/* Coefficient */
41 
42 	/* Simulation constants */
43 	double		gravity;		/* Gravity (in meters per cycle^2) */
44 
45 
46 	/* Callbacks, typical inputs are; realm pointer,
47 	 * model pointer, client data
48 	 */
49 
50 	/* Model just added to the realm */
51 	void		*init_model_cb_client_data;
52 	void		(*init_model_cb)(void *, SFMModelStruct *, void *);
53 
54 	/* Model just destroyed, WARNING arg2 is always invalid! */
55 	void		*destroy_model_cb_client_data;
56 	void		(*destroy_model_cb)(void *, SFMModelStruct *, void *);
57 
58 	/* Model has become airborne */
59 	void		*airborne_cb_client_data;
60 	void		(*airborne_cb)(void *, SFMModelStruct *, void *);
61 
62 	/* Model has touched down, arg4 is impact tolorance coeff */
63 	void		*touch_down_cb_client_data;
64 	void		(*touch_down_cb)(void *, SFMModelStruct *, void *, double);
65 
66 	/* Model has exceeded its maximum expected speed. arg4 is the
67 	 * current speed and arg5 is maximum expected speed (all units in
68 	 * meters per cycle)
69 	 *
70 	 * This function is called whenever the model is above its max
71 	 * expected speed (so this can be called multiple times)
72 	 */
73 	void		*overspeed_cb_client_data;
74 	void		(*overspeed_cb)(
75 	    void *, SFMModelStruct *, void *,
76 	    double,		/* Current speed, in meters per cycle */
77 	    double,		/* Expected overspeed, in meters per cycle */
78 	    double		/* Actual overspeed, in meters per cycle */
79 	);
80 
81 	/* Model has collided with another object, arg3 is the other
82 	 * that has been collided into, arg5 is the impact tolorance
83 	 * coeff.
84 	 */
85 	void		*collision_cb_client_data;
86 	void		(*collision_cb)(
87 	    void *, SFMModelStruct *, SFMModelStruct *,
88 	    void *, double
89 	);
90 
91 	/* Flight dynamics model list */
92 	SFMModelStruct	**model;
93 	int		total_models;
94 
95 } SFMRealmStruct;
96 
97 #define SFM_REALM(p)	((SFMRealmStruct *)(p))
98 
99 
100 /* In sfm.c */
101 extern SFMRealmStruct *SFMInit(int argc, char **argv);
102 extern void SFMShutdown(SFMRealmStruct *realm);
103 
104 extern void SFMSetTiming(SFMRealmStruct *realm, SFMTime lapsed_ms);
105 extern void SFMSetTimeCompression(SFMRealmStruct *realm, double compression);
106 extern void SFMUpdateRealm(SFMRealmStruct *realm, SFMTime lapsed_ms);
107 
108 
109 /* In sfmmath.c */
110 extern double SFMHypot2(double dx, double dy);
111 extern double SFMHypot3(double dx, double dy, double dz);
112 
113 extern double SFMSanitizeRadians(double r);
114 extern double SFMSanitizeDegrees(double d);
115 extern double SFMRadiansToDegrees(double r);
116 extern double SFMDegreesToRadians(double d);
117 
118 extern double SFMDeltaRadians(double a1, double a2);
119 extern void SFMOrthoRotate2D(double theta, double *i, double *j);
120 /*
121 extern int SFMRandom(void);
122  */
123 
124 extern double SFMMetersToFeet(double m);
125 extern double SFMFeetToMeters(double feet);
126 extern double SFMMetersToMiles(double m);
127 extern double SFMMilesToMeters(double miles);
128 extern double SFMMPHToMPC(double mph);
129 extern double SFMMPHToKTS(double mph);
130 extern double SFMKTSToMPH(double kts);
131 extern double SFMMPCToMPH(double mpc);
132 extern double SFMMPCToFPS(double mpc);
133 extern double SFMMPCToKPH(double mpc);
134 
135 extern double SFMLBSToKG(double lbs);
136 extern double SFMKGToLBS(double kg);
137 extern void SFMMToDMS(
138 	double m_x, double m_y, double m_r,
139 	double dms_x_offset, double dms_y_offset,
140 	float *dms_x, float *dms_y
141 );
142 extern char *SFMLongitudeToString(double dms_x);
143 extern char *SFMLatitudeToString(double dms_y);
144 
145 extern double SFMStallCoeff(
146 	double current_speed, double stall_speed, double speed_max
147 );
148 
149 
150 
151 /* In sfmmodel.c */
152 extern int SFMModelInRealm(SFMRealmStruct *realm, SFMModelStruct *model);
153 extern SFMModelStruct *SFMModelAllocate(void);
154 extern int SFMModelAdd(SFMRealmStruct *realm, SFMModelStruct *model);
155 extern void SFMModelDelete(SFMRealmStruct *realm, SFMModelStruct *model);
156 extern SFMBoolean SFMModelChangeValues(
157 	SFMRealmStruct *realm, SFMModelStruct *model,
158 	SFMModelStruct *value
159 );
160 extern void SFMModelUndefineValue(
161 	SFMRealmStruct *realm, SFMModelStruct *model, SFMFlags flags
162 );
163 
164 
165 /* In sfmsimforce.c */
166 extern int SFMForceApplyNatural(
167 	SFMRealmStruct *realm, SFMModelStruct *model
168 );
169 extern int SFMForceApplyArtificial(
170 	SFMRealmStruct *realm, SFMModelStruct *model
171 );
172 extern int SFMForceApplyControl(
173 	SFMRealmStruct *realm, SFMModelStruct *model
174 );
175 
176 
177 
178 
179 #endif	/* SFM_H */
180