Subversion Repositories NaviCtrl

Rev

Rev 487 | Rev 500 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 487 Rev 489
Line 5... Line 5...
5
// + www.MikroKopter.com
5
// + www.MikroKopter.com
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7
// + Software Nutzungsbedingungen (english version: see below)
7
// + Software Nutzungsbedingungen (english version: see below)
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand
22
// + des Mitverschuldens offen.
22
// + des Mitverschuldens offen.
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
24
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
24
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
25
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
25
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
26
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
26
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
Line 30... Line 30...
30
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
30
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// + Software LICENSING TERMS
32
// + Software LICENSING TERMS
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
35
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware 
35
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
37
// + The Software may only be used with the Licensor's products.
37
// + The Software may only be used with the Licensor's products.
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
40
// + agreement shall be the property of the Licensor.
40
// + agreement shall be the property of the Licensor.
Line 54... Line 54...
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Line 56... Line 56...
56
 
56
 
57
#include <string.h>
57
#include <string.h>
-
 
58
#include <math.h>
58
#include <math.h>
59
#include <stdlib.h>
59
#include "91x_lib.h"
60
#include "91x_lib.h"
60
#include "led.h"
61
#include "led.h"
61
#include "gps.h"
62
#include "gps.h"
62
#include "uart1.h"
63
#include "uart1.h"
63
#include "spi_slave.h"
64
#include "spi_slave.h"
64
#include "compass.h"
65
#include "compass.h"
65
#include "timer1.h"
66
#include "timer1.h"
66
#include "timer2.h"
67
#include "timer2.h"
67
#include "config.h"
68
#include "config.h"
68
#include "main.h"
-
 
69
#include "compass.h"
69
#include "main.h"
70
#include "params.h"
-
 
71
#include "stdlib.h"
70
#include "params.h"
72
#include "settings.h"
-
 
Line 73... Line 71...
73
#include "ncmag.h"
71
#include "settings.h"
74
 
72
 
75
#define SPI_RXSYNCBYTE1 0xAA
73
#define SPI_RXSYNCBYTE1 0xAA
76
#define SPI_RXSYNCBYTE2 0x83
74
#define SPI_RXSYNCBYTE2 0x83
Line 81... Line 79...
81
FromFlightCtrl_t   FromFlightCtrl;
79
FromFlightCtrl_t   FromFlightCtrl;
82
ToFlightCtrl_t     ToFlightCtrl;
80
ToFlightCtrl_t     ToFlightCtrl;
83
#define SPI0_TIMEOUT     2500  //ms
81
#define SPI0_TIMEOUT     2500  //ms
84
volatile u32 SPI0_Timeout = 0;
82
volatile u32 SPI0_Timeout = 0;
85
u8 Logging_FCStatusFlags1 = 0,Logging_FCStatusFlags2 = 0;
83
u8 Logging_FCStatusFlags1 = 0,Logging_FCStatusFlags2 = 0;
86
u8 SpeakHoTT = 0;
84
u8 SpeakHoTT = 0;
Line 87... Line 85...
87
 
85
 
88
// tx packet buffer
86
// tx packet buffer
89
#define SPI_TXBUFFER_LEN (2 + sizeof(ToFlightCtrl)) // 2 bytes at start are for synchronization
87
#define SPI_TXBUFFER_LEN (2 + sizeof(ToFlightCtrl)) // 2 bytes at start are for synchronization
90
volatile u8 SPI_TxBuffer[SPI_TXBUFFER_LEN + 10];
88
volatile u8 SPI_TxBuffer[SPI_TXBUFFER_LEN + 10];
Line 124... Line 122...
124
u32 FC_I2C_ErrorConter;
122
u32 FC_I2C_ErrorConter;
125
SPI_Version_t FC_Version;
123
SPI_Version_t FC_Version;
126
s16 POI_KameraNick = 0;
124
s16 POI_KameraNick = 0;
127
u8 NC_Wait_for_LED = 0;
125
u8 NC_Wait_for_LED = 0;
128
s16 GyroCompassCorrected = 0; // corrected with the magnetic declination
126
s16 GyroCompassCorrected = 0; // corrected with the magnetic declination
129
u8 FromFC_LowVoltageHomeActive = 0;
-
 
Line 130... Line 127...
130
 
127
 
