Rev 51 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
51 | osiair | 1 | //------------------------------------------------------------------------------ |
2 | // _ _ |
||
3 | // | | | | |
||
4 | // ___ _ __ ___ ___ _ _ ___| |_ ___ ___| |__ |
||
5 | // / _ \ '_ ` _ \/ __| | | / __| __/ _ \/ __| '_ \. |
||
6 | // | __/ | | | | \__ \ |_| \__ \ || __/ (__| | | | |
||
7 | // \___|_| |_| |_|___/\__, |___/\__\___|\___|_| |_| |
||
8 | // __/ | |
||
9 | // |___/ Engineering |
||
10 | // |
||
11 | // Filename: GPS.c |
||
12 | // Description: |
||
13 | // |
||
14 | // Author: Martin Steppuhn |
||
15 | // History: 15.06.2007 Initial version |
||
16 | // |
||
17 | //------------------------------------------------------------------------------ |
||
18 | |||
19 | |||
20 | /**** Includes ****************************************************************/ |
||
21 | |||
22 | #include "std_c.h" |
||
23 | #include "main.h" |
||
24 | #include "fc.h" |
||
25 | #include "gps_ubx.h" |
||
26 | |||
27 | /**** Preprocessing directives (#define) **************************************/ |
||
28 | |||
29 | /**** Type definitions (typedef) **********************************************/ |
||
30 | |||
31 | /**** Global constants ********************************************************/ |
||
32 | |||
33 | /**** Global variables ********************************************************/ |
||
34 | |||
35 | signed int GPS_Nick = 0; |
||
36 | signed int GPS_Roll = 0; |
||
37 | |||
38 | /**** Local constants ********************************************************/ |
||
39 | |||
40 | /**** Local variables *********************************************************/ |
||
41 | |||
42 | signed int test_nick = 0; |
||
43 | signed int test_roll = 0; |
||
44 | long GpsAktuell_X = 0; |
||
45 | long GpsAktuell_Y = 0; |
||
125 | osiair | 46 | long GpsAktuell_Z = 0; |
51 | osiair | 47 | long GpsZiel_X = 0; |
48 | long GpsZiel_Y = 0; |
||
49 | long gps_dx; |
||
50 | long gps_dy; |
||
125 | osiair | 51 | long gps_dz; |
51 | osiair | 52 | long gps_vx; |
53 | long gps_vy; |
||
125 | osiair | 54 | long gps_vz; |
51 | osiair | 55 | bool gps_hold; |
56 | uint8 print_pos; |
||
57 | |||
58 | /**** Local function prototypes ***********************************************/ |
||
59 | |||
60 | void print_uint16(uint16 value,uint8 width); |
||
61 | void print_int16(int16 value,uint8 width); |
||
62 | void print_string(char *s); |
||
63 | |||
64 | //------------------------------------------------------------------------------ |
||
65 | // Name: GPS_Neutral |
||
66 | // Function: |
||
67 | // |
||
68 | // Parameter: |
||
69 | // Return: |
||
70 | //------------------------------------------------------------------------------ |
||
71 | void GPS_Neutral(void) |
||
72 | { |
||
73 | GpsZiel_X = GpsAktuell_X; |
||
74 | GpsZiel_Y = GpsAktuell_Y; |
||
75 | |||
76 | GPS_Nick = 0; |
||
77 | GPS_Roll = 0; |
||
78 | |||
79 | // LED_GPS_DATA_OFF; |
||
80 | //LED_GPS_FIX_OFF; |
||
81 | //LED_GPS_DATA_ON; |
||
82 | |||
83 | } |
||
84 | |||
85 | //------------------------------------------------------------------------------ |
||
86 | // Name: gps_trace |
||
87 | // Function: |
||
88 | // |
||
89 | // Parameter: |
||
90 | // Return: |
||
91 | //------------------------------------------------------------------------------ |
||
92 | void gps_trace(void) |
||
93 | { |
||
94 | print_pos = 0; |
||
95 | |||
96 | print_uint16(nav_sol.gpsfix,1); |
||
97 | print_string(" "); |
||
98 | print_int16(gps_dy,7); |
||
99 | print_int16(gps_dx,7); |
||
100 | |||
101 | print_string(" | "); |
||
102 | |||
103 | print_int16(gps_vy,7); |
||
104 | print_int16(gps_vx,7); |
||
105 | |||
106 | print_string(" | "); |
||
107 | |||
108 | print_int16(GPS_Roll,7); |
||
109 | print_int16(GPS_Nick,7); |
||
110 | |||
111 | |||
112 | print_string(" # "); |
||
113 | |||
114 | print_int16(StickRoll,7); |
||
115 | print_int16(StickNick,7); |
||
116 | |||
117 | |||
118 | print_string("\r\n"); |
||
119 | UebertragungAbgeschlossen = 0; |
||
120 | UDR = SendeBuffer[0]; // Start |
||
121 | } |
||
122 | |||
123 | //------------------------------------------------------------------------------ |
||
124 | // Name: gps_main |
||
125 | // Function: |
||
126 | // |
||
127 | // Parameter: |
||
128 | // Return: |
||
129 | //------------------------------------------------------------------------------ |
||
130 | void GPS_Main(void) |
||
131 | { |
||
132 | if((Poti3 > 125) && (nav_sol.gpsfix) && (gps_hold == false)) // Enable Hold |
||
133 | { |
||
134 | GpsZiel_X = GpsAktuell_X; |
||
135 | GpsZiel_Y = GpsAktuell_Y; |
||
136 | gps_hold = true; |
||
137 | } |
||
138 | |||
139 | if(Poti3 < 125) // Disable Hold |
||
140 | { |
||
141 | GpsZiel_X = 0; |
||
142 | GpsZiel_Y = 0; |
||
143 | GPS_Nick = 0; |
||
144 | GPS_Roll = 0; |
||
145 | |||
146 | gps_hold = false; |
||
147 | } |
||
148 | |||
149 | |||
150 | |||
151 | |||
152 | if(ubx.update) |
||
153 | { |
||
154 | |||
155 | ubx.update = false; |
||
156 | ubx_decode(&ubx); |
||
157 | if(nav_sol.update) |
||
158 | { |
||
159 | //trace_nav_sol(); |
||
160 | nav_sol.update = false; |
||
161 | |||
162 | if(nav_sol.gpsfix) |
||
163 | { |
||
164 | LED_GPS_FIX_TOGGLE; |
||
165 | LED_GPS_DATA_OFF; |
||
166 | } |
||
167 | else |
||
168 | { |
||
169 | |||
170 | LED_GPS_DATA_TOGGLE; |
||
171 | LED_GPS_FIX_OFF; |
||
172 | } |
||
173 | |||
174 | //=== new Position ==================== |
||
175 | |||
176 | GpsAktuell_X = nav_sol.ecef_x; |
||
177 | GpsAktuell_Y = nav_sol.ecef_y; |
||
178 | |||
179 | gps_dx = GpsZiel_X - GpsAktuell_X; // Süden + |
||
180 | gps_dy = GpsZiel_Y - GpsAktuell_Y; // Osten + |
||
181 | |||
182 | |||
183 | gps_vx = -nav_sol.ecefvx; // cm/s ECEF X velocity |
||
184 | gps_vy = -nav_sol.ecefvy; // cm/s ECEF Y velocity |
||
185 | |||
186 | |||
187 | if(gps_hold) |
||
188 | { |
||
189 | GPS_Nick = ((gps_dx * Poti1) / 512) + ((gps_vx * Poti2) / 128); |
||
190 | GPS_Roll = ((gps_dy * Poti1) / 512) + ((gps_vy * Poti2) / 128); |
||
191 | } |
||
192 | else |
||
193 | { |
||
194 | GPS_Nick = 0; |
||
195 | GPS_Roll = 0; |
||
196 | } |
||
197 | |||
198 | //===================================== |
||
199 | } |
||
200 | gps_trace(); |
||
201 | } |
||
202 | } |
||
203 | |||
204 | |||
205 | |||
206 | //============================================================================== |
||
207 | //============================================================================== |
||
208 | //============================================================================== |
||
209 | // |
||
210 | //============================================================================== |
||
211 | //============================================================================== |
||
212 | //============================================================================== |
||
213 | |||
214 | |||
215 | //------------------------------------------------------------------------------ |
||
216 | // Name: |
||
217 | // Function: |
||
218 | // |
||
219 | // Parameter: |
||
220 | // Return: |
||
221 | //------------------------------------------------------------------------------ |
||
222 | void print_uint16(uint16 value,uint8 width) |
||
223 | { |
||
224 | uint8 i,s[10]; |
||
225 | |||
226 | for (i = 0; i < width; i++) |
||
227 | { |
||
228 | s[width - i - 1] = '0' + (value % 10); |
||
229 | value /= 10; |
||
230 | } |
||
231 | for (i=0; i<(width - 1); i++) // Overwrite trailing Zeros |
||
232 | { |
||
233 | if (s[i] == '0') s[i] = ' '; |
||
234 | else break; |
||
235 | } |
||
236 | |||
237 | for (i=0; i<width; i++) SendeBuffer[print_pos++] = s[i]; // Output String |
||
238 | // for (i=0; i<width; i++) putchar(s[i]); // Output String |
||
239 | |||
240 | } |
||
241 | |||
242 | //------------------------------------------------------------------------------ |
||
243 | // Name: |
||
244 | // Function: |
||
245 | // |
||
246 | // Parameter: |
||
247 | // Return: |
||
248 | //------------------------------------------------------------------------------ |
||
249 | void print_int16(int16 value,uint8 width) |
||
250 | { |
||
251 | uint8 i,s[10]; |
||
252 | bool neg; |
||
253 | |||
254 | neg = false; |
||
255 | if(value < 0) { value = -value; neg = true; } |
||
256 | |||
257 | for (i = 0; i < width; i++) |
||
258 | { |
||
259 | s[width - i - 1] = '0' + (value % 10); |
||
260 | value /= 10; |
||
261 | } |
||
262 | |||
263 | for (i=0; i<(width - 1); i++) // Overwrite trailing Zeros |
||
264 | { |
||
265 | if (s[i] == '0') s[i] = ' '; |
||
266 | else |
||
267 | { |
||
268 | if(neg) s[i-1] = '-'; |
||
269 | break; |
||
270 | } |
||
271 | } |
||
272 | for (i=0; i<width; i++) SendeBuffer[print_pos++] = s[i]; // Output String |
||
273 | // for (i=0; i<width; i++) putchar(s[i]); // Output String |
||
274 | } |
||
275 | |||
276 | //------------------------------------------------------------------------------ |
||
277 | // Name: |
||
278 | // Function: |
||
279 | // |
||
280 | // Parameter: |
||
281 | // Return: |
||
282 | //------------------------------------------------------------------------------ |
||
283 | void print_string(char *s) |
||
284 | { |
||
285 | while(*s) |
||
286 | { |
||
287 | SendeBuffer[print_pos++] = *s; |
||
288 | s++; |
||
289 | } |
||
290 | } |