Subversion Repositories FlightCtrl

Rev

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

Rev 885 Rev 886
Line 4... Line 4...
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 04.2007 Holger Buss
5
// + Copyright (c) 04.2007 Holger Buss
6
// + Nur für den privaten Gebrauch
6
// + Nur für den privaten Gebrauch
7
// + www.MikroKopter.com
7
// + www.MikroKopter.com
8
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), 
9
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
10
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. 
10
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
11
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
11
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
12
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
12
// + bzgl. der Nutzungsbedingungen aufzunehmen.
13
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
13
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
14
// + Verkauf von Luftbildaufnahmen, usw.
14
// + Verkauf von Luftbildaufnahmen, usw.
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, 
16
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
17
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
17
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
18
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
18
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
19
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
20
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
20
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
21
// + eindeutig als Ursprung verlinkt werden
21
// + eindeutig als Ursprung verlinkt werden
22
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
23
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
24
// + Benutzung auf eigene Gefahr
24
// + Benutzung auf eigene Gefahr
25
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
25
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur 
27
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
28
// + mit unserer Zustimmung zulässig
28
// + mit unserer Zustimmung zulässig
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
30
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
32
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
33
// + this list of conditions and the following disclaimer.
33
// + this list of conditions and the following disclaimer.
34
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
34
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
35
// +     from this software without specific prior written permission.
35
// +     from this software without specific prior written permission.
36
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet 
36
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
37
// +     for non-commercial use (directly or indirectly)
37
// +     for non-commercial use (directly or indirectly)
38
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
38
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
39
// +     with our written permission
39
// +     with our written permission
40
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
40
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
41
// +     clearly linked as origin 
41
// +     clearly linked as origin
42
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
42
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
43
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
44
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
46
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
47
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
47
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
48
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
48
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
49
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
49
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
50
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
51
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
52
// +  POSSIBILITY OF SUCH DAMAGE. 
52
// +  POSSIBILITY OF SUCH DAMAGE.
53
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
53
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
54
#include <stdlib.h>
-
 
55
#include <avr/io.h>
Line 54... Line 56...
54
 
56
 
55
#include "main.h"
57
#include "main.h"
-
 
58
#include "eeprom.h"
-
 
59
#include "timer0.h"
-
 
60
#include "_Settings.h"
-
 
61
#include "analog.h"
-
 
62
#include "fc.h"
-
 
63
#include "uart.h"
-
 
64
#include "rc.h"
-
 
65
#include "twimaster.h"
-
 
66
#include "timer2.h"
-
 
67
#ifdef USE_KILLAGREG
-
 
68
#include "mm3.h"
-
 
69
#include "gps.h"
-
 
70
#endif
-
 
71
#if  !defined (USE_KILLAGREG)  && !defined (USE_NAVICTRL)
-
 
72
#include "mk3mag.h"
-
 
73
#endif
-
 
74
#include "led.h"
-
 
75
 
-
 
76
volatile uint16_t I2CTimeout = 100;
-
 
77
// gyro readings
-
 
78
volatile int16_t Reading_GyroPitch, Reading_GyroRoll, Reading_GyroYaw;
-
 
79
// gyro neutral readings
-
 
80
volatile int16_t AdNeutralPitch = 0, AdNeutralRoll = 0, AdNeutralYaw = 0;
-
 
81
volatile int16_t StartNeutralRoll = 0, StartNeutralPitch = 0;
-
 
82
// mean accelerations
Line 56... Line -...
56
#include "eeprom.c"
-
 
57
 
83
volatile int16_t Mean_AccPitch, Mean_AccRoll, Mean_AccTop;
58
unsigned char h,m,s;
84
 
59
volatile unsigned int I2CTimeout = 100;
-
 
60
volatile int MesswertNick,MesswertRoll,MesswertGier;
-
 
61
volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
-
 
62
volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
85
// neutral acceleration readings
63
int NaviAccNick, NaviAccRoll,NaviCntAcc = 0;
-
 
64
volatile float NeutralAccZ = 0;
-
 
65
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
-
 
66
long IntegralNick = 0,IntegralNick2 = 0;
-
 
67
long IntegralRoll = 0,IntegralRoll2 = 0;
-
 
68
long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
-
 
69
long Integral_Gier = 0;
-
 
70
long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
-
 
71
long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
-
 
72
long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
-
 
73
long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
-
 
74
volatile long Mess_Integral_Hoch = 0;
-
 
75
volatile int  KompassValue = 0;
-
 
76
volatile int  KompassStartwert = 0;
-
 
77
volatile int  KompassRichtung = 0;
-
 
78
unsigned int  KompassSignalSchlecht = 500;
-
 
79
unsigned char  MAX_GAS,MIN_GAS;
-
 
80
unsigned char Notlandung = 0;
-
 
81
unsigned char HoehenReglerAktiv = 0;
-
 
82
unsigned char TrichterFlug = 0;
-
 
83
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
-
 
84
long  ErsatzKompass;
-
 
85
int   ErsatzKompassInGrad; // Kompasswert in Grad
-
 
86
int   GierGyroFehler = 0;
-
 
87
float GyroFaktor;
-
 
88
float IntegralFaktor;
-
 
89
volatile int  DiffNick,DiffRoll;
-
 
90
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
-
 
91
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
-
 
92
volatile unsigned char SenderOkay = 0;
-
 
93
int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0;
-
 
94
char MotorenEin = 0;
-
 
95
int HoehenWert = 0;
-
 
96
int SollHoehe = 0;
-
 
97
int LageKorrekturRoll = 0,LageKorrekturNick = 0;
-
 
98
float Ki =  FAKTOR_I;
-
 
99
unsigned char Looping_Nick = 0,Looping_Roll = 0;
-
 
100
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
-
 
101
 
-
 
102
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
-
 
103
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
-
 
104
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
-
 
105
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
-
 
106
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
-
 
107
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
-
 
108
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
-
 
109
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
-
 
110
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
-
 
111
unsigned char Parameter_UserParam1 = 0;
-
 
112
unsigned char Parameter_UserParam2 = 0;
-
 
113
unsigned char Parameter_UserParam3 = 0;
-
 
114
unsigned char Parameter_UserParam4 = 0;
-
 
115
unsigned char Parameter_UserParam5 = 0;
-
 
116
unsigned char Parameter_UserParam6 = 0;
-
 
117
unsigned char Parameter_UserParam7 = 0;
-
 
118
unsigned char Parameter_UserParam8 = 0;
-
 
119
unsigned char Parameter_ServoNickControl = 100;
-
 
120
unsigned char Parameter_LoopGasLimit = 70;
-
 
121
unsigned char Parameter_AchsKopplung1 = 0;
-
 
122
unsigned char Parameter_AchsGegenKopplung1 = 0;
-
 
123
unsigned char Parameter_DynamicStability = 100;
-
 
124
struct mk_param_struct EE_Parameter;
-
 
125
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
-
 
Line -... Line 86...
-
 
86
volatile int16_t NeutralAccX=0, NeutralAccY=0;
-
 
87
volatile float NeutralAccZ = 0;
-
 
88
 
-
 
89
// attitude gyro integrals
-
 
90
volatile int32_t IntegralPitch = 0,IntegralPitch2 = 0;
-
 
91
volatile int32_t IntegralRoll = 0,IntegralRoll2 = 0;
-
 
92
volatile int32_t IntegralYaw = 0;
-
 
93
volatile int32_t Reading_IntegralGyroPitch = 0, Reading_IntegralGyroPitch2 = 0;
-
 
94
volatile int32_t Reading_IntegralGyroRoll = 0,  Reading_IntegralGyroRoll2 = 0;
-
 
95
volatile int32_t Reading_IntegralGyroYaw = 0;
-
 
96
volatile int32_t MeanIntegralPitch;
-
 
97
volatile int32_t MeanIntegralRoll;
-
 
98
 
-
 
99
// attitude acceleration integrals
-
 
100
volatile int32_t IntegralAccPitch = 0, IntegralAccRoll = 0;
-
 
101
volatile int32_t Reading_Integral_Top = 0;
-
 
102
 
-
 
103
// compass course
-
 
104
volatile int16_t CompassHeading = -1; // negative angle indicates invalid data.
-
 
105
volatile int16_t CompassCourse = -1;
-
 
106
volatile int16_t CompassOffCourse = 0;
-
 
107
volatile uint8_t CompassCalState = 0;
-
 
108
uint8_t FunnelCourse = 0;
-
 
109
uint16_t BadCompassHeading = 500;
-
 
110
int32_t YawGyroHeading;
-
 
111
int16_t YawGyroDrift;
-
 
