Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2136 - 1
/*****************************************************************************
2
 *   Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de                  *
3
 *   Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net                  *
4
 *   Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net *
5
 *   Copyright (C) 2011 Harald Bongartz                                      *
6
 *                                                                           *
7
 *   This program is free software; you can redistribute it and/or modify    *
8
 *   it under the terms of the GNU General Public License as published by    *
9
 *   the Free Software Foundation; either version 2 of the License.          *
10
 *                                                                           *
11
 *   This program is distributed in the hope that it will be useful,         *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
14
 *   GNU General Public License for more details.                            *
15
 *                                                                           *
16
 *   You should have received a copy of the GNU General Public License       *
17
 *   along with this program; if not, write to the                           *
18
 *   Free Software Foundation, Inc.,                                         *
19
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.               *
20
 *                                                                           *
21
 *                                                                           *
22
 *   Credits to:                                                             *
23
 *   Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN  *
24
 *                          http://www.mikrokopter.de                        *
25
 *   Gregor "killagreg" Stobrawa for his version of the MK code              *
26
 *   Thomas Kaiser "thkais" for the original project. See                    *
27
 *                          http://www.ft-fanpage.de/mikrokopter/            *
28
 *                          http://forum.mikrokopter.de/topic-4061-1.html    *
29
 *   Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code *
30
 *                          http://www.mylifesucks.de/oss/c-osd/             *
31
 *   Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility*
32
 *****************************************************************************/
33
 
34
//############################################################################
35
//# HISTORY  mk_data-stucts.h
36
//#
37
//# 16.07.2015 Cebra
38
//# - chg: Receiver Selection
39
//#        RECEIVER_USER  8  -> RECEIVER_MLINK 8
40
//# - add: Receiver Selection
41
//#        RECEIVER_USER  9
42
//#
43
//# 26.01.2015 Cebra
44
//# - chg: #defines für ServoCompInvert an aktuelle Syntax angepasst
45
//#        SVNick   -> SERVO_NICK_INV
46
//#        SVRoll   -> SERVO_ROLL_INV
47
//#        SVRelMov -> SERVO_RELATIVE
48
//# - add: #define CH_DIRECTION_1 0x08  für ComingHome Ausrichtung
49
//#        #define CH_DIRECTION_2 0x10
50
//#
51
//# 19.06.2014 OG
52
//# - chg: Aktualisiert: struct Point_t (aus Quelle: NaviCtrl V2.06f/waypoints.h - Revision 546)
53
//#
54
//# 12.02.2014 OG
55
//# - del: die alten defines bzgl. MKVERSIONnnn und mk_param_struct_t entfernt
56
//#
57
//# 02.12.2013 Cebra
58
//# - add: #define MKVERSION201f, Erweiterung für FC201f
59
//#
60
//# 21.10.2013 Cebra
61
//# - add: #define MKVERSION201a, Erweiterung für FC201a
62
//#
63
//# 26.06.2013 OG
64
//# - chg: "0.91f" -> "0.91f/l"
65
//#
66
//# 13.06.2013 OG
67
//# - chg: "0.90j" -> "0.90h/j"
68
//# - chg: Code-Layout
69
//#
70
//# 05.06.2013 Cebra
71
//# - chg: Anpassungen an FC091c
72
//#
73
//# 03.06.2013 Cebra
74
//# - chg: #define Fehler beseitigt
75
//#
76
//# 30.05.2013 Cebra
77
//# - add: #define MKVERSION091a, Erweiterung für FC091a
78
//#
79
//# 13.05.2013 Cebra
80
//# - add: #define MKVERSION090h    // wegen GPS-Zeitausgabe NC
81
//#
82
//# 11.05.2013 OG
83
//# - add: DateTime_t
84
//#
85
//# 20.03.2013 OG
86
//# - add: BLData_t (http://www.mikrokopter.de/ucwiki/en/SerialCommands/BLDataStruct)
87
//############################################################################
88
 
89
 
90
#ifndef _MK_DATA_STRUCTS_H
91
#define _MK_DATA_STRUCTS_H
92
 
93
#include "main.h"
94
 
95
//##################################################################################
96
 
97
//##################################################################################
98
 
99
 
100
#define u8 uint8_t
101
#define s8 int8_t
102
#define u16 uint16_t
103
#define s16 int16_t
104
#define u32 uint32_t
105
#define s32 int32_t
106
 
107
#define NUMBER_OF_DEBUG_DATAS 32
108
#define ANALOG_NAME_LENGTH 16
109
 
110
 
