Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2136 | - | 1 | /* |
2 | * tracking.c |
||
3 | * |
||
4 | * Created on: 13.02.2012 |
||
5 | * Author: cebra |
||
6 | */ |
||
7 | |||
8 | |||
9 | //############################################################################ |
||
10 | //# HISTORY tracking.c |
||
11 | //# |
||
12 | //# 27.06.2014 OG |
||
13 | //# - umgestellt auf gps/gps_nmea.c |
||
14 | //# - Codeformattierung |
||
15 | //# - chg: auf #include "../gps/mymath.h" angepasst |
||
16 | //# - del: #include "tools.h" |
||
17 | //# |
||
18 | //# 25.06.2014 OG |
||
19 | //# - chg: PKT_tracking() - auskommentierungen um Zugriffe auf Config.gps_UsedGPSMouse |
||
20 | //# zu unterbinden. Anmerkung dazu siehe dort. |
||
21 | //# |
||
22 | //# 22.06.2014 OG |
||
23 | //# - chg: Tracking_NMEA() - do_tracking() auskommentiert (spaeter fuer |
||
24 | //# Tracking wieder geradeziehen) |
||
25 | //# - Variable 'CheckGPS' hinzugefuegt weil aus anderen Sourcen (setup.c) entfernt |
||
26 | //# |
||
27 | //# 18.06.2014 OG |
||
28 | //# - chg: Code-Formattierung |
||
29 | //# |
||
30 | //# 16.06.2014 OG |
||
31 | //# - add: NMEA_GPGGA_counter (zaehlt empfangene GPGGA-Pakete) |
||
32 | //# |
||
33 | //# 01.06.2014 OG |
||
34 | //# - chg: PKT_trackingMK() - verschiedene Anzeigefunktionen auskommentiert und |
||
35 | //# als DEPRICATED Klassifiziert wegen Cleanup der alten OSD Screens |
||
36 | //# |
||
37 | //# 30.05.2014 OG |
||
38 | //# - chg: calc_geo()- my_itoa() ersetzt durch writex_gpspos() und lcdx_printf_at_P() |
||
39 | //# weil my_itoa() nicht mehr vorhanden |
||
40 | //# |
||
41 | //# 13.05.2014 OG |
||
42 | //# - chg: PKT_trackingBT() - Variable 'BT_WhasOn' auskommentiert |
||
43 | //# wegen Warning: variable set but not used |
||
44 | //# - chg: PKT_trackingBT() - Variable 'flag' auskommentiert |
||
45 | //# wegen Warning: variable set but not used |
||
46 | //# |
||
47 | //# 28.04.2014 OG |
||
48 | //# - chg: PKT_trackingBT(), PKT_trackingMK() - OSD_Timeout() entfernt (weil es |
||
49 | //# das nicht mehr gibt) und erstmal durch ein PKT_Message_P() ersetzt |
||
50 | //# * ACHTUNG: UNGETESTET! * (bei Bedarf anpassen, tracking hat niedrige Prio) |
||
51 | //# - add: include "../pkt/pkt.h" |
||
52 | //# |
||
53 | //# 12.02.2014 OG |
||
54 | //# - del: mk_param_struct entfernt |
||
55 | //# |
||
56 | //# 29.08.2013 Cebra |
||
57 | //# - chg: falsche Parameterübergabe bei getLatitude/getLongitude |
||
58 | //# |
||
59 | //# 25.08.2013 Cebra |
||
60 | //# - add: #ifdef USE_TRACKING . NMEA Routinen werden nur noch für BT_NMEA genutzt |
||
61 | //# |
||
62 | //# 26.06.2013 Cebra |
||
63 | //# - chg: Modulumschaltung für WiFlypatch geändert |
||
64 | //# |
||
65 | //############################################################################ |
||
66 | |||
67 | |||
68 | #include "../cpu.h" |
||
69 | #include <string.h> |
||
70 | #include <util/delay.h> |
||
71 | #include <avr/interrupt.h> |
||
72 | #include <stdlib.h> |
||
73 | #include <math.h> |
||
74 | #include "../main.h" |
||
75 | |||
76 | |||
77 | //++++++++++++++++++++++++++++++++++ |
||
78 | #ifdef USE_TRACKING |
||
79 | //++++++++++++++++++++++++++++++++++ |
||
80 | |||
81 | |||
82 | #include "../tracking/tracking.h" |
||
83 | #include "../tracking/ng_servo.h" |
||
84 | #include <avr/pgmspace.h> |
||
85 | #include "../bluetooth/fifo.h" |
||
86 | #include "../bluetooth/bluetooth.h" |
||
87 | #include "../lcd/lcd.h" |
||
88 | |||
89 | #include "../mk-data-structs.h" |
||
90 | #include "../messages.h" |
||
91 | #include "../lcd/lcd.h" |
||
92 | #include "../eeprom/eeprom.h" |
||
93 | #include "../timer/timer.h" |
||
94 | #include "../uart/uart1.h" |
||
95 | #include "../uart/usart.h" |
||
96 | #include "../osd/osd.h" |
||
97 | #include "../gps/mymath.h" |
||
98 | #include "../setup/setup.h" |
||
99 | #include "../pkt/pkt.h" |
||
100 | //#include "../gps/gps_nmea.h" |
||
101 | #include "../avr-nmea-gps-library/nmea.h" |
||
102 | |||
103 | |||
104 | |||
105 | uint8_t CheckGPS = true; // Patch 22.06.2014 OG: hier integriert weil ais anseren Sourcen entfernt (u.a. setup.c) |
||
106 | |||
107 | char data_decode[RXD_BUFFER_SIZE]; |
||
108 | |||
109 | |||
110 | #define DLEFT 0 |
||
111 | #define DRIGHT 1 |
||
112 | #define DEG_TO_RAD 0.0174533 // degrees to radians = PI / 180 |
||
113 | #define RAD_TO_DEG 57.2957795 // radians to degrees = 180 / PI |
||
114 | #define AltFaktor 22.5 |
||
115 | #define TIMEOUT 200 // 2 sec |
||
116 | |||
117 | NaviData_t *naviData; |
||
118 | |||
119 | |||
120 | HomePos_t MK_pos; // Home position of station |
||
121 | GPS_Pos_t currentPos; // Current position of flying object |
||
122 | |||
123 | |||
124 | uint8_t tracking = TRACKING_MIN; |
||
125 | uint8_t track_hyst = TRACKING_HYSTERESE; |
||
126 | uint8_t track_tx =0; |
||
127 | uint8_t coldstart; // Flag erstmaliger MK-Start(Motore) nur nach GPS-Fix |
||
128 | geo_t geo; |
||
129 | int16_t anglePan, angleTilt; |
||
130 | |||
131 | |||
132 | |||
133 | |||
134 | //// Berechnung von Distanz und Winkel aus GPS-Daten home(MK eingeschaltet) |
||
135 | //// zur aktuellen Position(nach Motorstart) |
||
136 | //geo_t calc_geo(HomePos_t *home, GPS_Pos_t *pos) |
||
137 | //{ double lat1, lon1, lat2, lon2, d1, dlat; |
||
138 | // geo_t geo; |
||
139 | // |
||
140 | // lon1 = MK_pos.Home_Lon; |
||
141 | // lat1 = MK_pos.Home_Lat; |
||
142 | // lon2 = (double)pos->Longitude / 10000000.0; |
||
143 | // lat2 = (double)pos->Latitude / 10000000.0; |
||
144 | // |
||
145 | // // Formel verwendet von http://www.kompf.de/gps/distcalc.html |
||
146 | // // 111.3 km = Abstand zweier Breitenkreise und/oder zweier Längenkreise am Äquator |
||
147 | // // es wird jedoch in Meter weiter gerechnet |
||
148 | // d1 = 111300 * (double)cos((double)(lat1 + lat2) / 2 * DEG_TO_RAD) * (lon1 - lon2); |
||
149 | // dlat = 111300 * (double)(lat1 - lat2); |
||
150 | // // returns a value in metres http://www.kompf.de/gps/distcalc.html |
||
151 | // geo.bearing = fmod((RAD_TO_DEG * (double)atan2(d1, dlat)) + 180, 360); // +180 besserer Vergleich mit MkCockpit |
||
152 | // if (geo.bearing > 360) geo.bearing -= 360; // bekam schon Werte über 400 |
||
153 | // geo.distance = sqrt(d1 * d1 + dlat * dlat); |
||
154 | // return(geo); |
||
155 | //} |
||
156 | |||
157 | // Berechnung von Distanz und Winkel aus GPS-Daten home(MK eingeschaltet) |
||
158 | // zur aktuellen Position(nach Motorstart) |
||
159 | |||
160 | //-------------------------------------------------------------- |
||
161 | // bei Gelegenheit den Code auf gps/gps.c/gps_Deviation() aendern |
||
162 | //-------------------------------------------------------------- |
||
163 | geo_t calc_geo( HomePos_t *home, GPS_Pos_t *pos ) |
||
164 | { |
||
165 | int32_t lat1, lon1, lat2, lon2; |
||
166 | int32_t d1, dlat; |
||
167 | geo_t geo; |
||
168 | |||
169 | lon1 = home->Home_Lon; |
||
170 | lat1 = home->Home_Lat; |
||
171 | lon2 = pos->Longitude; |
||
172 | lat2 = pos->Latitude; |
||
173 | |||
174 | if( !CheckGPS ) |
||
175 | { |
||
176 | writex_gpspos( 0, 3, home->Home_Lat , MNORMAL, 0,0); // Anzeige: Breitengrad (Latitude) |
||
177 | writex_gpspos( 11, 3, home->Home_Lon , MNORMAL, 0,0); // Anzeige: Laengengrad (Longitude) |
||
178 | writex_gpspos( 0, 4, pos->Latitude , MNORMAL, 0,0); // Anzeige: Breitengrad (Latitude) |
||
179 | writex_gpspos( 11, 4, pos->Longitude , MNORMAL, 0,0); // Anzeige: Laengengrad (Longitude) |
||
180 | |||
181 | //lcd_puts_at (0, 3, my_itoa(home->Home_Lat, 10, 7, 7), 0); // 30.05.2014 OG: my_itoa() gibt es nicht mehr |
||
182 | //lcd_puts_at (11, 3, my_itoa(home->Home_Lon, 10, 7, 7), 0); // 30.05.2014 OG: my_itoa() gibt es nicht mehr |
||
183 | //lcd_puts_at (0, 4, my_itoa(pos->Latitude, 10, 7, 7), 0); // 30.05.2014 OG: my_itoa() gibt es nicht mehr |
||
184 | //lcd_puts_at (11, 4, my_itoa(pos->Longitude, 10, 7, 7), 0); // 30.05.2014 OG: my_itoa() gibt es nicht mehr |
||
185 | } |
||
186 | |||
187 | // Formel verwendet von http://www.kompf.de/gps/distcalc.html |
||
188 | // 111.3 km = Abstand zweier Breitenkreise und/oder zweier Langenkreise am Äquator |
||
189 | // es wird jedoch in dm Meter weiter gerechnet |
||
190 | // (tlon1 - tlon2)/10) sonst uint32_t-Überlauf bei cos(0) gleich 1 |
||
191 | d1 = (1359 * (int32_t)(c_cos_8192((lat1 + lat2) / 20000000)) * ((lon1 - lon2)/10))/ 10000000; |
||
192 | dlat = 1113 * (lat1 - lat2) / 10000; |
||
193 | geo.bearing = (my_atan2(d1, dlat) + 540) % 360; // 360 +180 besserer Vergleich mit MkCockpit |
||
194 | geo.distance = sqrt32(d1 * d1 + dlat * dlat); |
||
195 | |||
196 | if( !CheckGPS ) |
||
197 | { |
||
198 | lcd_printp_at (0, 5, PSTR("Bear:"), 0); |
||
199 | |||
200 | lcdx_printf_at_P( 5, 5, MNORMAL, 0,0, PSTR("%3d"), geo.bearing ); |
||
201 | //lcd_puts_at (5, 5, my_itoa((uint32_t)geo.bearing, 3, 0, 0), 0); // 30.05.2014 OG: my_itoa() gibt es nicht mehr |
||
202 | |||
203 | lcd_printp_at (8, 5, PSTR("\x1e"), 0); |
||
204 | lcd_printp_at (9, 5, PSTR("Dist:"), 0); |
||
205 | |||
206 | lcdx_printf_at_P( 15, 5, MNORMAL, 0,0, PSTR("%3d"), geo.distance ); |
||
207 | //lcd_puts_at (15, 5, my_itoa((uint32_t)geo.distance, 3, 1, 1), 0); // 30.05.2014 OG: my_itoa() gibt es nicht mehr |
||
208 | |||
209 | lcd_printp_at (20, 5, PSTR("m"), 0); |
||
210 | } |
||
211 | |||
212 | return(geo); |
||
213 | } |
||
214 | |||
215 | |||
216 | |||
217 | |||
218 | |||
219 | //-------------------------------------------------------------- |
||
220 | //-------------------------------------------------------------- |
||
221 | void do_tracking( void ) |
||
222 | { |
||
223 | static uint8_t hysteresis = 0; |
||
224 | |||
225 | geo = calc_geo(&MK_pos, ¤tPos); |
||
226 | angleTilt = my_atan2((currentPos.Altitude - MK_pos.Home_Alt) / 100, geo.distance); |
||
227 | |||
228 | if (geo.distance < 40 || (geo.distance < 60 && hysteresis)) |
||
229 | { // < 4m ==> Pan-Servo in Mittelstellung. Hysterese bis 6m, damit Servo im Grenzbereich nicht wild rumschl�gt |
||
230 | geo.bearing = MK_pos.direction; |
||
231 | if (currentPos.Altitude - MK_pos.Home_Alt < 4000) angleTilt = 0; // man fliegt nicht direkt �ber Kopf |
||
232 | hysteresis = 1; |
||
233 | } |
||
234 | else |
||
235 | { |
||
236 | hysteresis = 0; |
||
237 | } |
||
238 | |||
239 | // egal wo der Übergangspunkt 359, 360, 1grd ist => Winkelübergangspunkt auf 0 bzw. 180grd des Servos bringen |
||
240 | // 360 grd negative Winkelwerte als positive |
||
241 | anglePan = (geo.bearing + 450 - MK_pos.direction) % 360; // 450 = 360 + 90 |
||
242 | |||
243 | if (angleTilt < 0) |
||
244 | angleTilt = 0; |
||
245 | |||
246 | if (angleTilt > 180) |
||
247 | angleTilt = 180; |
||
248 | |||
249 | if (anglePan >= 180) |
||
250 | { // zwecks 360grd-Abdeckung flipt Pan-/Tilt-Servo |
||
251 | anglePan = anglePan - 180; |
||
252 | angleTilt = 180 - angleTilt; |
||
253 | } |
||
254 | |||
255 | servoSetAngle(0, anglePan); |
||
256 | servoSetAngle(1, angleTilt); |
||
257 | |||
258 | if (!CheckGPS) |
||
259 | { |
||
260 | lcd_printp_at (0, 6, PSTR("Pan :"), 0); |
||
261 | write_ndigit_number_u (6, 6, anglePan, 3, 1,0); |
||
262 | lcd_printp_at (11, 6, PSTR("Tilt:"), 0); |
||
263 | write_ndigit_number_u (17, 6, angleTilt, 3, 1,0); |
||
264 | } |
||
265 | |||
266 | // write_ndigit_number_u (0, 5, (uint16_t)(currentPos.Altitude/10000000), 2, 0,0); |
||
267 | //// lcd_printp_at (4, 4, PSTR("."), 0); |
||
268 | // write_ndigit_number_u (2, 5, (uint16_t)((currentPos.Altitude/1000) % 10000), 4, 1,0); |
||
269 | // write_ndigit_number_u (6, 5, (uint16_t)((currentPos.Altitude/10) % 100), 2, 1,0); |
||
270 | // |
||
271 | // write_ndigit_number_u (10, 5, (uint16_t)(MK_pos.Home_Alt/10000000), 2, 0,0); |
||
272 | //// lcd_printp_at (4, 4, PSTR("."), 0); |
||
273 | // write_ndigit_number_u (12, 5, (uint16_t)((MK_pos.Home_Alt/1000) % 10000), 4, 1,0); |
||
274 | // write_ndigit_number_u (16, 5, (uint16_t)((MK_pos.Home_Alt/10) % 100), 2, 1,0); |
||
275 | } |
||
276 | |||
277 | |||
278 | |||
279 | //-------------------------------------------------------------- |
||
280 | //-------------------------------------------------------------- |
||
281 | uint8_t PKT_trackingBT( void ) // Tracking mit NMEA-Daten von BT-Maus |
||
282 | { |
||
283 | //uint8_t BT_WhasOn = 0; |
||
284 | uint8_t BT_status; |
||
285 | //uint8_t flag; |
||
286 | uint8_t tmp_dat; |
||
287 | coldstart =1; |
||
288 | |||
289 | //lcd_printp_at(0,1, PSTR("try NMEA data from:"), 0); |
||
290 | lcd_puts_at (0, 1,Config.gps_UsedDevName, 0); |
||
291 | //set_BTOn(); |
||
292 | set_Modul_On(Bluetooth); |
||
293 | |||
294 | //BT_WhasOn = true; |
||
295 | if( Config.BTIsSlave==true ) |
||
296 | { |
||
297 | bt_downlink_init(); |
||
298 | } |
||
299 | |||
300 | lcd_printp_at (18, 1, PSTR(" ?? "), 0); |
||
301 | BT_status = bt_connect(Config.gps_UsedMac); |
||
302 | |||
303 | if( BT_status==true ) |
||
304 | { |
||
305 | lcd_printp_at (18, 1, PSTR(" OK "), 0); |
||
306 | receiveNMEA = true; |
||
307 | } |
||
308 | else |
||
309 | { |
||
310 | lcd_printp_at (17, 1, PSTR("FAIL"), 2); |
||
311 | } |
||
312 | |||
313 | |||
314 | if( receiveNMEA==true ) |
||
315 | { |
||
316 | lcd_cls_line( 0, 1, 20); |
||
317 | lcd_printp_at( 0, 2, PSTR(" Latitude Longitude"), 2); |
||
318 | lcd_printp_at( 0, 3, PSTR("H"), 0); |
||
319 | lcd_printp_at( 0, 4, PSTR("M"), 0); |
||
320 | |||
321 | bt_rx_ready = 0; |
||
322 | |||
323 | SwitchToNC(); |
||
324 | mode = 'O'; |
||
325 | |||
326 | // disable debug... |
||
327 | // RS232_request_mk_data (0, 'd', 0); |
||
328 | tmp_dat = 0; |
||
329 | SendOutData( 'd', ADDRESS_ANY, 1, &tmp_dat, 1); |
||
330 | |||
331 | // request OSD Data from NC every 100ms |
||
332 | // RS232_request_mk_data (1, 'o', 100); |
||
333 | tmp_dat = 10; |
||
334 | SendOutData( 'o', ADDRESS_NC, 1, &tmp_dat, 1); |
||
335 | |||
336 | //OSD_active = true; // benoetigt für Navidata Ausgabe an SV2 |
||
337 | //flag = 0; |
||
338 | |||
339 | timer = TIMEOUT; |
||
340 | abo_timer = ABO_TIMEOUT; |
||
341 | |||
342 | do |
||
343 | { |
||
344 | //bt_rx_ready = 0; |
||
345 | |||
346 | // if( !NMEA_receiveBT() ) |
||
347 | // break; |
||
348 | if (!NMEA_isdataready()) |
||
349 | break; |
||
350 | |||
351 | if( rxd_buffer_locked ) |
||
352 | { |
||
353 | timer = TIMEOUT; |
||
354 | Decode64 (); |
||
355 | naviData = (NaviData_t *) pRxData; |
||
356 | |||
357 | currentPos = naviData->CurrentPosition; |
||
358 | |||
359 | //currentPos.Altitude = MK_pos.Home_Alt + (4000 * (int32_t)(naviData->Altimeter) / AltFaktor + currentPos.Altitude - MK_pos.Home_Alt) / 5; |
||
360 | |||
361 | |||
362 | //----------------- |
||
363 | // MK: Lat / Long |
||
364 | //----------------- |
||
365 | writex_gpspos( 2, 4, currentPos.Latitude , MNORMAL, 0,0 ); // MK: Latitude |
||
366 | writex_gpspos(12, 4, currentPos.Longitude, MNORMAL, 0,0 ); // MK: Longitude |
||
367 | |||
368 | |||
369 | |||
370 | // NMEA_GetNewData(); // neue NMEA GPGGA Daten von der BT GPA-Maus holen |
||
371 | |||
372 | |||
373 | |||
374 | //----------------- |
||
375 | // GPS-Maus: Lat / Long |
||
376 | //----------------- |
||
377 | writex_gpspos( 2, 3, NMEA.Latitude , MNORMAL, 0,0 ); // GPS-Maus: Latitude |
||
378 | writex_gpspos(12, 3, NMEA.Longitude, MNORMAL, 0,0 ); // GPS-Maus: Longitude |
||
379 | |||
380 | |||
381 | //do_tracking(); // das geht so noch nicht mit einer BT GPS-Maus! do_tracking(); ueberarbeiten! |
||
382 | |||
383 | |||
384 | if( !CheckGPS ) |
||
385 | { |
||
386 | //lcd_printp_at( 0, 2, PSTR("GPS Time: "), 0); |
||
387 | lcd_puts_at( 13, 0, NMEA.Time , 2); |
||
388 | |||
389 | lcd_printp_at( 16, 1, PSTR("Sat:"), 0); |
||
390 | write_ndigit_number_u( 19, 1, NMEA.SatsInUse, 2, 1,0); |
||
391 | |||
392 | lcd_printp_at( 0, 1, PSTR("Fix:"), 0); |
||
393 | write_ndigit_number_u( 4, 1, NMEA.SatFix, 1, 1,0); |
||
394 | |||
395 | lcd_printp_at( 6, 1, PSTR("HDOP:"), 0); |
||
396 | write_ndigit_number_u_10th( 11, 1, NMEA.HDOP, 3, 0,0); |
||
397 | } |
||
398 | |||
399 | |||
400 | rxd_buffer_locked = FALSE; |
||
401 | |||
402 | |||
403 | if( !abo_timer ) |
||
404 | { |
||
405 | // renew abo every 3 sec |
||
406 | // request OSD Data from NC every 100ms |
||
407 | // RS232_request_mk_data (1, 'o', 100); |
||
408 | tmp_dat = 10; |
||
409 | SendOutData( 'o', ADDRESS_NC, 1, &tmp_dat, 1); |
||
410 | |||
411 | abo_timer = ABO_TIMEOUT; |
||
412 | } |
||
413 | |||
414 | } // end: if (rxd_buffer_locked) |
||
415 | |||
416 | |||
417 | |||
418 | if( !timer ) |
||
419 | { |
||
420 | //OSD_Timeout(flag); // <- 28.04.2014 OG: gibt es nicht mehr - ersetzt durch PKT_Message_P() (ungetestet) |
||
421 | |||
422 | //void PKT_Message_P( const char *text, uint8_t error, uint16_t timeout, uint8_t beep, uint8_t clearscreen ) |
||
423 | PKT_Message_P( strGet(OSD_ERROR), true, 200, true, true ); // max. 2 Sekunden anzeigen |
||
424 | |||
425 | //flag = 0; |
||
426 | error = 1; |
||
427 | } |
||
428 | |||
429 | } while( !get_key_press (1 << KEY_ESC) || !receiveNMEA==true || error ==1); |
||
430 | |||
431 | |||
432 | lcd_cls_line(0,1,21); |
||
433 | lcd_cls_line(0,2,21); |
||
434 | lcd_cls_line(0,3,21); |
||
435 | lcd_cls_line(0,4,21); |
||
436 | lcd_cls_line(0,5,21); |
||
437 | lcd_cls_line(0,6,21); |
||
438 | |||
439 | if( !receiveNMEA ) |
||
440 | lcd_printp_at (0, 2, PSTR("lost BT data"), 0); |
||
441 | |||
442 | |||
443 | lcd_printp_at (0, 3, PSTR("GPS trennen"), 0); |
||
444 | |||
445 | } // end: if( receiveNMEA==true ) |
||
446 | else |
||
447 | { |
||
448 | lcd_printp_at (0, 4, PSTR("Error at connecting"), 0); |
||
449 | lcd_printp_at (0, 5, PSTR("switch on BT Mouse!!"), 0); |
||
450 | while( !get_key_press (1 << KEY_ENTER) ); |
||
451 | } |
||
452 | |||
453 | receiveNMEA = false; |
||
454 | |||
455 | if( !bt_disconnect() ) |
||
456 | lcd_printp_at (0, 3, PSTR("Fehler beim Trennen"), 0); |
||
457 | |||
458 | //set_BTOff(); |
||
459 | set_Modul_On(USB); |
||
460 | return true; |
||
461 | } |
||
462 | |||
463 | |||
464 | |||
465 | //-------------------------------------------------------------- |
||
466 | //-------------------------------------------------------------- |
||
467 | uint8_t PKT_trackingMK( void ) // Tracking mit GPS-Daten vom Mikrokopter |
||
468 | { |
||
469 | //uint8_t BT_WhasOn = 0; |
||
470 | //uint8_t BT_status; |
||
471 | uint8_t GPSfix=0; |
||
472 | uint8_t tmp_dat; |
||
473 | uint8_t toggletimer=0; |
||
474 | coldstart = true; |
||
475 | |||
476 | |||
477 | lcd_printp_at (0, 2, PSTR("S Latitude Longitude"), 2); |
||
478 | |||
479 | lcd_cls_line (0,1,20); |
||
480 | |||
481 | //lcd_printp_at (0, 3, PSTR("H"), 0); |
||
482 | //lcd_printp_at (0, 4, PSTR("M"), 0); |
||
483 | |||
484 | SwitchToNC(); |
||
485 | mode = 'O'; |
||
486 | |||
487 | // disable debug... |
||
488 | // RS232_request_mk_data (0, 'd', 0); |
||
489 | tmp_dat = 0; |
||
490 | SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1); |
||
491 | |||
492 | // request OSD Data from NC every 100ms |
||
493 | // RS232_request_mk_data (1, 'o', 100); |
||
494 | tmp_dat = 10; |
||
495 | SendOutData ('o', ADDRESS_NC, 1, &tmp_dat, 1); |
||
496 | timer = TIMEOUT; |
||
497 | abo_timer = ABO_TIMEOUT; |
||
498 | error = 0; |
||
499 | |||
500 | do |
||
501 | { |
||
502 | if( rxd_buffer_locked ) |
||
503 | { |
||
504 | timer = TIMEOUT; |
||
505 | Decode64 (); |
||
506 | naviData = (NaviData_t *) pRxData; |
||
507 | //OSD_Screen_Element (18, 1, OSD_SATS_IN_USE,1); |
||
508 | //if (GPSfix == true) OSD_Screen_Element (0, 1, OSD_STATUS_FLAGS,1); |
||
509 | |||
510 | //--- |
||
511 | // 01.06.2014 OG: DEPRICATED (alte Funktionen in osd/osdold_screens.c - nicht mehr verwenden!) |
||
512 | //--- |
||
513 | //OSD_Element_SatsInUse( 18, 1, 1); |
||
514 | |||
515 | //--- |
||
516 | // 01.06.2014 OG: DEPRICATED (alte Funktionen in osd/osdold_screens.c - nicht mehr verwenden!) |
||
517 | //--- |
||
518 | //if (GPSfix == true) OSD_Element_StatusFlags( 0, 1); |
||
519 | |||
520 | if (!(naviData->NCFlags & NC_FLAG_GPS_OK)) |
||
521 | { |
||
522 | toggletimer++; |
||
523 | if (toggletimer == 50) toggletimer = 0; |
||
524 | if (toggletimer == 25) lcd_printp_at(0,1, PSTR("Whait for GPS Fix "), 2); |
||
525 | if (toggletimer == 1) lcd_printp_at(0,1, PSTR("Whait for GPS Fix "), 0); |
||
526 | |||
527 | rxd_buffer_locked = false; |
||
528 | GPSfix = false; |
||
529 | } |
||
530 | else GPSfix = true; |
||
531 | |||
532 | |||
533 | if( GPSfix ) |
||
534 | { |
||
535 | if( coldstart ) |
||
536 | { |
||
537 | // erst nach Neustart NGVideo und beim Motorstart werden Daten vom MK übernommen |
||
538 | if (naviData->FCStatusFlags & FC_FLAG_MOTOR_START) |
||
539 | { |
||
540 | MK_pos.Home_Lon = naviData->HomePosition.Longitude; |
||
541 | MK_pos.Home_Lat = naviData->HomePosition.Latitude; |
||
542 | MK_pos.Home_Alt = naviData->HomePosition.Altitude; |
||
543 | MK_pos.direction = naviData->CompassHeading; |
||
544 | coldstart = false; |
||
545 | rxd_buffer_locked = false; |
||
546 | lcd_printp_at(0,1, PSTR(" "), 0); |
||
547 | } |
||
548 | else |
||
549 | { |
||
550 | lcd_printp_at(0,1, PSTR("GPS ok, start ok "), 0); |
||
551 | rxd_buffer_locked = false; |
||
552 | } |
||
553 | } // end: if( coldstart ) |
||
554 | else |
||
555 | { |
||
556 | //run |
||
557 | currentPos = naviData->CurrentPosition; |
||
558 | currentPos.Altitude = MK_pos.Home_Alt + (4000 * (int32_t)(naviData->Altimeter) / AltFaktor + currentPos.Altitude - MK_pos.Home_Alt) / 5; |
||
559 | do_tracking(); |
||
560 | |||
561 | //lcd_puts_at (13, 0, NMEAtime, 2); |
||
562 | //lcd_printp_at (16, 1, PSTR("Sat:"), 0); |
||
563 | //write_ndigit_number_u (19, 1, NMEAsatsInUse, 2, 1,0); |
||
564 | //lcd_printp_at (0, 1, PSTR("Fix:"), 0); |
||
565 | //write_ndigit_number_u (4, 1, posfix, 1, 1,0); |
||
566 | //lcd_printp_at (6, 1, PSTR("HDOP:"), 0); |
||
567 | //write_ndigit_number_u_10th (11, 1, HDOP, 3, 0,0); |
||
568 | |||
569 | rxd_buffer_locked = FALSE; |
||
570 | } // run |
||
571 | } |
||
572 | |||
573 | |||
574 | if( !abo_timer ) |
||
575 | { |
||
576 | // renew abo every 3 sec |
||
577 | // request OSD Data from NC every 100ms |
||
578 | // RS232_request_mk_data (1, 'o', 100); |
||
579 | tmp_dat = 10; |
||
580 | SendOutData( 'o', ADDRESS_NC, 1, &tmp_dat, 1); |
||
581 | |||
582 | abo_timer = ABO_TIMEOUT; |
||
583 | } |
||
584 | |||
585 | } // end: if( rxd_buffer_locked ) |
||
586 | |||
587 | |||
588 | if( !timer ) |
||
589 | { |
||
590 | //OSD_Timeout(1); // <- 28.04.2014 OG: gibt es nicht mehr - ersetzt durch PKT_Message_P() (ungetestet) |
||
591 | |||
592 | //void PKT_Message_P( const char *text, uint8_t error, uint16_t timeout, uint8_t beep, uint8_t clearscreen ) |
||
593 | PKT_Message_P( strGet(OSD_ERROR), true, 200, true, true ); // max. 2 Sekunden anzeigen |
||
594 | |||
595 | error = 1; |
||
596 | } |
||
597 | |||
598 | } while( (!get_key_press (1 << KEY_ENTER)) && (error ==0) ); |
||
599 | |||
600 | |||
601 | lcd_cls_line(0,1,21); |
||
602 | lcd_cls_line(0,2,21); |
||
603 | lcd_cls_line(0,3,21); |
||
604 | lcd_cls_line(0,4,21); |
||
605 | lcd_cls_line(0,5,21); |
||
606 | lcd_cls_line(0,6,21); |
||
607 | |||
608 | if (error ==1) |
||
609 | { |
||
610 | lcd_printp_at (0, 2, PSTR("lost Wi.232 data"), 0); |
||
611 | _delay_ms(2000); |
||
612 | } |
||
613 | |||
614 | return true; |
||
615 | } |
||
616 | |||
617 | |||
618 | |||
619 | //-------------------------------------------------------------- |
||
620 | //-------------------------------------------------------------- |
||
621 | void PKT_tracking(void) |
||
622 | { |
||
623 | clear_key_all(); |
||
624 | lcd_cls (); |
||
625 | |||
626 | // 25.06.2014 OG: auskommentiert weil erstmal kein Config.gps_UsedGPSMouse mehr unterstuetzt |
||
627 | // wird. Falls tracking.c mal richtig implementiert wird sollte man sich auf eine BT-GPS-Maus |
||
628 | // konzentrieren bis Tracking einwandfrei laeuft - wenn dann noch immer Bedarf nach MK-GPS ist |
||
629 | // kann man das ja wieder einbauen |
||
630 | // |
||
631 | //if (Config.gps_UsedGPSMouse==GPS_Bluetoothmouse1) lcd_printp_at(0,0, PSTR("Tracking Bluetooth "), 2); |
||
632 | //if (Config.gps_UsedGPSMouse==GPS_Mikrokopter) lcd_printp_at(0,0, PSTR(" Tracking Mikrokopter"), 2); |
||
633 | //if (Config.gps_UsedGPSMouse==GPS_Bluetoothmouse1) PKT_trackingBT(); |
||
634 | //if (Config.gps_UsedGPSMouse==GPS_Mikrokopter) PKT_trackingMK(); |
||
635 | |||
636 | lcd_printp_at( 0,0, PSTR("Tracking Bluetooth "), MINVERS); |
||
637 | lcd_printp_at(12, 7, strGet(ENDE), MNORMAL); // Keyline |
||
638 | PKT_trackingBT(); |
||
639 | clear_key_all(); |
||
640 | } |
||
641 | |||
642 | |||
643 | |||
644 | |||
645 | //++++++++++++++++++++++++++++++++++ |
||
646 | #endif // #ifdef USE_TRACKING |
||
647 | //++++++++++++++++++++++++++++++++++ |
||
648 |