112
 
-
 
113
 
-
 
114
int16_t NaviAccPitch = 0, NaviAccRoll = 0, NaviCntAcc = 0;
-
 
115
 
-
 
116
 
-
 
117
// flags
-
 
118
uint8_t MotorsOn = 0;
-
 
119
uint8_t EmergencyLanding = 0;
-
 
120
uint16_t Model_Is_Flying = 0;
-
 
121
 
-
 
122
int32_t TurnOver180Pitch = 250000L, TurnOver180Roll = 250000L;
-
 
123
 
-
 
124
float Gyro_P_Factor;
-
 
125
float Gyro_I_Factor;
-
 
126
 
-
 
127
volatile int16_t  DiffPitch, DiffRoll;
-
 
128
 
-
 
129
int16_t  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0;
-
 
130
 
-
 
131
// setpoints for motors
-
 
132
volatile uint8_t Motor_Front, Motor_Rear, Motor_Right, Motor_Left;
-
 
133
 
-
 
134
// stick values derived by rc channels readings
-
 
135
int16_t StickPitch = 0, StickRoll = 0, StickYaw = 0, StickThrust = 0;
-
 
136
int16_t GPS_Pitch = 0, GPS_Roll = 0;
-
 
137
 
-
 
138
int16_t MaxStickPitch = 0, MaxStickRoll = 0;
-
 
139
// stick values derived by uart inputs
-
 
140
int16_t ExternStickPitch = 0, ExternStickRoll = 0, ExternStickYaw = 0, ExternHeightValue = -20;
-
 
141
 
-
 
142
 
-
 
143
 
-
 
144
 
-
 
145
int16_t ReadingHeight = 0;
-
 
146
int16_t SetPointHeight = 0;
-
 
147
 
-
 
148
int16_t AttitudeCorrectionRoll = 0, AttitudeCorrectionPitch = 0;
-
 
149
 
-
 
150
float Ki =  FACTOR_I;
-
 
151
 
-
 
152
uint8_t Looping_Pitch = 0, Looping_Roll = 0;
-
 
153
uint8_t Looping_Left = 0, Looping_Right = 0, Looping_Down = 0, Looping_Top = 0;
-
 
154
 
-
 
155
 
-
 
156
fc_param_t FCParam = {48,251,16,58,64,150,150,2,10,0,0,0,0,0,0,0,0,100,70,0,0,100};
-
 
157
 
-
 
158
 
126
int MaxStickNick = 0,MaxStickRoll = 0;
159
/************************************************************************/
127
unsigned int  modell_fliegt = 0;
160
/*  Creates numbeeps beeps at the speaker                               */
128
 
161
/************************************************************************/
129
void Piep(unsigned char Anzahl)
162
void Beep(uint8_t numbeeps)
130
{
163
{
131
 while(Anzahl--)
164
        while(numbeeps--)
132
 {
165
        {
-
 
166
                if(MotorsOn) return; //auf keinen Fall im Flug!
-
 
167
                BeepTime = 100; // 0.1 second
133
  if(MotorenEin) return; //auf keinen Fall im Flug!
168
                Delay_ms(250); // blocks 250 ms as pause to next beep,
134
  beeptime = 100;
169
                // this will block the flight control loop,
Line 135... Line 170...
135
  Delay_ms(250);
170
                // therefore do not use this funktion if motors are running
136
 }
171
        }
-
 
172
}
137
}
173
 
138
 
-
 
139
//############################################################################
174
/************************************************************************/
140
//  Nullwerte ermitteln
175
/*  Neutral Readings                                                    */
141
void SetNeutral(void)
176
/************************************************************************/
142
//############################################################################
177
void SetNeutral(void)
143
{
178
{
144
        NeutralAccX = 0;
179
        NeutralAccX = 0;
145
        NeutralAccY = 0;
180
        NeutralAccY = 0;
146
        NeutralAccZ = 0;
181
        NeutralAccZ = 0;
147
    AdNeutralNick = 0; 
182
    AdNeutralPitch = 0;
148
        AdNeutralRoll = 0;     
183
        AdNeutralRoll = 0;
149
        AdNeutralGier = 0;
184
        AdNeutralYaw = 0;
150
    Parameter_AchsKopplung1 = 0;
185
    FCParam.Yaw_PosFeedback = 0;
151
    Parameter_AchsGegenKopplung1 = 0;
186
    FCParam.Yaw_NegFeedback = 0;
152
    CalibrierMittelwert();     
-
 
153
    Delay_ms_Mess(100);
-
 
154
        CalibrierMittelwert();
-
 
155
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
-
 
156
     {    
-
 
157
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
-
 
158
     }
-
 
159
 
-
 
160
     AdNeutralNick= AdWertNick;
-
 
161
         AdNeutralRoll= AdWertRoll;    
-
 
162
         AdNeutralGier= AdWertGier;
187
    CalibMean();
163
     StartNeutralRoll = AdNeutralRoll;
188
    Delay_ms_Mess(100);
164
     StartNeutralNick = AdNeutralNick;
-
 
165
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4)
-
 
166
    {
189
        CalibMean();
-
 
190
    if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL))  // Height Control activated?
-
 
191
    {
167
      NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
192
                if((ReadingAirPressure > 950) || (ReadingAirPressure < 750)) SearchAirPressureOffset();
-
 
193
    }
-
 
194
        AdNeutralPitch = AdValueGyrPitch;
-
 
195
        AdNeutralRoll  = AdValueGyrRoll;
168
          NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
196
        AdNeutralYaw   = AdValueGyrYaw;
169
          NeutralAccZ = Aktuell_az;
197
        StartNeutralRoll  = AdNeutralRoll;
170
    }
198
        StartNeutralPitch = AdNeutralPitch;
171
    else
199
    if(GetParamWord(PID_ACC_PITCH) > 1023)
172
    {
200
    {
-
 
201
                NeutralAccY = abs(Mean_AccRoll) / ACC_AMPLIFY;
-
 
202
                NeutralAccX = abs(Mean_AccPitch) / ACC_AMPLIFY;
-
 
203
                NeutralAccZ = Current_AccZ;
-
 
204
    }
-
 
205
    else
173
      NeutralAccX = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1]);
206
    {
174
          NeutralAccY = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1]);
207
                NeutralAccX = (int16_t)GetParamWord(PID_ACC_PITCH);
175
          NeutralAccZ = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1]);
208
            NeutralAccY = (int16_t)GetParamWord(PID_ACC_ROLL);
176
    }
209
            NeutralAccZ = (int16_t)GetParamWord(PID_ACC_Z);
177
   
210
    }
178
        Mess_IntegralNick = 0; 
211
        Reading_IntegralGyroPitch = 0;
179
    Mess_IntegralNick2 = 0;
212
    Reading_IntegralGyroPitch2 = 0;
180
    Mess_IntegralRoll = 0;     
213
    Reading_IntegralGyroRoll = 0;
181
    Mess_IntegralRoll2 = 0;
214
    Reading_IntegralGyroRoll2 = 0;
182
    Mess_Integral_Gier = 0;    
215
    Reading_IntegralGyroYaw = 0;
183
    MesswertNick = 0;
216
    Reading_GyroPitch = 0;
184
    MesswertRoll = 0;
217
    Reading_GyroRoll = 0;
185
    MesswertGier = 0;
218
    Reading_GyroYaw = 0;
186
    StartLuftdruck = Luftdruck;
-
 
187
    HoeheD = 0;
219
    StartAirPressure = AirPressure;
188
    Mess_Integral_Hoch = 0;
220
    HeightD = 0;
189
    KompassStartwert = KompassValue;
221
    Reading_Integral_Top = 0;
190
    GPS_Neutral();
222
    CompassCourse = CompassHeading;
191
    beeptime = 50;  
223
    BeepTime = 50;
192
        Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L;
224
        TurnOver180Pitch = ((int32_t) ParamSet.AngleTurnOverPitch * 2500L) +15000L;
-
 
225
        TurnOver180Roll =  ((int32_t) ParamSet.AngleTurnOverRoll *  2500L) +15000L;
193
        Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L;
226
    ExternHeightValue = 0;
194
    ExternHoehenValue = 0;
227
    GPS_Pitch = 0;
Line 195... Line 228...
195
    ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
228
    GPS_Roll = 0;
196
    GierGyroFehler = 0;
229
    YawGyroHeading = CompassHeading * YAW_GYRO_DEG_FACTOR;
-
 
230
    YawGyroDrift = 0;
197
    SendVersionToNavi = 1;
231
}
198
}
-
 
199
 
232
 
200
//############################################################################
233
/************************************************************************/
-
 
