Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1920 - 1
/*
2
 * FollowMe.c
3
 *
4
 *  Created on: 18.05.2012
5
 *      Author: cebra
6
 */
7
/*****************************************************************************
8
 *   Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net *
9
 *                                                                           *
10
 *   This program is free software; you can redistribute it and/or modify    *
11
 *   it under the terms of the GNU General Public License as published by    *
12
 *   the Free Software Foundation; either version 2 of the License.          *
13
 *                                                                           *
14
 *   This program is distributed in the hope that it will be useful,         *
15
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
16
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
17
 *   GNU General Public License for more details.                            *
18
 *                                                                           *
19
 *   You should have received a copy of the GNU General Public License       *
20
 *   along with this program; if not, write to the                           *
21
 *   Free Software Foundation, Inc.,                                         *
22
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.               *
23
 *                                                                           *
24
 *                                                                           *
25
 *   Credits to:                                                             *
26
 *   Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN  *
27
 *                          http://www.mikrokopter.de                        *
28
 *   Gregor "killagreg" Stobrawa for his version of the MK code              *
29
 *   Thomas Kaiser "thkais" for the original project. See                    *
30
 *                          http://www.ft-fanpage.de/mikrokopter/            *
31
 *                          http://forum.mikrokopter.de/topic-4061-1.html    *
32
 *   Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code *
33
 *                          http://www.mylifesucks.de/oss/c-osd/             *
34
 *   Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility*
35
 *****************************************************************************/
36
 
37
#include "../cpu.h"
38
#include <avr/io.h>
39
#include <inttypes.h>
40
#include <stdlib.h>
41
#include <avr/pgmspace.h>
42
#include <util/delay.h>
43
 
44
#include "../main.h"
45
#include "../followme/followme.h"
46
#include "../osd/osd.h"
47
#include "../lcd/lcd.h"
48
#include "../timer/timer.h"
49
#include "../uart/usart.h"
50
#include "../eeprom/eeprom.h"
51
#include "../messages.h"
52
#include "../parameter.h"
53
#include "../mk-data-structs.h"
54
 
55
#define COSD_WASFLYING 4
56
#define TIMEOUT 200     // 2 sec
57
 
58
// global definitions and global vars
59
NaviData_t *naviData;
60
mk_param_struct_t *mk_param_struct;
61
//uint16_t old_hh = 0;
62
uint8_t Flags_ExtraConfig;
63
uint8_t Flags_GlobalConfig;
64
uint8_t Flags_GlobalConfig3;
65
unsigned char Element;
66
uint16_t heading_home;
67
 
68
// Hier Höhenanzeigefehler Korrigieren
69
#define AltimeterAdjust 1.5
70
 
71
 
72
// Positionen der Anzeigeelemente im Bildschirm
73
#define OSD_ALTITUDE_CONTROL    1
74
#define OSD_ALTITUDE                     2
75
#define OSD_BATTERY_LEVEL               3
76
#define OSD_CAPACITY                    4
77
#define OSD_CARE_FREE                   5
78
#define OSD_COMPASS_DEGREE              6
79
#define OSD_COMPASS_DIRECTION   7
80
#define OSD_COMPASS_ROSE                8
81
#define OSD_CURRENT                             9
82
#define OSD_FLYING_TIME                 10
83
#define OSD_GROUND_SPEED                11
84
#define OSD_HOME_CIRCLE                 12
85
#define OSD_HOME_DEGREE                 13
86
#define OSD_HOME_DISTANCE               14
87
#define OSD_LED1_OUTPUT                 15
88
#define OSD_LED2_OUTPUT                 16
89
#define OSD_MANUELL                             17
90
#define OSD_NAVI_MODE                   18
91
#define OSD_RC_INTENSITY                19
92
#define OSD_SATS_IN_USE                 20
93
#define OSD_STATUS_FLAGS                21
94
#define OSD_VARIOMETER                  22
95
 
96
// Flags
97
//uint8_t COSD_FLAGS2 = 0;
98
//
99
//GPS_Pos_t last5pos[7];
100
uint8_t FM_error = 0;
101
 