111
// Version of supported serial protocol
112
#define MIN_VERSION 7
113
#define MAX_VERSION 10
114
 
115
 
116
// Setting index
117
#define SETTING_1   1
118
#define SETTING_2   2
119
#define SETTING_3   3
120
#define SETTING_4   4
121
#define SETTING_5   5
122
#define SETTING_CURRENT 0xff
123
 
124
 
125
// MikroKopter defines
126
// taken from
127
// FC Software eeprom.h
128
//
129
 
130
//GlobalConfig3 aus FC/eeprom.h
131
#define CFG3_NO_SDCARD_NO_START                 0x01
132
#define CFG3_DPH_MAX_RADIUS                     0x02
133
#define CFG3_VARIO_FAILSAFE                     0x04
134
#define CFG3_MOTOR_SWITCH_MODE                  0x08    //FC0.88L 7.5.12
135
#define CFG3_NO_GPSFIX_NO_START                 0x10    //FC0.88L 7.5.12
136
#define CFG3_USE_NC_FOR_OUT1                    0x20
137
#define CFG3_SPEAK_ALL                          0x40
138
#define CFG3_SERVO_NICK_COMP_OFF                0x80
139
 
140
 
141
//GlobalConfig
142
#define CFG_HOEHENREGELUNG                      0x01
143
#define CFG_HOEHEN_SCHALTER                     0x02
144
#define CFG_HEADING_HOLD                        0x04
145
#define CFG_KOMPASS_AKTIV                       0x08
146
#define CFG_KOMPASS_FIX                         0x10
147
#define CFG_GPS_AKTIV                           0x20
148
#define CFG_ACHSENKOPPLUNG_AKTIV                0x40
149
#define CFG_DREHRATEN_BEGRENZER                 0x80
150
 
151
//Bitconfig MAsk
152
#define CFG_LOOP_OBEN                           0x01
153
#define CFG_LOOP_UNTEN                          0x02
154
#define CFG_LOOP_LINKS                          0x04
155
#define CFG_LOOP_RECHTS                         0x08
156
#define CFG_MOTOR_BLINK1                        0x10
157
#define CFG_MOTOR_OFF_LED1                      0x20
158
#define CFG_MOTOR_OFF_LED2                      0x40
159
#define CFG_MOTOR_BLINK2                        0x80
160
 
161
// ServoCompInvert, FC0.89 entfällt und geändert s.u.
162
 
163
//#define SVNick                                  0x01
164
//#define SVRoll                                  0x02
165
//#define SVRelMov                                0x04
166
 
167
 
168
//ab FC 209a (26.1.2015 cebra)
169
 
170
// bitcoding for EE_Parameter.ServoCompInvert
171
#define SERVO_NICK_INV 0x01
172
#define SERVO_ROLL_INV 0x02
173
#define SERVO_RELATIVE 0x04                     //  direct poti control or relative moving of the servo value
174
#define CH_DIRECTION_1 0x08
175
#define CH_DIRECTION_2 0x10
176
 
177
//CH Orientation     ServoBits          0x10    0x08
178
// --> no change                        0       0
179
// --> front to starting point          0       1
180
// --> rear to to starting point        1       0
181
//-> start orientation                  1       1
182
 
183
 
184
// ExtraConfig
185
#define CFG2_HEIGHT_LIMIT                       0x01
186
#define CFG2_VARIO_BEEP                         0x02
187
#define CFG_SENSITIVE_RC                        0x04  // 26.1.2015 entfällt ab FC 209a, cebra
188
#define CFG_3_3V_REFERENCE                      0x08
189
#define CFG_NO_RCOFF_BEEPING                    0x10
190
#define CFG_GPS_AID                             0x20
191
#define CFG_LEARNABLE_CAREFREE                  0x40
192
#define CFG_IGNORE_MAG_ERR_AT_STARTUP           0x80
193
 
194
// bit mask for ParamSet.Config0
195
#define CFG0_AIRPRESS_SENSOR                    0x01
196
#define CFG0_HEIGHT_SWITCH                      0x02
197
#define CFG0_HEADING_HOLD                       0x04
198
#define CFG0_COMPASS_ACTIVE                     0x08
199
#define CFG0_COMPASS_FIX                        0x10
200
#define CFG0_GPS_ACTIVE                         0x20
201
#define CFG0_AXIS_COUPLING_ACTIVE               0x40
202
#define CFG0_ROTARY_RATE_LIMITER                0x80
203
 