234
/*  Averaging Measurement Readings                                      */
-
 
235
/************************************************************************/
201
// Bearbeitet die Messwerte
236
void Mean(void)
202
void Mittelwert(void)
237
{
203
//############################################################################
238
    static int32_t tmpl,tmpl2;
204
{      
239
 
205
    static signed long tmpl,tmpl2;     
240
 // Get offset corrected gyro readings (~ to angular velocity)
206
    MesswertGier = (signed int) AdNeutralGier - AdWertGier;
241
    Reading_GyroYaw   = AdNeutralYaw    - AdValueGyrYaw;
207
    MesswertRoll = (signed int) AdWertRoll - AdNeutralRoll;
-
 
208
    MesswertNick = (signed int) AdWertNick - AdNeutralNick;
-
 
209
 
242
    Reading_GyroRoll  = AdValueGyrRoll  - AdNeutralRoll;
210
//DebugOut.Analog[26] = MesswertNick;
243
    Reading_GyroPitch = AdValueGyrPitch - AdNeutralPitch;
211
DebugOut.Analog[28] = MesswertRoll;
244
 
-
 
245
// Acceleration Sensor
-
 
246
        // sliding average sensor readings
212
 
247
        Mean_AccPitch = ((int32_t)Mean_AccPitch * 1 + ((ACC_AMPLIFY * (int32_t)AdValueAccPitch))) / 2L;
213
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
248
        Mean_AccRoll  = ((int32_t)Mean_AccRoll * 1 + ((ACC_AMPLIFY * (int32_t)AdValueAccRoll))) / 2L;
-
 
249
        Mean_AccTop   = ((int32_t)Mean_AccTop * 1 + ((int32_t)AdValueAccTop)) / 2L;
214
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 1 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 2L;
250
 
215
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 1 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 2L;
251
        // sum sensor readings for later averaging
216
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 1 + ((long)AdWertAccHoch)) / 2L;
252
    IntegralAccPitch += ACC_AMPLIFY * AdValueAccPitch;
-
 
253
    IntegralAccRoll  += ACC_AMPLIFY * AdValueAccRoll;
-
 
254
 
217
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
255
    NaviAccPitch += AdValueAccPitch;
218
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
-
 
219
    NaviAccNick    += AdWertAccNick;
-
 
220
    NaviAccRoll    += AdWertAccRoll;
256
    NaviAccRoll  += AdValueAccRoll;
221
    NaviCntAcc++;
257
    NaviCntAcc++;
222
    IntegralAccZ    += Aktuell_az - NeutralAccZ;
258
 
223
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
259
// Yaw
-
 
260
        // calculate yaw gyro integral (~ to rotation angle)
-
 
261
        Reading_IntegralGyroYaw  += Reading_GyroYaw;
224
            ErsatzKompass +=  MesswertGier;
262
        YawGyroHeading += Reading_GyroYaw;
225
            Mess_Integral_Gier +=  MesswertGier;
263
    if(YawGyroHeading >= (360L * YAW_GYRO_DEG_FACTOR)) YawGyroHeading -= 360L * YAW_GYRO_DEG_FACTOR;  // 360° Wrap
226
            Mess_Integral_Gier2 += MesswertGier;
264
        if(YawGyroHeading < 0)                             YawGyroHeading += 360L * YAW_GYRO_DEG_FACTOR;
227
                    if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR;  // 360° Umschlag
265
 
228
                    if(ErsatzKompass < 0)                          ErsatzKompass += 360L * GIER_GRAD_FAKTOR;
266
 
229
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
267
        // Coupling fraction
230
      if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
268
        if(!Looping_Pitch && !Looping_Roll && (ParamSet.GlobalConfig & CFG_AXIS_COUPLING_ACTIVE))
231
         {
269
        {
232
            tmpl = (MesswertGier * Mess_IntegralNick) / 2048L;
270
                tmpl = (Reading_GyroYaw * Reading_IntegralGyroPitch) / 2048L;
233
            tmpl *= Parameter_AchsKopplung1;  //125
271
                tmpl *= FCParam.Yaw_PosFeedback;
234
            tmpl /= 4096L;
272
                tmpl /= 4096L;
235
            tmpl2 = (MesswertGier * Mess_IntegralRoll) / 2048L;
273
                tmpl2 = ( Reading_GyroYaw * Reading_IntegralGyroRoll) / 2048L;
-
 
274
                tmpl2 *= FCParam.Yaw_PosFeedback;
236
            tmpl2 *= Parameter_AchsKopplung1;
275
                tmpl2 /= 4096L;
237
            tmpl2 /= 4096L;
276
                if(labs(tmpl) > 128 || labs(tmpl2) > 128) FunnelCourse = 1;
238
            if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1;
277
        }
239
         }
278
        else  tmpl = tmpl2 = 0;
240
      else  tmpl = tmpl2 = 0;
279
 
241
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
280
// Roll
242
            MesswertRoll += tmpl;
281
        Reading_GyroRoll += tmpl;
243
            MesswertRoll += (tmpl2*Parameter_AchsGegenKopplung1)/512L; //109
282
        Reading_GyroRoll += (tmpl2 * FCParam.Yaw_NegFeedback) / 512L;
244
            Mess_IntegralRoll2 += MesswertRoll;
283
        Reading_IntegralGyroRoll2 += Reading_GyroRoll;
245
            Mess_IntegralRoll +=  MesswertRoll - LageKorrekturRoll;
284
        Reading_IntegralGyroRoll +=  Reading_GyroRoll - AttitudeCorrectionRoll;
246
            if(Mess_IntegralRoll > Umschlag180Roll)
285
        if(Reading_IntegralGyroRoll > TurnOver180Roll)
247
            {
286
        {
248
             Mess_IntegralRoll  = -(Umschlag180Roll - 25000L);
287
                Reading_IntegralGyroRoll  = -(TurnOver180Roll - 10000L);
249
             Mess_IntegralRoll2 = Mess_IntegralRoll;
288
                Reading_IntegralGyroRoll2 = Reading_IntegralGyroRoll;
250
            }
289
        }
251
            if(Mess_IntegralRoll <-Umschlag180Roll)
290
        if(Reading_IntegralGyroRoll < -TurnOver180Roll)
252
            {
291
        {
253
             Mess_IntegralRoll =  (Umschlag180Roll - 25000L);
292
                Reading_IntegralGyroRoll =  (TurnOver180Roll - 10000L);
254
             Mess_IntegralRoll2 = Mess_IntegralRoll;
293
                Reading_IntegralGyroRoll2 = Reading_IntegralGyroRoll;
255
            }  
294
        }
256
            if(AdWertRoll < 15)   MesswertRoll = -1000;
295
        if(AdValueGyrRoll < 15)   Reading_GyroRoll = -1000;
257
            if(AdWertRoll <  7)   MesswertRoll = -2000;
296
        if(AdValueGyrRoll <  7)   Reading_GyroRoll = -2000;
258
            if(PlatinenVersion == 10)
297
        if(BoardRelease == 10)
259
                         {
298
        {
260
              if(AdWertRoll > 1010) MesswertRoll = +1000;
299
                if(AdValueGyrRoll > 1010) Reading_GyroRoll = +1000;
261
              if(AdWertRoll > 1017) MesswertRoll = +2000;
300
                if(AdValueGyrRoll > 1017) Reading_GyroRoll = +2000;
262
                         }
301
        }
263
                         else
302
        else
264
                         {
303
        {
265
              if(AdWertRoll > 2020) MesswertRoll = +1000;
304
                if(AdValueGyrRoll > 2020) Reading_GyroRoll = +1000;
266
              if(AdWertRoll > 2034) MesswertRoll = +2000;
305
                if(AdValueGyrRoll > 2034) Reading_GyroRoll = +2000;
267
                         }
306
        }
268
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
-
 
269
            MesswertNick -= tmpl2;
307
// Pitch
270
            MesswertNick -= (tmpl*Parameter_AchsGegenKopplung1)/512L;
308
        Reading_GyroPitch -= tmpl2;
271
            Mess_IntegralNick2 += MesswertNick;
309
        Reading_GyroPitch -= (tmpl*FCParam.Yaw_NegFeedback) / 512L;
272
            Mess_IntegralNick  += MesswertNick - LageKorrekturNick;
310
        Reading_IntegralGyroPitch2 += Reading_GyroPitch;
273
 
311
        Reading_IntegralGyroPitch  += Reading_GyroPitch - AttitudeCorrectionPitch;
274
            if(Mess_IntegralNick > Umschlag180Nick)
312
        if(Reading_IntegralGyroPitch > TurnOver180Pitch)
275
             {
313
        {
276
              Mess_IntegralNick = -(Umschlag180Nick - 25000L);
314
         Reading_IntegralGyroPitch = -(TurnOver180Pitch - 25000L);
277
              Mess_IntegralNick2 = Mess_IntegralNick;
315
         Reading_IntegralGyroPitch2 = Reading_IntegralGyroPitch;
278
             }
316
        }
279
            if(Mess_IntegralNick <-Umschlag180Nick)
317
        if(Reading_IntegralGyroPitch < -TurnOver180Pitch)
280
            {
318
        {
281
             Mess_IntegralNick =  (Umschlag180Nick - 25000L);
319
         Reading_IntegralGyroPitch =  (TurnOver180Pitch - 25000L);
282
             Mess_IntegralNick2 = Mess_IntegralNick;
320
         Reading_IntegralGyroPitch2 = Reading_IntegralGyroPitch;
283
            }
321
        }
284
            if(AdWertNick < 15)   MesswertNick = -1000;
322
        if(AdValueGyrPitch < 15)   Reading_GyroPitch = -1000;
285
            if(AdWertNick <  7)   MesswertNick = -2000;
323
        if(AdValueGyrPitch <  7)   Reading_GyroPitch = -2000;
286
            if(PlatinenVersion == 10)
324
        if(BoardRelease == 10)
287
                         {
325
        {
288
              if(AdWertNick > 1010) MesswertNick = +1000;
326
                if(AdValueGyrPitch > 1010) Reading_GyroPitch = +1000;
289
              if(AdWertNick > 1017) MesswertNick = +2000;
327
                if(AdValueGyrPitch > 1017) Reading_GyroPitch = +2000;
290
                         }
328
        }
-
 
329
        else
291
                         else
330
        {
292
                         {
-
 
293
              if(AdWertNick > 2020) MesswertNick = +1000;
331
                if(AdValueGyrPitch > 2020) Reading_GyroPitch = +1000;
294
              if(AdWertNick > 2034) MesswertNick = +2000;
-
 
295
                         }
332
                if(AdValueGyrPitch > 2034) Reading_GyroPitch = +2000;
296
//++++++++++++++++++++++++++++++++++++++++++++++++
333
        }
297
// ADC einschalten
334
 
298
    ANALOG_ON; 
335
// start ADC again to capture measurement values for the next loop
299
//++++++++++++++++++++++++++++++++++++++++++++++++
336
    ADC_Enable();
300
 
337
 
301
    Integral_Gier  = Mess_Integral_Gier;
338
    IntegralYaw    = Reading_IntegralGyroYaw;
302
    IntegralNick = Mess_IntegralNick;
339
    IntegralPitch  = Reading_IntegralGyroPitch;
303
    IntegralRoll = Mess_IntegralRoll;
340
    IntegralRoll   = Reading_IntegralGyroRoll;
304
    IntegralNick2 = Mess_IntegralNick2;
341
    IntegralPitch2 = Reading_IntegralGyroPitch2;
305
    IntegralRoll2 = Mess_IntegralRoll2;
342
    IntegralRoll2  = Reading_IntegralGyroRoll2;
306
 
343
 
307
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
344
        if((ParamSet.GlobalConfig & CFG_ROTARY_RATE_LIMITER) && !Looping_Pitch && !Looping_Roll)
308
  {
345
        {
309
    if(MesswertNick > 200)       MesswertNick += 4 * (MesswertNick - 200);
-
 
310
    else if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
-
 
311
    if(MesswertRoll > 200)       MesswertRoll += 4 * (MesswertRoll - 200);
-
 
312
    else if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
-
 
313
  }
-
 
314
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
-
 
315
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
-
 
316
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
-
 
317
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
346
                if(Reading_GyroPitch > 200)       Reading_GyroPitch += 4 * (Reading_GyroPitch - 200);
Line 318... Line 347...
318
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
347
                else if(Reading_GyroPitch < -200) Reading_GyroPitch += 4 * (Reading_GyroPitch + 200);
319
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
348
                if(Reading_GyroRoll > 200)        Reading_GyroRoll  += 4 * (Reading_GyroRoll - 200);
-
 
349
                else if(Reading_GyroRoll < -200)  Reading_GyroRoll  += 4 * (Reading_GyroRoll + 200);
320
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
350
        }
321
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
-
 
322
}
351
}
323
 