102
//--------------------------------------------------------------
103
void FollowMe (void)
104
{
105
        uint8_t flag;
106
        uint8_t tmp_dat;
107
//        uint8_t OSD_Mode;
108
//        uint8_t info_3D = 0;
109
        uint8_t status;
110
 
111
        // Clear statistics
112
//        max_Altimeter = 0;
113
//        max_GroundSpeed = 0;
114
//        max_Distance = 0;
115
//        min_UBat = 255;
116
//        max_FlyingTime = 0;
117
 
118
        // flags from last round to check for changes
119
        uint8_t old_FCFlags = 0;
120
 
121
//        uint8_t old_AngleNick = 0;
122
//        uint8_t old_AngleRoll = 0;
123
        lcd_cls();
124
 
125
 
126
 
127
 
128
 
129
 
130
        if (hardware == FC)
131
        {
132
                lcd_puts_at(0, 3, strGet(ONLY_NC), 0);  // Nur mit NC
133
                timer = 100;
134
                while (timer > 0);
135
 
136
                return;
137
        }
138
 
139
        SwitchToFC();
140
 
141
        status = load_setting(0xff);
142
        if(status == 255)
143
        {
144
                lcd_puts_at(0, 0, strGet(NO_SETTINGS), 0);      // Keine Setings
145
                _delay_ms(2000);
146
        }
147
        Flags_ExtraConfig = mk_param_struct->ExtraConfig;
148
        Flags_GlobalConfig = mk_param_struct->GlobalConfig;
149
        Flags_GlobalConfig3 = mk_param_struct->GlobalConfig3;
150
 
151
        SwitchToNC();
152
 
153
        mode = 'O';
154
 
155
        // disable debug...
156
        //      RS232_request_mk_data (0, 'd', 0);
157
        tmp_dat = 0;
158
        SendOutData ('d', ADDRESS_ANY, 1, &tmp_dat, 1);
159
 
160
        // request OSD Data from NC every 100ms
161
        //      RS232_request_mk_data (1, 'o', 100);
162
        tmp_dat = 10;
163
//        OSD_active = true;              // benötigt für Navidata Ausgabe an SV2
164
        SendOutData ('o', ADDRESS_NC, 1, &tmp_dat, 1);
165
 
166
        flag = 0;
167
        timer = TIMEOUT;
168
        abo_timer = ABO_TIMEOUT;
169
 
170
        do
171
        {
172
                if (rxd_buffer_locked)
173
                {
174
                        timer = TIMEOUT;
175
                        Decode64 ();
176
                        naviData = (NaviData_t *) pRxData;
177
 
178
                        if(FM_error == 1)
179
                                lcd_cls();
180
 
181
                        FM_error = 0;
182
                        GPS_Pos_t currpos;
183
                        currpos.Latitude = naviData->CurrentPosition.Latitude;
184
                        currpos.Longitude = naviData->CurrentPosition.Longitude;
185
 
186
 
187
                        flag = 1;
188
 
189
 
190
                        {
191
                                                                //-------------------------------------------
192
                                                                // OSD_Screen_Element() is depricated!
193
                                                                // USE NEW OSD_Element_xyz() FUNCTIONS!
194
                                                                //-------------------------------------------
195
 
196
                                // Altitude Control
197
                                //OSD_Screen_Element (0, 3, OSD_ALTITUDE_CONTROL,Config.OSD_ScreenMode);
198
                                OSD_Element_AltitudeControl( 0, 0 );
199
 
200
//
201
//                                // Altitude
202
//                                OSD_Screen_Element (11, 3, OSD_ALTITUDE);
203
 
204
                                // Battery level
205
                                //OSD_Screen_Element (0, 7, OSD_BATTERY_LEVEL,Config.OSD_ScreenMode);
206
                                                                OSD_Element_BatteryLevel( 0, 7, Config.OSD_ScreenMode );
207
 
208
                                // Capacity
209
                                //OSD_Screen_Element (13, 7, OSD_CAPACITY,Config.OSD_ScreenMode);
210
                                                                OSD_Element_Capacity( 13, 7 );
211
 
212
                                // Care Free
213
                                //OSD_Screen_Element (12, 2, OSD_CARE_FREE,Config.OSD_ScreenMode);
214
                                OSD_Element_CareFree( 12, 2 );
215
 
216
 
217
//                                // Compass Degree
218
//                                OSD_Screen_Element (13, 0, OSD_COMPASS_DEGREE);
219
//
220
//                                // Compass Direction
221
//                                OSD_Screen_Element (18, 0, OSD_COMPASS_DIRECTION);
222
//
223
//                                // Compass Rose
224
//                                OSD_Screen_Element (12, 1, OSD_COMPASS_ROSE);
225
 
226
                                // Current
227
                                //OSD_Screen_Element (7, 7, OSD_CURRENT,Config.OSD_ScreenMode);
228
                                OSD_Element_Current( 7, 7 );
229
 
230
 
231
                                // Flying time
232
                                lcd_printp_at (0, 1, PSTR("Flytime:"), 0);
233
                                //OSD_Screen_Element (8, 1, OSD_FLYING_TIME,Config.OSD_ScreenMode);
234
                                OSD_Element_FlyingTime( 8, 1 );
235
 
236
 
237
                                // Ground Speed
238
                                lcd_printp_at (0, 0, PSTR("Speed:"), 0);
239
                                //OSD_Screen_Element (6, 0, OSD_GROUND_SPEED,Config.OSD_ScreenMode);
240
                                OSD_Element_GroundSpeed( 6, 0 );
241
 
242
                                // Sats in use
243
                                //OSD_Screen_Element (16, 0, OSD_SATS_IN_USE,Config.OSD_ScreenMode);
244
                                                                OSD_Element_SatsInUse( 16, 0, Config.OSD_ScreenMode );
245
 
246
//                                // Home Circle
247
//                                OSD_Screen_Element (16, 4, OSD_HOME_CIRCLE);
248
//
249
//                                // Home Degree
250
//                                OSD_Screen_Element (12, 4, OSD_HOME_DEGREE);
251
 
252
                                // Home Distance
253
                                lcd_printp_at (11, 3, PSTR("Dist:"), 0);
254
                                //OSD_Screen_Element (17, 3, OSD_HOME_DISTANCE,Config.OSD_ScreenMode);
255
                                OSD_Element_HomeDistance( 17, 3, Config.OSD_ScreenMode );
256
 
257
//
258
//                                // LED1 Output
259
//                                OSD_Screen_Element (0, 6, OSD_LED1_OUTPUT);
260
//
261
//                                // LED2 Output
262
//                                OSD_Screen_Element (5, 6, OSD_LED2_OUTPUT);
263
 
264
                                // Manuell
265
                        //      OSD_Screen_Element (7, 0, OSD_MANUELL);
266
 
267
                                // Navi Mode
268
                                //OSD_Screen_Element (0, 2, OSD_NAVI_MODE,Config.OSD_ScreenMode);
269
                                OSD_Element_NaviMode( 0, 2 );
270
 
271
 
272
                                // RC Intensity
273
                        //      OSD_Screen_Element (11, 6, OSD_RC_INTENSITY);
274
 
275
 
276
                                // Status Flags
277
//                                OSD_Screen_Element (0, 2, OSD_STATUS_FLAGS);
278
 
279
//                                // Variometer
280
//                                OSD_Screen_Element (9, 0, OSD_VARIOMETER);
281
 
282
                                lcd_printp_at (0, 4, PSTR("MK:"), 0);
283
                                write_ndigit_number_u (3, 4, (uint16_t)(currpos.Latitude/10000000), 2, 0,0);
284
                                lcd_printp_at (5, 4, PSTR("."), 0);
285
                                write_ndigit_number_u (6, 4, (uint16_t)((currpos.Latitude/1000) % 10000), 4, 1,0);
286
                                write_ndigit_number_u (10, 4, (uint16_t)((currpos.Latitude/10) % 100), 2, 1,0);
287
 
288
 
289
                                write_ndigit_number_u (12, 4, (uint16_t)(currpos.Longitude/10000000), 2, 0,0);
290
                                lcd_printp_at (14, 4, PSTR("."), 0);
291
                                write_ndigit_number_u (15, 4, (uint16_t)((currpos.Longitude/1000) % 10000), 4, 1,0);
292
                                write_ndigit_number_u (19, 4, (uint16_t)((currpos.Longitude/10) % 100), 2, 1,0);
293
 
294
                                lcd_printp_at (0, 5, PSTR("!!!not implemented!!!"), 2);
295
 
296
                                // Akku Warnung
297
                                if (naviData->UBat < Config.MK_LowBat)
298
                                { //Beeper ein
299
                                        set_beep ( 3000, 0x0020, BeepNormal);
300
                                }
301
                                if (naviData->UBat > Config.MK_LowBat)  //bei kurzzeitigen Schwankungen Beeper erst wieder aus wenn UBat 0,2 V höher als Warnschwelle
302
                                { //Beeper aus
303
                                    set_beep ( 0, 0, BeepOff);
304
                                }
305
//                               Akku Warnung Ende
306
 
307
                                old_FCFlags = naviData->FCStatusFlags;
308
 
309
                                rxd_buffer_locked = FALSE;
310
                        }
311
 
312
 
313
                        if (!abo_timer)
314
                        {       // renew abo every 3 sec
315
                                // request OSD Data from NC every 100ms
316
                                //      RS232_request_mk_data (1, 'o', 100);
317
                                tmp_dat = 10;
318
                                SendOutData ('o', ADDRESS_NC, 1, &tmp_dat, 1);
319
 
320
                                abo_timer = ABO_TIMEOUT;
321
                        }
322
                }
323
                if (!timer)
324
                {
325
                        OSD_Timeout(flag);
326
                        flag = 0;
327
                        FM_error = 1;
328
                }
329
        }
330
 
331
        while (!get_key_press (1 << KEY_ESC));
332
        OSD_active = false;
333
 
334
}
335
 
336
 
337
 
338