File: sfm.h

package info (click to toggle)
searchandrescue 0.8.2-7
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,648 kB
  • ctags: 6,112
  • sloc: ansic: 89,072; cpp: 7,691; sh: 90; makefile: 77
file content (179 lines) | stat: -rw-r--r-- 4,835 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
			  SAR Flight Model

	Flight dynamics model employing a new `simple' dimensional
	recursive approach to flight dynamics.

 */

#ifndef SFM_H
#define SFM_H

#include "sfmtypes.h"
#include "sfmmodel.h"


/*
 *	Unit cycle constant, in milliseconds. This value determines
 *	what SFM considers a `unit cycle'.
 */
#define SFMCycleUnitsMS		1000
#define SFMCycleUnitsUS		(SFMCycleUnitsMS * 1000)


/*
 *	Default gravity in (meters per cycle^2).
 */
#define SFMDefaultGravity	9.8



/*
 *	Core structure:
 */
typedef struct {


	/* Timings for current management */
	SFMTime		lapsed_time;		/* In milliseconds */
	double		time_compensation;	/* Coefficient */
	double		time_compression;	/* Coefficient */

	/* Simulation constants */
	double		gravity;		/* Gravity (in meters per cycle^2) */


	/* Callbacks, typical inputs are; realm pointer,
	 * model pointer, client data
	 */

	/* Model just added to the realm */
	void		*init_model_cb_client_data;
	void		(*init_model_cb)(void *, SFMModelStruct *, void *);

	/* Model just destroyed, WARNING arg2 is always invalid! */
	void		*destroy_model_cb_client_data;
	void		(*destroy_model_cb)(void *, SFMModelStruct *, void *);

	/* Model has become airborne */
	void		*airborne_cb_client_data;
	void		(*airborne_cb)(void *, SFMModelStruct *, void *);

	/* Model has touched down, arg4 is impact tolorance coeff */
	void		*touch_down_cb_client_data;
	void		(*touch_down_cb)(void *, SFMModelStruct *, void *, double);

	/* Model has exceeded its maximum expected speed. arg4 is the
	 * current speed and arg5 is maximum expected speed (all units in
	 * meters per cycle)
	 *
	 * This function is called whenever the model is above its max
	 * expected speed (so this can be called multiple times)
	 */
	void		*overspeed_cb_client_data;
	void		(*overspeed_cb)(
	    void *, SFMModelStruct *, void *,
	    double,		/* Current speed, in meters per cycle */
	    double,		/* Expected overspeed, in meters per cycle */
	    double		/* Actual overspeed, in meters per cycle */
	);

	/* Model has collided with another object, arg3 is the other
	 * that has been collided into, arg5 is the impact tolorance
	 * coeff.
	 */
	void		*collision_cb_client_data;
	void		(*collision_cb)(
	    void *, SFMModelStruct *, SFMModelStruct *,
	    void *, double
	);

	/* Flight dynamics model list */
	SFMModelStruct	**model;
	int		total_models;

} SFMRealmStruct;

#define SFM_REALM(p)	((SFMRealmStruct *)(p))


/* In sfm.c */
extern SFMRealmStruct *SFMInit(int argc, char **argv);
extern void SFMShutdown(SFMRealmStruct *realm);

extern void SFMSetTiming(SFMRealmStruct *realm, SFMTime lapsed_ms);
extern void SFMSetTimeCompression(SFMRealmStruct *realm, double compression);
extern void SFMUpdateRealm(SFMRealmStruct *realm, SFMTime lapsed_ms);


/* In sfmmath.c */
extern double SFMHypot2(double dx, double dy);
extern double SFMHypot3(double dx, double dy, double dz);

extern double SFMSanitizeRadians(double r);
extern double SFMSanitizeDegrees(double d);
extern double SFMRadiansToDegrees(double r);
extern double SFMDegreesToRadians(double d);

extern double SFMDeltaRadians(double a1, double a2);
extern void SFMOrthoRotate2D(double theta, double *i, double *j);
/*
extern int SFMRandom(void);
 */

extern double SFMMetersToFeet(double m);
extern double SFMFeetToMeters(double feet);
extern double SFMMetersToMiles(double m);
extern double SFMMilesToMeters(double miles);
extern double SFMMPHToMPC(double mph);
extern double SFMMPHToKTS(double mph);
extern double SFMKTSToMPH(double kts);
extern double SFMMPCToMPH(double mpc);
extern double SFMMPCToFPS(double mpc);
extern double SFMMPCToKPH(double mpc);

extern double SFMLBSToKG(double lbs);
extern double SFMKGToLBS(double kg);
extern void SFMMToDMS(
	double m_x, double m_y, double m_r,
	double dms_x_offset, double dms_y_offset,
	float *dms_x, float *dms_y
);
extern char *SFMLongitudeToString(double dms_x);
extern char *SFMLatitudeToString(double dms_y);

extern double SFMStallCoeff(
	double current_speed, double stall_speed, double speed_max
);



/* In sfmmodel.c */
extern int SFMModelInRealm(SFMRealmStruct *realm, SFMModelStruct *model);
extern SFMModelStruct *SFMModelAllocate(void);
extern int SFMModelAdd(SFMRealmStruct *realm, SFMModelStruct *model);
extern void SFMModelDelete(SFMRealmStruct *realm, SFMModelStruct *model);
extern SFMBoolean SFMModelChangeValues(
	SFMRealmStruct *realm, SFMModelStruct *model,
	SFMModelStruct *value
);
extern void SFMModelUndefineValue(
	SFMRealmStruct *realm, SFMModelStruct *model, SFMFlags flags
);


/* In sfmsimforce.c */
extern int SFMForceApplyNatural(
	SFMRealmStruct *realm, SFMModelStruct *model
);
extern int SFMForceApplyArtificial(
	SFMRealmStruct *realm, SFMModelStruct *model
);
extern int SFMForceApplyControl(
	SFMRealmStruct *realm, SFMModelStruct *model
);




#endif	/* SFM_H */