352
 
324
//############################################################################
353
/************************************************************************/
-
 
354
/*  Averaging Measurement Readings  for Calibration                     */
325
// Messwerte beim Ermitteln der Nullage
355
/************************************************************************/
326
void CalibrierMittelwert(void)
356
void CalibMean(void)
327
//############################################################################
357
{
-
 
358
    // stop ADC to avoid changing values during calculation
328
{                
359
        ADC_Disable();
329
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
360
 
330
        ANALOG_OFF;
361
        Reading_GyroPitch = AdValueGyrPitch;
-
 
362
        Reading_GyroRoll  = AdValueGyrRoll;
331
        MesswertNick = AdWertNick;
363
        Reading_GyroYaw   = AdValueGyrYaw;
332
        MesswertRoll = AdWertRoll;
364
 
333
        MesswertGier = AdWertGier;
-
 
334
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
-
 
335
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
-
 
336
        Mittelwert_AccHoch = (long)AdWertAccHoch;
-
 
337
   // ADC einschalten
-
 
338
    ANALOG_ON; 
-
 
339
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
-
 
340
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
-
 
Line 341... Line 365...
341
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
365
        Mean_AccPitch = ACC_AMPLIFY * (int32_t)AdValueAccPitch;
342
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
366
        Mean_AccRoll  = ACC_AMPLIFY * (int32_t)AdValueAccRoll;
343
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
367
        Mean_AccTop   = (int32_t)AdValueAccTop;
Line 344... Line 368...
344
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
368
    // start ADC (enables internal trigger so that the ISR in analog.c
345
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
369
    // updates the readings once)
-
 
370
    ADC_Enable();
346
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
371
 
347
 
-
 
348
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
372
        TurnOver180Pitch = (int32_t) ParamSet.AngleTurnOverPitch * 2500L;
349
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
373
        TurnOver180Roll =  (int32_t) ParamSet.AngleTurnOverRoll  * 2500L;
350
}
374
}
351
 
375
 
352
//############################################################################
376
/************************************************************************/
353
// Senden der Motorwerte per I2C-Bus
377
/*  Transmit Motor Data via I2C                                         */
354
void SendMotorData(void)
378
/************************************************************************/
355
//############################################################################
379
void SendMotorData(void)
356
{
380
{
357
    if(MOTOR_OFF || !MotorenEin)
381
    if(MOTOR_OFF || !MotorsOn)
358
        {
382
    {
359
        Motor_Hinten = 0;
383
        Motor_Rear = 0;
360
        Motor_Vorne = 0;
384
        Motor_Front = 0;
361
        Motor_Rechts = 0;
385
        Motor_Right = 0;
362
        Motor_Links = 0;
386
        Motor_Left = 0;
363
        if(MotorTest[0]) Motor_Vorne = MotorTest[0];
387
        if(MotorTest[0]) Motor_Front = MotorTest[0];
364
        if(MotorTest[1]) Motor_Hinten = MotorTest[1];
388
        if(MotorTest[1]) Motor_Rear  = MotorTest[1];
Line 365... Line 389...
365
        if(MotorTest[2]) Motor_Links = MotorTest[2];
389
        if(MotorTest[2]) Motor_Left  = MotorTest[2];
366
        if(MotorTest[3]) Motor_Rechts = MotorTest[3];
390
        if(MotorTest[3]) Motor_Right = MotorTest[3];
367
        }
391
     }
368
 
392
 
369
    DebugOut.Analog[12] = Motor_Vorne;
393
    DebugOut.Analog[12] = Motor_Front;
Line 370... Line 394...
370
    DebugOut.Analog[13] = Motor_Hinten;
394
    DebugOut.Analog[13] = Motor_Rear;
371
    DebugOut.Analog[14] = Motor_Links;
395
    DebugOut.Analog[14] = Motor_Left;
-
 
396
    DebugOut.Analog[15] = Motor_Right;
372
    DebugOut.Analog[15] = Motor_Rechts;  
397
 
373
 
-
 
374
    //Start I2C Interrupt Mode
398
    //Start I2C Interrupt Mode
-
 
399
    twi_state = 0;
-
 
400
    motor = 0;
375
    twi_state = 0;
401
    I2C_Start();
-
 
402
}
376
    motor = 0;
403
 
377
    i2c_start();
404
 
378
}
405
 