131
//--------------------------------------------------------------
128
//--------------------------------------------------------------
132
void SSP0_IRQHandler(void)
129
void SSP0_IRQHandler(void)
133
{
130
{
Line 291... Line 288...
291
void SPI0_UpdateBuffer(void)
288
void SPI0_UpdateBuffer(void)
292
{
289
{
293
        static u32 timeout = 0;
290
        static u32 timeout = 0;
294
        static u8 counter = 50,hott_index = 0, last_error_code = 0, enable_injecting = 0;
291
        static u8 counter = 50,hott_index = 0, last_error_code = 0, enable_injecting = 0;
295
        static s16 last_wp_event = 0;
292
        static s16 last_wp_event = 0;
296
        s16 tmp;
293
        s16 tmp;
297
        s32 i1,i2;
294
        s32 i1,i2;
298
/*
295
/*
299
        union
296
        union
300
        {
297
        {
301
                unsigned char Byte[4];
298
                unsigned char Byte[4];
302
                unsigned int Int[2];
299
                unsigned int Int[2];
303
                unsigned long Long;
300
                unsigned long Long;
304
        } Temp;
301
        } Temp;
305
*/     
302
*/
306
    SPIWatchDog = 3500;    // stop communication to FC after this timeout
303
    SPIWatchDog = 3500;    // stop communication to FC after this timeout
307
        if(SPI_RxBuffer_Request)
304
        if(SPI_RxBuffer_Request)
308
        {
305
        {
309
                // avoid sending data via SPI during the update of the  ToFlightCtrl structure
306
                // avoid sending data via SPI during the update of the  ToFlightCtrl structure
310
                VIC_ITCmd(SSP0_ITLine, DISABLE); // disable SPI interrupt
307
                VIC_ITCmd(SSP0_ITLine, DISABLE); // disable SPI interrupt
Line 315... Line 312...
315
                ToFlightCtrl.MagVecX = MagVector.X;
312
                ToFlightCtrl.MagVecX = MagVector.X;
316
                ToFlightCtrl.MagVecY = MagVector.Y;
313
                ToFlightCtrl.MagVecY = MagVector.Y;
317
                ToFlightCtrl.MagVecZ = MagVector.Z;
314
                ToFlightCtrl.MagVecZ = MagVector.Z;
318
//              ToFlightCtrl.NCStatus = 0;
315
//              ToFlightCtrl.NCStatus = 0;
319
                // cycle spi commands
316
                // cycle spi commands
320
                if(ErrorCode != last_error_code && enable_injecting)
317
                if(ErrorCode != last_error_code && enable_injecting)
321
                 {
318
                 {
322
                  ToFlightCtrl.Command = SPI_NCCMD_VERSION;
319
                  ToFlightCtrl.Command = SPI_NCCMD_VERSION;
323
                  last_error_code = ErrorCode;
320
                  last_error_code = ErrorCode;
324
                  enable_injecting = 0;
321
                  enable_injecting = 0;
325
                 }
322
                 }
326
                else
323
                else
327
                if(FC_WP_EventChannel != last_wp_event && enable_injecting)
324
                if(FC_WP_EventChannel != last_wp_event && enable_injecting)
328
                 {
325
                 {
329
                  ToFlightCtrl.Command = SPI_NCCMD_GPSINFO;
326
                  ToFlightCtrl.Command = SPI_NCCMD_GPSINFO;
330
                  last_wp_event = FC_WP_EventChannel;
327
                  last_wp_event = FC_WP_EventChannel;
331
                  enable_injecting = 0;
328
                  enable_injecting = 0;
332
                 }
329
                 }
333
                else
330
                else
334
                 {
331
                 {
335
                  ToFlightCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++];
332
                  ToFlightCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++];
336
                // restart command cycle at the end
333
                // restart command cycle at the end
337
                  if(SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0;
334
                  if(SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0;
338
                  if(ToFlightCtrl.Command == SPI_NCCMD_KALMAN) enable_injecting = 1;
335
                  if(ToFlightCtrl.Command == SPI_NCCMD_KALMAN) enable_injecting = 1;
Line 365... Line 362...
365
                                        POI_KameraNick = tmp;
362
                                        POI_KameraNick = tmp;
366
                                }
363
                                }
367
                                else
364
                                else
368
                                {
365
                                {
369
                                        //if(FC.StatusFlags2 & FC_STATUS2_CAREFREE) // only, if carefree is active
366
                                        //if(FC.StatusFlags2 & FC_STATUS2_CAREFREE) // only, if carefree is active
370
                                        POI_KameraNick = CAM_Orientation.Elevation;
367
                                        POI_KameraNick = CAM_Orientation.Elevation;
371
                                        //else ToFlightCtrl.Param.sInt[5] = 0;
368
                                        //else ToFlightCtrl.Param.sInt[5] = 0;
372
                                }
369
                                }
373
                                ToFlightCtrl.Param.sInt[5] = POI_KameraNick;
370
                                ToFlightCtrl.Param.sInt[5] = POI_KameraNick;
374
                                break;
371
                                break;
Line 453... Line 450...
453
                        case SPI_NCCMD_HOTT_INFO:
450
                        case SPI_NCCMD_HOTT_INFO:
454
                                switch(hott_index++)
451
                                switch(hott_index++)
455
                                {
452
                                {
456
                                case 0:
453
                                case 0:
457
                                        //Dezimalgrad            --> Grad mit Dezimalminuten     --> Grad, Minuten, Sekunden
454
                                        //Dezimalgrad            --> Grad mit Dezimalminuten     --> Grad, Minuten, Sekunden
458
                                        //53.28 5788 7.4847269   --> N53° 17.14728 E7° 29.08362  --> N53° 17' 8.837" E7° 29' 5.017" 
455
                                        //53.28 5788 7.4847269   --> N53° 17.14728 E7° 29.08362  --> N53° 17' 8.837" E7° 29' 5.017"
459
                                        ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID;
456
                                        ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID;
460
                                        ToFlightCtrl.Param.Byte[0] = 3+3;       // index  +3, weil bei HoTT V4 3 Bytes eingeschoben wurden
457
                                        ToFlightCtrl.Param.Byte[0] = 3+3;       // index  +3, weil bei HoTT V4 3 Bytes eingeschoben wurden
461
                                        ToFlightCtrl.Param.Byte[1] = 9-1;       // how many
458
                                        ToFlightCtrl.Param.Byte[1] = 9-1;       // how many
462
                                        //-----------------------------
459
                                        //-----------------------------
463
                                        ToFlightCtrl.Param.Byte[2] = GyroCompassCorrected / 20;//NaviData.HomePositionDeviation.Bearing / 2; 
460
                                        ToFlightCtrl.Param.Byte[2] = GyroCompassCorrected / 20;//NaviData.HomePositionDeviation.Bearing / 2;
464
                                        i1 = GPSData.Speed_Ground; // in cm/sec
461
                                        i1 = GPSData.Speed_Ground; // in cm/sec
465
                                        i1 *= 36;
462
                                        i1 *= 36;
466
                                        i1 /= 1000;
463
                                        i1 /= 1000;
467
                                        ToFlightCtrl.Param.Byte[3] = i1 % 256;
464
                                        ToFlightCtrl.Param.Byte[3] = i1 % 256;
468
                                        ToFlightCtrl.Param.Byte[4] = i1 / 256;
465
                                        ToFlightCtrl.Param.Byte[4] = i1 / 256;
Line 470... Line 467...
470
                                        if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5]  = 1; // 1 = S
467
                                        if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5]  = 1; // 1 = S
471
                                        else ToFlightCtrl.Param.Byte[5]  = 0; // 1 = S
468
                                        else ToFlightCtrl.Param.Byte[5]  = 0; // 1 = S
472
                                        i1 = abs(GPSData.Position.Latitude)/10000000L;
469
                                        i1 = abs(GPSData.Position.Latitude)/10000000L;
473
                                        i2 = abs(GPSData.Position.Latitude)%10000000L;
470
                                        i2 = abs(GPSData.Position.Latitude)%10000000L;
474
                                        if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;}
471
                                        if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;}
475
                                        i1 *= 100;
472
                                        i1 *= 100;
476
                                // Minuten
473
                                // Minuten
477
                                i2 *= 6;
474
                                i2 *= 6;
478
                                i2 /= 10;
475
                                i2 /= 10;
479
                                        i1 += i2 / 100000;
476
                                        i1 += i2 / 100000;
480
                                        i2  = i2 % 100000;
477
                                        i2  = i2 % 100000;
Line 492... Line 489...
492
                                        if(GPSData.Position.Longitude < 0) ToFlightCtrl.Param.Byte[2]  = 1; // 1 = E
489
                                        if(GPSData.Position.Longitude < 0) ToFlightCtrl.Param.Byte[2]  = 1; // 1 = E
493
                                        else ToFlightCtrl.Param.Byte[2]  = 0; // 1 = S
490
                                        else ToFlightCtrl.Param.Byte[2]  = 0; // 1 = S
494
                                        i1 = abs(GPSData.Position.Longitude)/10000000L;
491
                                        i1 = abs(GPSData.Position.Longitude)/10000000L;
495
                                        i2 = abs(GPSData.Position.Longitude)%10000000L;
492
                                        i2 = abs(GPSData.Position.Longitude)%10000000L;
496
                                        if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;}
493
                                        if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;}
497
                                        i1 *= 100;
494
                                        i1 *= 100;
498
                                // Minuten
495
                                // Minuten
499
                                i2 *= 6;
496
                                i2 *= 6;
500
                                i2 /= 10;
497
                                i2 /= 10;
501
                                        i1 += i2 / 100000;
498
                                        i1 += i2 / 100000;
502
                                        i2  = i2 % 100000;
499
                                        i2  = i2 % 100000;
Line 504... Line 501...
504
                                        ToFlightCtrl.Param.Byte[3]  = i1 % 256;
501
                                        ToFlightCtrl.Param.Byte[3]  = i1 % 256;
505
                                        ToFlightCtrl.Param.Byte[4]  = i1 / 256;
502
                                        ToFlightCtrl.Param.Byte[4]  = i1 / 256;
506
                                        ToFlightCtrl.Param.Byte[5]  = i2 % 256;
503
                                        ToFlightCtrl.Param.Byte[5]  = i2 % 256;
507
                                        ToFlightCtrl.Param.Byte[6]  = i2 / 256;
504
                                        ToFlightCtrl.Param.Byte[6]  = i2 / 256;
508
                                        //-----------------------------
505
                                        //-----------------------------
509
                                        i1 = NaviData.HomePositionDeviation.Distance / 10; // dann in m 
506
                                        i1 = NaviData.HomePositionDeviation.Distance / 10; // dann in m
510
                                        ToFlightCtrl.Param.Byte[7]  = i1 % 256;
507
                                        ToFlightCtrl.Param.Byte[7]  = i1 % 256;
511
                                        ToFlightCtrl.Param.Byte[8]  = i1 / 256;
508
                                        ToFlightCtrl.Param.Byte[8]  = i1 / 256;
512
                                        break;
509
                                        break;
513
                                 case 2:
510
                                 case 2:
514
                                        ToFlightCtrl.Param.Byte[11] = HOTT_GENERAL_PACKET_ID;
511
                                        ToFlightCtrl.Param.Byte[11] = HOTT_GENERAL_PACKET_ID;
515
                                        ToFlightCtrl.Param.Byte[0] = 5+3;       // index   // +3, weil bei HoTT V4 3 Bytes eingeschoben wurden
512
                                        ToFlightCtrl.Param.Byte[0] = 5+3;       // index   // +3, weil bei HoTT V4 3 Bytes eingeschoben wurden
516
                                        ToFlightCtrl.Param.Byte[1] = 2; // how many
513
                                        ToFlightCtrl.Param.Byte[1] = 2; // how many
517
                                        ToFlightCtrl.Param.Byte[2] = EarthMagneticField / (5 * 2);
514
                                        ToFlightCtrl.Param.Byte[2] = EarthMagneticField / (5 * 2);
518
                                        ToFlightCtrl.Param.Byte[3] = EarthMagneticInclination / 2;
515
                                        ToFlightCtrl.Param.Byte[3] = EarthMagneticInclination / 2;
519
                                        break;
516
                                        break;
520
                                 case 3:
517
                                 case 3:
521
                                        ToFlightCtrl.Param.Byte[11] = JETI_GPS_PACKET_ID1;
518
                                        ToFlightCtrl.Param.Byte[11] = JETI_GPS_PACKET_ID1;
522
                                        ToFlightCtrl.Param.Byte[0] = 0; // index   
519
                                        ToFlightCtrl.Param.Byte[0] = 0; // index
523
                                        ToFlightCtrl.Param.Byte[1] = 4; // how many
520
                                        ToFlightCtrl.Param.Byte[1] = 4; // how many
524
                                        //JetiExData[14].Value =  53 * 0x10000 + 23467;
521
                                        //JetiExData[14].Value =  53 * 0x10000 + 23467;
525
                                        if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 0x40;
522
                                        if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 0x40;
526
                                        else ToFlightCtrl.Param.Byte[5] = 0x00;
523
                                        else ToFlightCtrl.Param.Byte[5] = 0x00;
527
                                        ToFlightCtrl.Param.Byte[4] = abs(GPSData.Position.Latitude)/10000000L;
524
                                        ToFlightCtrl.Param.Byte[4] = abs(GPSData.Position.Latitude)/10000000L;
528
                                        i2 = abs(GPSData.Position.Latitude)%10000000L;
525
                                        i2 = abs(GPSData.Position.Latitude)%10000000L;
529
                                        i2 *= 6;
526
                                        i2 *= 6;
530
                                        i2 /= 1000;
527
                                        i2 /= 1000;
531
                                        ToFlightCtrl.Param.Byte[3] = i2 / 256;
528
                                        ToFlightCtrl.Param.Byte[3] = i2 / 256;
532
                                        ToFlightCtrl.Param.Byte[2] = i2 % 256;
529
                                        ToFlightCtrl.Param.Byte[2] = i2 % 256;
533
                                        break;
530
                                        break;
534
                                 case 4:
531
                                 case 4:
535
                                        ToFlightCtrl.Param.Byte[11] = JETI_GPS_PACKET_ID2;
532
                                        ToFlightCtrl.Param.Byte[11] = JETI_GPS_PACKET_ID2;
536
                                        ToFlightCtrl.Param.Byte[0] = 0; // index   
533
                                        ToFlightCtrl.Param.Byte[0] = 0; // index
537
                                        ToFlightCtrl.Param.Byte[1] = 4; // how many
534
                                        ToFlightCtrl.Param.Byte[1] = 4; // how many
538
                                        if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 0x60;
535
                                        if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 0x60;
539
                                        else ToFlightCtrl.Param.Byte[5] = 0x20;
536
                                        else ToFlightCtrl.Param.Byte[5] = 0x20;
540
                                        ToFlightCtrl.Param.Byte[4] = abs(GPSData.Position.Longitude)/10000000L;
537
                                        ToFlightCtrl.Param.Byte[4] = abs(GPSData.Position.Longitude)/10000000L;
541
                                        i2 = abs(GPSData.Position.Longitude)%10000000L;
538
                                        i2 = abs(GPSData.Position.Longitude)%10000000L;
542
                                        i2 *= 6;
539
                                        i2 *= 6;
543
                                        i2 /= 1000;
540
                                        i2 /= 1000;
544
                                        ToFlightCtrl.Param.Byte[3] = i2 / 256;
541
                                        ToFlightCtrl.Param.Byte[3] = i2 / 256;
545
                                        ToFlightCtrl.Param.Byte[2] = i2 % 256;
542
                                        ToFlightCtrl.Param.Byte[2] = i2 % 256;
546
                        hott_index = 0;
543
                        hott_index = 0;
547
                                        break;
544
                                        break;
548
                                 default:
545
                                 default:
549
                                        ToFlightCtrl.Param.Byte[0] = 255;
546
                                        ToFlightCtrl.Param.Byte[0] = 255;
550
                                        hott_index = 0;
547
                                        hott_index = 0;
551
                                        break;
548
                                        break;
552
                                }
549
                                }