204
// defines for the receiver selection
205
#define RECEIVER_PPM                            0
206
#define RECEIVER_SPEKTRUM                       1
207
#define RECEIVER_SPEKTRUM_HI_RES                2
208
#define RECEIVER_SPEKTRUM_LOW_RES               3
209
#define RECEIVER_JETI                           4
210
#define RECEIVER_ACT_DSL                        5
211
#define RECEIVER_HOTT                           6
212
#define RECEIVER_SBUS                           7
213
#define RECEIVER_MLINK                          8       //FC2.11 16.7.2015 CB
214
#define RECEIVER_USER                           9       //FC2.11 16.7.2015 CB
215
#define RECEIVER_UNKNOWN                        0xFF
216
 
217
// MikroKopter Flags
218
// taken from
219
// http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Ftags%2FV0.73d%2Ffc.h
220
//alt 0.86
221
//#define FCFLAG_MOTOR_RUN    0x01
222
//#define FCFLAG_FLY          0x02
223
//#define FCFLAG_CALIBRATE    0x04
224
//#define FCFLAG_START        0x08
225
//#define FCFLAG_NOTLANDUNG   0x10
226
//#define FCFLAG_LOWBAT       0x20
227
//#define FCFLAG_SPI_RX_ERR   0x40
228
//#define FCFLAG_I2CERR       0x80
229
// FC_StatusFlags 0.88
230
#define FC_STATUS_MOTOR_RUN                     0x01
231
#define FC_STATUS_FLY                           0x02
232
#define FC_STATUS_CALIBRATE                     0x04
233
#define FC_STATUS_START                         0x08
234
#define FC_STATUS_EMERGENCY_LANDING             0x10
235
#define FC_STATUS_LOWBAT                        0x20
236
#define FC_STATUS_VARIO_TRIM_UP                 0x40
237
#define FC_STATUS_VARIO_TRIM_DOWN               0x80
238
 
239
// FC_StatusFlags2
240
#define FC_STATUS2_CAREFREE                     0x01
241
#define FC_STATUS2_ALTITUDE_CONTROL             0x02
242
#define FC_STATUS2_RC_FAILSAVE_ACTIVE           0x04
243
#define FC_STATUS2_OUT1_ACTIVE                  0x08
244
#define FC_STATUS2_OUT2_ACTIVE                  0x10
245
 
246
 
247
 
248
// NaviCtrl Flags
249
// taken from
250
// http://mikrocontroller.cco-ev.de/mikrowebsvn/filedetails.php?repname=NaviCtrl&path=%2Ftags%2FV0.15c%2Fuart1.h
251
#define NC_FLAG_FREE                            0x01
252
#define NC_FLAG_PH                              0x02
253
#define NC_FLAG_CH                              0x04
254
#define NC_FLAG_RANGE_LIMIT                     0x08
255
#define NC_FLAG_NOSERIALLINK                    0x10
256
#define NC_FLAG_TARGET_REACHED                  0x20
257
#define NC_FLAG_MANUAL_CONTROL                  0x40
258
#define NC_FLAG_GPS_OK                          0x80
259
 
260
 
261
typedef struct
262
{
263
    unsigned char SWMajor;
264
    unsigned char SWMinor;
265
    unsigned char ProtoMajor;
266
    unsigned char ProtoMinor;
267
    unsigned char SWPatch;
268
    unsigned char HardwareError[5];
269
} __attribute__((packed)) Version_t;
270
 
271
 
272
 
273
// FC Debug Struct
274
// portions taken and adapted from
275
// http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Ftags%2FV0.72p%2Fuart.h
276
typedef struct // 0.86
277
{
278
        uint8_t Digital[2];
279
        // NC: unsigned; FC: signed !!!!
280
        int16_t Analog[32];     // Debugvalues
281
} __attribute__((packed)) DebugData_t;
282
 
283
 
284
 
285
//******************************************************************
286
// uart1.h NC 0.87, zur Zeit hier nicht verwendet 28.01.2012 CB
287
#define AMPEL_FC                0x01
288
#define AMPEL_BL                0x02
289
#define AMPEL_NC                0x04
290
#define AMPEL_COMPASS           0x08
291
 
292
 
293
 
294
typedef struct  //0.87
295
{
296
        u8 StatusGreen;
297
        u8 StatusRed;
298
        u16 Analog[32];    // Debugwerte
299
} __attribute__((packed)) DebugOut_t;
300
//******************************************************************
301
 
302
 
303
// NaviCtrl OSD Structs
304
// portions taken and adapted from
305
// http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=NaviCtrl&path=%2Ftags%2FV0.15c%2Fuart1.h
306
//
307
 