379
 
406
/************************************************************************/
380
 
407
/*  Maps the parameter to poti values                                   */
381
 
408
/************************************************************************/
382
//############################################################################
409
void ParameterMapping(void)
383
// Trägt ggf. das Poti als Parameter ein
410
{
384
void ParameterZuordnung(void)
411
        if(RC_Quality > 160) // do the mapping of RC-Potis only if the rc-signal is ok
385
//############################################################################
412
        // else the last updated values are used
386
{
413
        {
387
 
414
                 //update poti values by rc-signals
388
 #define CHK_POTI(b,a,min,max) { if(a > 250) { if(a == 251) b = Poti1; else if(a == 252) b = Poti2; else if(a == 253) b = Poti3; else if(a == 254) b = Poti4;} else b = a; if(b <= min) b = min; else if(b >= max) b = max;}
415
                #define CHK_POTI(b,a,min,max) { if(a > 250) { if(a == 251) b = Poti1; else if(a == 252) b = Poti2; else if(a == 253) b = Poti3; else if(a == 254) b = Poti4;} else b = a; if(b <= min) b = min; else if(b >= max) b = max;}
389
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
416
                CHK_POTI(FCParam.MaxHeight,ParamSet.MaxHeight,0,255);
390
 CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
417
                CHK_POTI(FCParam.Height_D,ParamSet.Height_D,0,100);
391
 CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
418
                CHK_POTI(FCParam.Height_P,ParamSet.Height_P,0,100);
392
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
419
                CHK_POTI(FCParam.Height_ACC_Effect,ParamSet.Height_ACC_Effect,0,255);
393
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
420
                CHK_POTI(FCParam.CompassYawEffect,ParamSet.CompassYawEffect,0,255);
394
 CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
421
                CHK_POTI(FCParam.Gyro_P,ParamSet.Gyro_P,10,255);
395
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
422
                CHK_POTI(FCParam.Gyro_I,ParamSet.Gyro_I,0,255);
396
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
423
                CHK_POTI(FCParam.I_Factor,ParamSet.I_Factor,0,255);
397
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
424
                CHK_POTI(FCParam.UserParam1,ParamSet.UserParam1,0,255);
398
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
-
 
399
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
425
                CHK_POTI(FCParam.UserParam2,ParamSet.UserParam2,0,255);
400
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
-
 
401
 CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5,0,255);
-
 
-
 
426
                CHK_POTI(FCParam.UserParam3,ParamSet.UserParam3,0,255);
402
 CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6,0,255);
427
                CHK_POTI(FCParam.UserParam4,ParamSet.UserParam4,0,255);
Line -... Line 428...
-
 
428
                CHK_POTI(FCParam.UserParam5,ParamSet.UserParam5,0,255);
-
 
429
                CHK_POTI(FCParam.UserParam6,ParamSet.UserParam6,0,255);
-
 
430
                CHK_POTI(FCParam.UserParam7,ParamSet.UserParam7,0,255);
-
 
431
                CHK_POTI(FCParam.UserParam8,ParamSet.UserParam8,0,255);
-
 
432
                CHK_POTI(FCParam.ServoPitchControl,ParamSet.ServoPitchControl,0,255);
-
 
433
                CHK_POTI(FCParam.LoopThrustLimit,ParamSet.LoopThrustLimit,0,255);
-
 
434
                CHK_POTI(FCParam.Yaw_PosFeedback,ParamSet.Yaw_PosFeedback,0,255);
-
 
435
                CHK_POTI(FCParam.Yaw_NegFeedback,ParamSet.Yaw_NegFeedback,0,255);
-
 
436
                CHK_POTI(FCParam.DynamicStability,ParamSet.DynamicStability,0,255);
-
 
437
                Ki = (float) FCParam.I_Factor * FACTOR_I;
-
 
438
        }
-
 
439
}
-
 
440
 
-
 
441
 
-
 
442
void SetCompassCalState(void)
-
 
443
{
Line 403... Line 444...
403
 CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7,0,255);
444
        static uint8_t stick = 1;
404
 CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8,0,255);
-
 
-
 
445
 
-
 
446
    // if pitch is centered or top set stick to zero
405
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
447
        if(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > -20) stick = 0;
406
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255);
-
 
407
 CHK_POTI(Parameter_AchsKopplung1,    EE_Parameter.AchsKopplung1,0,255);
448
        // if pitch is down trigger to next cal state
Line 617... Line 730...
617
    stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
730
                // calculate Stick inputs by rc channels (P) and changing of rc channels (D)
618
    stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
731
                StickPitch = (StickPitch * 3 + PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] * ParamSet.Stick_P) / 4;
619
    StickRoll = stick_roll - (GPS_Roll + GPS_Roll2);
732
                StickPitch += PPM_diff[ParamSet.ChannelAssignment[CH_PITCH]] * ParamSet.Stick_D;
-
 
733
                StickPitch -= (GPS_Pitch);
620
 
734
 
621
//    StickRoll = (StickRoll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
735
                StickRoll = (StickRoll * 3 + PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] * ParamSet.Stick_P) / 4;
622
 
736
                StickRoll += PPM_diff[ParamSet.ChannelAssignment[CH_ROLL]] * ParamSet.Stick_D;
623
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
737
                StickRoll -= (GPS_Roll);
-
 
738
 
624
        StickGas  = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
739
                // direct mapping of yaw and thrust
625
 
740
                StickYaw = -PPM_in[ParamSet.ChannelAssignment[CH_YAW]];
626
/*   if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]) > MaxStickNick)
741
                StickThrust  = PPM_in[ParamSet.ChannelAssignment[CH_THRUST]] + 120;// shift to positive numbers
-
 
742
 
627
     MaxStickNick = abs(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]); else MaxStickNick--;
743
                // update gyro control loop factors
628
   if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > MaxStickRoll)
744
                Gyro_P_Factor = ((float) FCParam.Gyro_P + 10.0) / (256.0 / STICK_GAIN);
629
     MaxStickRoll = abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]); else MaxStickRoll--;
745
                Gyro_I_Factor = ((float) FCParam.Gyro_I) / (44000 / STICK_GAIN);
630
*/
746
 
631
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / (256.0/STICK_GAIN);
747
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
632
    IntegralFaktor = ((float) Parameter_Gyro_I) / (44000 / STICK_GAIN);
748
// Digital Control via DubWise
633
 
749
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
634
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
750
 
635
//+ Digitale Steuerung per DubWise
751
                #define KEY_VALUE (FCParam.UserParam8 * 4) // step width
636
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
752
                if(DubWiseKeys[1]) BeepTime = 10;
-
 
753
                if(DubWiseKeys[1] & DUB_KEY_UP)  tmp_int = KEY_VALUE;
637
#define KEY_VALUE (Parameter_UserParam8 * 4)  //(Poti3 * 8)
754
                else if(DubWiseKeys[1] & DUB_KEY_DOWN)  tmp_int = -KEY_VALUE;
638
if(DubWiseKeys[1]) beeptime = 10;
755
                else tmp_int = 0;
639
    if(DubWiseKeys[1] & DUB_KEY_UP)    tmp_int = KEY_VALUE;   else
756
                ExternStickPitch = (ExternStickPitch * 7 + tmp_int) / 8;
640
    if(DubWiseKeys[1] & DUB_KEY_DOWN)  tmp_int = -KEY_VALUE;  else   tmp_int = 0;
-
 
641
    ExternStickNick = (ExternStickNick * 7 + tmp_int) / 8;
-
 
642
    if(DubWiseKeys[1] & DUB_KEY_LEFT)  tmp_int = KEY_VALUE; else
-
 
643
    if(DubWiseKeys[1] & DUB_KEY_RIGHT) tmp_int = -KEY_VALUE; else tmp_int = 0;
-
 
644
    ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8;
-
 
645
 
-
 
646
    if(DubWiseKeys[0] & 8)  ExternStickGier = 50;else
-
 
647
    if(DubWiseKeys[0] & 4)  ExternStickGier =-50;else ExternStickGier = 0;
-
 
648
    if(DubWiseKeys[0] & 2)  ExternHoehenValue++;
-
 
Line -... Line 757...
-
 
757
                if(DubWiseKeys[1] & DUB_KEY_LEFT)  tmp_int = KEY_VALUE;
-
 
758
                else if(DubWiseKeys[1] & DUB_KEY_RIGHT) tmp_int = -KEY_VALUE;
-
 
759
                else tmp_int = 0;
-
 
760
                ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8;
-
 
761
 
-
 
762
                if(DubWiseKeys[0] & 8)  ExternStickYaw = 50;else
-
 