553
                                break;
550
                                break;
554
                        default:
551
                        default:
555
                                break;
552
                                break;
Line 585... Line 582...
585
                                        FCCalibActive = 10;
582
                                        FCCalibActive = 10;
586
                                        FC_is_Calibrated = 0;
583
                                        FC_is_Calibrated = 0;
587
                                }
584
                                }
588
                                else
585
                                else
589
                                {
586
                                {
590
                                        if(FCCalibActive)
587
                                        if(FCCalibActive)
591
                                         {
588
                                        {
592
                                            if(--FCCalibActive == 0)
589
                                                if(--FCCalibActive == 0)
593
                                                 {
590
                                                {
594
                                                  FC_is_Calibrated = 1;
591
                                                        FC_is_Calibrated = 1;
595
                                                  ExtCompassOrientation = GetExtCompassOrientation();
592
                                                        Compass_Check();
596
if(ExtCompassOrientation != Calibration.Version / 16) NCMAG_IsCalibrated = 0;
-
 
597
                                                 }
593
                                                }
598
                                         }
594
                                        }
-
 
595
                                }
-
 
596
                                if(FC.StatusFlags & FC_STATUS_START)
-
 
597
                                {
-
 
598
                                        if(Compass_Heading != -1) HeadFreeStartAngle = (3600 + Compass_Heading * 10 - GeoMagDec) % 3600; else
-
 
599
                                        HeadFreeStartAngle = GyroCompassCorrected;
599
                                }
600
                                }