308
typedef struct  //NC uart1.h
309
{
310
        s16 AngleNick;  // in 0.1 deg
311
        s16 AngleRoll;   // in 0.1 deg
312
        s16 Heading;    // in 0.1 deg
313
        u8 StickNick;
314
        u8 StickRoll;
315
        u8 StickYaw;
316
        u8 StickGas;
317
        u8 reserve[4];
318
} __attribute__((packed)) Data3D_t;
319
 
320
 
321
 
322
typedef struct
323
{
324
    s32 Longitude;      // in 1E-7 deg
325
    s32 Latitude;       // in 1E-7 deg
326
    s32 Altitude;       // in mm
327
    u8 Status;          // validity of data
328
} __attribute__((packed)) GPS_Pos_t;
329
 
330
 
331
 
332
typedef struct
333
{
334
    u16 Distance;       // distance to target in cm
335
    s16 Bearing;        // course to target in deg
336
} __attribute__((packed)) GPS_PosDev_t;
337
 
338
 
339
 
340
 
341
//----------------------------
342
// aus NC waypoint.h
343
//
344
// AKTUALISIERT: 18.06.2014 OG
345
//
346
// Anmerkung 18.06.2014 OG
347
//   "Name" hinzugefuegt - das gibt es
348
//   seit dem 23.03.2012!
349
//----------------------------
350
typedef struct
351
{
352
        GPS_Pos_t Position;             // the gps position of the waypoint, see ubx.h for details
353
        s16 Heading;                    // orientation, 0 no action, 1...360 fix heading, neg. = Index to POI in WP List
354
        u8  ToleranceRadius;                    // in meters, if the MK is within that range around the target, then the next target is triggered
355
        u8  HoldTime;                   // in seconds, if the was once in the tolerance area around a WP, this time defines the delay before the next WP is triggered
356
        u8  Event_Flag;                 // future implementation
357
        u8  Index;                              // to indentify different waypoints, workaround for bad communications PC <-> NC
358
        u8  Type;                       // typeof Waypoint
359
        u8  WP_EventChannelValue;               // Will be transferred to the FC and can be used as Poti value there
360
        u8  AltitudeRate;               // rate to change the setpoint in steps of 0.1m/s
361
        u8  Speed;                      // rate to change the Position(0 = max) in steps of 0.1m/s
362
        u8  CamAngle;                   // Camera servo angle in degree (255 -> POI-Automatic)
363
        u8  Name[4];                    // Name of that point (ASCII)
364
    u8  reserve[2];                     // reserve
365
} __attribute__((packed)) Point_t;
366
 
367
 
368
 
369
 
370
//----------------------------
371
// aus NC waypoint.h
372
// VERALTET! 18.06.2014 OG
373
//----------------------------
374
/*
375
typedef struct
376
{
377
        GPS_Pos_t Position;             // the gps position of the waypoint, see ubx.h for details
378
        s16 Heading;                    // orientation, 0 no action, 1...360 fix heading, neg. = Index to POI in WP List
379
        u8  ToleranceRadius;            // in meters, if the MK is within that range around the target, then the next target is triggered
380
        u8  HoldTime;                   // in seconds, if the was once in the tolerance area around a WP, this time defines the delay before the next WP is triggered
381
        u8  Event_Flag;                 // future implementation
382
        u8  Index;                      // to indentify different waypoints, workaround for bad communications PC <-> NC
383
        u8  Type;                       // typeof Waypoint
384
        u8  WP_EventChannelValue;       //
385
        u8  AltitudeRate;               // rate to change the setpoint
386
        u8  Speed;                      // rate to change the Position
387
        u8  CamAngle;                   // Camera servo angle
388
        u8  reserve[6];                 // reserve
389
} __attribute__((packed)) Point_t;
390
*/
391
 
392
 
393
// NaviCtrl struct
394
// taken from
395
// http://mikrocontroller.cco-ev.de/mikrowebsvn/filedetails.php?repname=NaviCtrl&path=%2Ftags%2FV0.15c%2Fuart1.h
396
//
397
#define NAVIDATA_VERSION 5
398
 