763
                if(DubWiseKeys[0] & 4)  ExternStickYaw =-50;else ExternStickYaw = 0;
-
 
764
                if(DubWiseKeys[0] & 2)  ExternHeightValue++;
-
 
765
                if(DubWiseKeys[0] & 16) ExternHeightValue--;
-
 
766
 
-
 
767
                StickPitch += (STICK_GAIN * ExternStickPitch) / 8;
649
    if(DubWiseKeys[0] & 16) ExternHoehenValue--;
768
                StickRoll  += (STICK_GAIN * ExternStickRoll) / 8;
-
 
769
                StickYaw   += (STICK_GAIN * ExternStickYaw);
650
 
770
 
651
    StickNick += (STICK_GAIN * ExternStickNick) / 8;
771
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
772
//+ Analog control via serial communication
-
 
773
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
774
 
-
 
775
                if(ExternControl.Config & 0x01 && FCParam.UserParam8 > 128)
-
 
776
                {
-
 
777
                         StickPitch += (int16_t) ExternControl.Pitch * (int16_t) ParamSet.Stick_P;
-
 
778
                         StickRoll += (int16_t) ExternControl.Roll * (int16_t) ParamSet.Stick_P;
-
 
779
                         StickYaw += ExternControl.Yaw;
Line 652... Line -...
652
    StickRoll += (STICK_GAIN * ExternStickRoll) / 8;
-
 
653
    StickGier += STICK_GAIN * ExternStickGier;
-
 
654
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
655
//+ Analoge Steuerung per Seriell
-
 
656
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
780
                         ExternHeightValue =  (int16_t) ExternControl.Height * (int16_t)ParamSet.Height_Gain;
657
   if(ExternControl.Config & 0x01 && Parameter_UserParam8 > 128)
781
                         if(ExternControl.Thrust < StickThrust) StickThrust = ExternControl.Thrust;
658
    {
-
 
659
         StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P;
-
 
660
         StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P;
-
 
661
         StickGier += ExternControl.Gier;
-
 
662
     ExternHoehenValue =  (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung;
-
 
663
     if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
-
 
664
    }
-
 
665
    if(StickGas < 0) StickGas = 0;
-
 
666
 
-
 
667
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
-
 
668
    if(GyroFaktor < 0) GyroFaktor = 0;
-
 
669
    if(IntegralFaktor < 0) IntegralFaktor = 0;
-
 
670
 
-
 
671
    if(abs(StickNick/STICK_GAIN) > MaxStickNick) MaxStickNick = abs(StickNick)/STICK_GAIN; else MaxStickNick--;
-
 
672
    if(abs(StickRoll/STICK_GAIN) > MaxStickRoll) MaxStickRoll = abs(StickRoll)/STICK_GAIN; else MaxStickRoll--;
-
 
673
    if(Notlandung)  {MaxStickNick = 0; MaxStickRoll = 0;}
-
 
674
 
-
 
675
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
-
 
676
// Looping?
-
 
677
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
-
 
678
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
-
 
679
  else
-
 
680
   {
-
 
681
     {
-
 
682
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;  
-
 
683
     }  
-
 
684
   }
-
 
685
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
-
 
686
   else
-
 
687
   {
-
 
688
   if(Looping_Rechts) // Hysterese
-
 
689
     {
-
 
690
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
-
 
691
     }
-
 
692
   }
-
 
693
 
-
 
694
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
-
 
695
  else
-
 
696
   {
-
 
697
    if(Looping_Oben)  // Hysterese
-
 
698
     {
-
 
699
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;  
-
 
700
     }  
-
 
701
   }
-
 
702
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
-
 
703
   else
-
 
704
   {
-
 
705
    if(Looping_Unten) // Hysterese
-
 
706
     {
-
 
707
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
-
 
708
     }
-
 
709
   }
-
 
710
 
-
 
711
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
-
 
712
   if(Looping_Oben  || Looping_Unten) {Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
-
 
713
  } // Ende neue Funken-Werte
-
 
714
 
-
 
715
  if(Looping_Roll) beeptime = 100;
-
 
716
  if(Looping_Roll || Looping_Nick)
-
 
717
   {
-
 
718
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
-
 
719
   }
-
 
720
   
-
 
721
 
-
 
722
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
-
 
723
// Bei Empfangsausfall im Flug 
-
 
724
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
-
 
725
   if(Notlandung)
-
 
726
    {
-
 
727
     StickGier = 0;
-
 
728
     StickNick = 0;
-
 
729
     StickRoll = 0;
-
 
730
     GyroFaktor     = (float) 100 / (256.0 / STICK_GAIN);
-
 
731
     IntegralFaktor = (float) 120 / (44000 / STICK_GAIN);
-
 
732
     Looping_Roll = 0;
-
 
733
     Looping_Nick = 0;
-
 
734
    }  
-
 
735
 
-
 
736
 
-
 
737
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
-
 
738
// Integrale auf ACC-Signal abgleichen
-
 
739
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
-
 
740
#define ABGLEICH_ANZAHL 256L
-
 
741
 
-
 
742
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
-
 
743
 MittelIntegralRoll  += IntegralRoll;
782
                }
744
 MittelIntegralNick2 += IntegralNick2;
-
 
745
 MittelIntegralRoll2 += IntegralRoll2;
-
 
746
 
-
 
747
 if(Looping_Nick || Looping_Roll)
-
 
748
  {
-
 
749
    IntegralAccNick = 0;
-
 
750
    IntegralAccRoll = 0;
-
 
751
    MittelIntegralNick = 0;
-
 
752
    MittelIntegralRoll = 0;
-
 
753
    MittelIntegralNick2 = 0;
-
 
754
    MittelIntegralRoll2 = 0;
-
 
755
    Mess_IntegralNick2 = Mess_IntegralNick;
-
 
756
    Mess_IntegralRoll2 = Mess_IntegralRoll;
-
 
757
    ZaehlMessungen = 0;
-
 
758
    LageKorrekturNick = 0;
-
 
759
    LageKorrekturRoll = 0;
-
 
760
  }
-
 
Line 761... Line -...
761
 
-
 
762
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
783
                if(StickThrust < 0) StickThrust = 0;
-
 
784
 
-
 
785
                // disable I part of gyro control feedback
763
  if(!Looping_Nick && !Looping_Roll)
786
                if(ParamSet.GlobalConfig & CFG_HEADING_HOLD) Gyro_I_Factor =  0;
-
 
787
                // avoid negative scaling factors
764
  {
788
                if(Gyro_P_Factor < 0) Gyro_P_Factor = 0;
-
 
789
                if(Gyro_I_Factor < 0) Gyro_I_Factor = 0;
-
 
790
 
765
   long tmp_long, tmp_long2;
791
 
-
 
792
                // update max stick positions for pitch and roll
766
    tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
793
 
767
    tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
794
                if(abs(StickPitch / STICK_GAIN) > MaxStickPitch) MaxStickPitch = abs(StickPitch)/STICK_GAIN;
-
 
795
                else MaxStickPitch--;
768
    tmp_long /= 16;
796
                if(abs(StickRoll / STICK_GAIN) > MaxStickRoll) MaxStickRoll = abs(StickRoll)/STICK_GAIN;
-
 
797
                else MaxStickRoll--;
769
    tmp_long2 /= 16;
798
 
770
   if((MaxStickNick > 32) || (MaxStickRoll > 32))
-
 
771
    {
799
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
772
    tmp_long  /= 3;
800
// Looping?
-
 
801
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
773
    tmp_long2 /= 3;
802
 
774
    }
-
 
775
   if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
803
                if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_LEFT)  Looping_Left = 1;
-
 
804
                else
776
    {
805
                {
-
 
806
                        if(Looping_Left) // Hysteresis
-
 
807
                        {
777
    tmp_long  /= 3;
808
                                if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < (ParamSet.LoopThreshold - ParamSet.LoopHysteresis))) Looping_Left = 0;
-
 
809
                        }
778
    tmp_long2 /= 3;
810
                }
779
    }
811
                if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < -ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_RIGHT) Looping_Right = 1;
-
 
812
                else
780
 
813
                {
-
 
814
                        if(Looping_Right) // Hysteresis
-
 
815
                        {
-
 
816
                                if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > -(ParamSet.LoopThreshold - ParamSet.LoopHysteresis)) Looping_Right = 0;
781
 #define AUSGLEICH 32
817
                        }
782
    if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
818
                }
783
    if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
819
 
-
 