600
                                if(FC.StatusFlags & FC_STATUS_START)
-
 
601
                             {
-
 
602
                                   if(Compass_Heading != -1) HeadFreeStartAngle = (3600 + Compass_Heading * 10 - GeoMagDec) % 3600; else
-
 
603
                                   HeadFreeStartAngle = GyroCompassCorrected;
-
 
604
                                 }
-
 
Line 605... Line 601...
605
 
601
 
606
                                 if((Parameter.ExtraConfig & CFG_TEACHABLE_CAREFREE))
602
                                if((Parameter.ExtraConfig & CFG_TEACHABLE_CAREFREE))
607
                                  {
603
                                {
608
                                   if(!(FC.StatusFlags2 & FC_STATUS2_CAREFREE)) // CF ist jetzt ausgeschaltet -> neue Richtung lernen
604
                                        if(!(FC.StatusFlags2 & FC_STATUS2_CAREFREE)) // CF ist jetzt ausgeschaltet -> neue Richtung lernen
609
                                    {
605
                                        {
610
                                         if((NaviData.HomePositionDeviation.Distance > 200) && (NCFlags & NC_FLAG_GPS_OK))       // nur bei ausreichender Distance -> 20m
606
                                                if((NaviData.HomePositionDeviation.Distance > 200) && (NCFlags & NC_FLAG_GPS_OK))        // nur bei ausreichender Distance -> 20m
611
                                         {
607
                                                {
612
                                          HeadFreeStartAngle = (10 * NaviData.HomePositionDeviation.Bearing + 1800 + 3600 -  Parameter.OrientationAngle * 150) % 3600; // in 0.1°
608
                                                        HeadFreeStartAngle = (10 * NaviData.HomePositionDeviation.Bearing + 1800 + 3600 -  Parameter.OrientationAngle * 150) % 3600; // in 0.1°
613
                                         }
609
                                                }
614
                                         else                                                                                            // Ansonsten die aktuelle Richtung übernehmen
610
                                                else                                                                                             // Ansonsten die aktuelle Richtung übernehmen
615
                                          HeadFreeStartAngle = GyroCompassCorrected; // in 0.1°   
611
                                                HeadFreeStartAngle = GyroCompassCorrected; // in 0.1°
616
                                        }
612
                                        }
-
 
613
                                }
617
                                }
