-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathglobals.h
213 lines (186 loc) · 5.42 KB
/
globals.h
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
* GLOBALS DEFINITION
*
* This file contains the list of all the macros used in the application and
* also contains the definitions of all the data structures
*
* Created on: 25/nov/2015
* Author: Paolo Sassi
*/
#ifndef GLOBALS_H_
#define GLOBALS_H_
#include <stdlib.h>
#include <stdio.h>
/* +-------------------------------------------------------------------------+
* | |
* | GLOBAL MACROS |
* | |
* +-------------------------------------------------------------------------+
*/
/* TASK MACROS */
#define TASK_NUM 12
#define MAX_TARGETS 4
#define MAX_PATRIOTS 4
#define DISPLAY_INDEX 0
#define DISPLAY_PER 42
#define DISPLAY_DL DISPLAY_PER
#define DISPLAY_PRIO 99
#define RADAR_INDEX 1
#define RADAR_PER 110
#define RADAR_DL RADAR_PER
#define RADAR_PRIO 96
#define KEYBOARD_INDEX 2
#define KEYBOARD_PER 150
#define KEYBOARD_DL KEYBOARD_PER
#define KEYBOARD_PRIO 95
#define ECS_INDEX 3
#define ECS_PER 45
#define ECS_DL ECS_PER
#define ECS_PRIO 98
#define TARGET_INDEX 4
#define TARGET_PER 50
#define TARGET_DL TARGET_PER
#define TARGET_PRIO 97
#define PATRIOT_INDEX 8
#define PATRIOT_PER 50
#define PATRIOT_DL PATRIOT_PER
#define PATRIOT_PRIO 97
/* GRAPHICS MACROS */
#define SCALE 150
#define SCREEN_WIDTH 1000
#define SCREEN_HEIGHT 600
#define TS_WIDTH 800
#define TS_HEIGHT 60
#define TS_POS_X 0
#define TS_POS_Y 20
#define BOX_WIDTH 800
#define BOX_HEIGHT 540
#define BOX_POS_X 0
#define BOX_POS_Y TS_POS_Y + TS_HEIGHT
#define SS_WIDTH 198
#define SS_HEIGHT 300
#define TARGET_WIDTH 40
#define TARGET_HEIGHT 12
#define PATRIOT_WIDTH 40
#define PATRIOT_HEIGHT 12
#define CITY_WIDTH 800
#define CITY_HEIGHT 167
#define CITY_POS_X 0
#define CITY_POS_Y (520 - CITY_HEIGHT)
#define RADAR_WIDTH 40
#define RADAR_HEIGHT 36
#define RADAR_POS_X 380
#define RADAR_POS_Y 484
#define RADAR_CENTROID 0
#define PRED_CENTROID 1
#define CITY_PATH "img/skyline.bmp"
#define RADAR_PATH "img/radar.bmp"
#define TARGET_PATH "img/target_"
#define PATRIOT_PATH "img/patriot.bmp"
#define VECTOR_LEN 20
#define CITY_COLLISION_Y 70 * SCALE
#define radtofix(x) ftofix(((-x) * 128) / PI)
#define realToAllegX(x) (int32_t)(x / SCALE)
#define realToAllegY(y) BOX_HEIGHT - (int32_t)(y / SCALE)
/* PHYSICS MACROS */
#define TSCALE 1
#define G0 9.8
#define MIN_T_X0 0
#define MAX_T_X0 120000
#define MIN_T_V 680
#define MAX_T_V 1500
#define T_DA 5 /* max target speed angle deviation */
/* target initial y (real) coordinate */
#define TARGET_Y0 BOX_HEIGHT * SCALE
/* target acceleration vector angle */
#define TARGET_ACC_DEG (float32_t)-((0.5) * PI)
/* patriot initial x (real) coordinate */
#define PATRIOT_0_X0 370 * SCALE
#define PATRIOT_1_X0 390 * SCALE
#define PATRIOT_2_X0 410 * SCALE
#define PATRIOT_3_X0 430 * SCALE
/* patriot initial y (real) coordinate */
#define PATRIOT_Y0 100 * SCALE
#define PATRIOT_V_MAX 1700
#define PATRIOT_ACC 300
#define PATRIOT_A_THETA PI / 2
#define PI 3.14159265
#define P1 0.9 /* constant used for filtering the position */
#define P2 0.95/* constant used for filtering the speed */
#define P3 0.98/* constant used for acc. filtering */
#define FILTER_STEP 0.01
#define FILTER_MAX 0.99
#define FILTER_MIN 0.00
#define COLL_DIST 18 * SCALE
#define T_MAX 25
#define T_STEP 0.05
#define THETA_DEV 35 /* angle deviation for intercept */
#define THETA_STEP 1 /* angle increase step */
#define radToDeg(x) x * (180 / PI)
#define degToRad(x) x * (PI / 180)
/* RADAR MACROS */
#define RAD_RANGE_X BOX_WIDTH
#define RAD_RANGE_Y BOX_HEIGHT
#define RAD_RANGE_MIN 100
#define RAD_DEG 180
#define RAD_STEP 1
#define RAD_AREA_X (BOX_WIDTH - RAD_RANGE_X) / 2
#define RAD_AREA_Y (BOX_HEIGHT - RAD_RANGE_Y) + BOX_POS_Y
#define MIN_RAD_CYCLE 50
/* ERROR CODES */
#define CREATE_ERR 0
#define DMISS 1
/* +-------------------------------------------------------------------------+
* | |
* | GLOBAL DATA STRUCTURES |
* | |
* +-------------------------------------------------------------------------+
*/
/* MISRA-C Compliant data types */
typedef char char_t;
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef signed long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long uint64_t;
typedef float float32_t;
typedef double float64_t;
typedef long double float128_t;
/* Missile status data structure, used for both enemy target
* and Patriot missile. Data are stored using MKS units.
*/
typedef struct _stat {
float32_t x;
float32_t y;
float32_t v; /* speed vector modulus */
float32_t v_theta; /* speed vector angle in radians */
float32_t a; /* acceleration vector modulus */
float32_t a_theta; /* acceleration vector angle in radians */
} stat;
/* Data structure used to store the information
* to compute predictions
*/
typedef struct _filter_stat {
float32_t xf;
float32_t yf;
float32_t vxf;
float32_t vyf;
float32_t axf;
float32_t ayf;
} filter_stat;
/* Simulation statistics */
typedef struct _sim_stats {
uint8_t t_fired;
uint8_t t_missed;
uint8_t t_hit;
float32_t t_hitratio;
} sim_stats;
/* Screen coordinates data structure */
typedef struct _coords {
int32_t x;
int32_t y;
} coords;
#endif /* GLOBALS_H_ */