820
                if((PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_UP) Looping_Top = 1;
-
 
821
                else
784
    if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
822
                {
785
    if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
-
 
786
 
-
 
787
    Mess_IntegralNick -= tmp_long;
-
 
788
    Mess_IntegralRoll -= tmp_long2;
-
 
789
  }
823
                        if(Looping_Top)  // Hysteresis
-
 
824
                        {
790
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
825
                                if((PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] < (ParamSet.LoopThreshold - ParamSet.LoopHysteresis))) Looping_Top = 0;
-
 
826
                        }
Line 791... Line -...
791
 
-
 
792
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
-
 
Line -... Line 827...
-
 
827
                }
-
 
828
                if((PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] < -ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_DOWN) Looping_Down = 1;
-
 
829
                else
-
 
830
                {
-
 
831
                        if(Looping_Down) // Hysteresis
-
 
832
                        {
-
 
833
                                if(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > -(ParamSet.LoopThreshold - ParamSet.LoopHysteresis)) Looping_Down = 0;
793
 {
834
                        }
-
 
835
                }
-
 
836
 
-
 
837
                if(Looping_Left || Looping_Right)   Looping_Roll = 1; else Looping_Roll = 0;
-
 
838
                if(Looping_Top  || Looping_Down) {Looping_Pitch = 1; Looping_Roll = 0; Looping_Left = 0; Looping_Right = 0;} else Looping_Pitch = 0;
794
  static int cnt = 0;
839
        } // End of new RC-Values or Emergency Landing
-
 
840
 
-
 
841
 
-
 
842
        if(Looping_Roll) BeepTime = 100;
-
 
843
        if(Looping_Roll || Looping_Pitch)
-
 
844
        {
-
 
845
                if(ThrustMixFraction > ParamSet.LoopThrustLimit) ThrustMixFraction = ParamSet.LoopThrustLimit;
-
 
846
        }
795
  static char last_n_p,last_n_n,last_r_p,last_r_n;
847
 
796
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
848
 
797
  if(!Looping_Nick && !Looping_Roll && !TrichterFlug)
849
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
798
  {
850
//+ LED Control on J16/J17
799
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
851
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
800
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
852
        LED1_Time = FCParam.UserParam7;
801
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
853
        LED2_Time = FCParam.UserParam8;
-
 
854
        LED_Update();
-
 
855
 
-
 
856
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
802
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
857
// in case of emergency landing
803
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
858
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
859
        // set all inputs to save values
-
 
860
        if(EmergencyLanding)
-
 
861
        {
-
 
862
                StickYaw = 0;
-
 
863
                StickPitch = 0;
-
 
864
                StickRoll = 0;
-
 
865
                Gyro_P_Factor  = (float) 100 / (256.0 / STICK_GAIN);
-
 
866
                Gyro_I_Factor = (float) 120 / (44000 / STICK_GAIN);
-
 
867
                Looping_Roll = 0;
-
 
868
                Looping_Pitch = 0;
-
 
869
                MaxStickPitch = 0;
-
 
870
                MaxStickRoll = 0;
804
#define MAX_I 0//(Poti2/10)
871
        }
805
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
872
 
-
 
873
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
874
// Trim Gyro-Integrals to ACC-Signals
-
 
875
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
876
 
-
 
877
        #define BALANCE_NUMBER 256L
-
 
878
        // sum for averaging
806
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
879
        MeanIntegralPitch  += IntegralPitch;
-
 
880
        MeanIntegralRoll  += IntegralRoll;
-
 
881
 
-
 
882
        if(Looping_Pitch || Looping_Roll) // if looping in any direction
-
 
883
        {
-
 
884
                // reset averaging for acc and gyro integral as well as gyro integral acc correction
-
 
885
                MeasurementCounter = 0;
-
 
886
 
807
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
887
                IntegralAccPitch = 0;
-
 
888
                IntegralAccRoll = 0;
-
 
889
 
-
 
890
                MeanIntegralPitch = 0;
-
 
891
                MeanIntegralRoll = 0;
-
 
892
 
-
 
893
                Reading_IntegralGyroPitch2 = Reading_IntegralGyroPitch;
-
 
894
                Reading_IntegralGyroRoll2 = Reading_IntegralGyroRoll;
-
 
895
 
-
 
896
                AttitudeCorrectionPitch = 0;
-
 
897
                AttitudeCorrectionRoll = 0;
-
 
898
        }
-
 
899
 
-
 
900
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
901
        if(!Looping_Pitch && !Looping_Roll) // if not lopping in any direction
-
 
902
        {
-
 
903
                int32_t tmp_long, tmp_long2;
-
 
904
                // determine the deviation of gyro integral from averaged acceleration sensor
-
 
905
                tmp_long   =  (int32_t)(IntegralPitch / ParamSet.GyroAccFactor - (int32_t)Mean_AccPitch);
808
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++     
906
                tmp_long  /= 16;
809
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
907
                tmp_long2  = (int32_t)(IntegralRoll   / ParamSet.GyroAccFactor - (int32_t)Mean_AccRoll);
-
 
908
                tmp_long2 /= 16;
-
 
909
 
810
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
910
                if((MaxStickPitch > 32) || (MaxStickRoll > 32)) // reduce effect during stick commands
-
 
911
                {
-
 
912
                        tmp_long  /= 3;
-
 
913
                        tmp_long2 /= 3;
-
 
914
                }
811
 
915
                if(abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25) // reduce further if yaw stick is active
812
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
916
                {
813
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
917
                        tmp_long  /= 3;
814
 
918
                        tmp_long2 /= 3;
815
   if((MaxStickNick > 32) || (MaxStickRoll > 32) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25))
919
                }
-
 
920
 
816
    {
921
                #define BALANCE 32
-
 
922
                // limit correction effect
-
 
923
                if(tmp_long >  BALANCE)  tmp_long  = BALANCE;
817
     LageKorrekturNick /= 2;
924
                if(tmp_long < -BALANCE)  tmp_long  =-BALANCE;
818
     LageKorrekturRoll /= 2;
925
                if(tmp_long2 > BALANCE)  tmp_long2 = BALANCE;
-
 
926
                if(tmp_long2 <-BALANCE)  tmp_long2 =-BALANCE;
-
 
927
                // correct current readings
819
    }
928
                Reading_IntegralGyroPitch -= tmp_long;
-
 
929
                Reading_IntegralGyroRoll -= tmp_long2;
-
 
930
        }
-
 
931
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
932
        // MeasurementCounter is incremented in the isr of analog.c
-
 
933
        if(MeasurementCounter >= BALANCE_NUMBER) // averaging number has reached
-
 