614
 
618
                                Parameter.ActiveSetting = FromFlightCtrl.Param.Byte[9];
615
                                Parameter.ActiveSetting = FromFlightCtrl.Param.Byte[9];
619
                                FC.BAT_Voltage = FromFlightCtrl.Param.Byte[10];
616
                                FC.BAT_Voltage = FromFlightCtrl.Param.Byte[10];
620
                                DebugOut.Analog[7] = FC.BAT_Voltage;
617
                                DebugOut.Analog[7] = FC.BAT_Voltage;
621
                                DebugOut.Analog[5] = FC.StatusFlags;
618
                                DebugOut.Analog[5] = FC.StatusFlags;
622
                                NaviData.FCStatusFlags = FC.StatusFlags;
619
                                NaviData.FCStatusFlags = FC.StatusFlags;
623
                                if(FC.StatusFlags2 & FC_STATUS2_WAIT_FOR_TAKEOFF) NaviData.FCStatusFlags &= ~FC_STATUS_FLY;
620
                                if(FC.StatusFlags2 & FC_STATUS2_WAIT_FOR_TAKEOFF) NaviData.FCStatusFlags &= ~FC_STATUS_FLY;
624
                                FC.StatusFlags2 = FromFlightCtrl.Param.Byte[11];
621
                                FC.StatusFlags2 = FromFlightCtrl.Param.Byte[11];