399
typedef struct
400
{
401
        u8 Version;                                     // version of the data structure
402
        GPS_Pos_t CurrentPosition;                      // see ubx.h for details
403
        GPS_Pos_t TargetPosition;
404
        GPS_PosDev_t TargetPositionDeviation;
405
        GPS_Pos_t HomePosition;
406
        GPS_PosDev_t HomePositionDeviation;
407
        u8  WaypointIndex;                              // index of current waypoints running from 0 to WaypointNumber-1
408
        u8  WaypointNumber;                             // number of stored waypoints
409
        u8  SatsInUse;                                  // number of satellites used for position solution
410
        s16 Altimeter;                                  // hight according to air pressure
411
        s16 Variometer;                                 // climb(+) and sink(-) rate
412
        u16 FlyingTime;                                 // in seconds
413
        u8  UBat;                                       // Battery Voltage in 0.1 Volts
414
        u16 GroundSpeed;                                // speed over ground in cm/s (2D)
415
        s16 Heading;                                    // current flight direction in ° as angle to north
416
        s16 CompassHeading;                             // current compass value in
417
        s8  AngleNick;                                  // current Nick angle in 1
418
        s8  AngleRoll;                                  // current Roll angle in 1
419
        u8  RC_Quality;                                 // RC_Quality
420
        u8  FCStatusFlags;                              // Flags from FC
421
        u8  NCFlags;                                    // Flags from NC
422
        u8  Errorcode;                                  // 0 --> okay
423
        u8  OperatingRadius;                            // current operation radius around the Home Position in m
424
        s16 TopSpeed;                                   // velocity in vertical direction in cm/s
425
        u8  TargetHoldTime;                             // time in s to stay at the given target, counts down to 0 if target has been reached
426
        u8  FCStatusFlags2;                             // StatusFlags2 (since version 5 added)
427
        s16 SetpointAltitude;                           // setpoint for altitude
428
        u8  Gas;                                        // for future use
429
        u16 Current;                                    // actual current in 0.1A steps
430
        u16 UsedCapacity;                               // used capacity in mAh
431
} __attribute__((packed)) NaviData_t;
432
 
433
 
434
 
435
typedef struct
436
{
437
        uint8_t Version;                        // the version of the BL (0 = old)
438
        uint8_t SetPoint;                       // written by attitude controller
439
        uint8_t SetPointLowerBits;      // for higher Resolution of new BLs
440
        uint8_t State;                          // 7 bit for I2C error counter, highest bit indicates if motor is present
441
        uint8_t ReadMode;                       // select data to read
442
        // the following bytes must be exactly in that order!
443
        uint8_t Current;                        // in 0.1 A steps, read back from BL
444
        uint8_t MaxPWM;                         // read back from BL -> is less than 255 if BL is in current limit, not running (250) or starting (40)
445
        int8_t  Temperature;                    // old BL-Ctrl will return a 255 here, the new version the temp. in �C
446
} __attribute__((packed)) MotorData_t;
447
 
448
 
449
 
450
typedef struct
451
{
452
        uint8_t Revision;                       // must be BL_REVISION
453
        uint8_t SetMask;                        // settings mask
454
        uint8_t PwmScaling;                     // maximum value of control pwm, acts like a thrust limit
455
        uint8_t CurrentLimit;           // current limit in A
456
        uint8_t TempLimit;                      // in �C
457
        uint8_t CurrentScaling;         // scaling factor for current measurement
458
        uint8_t BitConfig;                      // see defines above
459
        uint8_t crc;                            // checksum
460
}  __attribute__((packed)) BLConfig_t;
461
 
462
 
463
 
464
//##############################################################################
465
//# Datenstruktur von ehemals mk_param_struct_t jetzt via mk/paramset.c !
466
//##############################################################################
467
 
468
 
469
//-------------------------------------
470
// 20.03.2013 OG: BLData_t
471
// aus: http://www.mikrokopter.de/ucwiki/en/SerialCommands/BLDataStruct
472
//-------------------------------------
473
typedef struct
474
{
475
            unsigned char Index;            // address of BL-Ctrl 
476
            unsigned char Current;          // in 0.1 A steps, read back from BL
477
            unsigned char Temperature;      // old BL-Ctrl will return a 255 here, the new version (>= V2.0) the temp. in °C
478
            unsigned char MaxPWM;           // EVENTUELL: read back from BL -> is less than 255 if BL is in current limit, not running (250) or starting (40)
479
            unsigned char Status;           // EVENTUELL: 7 bit for I2C error counter, highest bit indicates if motor is present
480
}  BLData_t;
481
 
482
 
483
 
484
//-------------------------------------
485
// 11.05.2013 OG: DateTime_t
486
// aus: NC v0.30g timer1.h
487
//-------------------------------------
488
typedef struct{
489
    u16    Year;
490
    u8    Month;
491
    u8    Day;
492
    u8    Hour;
493
    u8    Min;
494
    u8    Sec;
495
    u16 mSec;
496
    u8  Valid;
497
}  DateTime_t;
498
 
499
 
500
 
501
#endif