934
        {
-
 
935
                static int16_t cnt = 0;
-
 
936
                static int8_t last_n_p, last_n_n, last_r_p, last_r_n;
820
 
937
                static int32_t MeanIntegralPitch_old, MeanIntegralRoll_old;
-
 
938
 
821
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
939
                // if not lopping in any direction (this should be alwais the case,
-
 
940
                // because the Measurement counter is reset to 0 if looping in any direction is active.)
-
 
941
                if(!Looping_Pitch && !Looping_Roll && !FunnelCourse)
-
 
942
                {
-
 
943
                        // Calculate mean value of the gyro integrals
-
 
944
                        MeanIntegralPitch /= BALANCE_NUMBER;
822
// Gyro-Drift ermitteln
945
                        MeanIntegralRoll  /= BALANCE_NUMBER;
-
 
946
 
-
 
947
                        // Calculate mean of the acceleration values
-
 
948
                        IntegralAccPitch = (ParamSet.GyroAccFactor * IntegralAccPitch) / BALANCE_NUMBER;
-
 
949
                        IntegralAccRoll  = (ParamSet.GyroAccFactor * IntegralAccRoll ) / BALANCE_NUMBER;
823
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
950
 
824
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
951
                        // Pitch ++++++++++++++++++++++++++++++++++++++++++++++++
-
 
952
                        // Calculate deviation of the averaged gyro integral and the averaged acceleration integral
825
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
953
                        IntegralErrorPitch = (int32_t)(MeanIntegralPitch - (int32_t)IntegralAccPitch);
826
    tmp_long  = IntegralNick2 - IntegralNick;
954
                        CorrectionPitch = IntegralErrorPitch / ParamSet.GyroAccTrim;
827
    tmp_long2 = IntegralRoll2 - IntegralRoll;
955
                        AttitudeCorrectionPitch = CorrectionPitch / BALANCE_NUMBER;
828
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
956
                        // Roll ++++++++++++++++++++++++++++++++++++++++++++++++
829
 
957
                        // Calculate deviation of the averaged gyro integral and the averaged acceleration integral
830
    IntegralFehlerNick = tmp_long;
958
                        IntegralErrorRoll = (int32_t)(MeanIntegralRoll - (int32_t)IntegralAccRoll);
831
    IntegralFehlerRoll = tmp_long2;
959
                        CorrectionRoll  = IntegralErrorRoll / ParamSet.GyroAccTrim;
-
 
960
                        AttitudeCorrectionRoll  = CorrectionRoll  / BALANCE_NUMBER;
-
 
961
 
-
 
962
                        if((MaxStickPitch > 32) || (MaxStickRoll > 32) || (abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25))
-
 
963
                        {
-
 
964
                                AttitudeCorrectionPitch /= 2;
-
 
965
                                AttitudeCorrectionRoll /= 2;
-
 
966
                        }
832
    Mess_IntegralNick2 -= IntegralFehlerNick;
967
 
833
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
968
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
834
 
969
        // Gyro-Drift ermitteln
Line 835... Line 970...
835
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
970
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
836
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
971
                        // deviation of gyro pitch integral (IntegralPitch is corrected by averaged acc sensor)
837
    if(GierGyroFehler > ABGLEICH_ANZAHL/2) AdNeutralGier++;
972
                        IntegralErrorPitch  = IntegralPitch2 - IntegralPitch;
838
    if(GierGyroFehler <-ABGLEICH_ANZAHL/2) AdNeutralGier--;
973
                        Reading_IntegralGyroPitch2 -= IntegralErrorPitch;
839
 
974
                        // deviation of gyro pitch integral (IntegralPitch is corrected by averaged acc sensor)
-
 
975
                        IntegralErrorRoll = IntegralRoll2 - IntegralRoll;
840
DebugOut.Analog[22] = MittelIntegralRoll / 26;
976
                        Reading_IntegralGyroRoll2 -= IntegralErrorRoll;
841
 
977
 
842
    GierGyroFehler = 0;
978
                        if(YawGyroDrift >  BALANCE_NUMBER/2) AdNeutralYaw++;
843
 
979
                        if(YawGyroDrift < -BALANCE_NUMBER/2) AdNeutralYaw--;
844
 
980
                        YawGyroDrift = 0;
845
/*DebugOut.Analog[17] = IntegralAccNick / 26;
981
/*
846
DebugOut.Analog[18] = IntegralAccRoll / 26;
982
                        DebugOut.Analog[17] = IntegralAccPitch / 26;
847
DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
983
                        DebugOut.Analog[18] = IntegralAccRoll / 26;
848
DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
984
                        DebugOut.Analog[19] = IntegralErrorPitch;// / 26;
849
*/
985
                        DebugOut.Analog[20] = IntegralErrorRoll;// / 26;
850
//DebugOut.Analog[21] = MittelIntegralNick / 26;
986
                        DebugOut.Analog[21] = MeanIntegralPitch / 26;
851
//MittelIntegralRoll = MittelIntegralRoll;
987
                        DebugOut.Analog[22] = MeanIntegralRoll / 26;
-
 
988
                        //DebugOut.Analog[28] = CorrectionPitch;
852
//DebugOut.Analog[28] = ausgleichNick;
989
                        DebugOut.Analog[29] = CorrectionRoll;
853
/*
990
                        DebugOut.Analog[30] = AttitudeCorrectionRoll * 10;
854
DebugOut.Analog[29] = ausgleichRoll;
991
*/
855
DebugOut.Analog[30] = LageKorrekturRoll * 10;
992
 
856
*/
993
                        #define ERROR_LIMIT  (BALANCE_NUMBER * 4)
857
 
994
                        #define ERROR_LIMIT2 (BALANCE_NUMBER * 16)
858
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL * 4)
995
                        #define MOVEMENT_LIMIT 20000
859
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16)
996
        // Pitch +++++++++++++++++++++++++++++++++++++++++++++++++
860
#define BEWEGUNGS_LIMIT 20000
997
                        cnt = 1;// + labs(IntegralErrorPitch) / 4096;
861
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
998
                        CorrectionPitch = 0;
862
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
999
                        if(labs(MeanIntegralPitch_old - MeanIntegralPitch) < MOVEMENT_LIMIT)
-
 
1000
                        {
863
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT)
1001
                                if(IntegralErrorPitch >  ERROR_LIMIT2)
864
        {
1002
                                {
865
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
1003
                                        if(last_n_p)
866
         {
1004
                                        {
867
           if(last_n_p)
1005
                                                cnt += labs(IntegralErrorPitch) / ERROR_LIMIT2;
868
           {
1006
                                                CorrectionPitch = IntegralErrorPitch / 8;
869
            cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
1007
                                                if(CorrectionPitch > 5000) CorrectionPitch = 5000;
870
            ausgleichNick = IntegralFehlerNick / 8;
1008
                                                AttitudeCorrectionPitch += CorrectionPitch / BALANCE_NUMBER;
-
 
1009
                                        }
871
            if(ausgleichNick > 5000) ausgleichNick = 5000;
1010
                                        else last_n_p = 1;
872
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1011
                                }
873
           }
1012
                                else  last_n_p = 0;
874
           else last_n_p = 1;
1013
                                if(IntegralErrorPitch < -ERROR_LIMIT2)
875
         } else  last_n_p = 0;
1014
                                {
876
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
-
 
877
         {
1015
                                        if(last_n_n)
878
           if(last_n_n)
1016
                                        {
879
            {
1017
                                                cnt += labs(IntegralErrorPitch) / ERROR_LIMIT2;
880
             cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
1018
                                                CorrectionPitch = IntegralErrorPitch / 8;
881
             ausgleichNick = IntegralFehlerNick / 8;
1019
                                                if(CorrectionPitch < -5000) CorrectionPitch = -5000;
882
             if(ausgleichNick < -5000) ausgleichNick = -5000;
1020
                                                AttitudeCorrectionPitch += CorrectionPitch / BALANCE_NUMBER;
883
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1021
                                        }
884
            }
1022
                                        else last_n_n = 1;
885
           else last_n_n = 1;
1023
                                }
886
         } else  last_n_n = 0;
1024
                                else  last_n_n = 0;
887
        }
1025
                        }
888
        else
1026
                        else
889
        {
1027
                        {
-
 
1028
                                cnt = 0;
890
         cnt = 0;
1029
                                BadCompassHeading = 500;
891
         KompassSignalSchlecht = 500;
1030
                        }
892
        }
1031
                        if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp;
893
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1032
                        // correct Gyro Offsets
894
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
1033
                        if(IntegralErrorPitch >  ERROR_LIMIT)   AdNeutralPitch += cnt;
895
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
1034
                        if(IntegralErrorPitch < -ERROR_LIMIT)   AdNeutralPitch -= cnt;
896
 
1035
 
897
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
1036
        // Roll +++++++++++++++++++++++++++++++++++++++++++++++++
898
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
1037
                        cnt = 1;// + labs(IntegralErrorPitch) / 4096;
899
 
1038
                        CorrectionRoll = 0;
900
        ausgleichRoll = 0;
1039
                        if(labs(MeanIntegralRoll_old - MeanIntegralRoll) < MOVEMENT_LIMIT)
-
 
1040
                        {
901
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT)
1041
                                if(IntegralErrorRoll >  ERROR_LIMIT2)
-
 
1042
                                {
902
        {
1043
                                        if(last_r_p)
903
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
1044
                                        {
904
         {
1045
                                                cnt += labs(IntegralErrorRoll) / ERROR_LIMIT2;
905
           if(last_r_p)
1046
                                                CorrectionRoll = IntegralErrorRoll / 8;
906
           {
1047
                                                if(CorrectionRoll > 5000) CorrectionRoll = 5000;
907
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
-
 
-
 
1048
                                                AttitudeCorrectionRoll += CorrectionRoll / BALANCE_NUMBER;
908
            ausgleichRoll = IntegralFehlerRoll / 8;
1049
                                        }
909
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
1050
                                        else last_r_p = 1;
910
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1051
                                }
-
 
1052
                                else  last_r_p = 0;
911
           }
1053
                                if(IntegralErrorRoll < -ERROR_LIMIT2)
912
           else last_r_p = 1;
1054
                                {
913
         } else  last_r_p = 0;
1055
                                        if(last_r_n)
914
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
1056
                                        {
Line 1003... Line 1195...
1003
       w = (w * Parameter_KompassWirkung) / 64;           // auf die Wirkung normieren
1195
                                BadCompassHeading = 250;
1004
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
1196
                        }
1210
        DiffRoll = MesswertRoll - StickRoll;    // Differenz bestimmen
1408
    if(Gyro_I_Factor) SumRoll += IntegralRoll * Gyro_I_Factor - StickRoll; // I-part for attitude control