Line 625... Line 622...
625
                                NaviData.FCStatusFlags2 = (NaviData.FCStatusFlags2 & (FC_STATUS2_OUT1_ACTIVE | FC_STATUS2_OUT2_ACTIVE)) | (FC.StatusFlags2 & (0xff - (FC_STATUS2_OUT1_ACTIVE | FC_STATUS2_OUT2_ACTIVE)));
622
                                NaviData.FCStatusFlags2 = (NaviData.FCStatusFlags2 & (FC_STATUS2_OUT1_ACTIVE | FC_STATUS2_OUT2_ACTIVE)) | (FC.StatusFlags2 & (0xff - (FC_STATUS2_OUT1_ACTIVE | FC_STATUS2_OUT2_ACTIVE)));
626
 
623
 
627
                                if((!(LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) && (FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) NaviData.FCStatusFlags2 |= FC_STATUS2_OUT1_ACTIVE;
624
                                if((!(LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) && (FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) NaviData.FCStatusFlags2 |= FC_STATUS2_OUT1_ACTIVE;
Line 628... Line 625...
628
                                else
625
                                else
629
                                if(((LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) && !(FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) NaviData.FCStatusFlags2 &= ~FC_STATUS2_OUT1_ACTIVE;
626
                                if(((LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) && !(FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) NaviData.FCStatusFlags2 &= ~FC_STATUS2_OUT1_ACTIVE;
630
 
627
 
Line 631... Line 628...
631
                                if((!(LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) && (FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) NaviData.FCStatusFlags2 |= FC_STATUS2_OUT2_ACTIVE;
628
                                if((!(LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) && (FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) NaviData.FCStatusFlags2 |= FC_STATUS2_OUT2_ACTIVE;
632
                                else
629
                                else
633
                                if(((LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) && !(FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) NaviData.FCStatusFlags2 &= ~FC_STATUS2_OUT2_ACTIVE;
630
                                if(((LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) && !(FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) NaviData.FCStatusFlags2 &= ~FC_STATUS2_OUT2_ACTIVE;
Line 671... Line 668...
671
                                break;
668
                                break;
672
                        case SPI_FCCMD_PARAMETER2:
669
                        case SPI_FCCMD_PARAMETER2:
673
                                CHK_POTI_MM(Parameter.NaviOut1Parameter,FromFlightCtrl.Param.Byte[0],0,255);
670
                                CHK_POTI_MM(Parameter.NaviOut1Parameter,FromFlightCtrl.Param.Byte[0],0,255);
674
                                if(FromFlightCtrl.Param.Byte[1]) FC.FromFC_SpeakHoTT = FromFlightCtrl.Param.Byte[1];     // will be cleared in the SD-Logging
671
                                if(FromFlightCtrl.Param.Byte[1]) FC.FromFC_SpeakHoTT = FromFlightCtrl.Param.Byte[1];     // will be cleared in the SD-Logging
675
                Parameter.FromFC_LandingSpeed = FromFlightCtrl.Param.Byte[2];
672
                Parameter.FromFC_LandingSpeed = FromFlightCtrl.Param.Byte[2];
676
                                Parameter.ComingHomeAltitude = FromFlightCtrl.Param.Byte[3];
673
                                Parameter.ComingHomeAltitude = FromFlightCtrl.Param.Byte[3];
677
                                FromFC_LowVoltageHomeActive = FromFlightCtrl.Param.Byte[4];
674
                                Parameter.FromFC_LowVoltageHomeActive = FromFlightCtrl.Param.Byte[4];
678
                                break;
675
                                break;
679
                        case SPI_FCCMD_STICK:
676
                        case SPI_FCCMD_STICK:
680
                                FC.StickGas     = FromFlightCtrl.Param.sByte[0];
677
                                FC.StickGas     = FromFlightCtrl.Param.sByte[0];
681
                                FC.StickYaw     = FromFlightCtrl.Param.sByte[1];
678
                                FC.StickYaw     = FromFlightCtrl.Param.sByte[1];
682
                                FC.StickRoll    = FromFlightCtrl.Param.sByte[2];
679
                                FC.StickRoll    = FromFlightCtrl.Param.sByte[2];
Line 693... Line 690...
693
                                break;
690
                                break;
Line 694... Line 691...
694
 
691
 
695
                        case SPI_FCCMD_MISC:
692
                        case SPI_FCCMD_MISC:
696
                                if(CompassCalState != FromFlightCtrl.Param.Byte[0])
693
                                if(CompassCalState != FromFlightCtrl.Param.Byte[0])
697
                                {       // put only new CompassCalState into queue to send via I2C
694
                                {       // put only new CompassCalState into queue to send via I2C
698
//                                      if(FromFlightCtrl.Param.Byte[0] == CompassCalState+1 || FromFlightCtrl.Param.Byte[0] == 0) 
695
//                                      if(FromFlightCtrl.Param.Byte[0] == CompassCalState+1 || FromFlightCtrl.Param.Byte[0] == 0)
699
                                         {
696
                                         {
700
                                           CompassCalState = FromFlightCtrl.Param.Byte[0];
697
                                           CompassCalState = FromFlightCtrl.Param.Byte[0];
701
                                           Compass_SetCalState(CompassCalState);
698
                                           Compass_SetCalState(CompassCalState);
702
                                         }
699
                                         }
Line 739... Line 736...
739
                                FC_Version.Patch                = FromFlightCtrl.Param.Byte[2];
736
                                FC_Version.Patch                = FromFlightCtrl.Param.Byte[2];
740
                                FC_Version.Compatible   = FromFlightCtrl.Param.Byte[3];
737
                                FC_Version.Compatible   = FromFlightCtrl.Param.Byte[3];
741
                                FC_Version.Hardware             = FromFlightCtrl.Param.Byte[4];
738
                                FC_Version.Hardware             = FromFlightCtrl.Param.Byte[4];
742
                                FC.Error[0]                     |= FromFlightCtrl.Param.Byte[5];
739
                                FC.Error[0]                     |= FromFlightCtrl.Param.Byte[5];
743
                                FC.Error[1]                     |= FromFlightCtrl.Param.Byte[6];
740
                                FC.Error[1]                     |= FromFlightCtrl.Param.Byte[6];
744
                                if(FromFlightCtrl.Param.Byte[7] >= 68 && FromFlightCtrl.Param.Byte[7] <= 188)
741
                                if(FromFlightCtrl.Param.Byte[7] >= 68 && FromFlightCtrl.Param.Byte[7] <= 188)
745
                                {
742
                                {
746
                                 FC.FromFC_DisableDeclination = 1;
743
                                        FC.FromFC_DisableDeclination = 1;
747
                                 FC.FromFC_CompassOffset = 10 * (signed char) ((unsigned char) FromFlightCtrl.Param.Byte[7] - 128);
744
                                        FC.FromFC_CompassOffset = 10 * (s8) (FromFlightCtrl.Param.Byte[7] - 128);
748
                                 GeoMagDec = 0;
745
                                        GeoMagDec = 0;
749
                                }
746
                                }
750
                                else
747
                                else
751
                                {
748
                                {
752
                                 FC.FromFC_DisableDeclination = 0;
749
                                        FC.FromFC_DisableDeclination = 0;
753
                                 FC.FromFC_CompassOffset = 10 * (signed char) FromFlightCtrl.Param.Byte[7];
750
                                        FC.FromFC_CompassOffset = 10 * FromFlightCtrl.Param.sByte[7];
754
                                }
751
                                }
755
                                Parameter.GlobalConfig = FromFlightCtrl.Param.Byte[8];
752
                                Parameter.GlobalConfig = FromFlightCtrl.Param.Byte[8];
756
                                Parameter.ExtraConfig = FromFlightCtrl.Param.Byte[9];
753
                                Parameter.ExtraConfig = FromFlightCtrl.Param.Byte[9];
757
                                Parameter.OrientationAngle = FromFlightCtrl.Param.Byte[10];
754
                                Parameter.OrientationAngle = FromFlightCtrl.Param.Byte[10];
758
                                Parameter.GlobalConfig3 = FromFlightCtrl.Param.Byte[11];
755
                                Parameter.GlobalConfig3 = FromFlightCtrl.Param.Byte[11];
Line 818... Line 815...
818
                        SPI0_UpdateBuffer();
815
                        SPI0_UpdateBuffer();
819
                        if (FC_Version.Major != 0xFF)  break;
816
                        if (FC_Version.Major != 0xFF)  break;
820
                }while (!CheckDelay(timeout));
817
                }while (!CheckDelay(timeout));
821
                UART1_PutString(".");
818
                UART1_PutString(".");
822
                repeat++;
819
                repeat++;
823
//              FCCalibActive = 1;
820
                FCCalibActive = 1;
824
        }while((FC_Version.Major == 0xFF) && (repeat < 40)); // 40*250ms = 10s
821
        }while((FC_Version.Major == 0xFF) && (repeat < 40)); // 40*250ms = 10s
825
        // if we got it
822
        // if we got it
826
        if (FC_Version.Major != 0xFF)
823
        if (FC_Version.Major != 0xFF)
827
        {
824
        {
828
                sprintf(msg, " FC V%d.%02d%c HW:%d.%d", FC_Version.Major, FC_Version.Minor, 'a'+FC_Version.Patch, FC_Version.Hardware/10,FC_Version.Hardware%10);
825
                sprintf(msg, " FC V%d.%d%c HW:%d.%02d", FC_Version.Major, FC_Version.Minor, 'a'+FC_Version.Patch, FC_Version.Hardware/10,FC_Version.Hardware%10);
829
                UART1_PutString(msg);
826
                UART1_PutString(msg);
830
        }
827
        }
831
        else UART1_PutString("\n\r not found!");
828
        else UART1_PutString("\n\r not found!");
832
}
829
}
Line -... Line 830...
-
 
830
 
-
 
831
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
832
// + extended Current measurement -> 200 = 20A    201 = 21A    255 = 75A (20+55)
-
 
833
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
834
u16 BL3_Current(u8 who) // in 0,1A
-
 
835
{
-
 
836
        if(Motor[who].Current <= 200) return((u16) Motor[who].Current);
-
 
837
        else
-
 
838
        {
-
 
839
                if(Motor_Version[who] & MOTOR_STATE_BL30) return(200 + 10 * (u16) (Motor[who].Current - 200));
-
 
840
                else return((u16) Motor[who].Current);
-
 
841
        }