Subversion Repositories FlightCtrl

Rev

Rev 688 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 688 Rev 690
1
/*#######################################################################################
1
/*#######################################################################################
2
Flight Control
2
Flight Control
3
#######################################################################################*/
3
#######################################################################################*/
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>
54
#include <stdlib.h>
55
#include <avr/io.h>
55
#include <avr/io.h>
56
 
56
 
57
#include "main.h"
57
#include "main.h"
58
#include "eeprom.h"
58
#include "eeprom.h"
59
#include "timer0.h"
59
#include "timer0.h"
60
#include "_Settings.h"
60
#include "_Settings.h"
61
#include "analog.h"
61
#include "analog.h"
62
#include "fc.h"
62
#include "fc.h"
63
#include "gps.h"
63
#include "gps.h"
64
#include "uart.h"
64
#include "uart.h"
65
#include "rc.h"
65
#include "rc.h"
66
#include "twimaster.h"
66
#include "twimaster.h"
67
 
67
 
68
unsigned char h,m,s;
68
unsigned char h,m,s;
69
volatile unsigned int I2CTimeout = 100;
69
volatile unsigned int I2CTimeout = 100;
70
volatile int MesswertNick,MesswertRoll,MesswertGier;
70
volatile int MesswertNick,MesswertRoll,MesswertGier;
71
volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
71
volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
72
volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
72
volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
73
volatile float NeutralAccZ = 0;
73
volatile float NeutralAccZ = 0;
74
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
-
 
75
volatile long IntegralNick = 0,IntegralNick2 = 0;
74
volatile long IntegralNick = 0,IntegralNick2 = 0;
76
volatile long IntegralRoll = 0,IntegralRoll2 = 0;
75
volatile long IntegralRoll = 0,IntegralRoll2 = 0;
77
volatile long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
76
volatile long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
78
volatile long Integral_Gier = 0;
77
volatile long Integral_Gier = 0;
79
volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
78
volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
80
volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
79
volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
81
volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
80
volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
82
volatile long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
81
volatile long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
83
volatile long Mess_Integral_Hoch = 0;
82
volatile long Mess_Integral_Hoch = 0;
84
volatile int  KompassValue = 0;
83
volatile int  KompassValue = 0;
85
volatile int  KompassStartwert = 0;
84
volatile int  KompassStartwert = 0;
86
volatile int  KompassRichtung = 0;
85
volatile int  KompassRichtung = 0;
87
unsigned char MAX_GAS,MIN_GAS;
86
unsigned char MAX_GAS,MIN_GAS;
88
unsigned char Notlandung = 0;
87
unsigned char Notlandung = 0;
89
unsigned char HoehenReglerAktiv = 0;
88
unsigned char HoehenReglerAktiv = 0;
90
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
89
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
91
 
90
 
92
float GyroFaktor;
91
float GyroFaktor;
93
float IntegralFaktor;
92
float IntegralFaktor;
94
volatile int  DiffNick,DiffRoll;
93
volatile int  DiffNick,DiffRoll;
95
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
94
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
96
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
95
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
97
unsigned char MotorWert[5];
96
unsigned char MotorWert[5];
98
int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0;
97
int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0;
99
char MotorenEin = 0;
98
char MotorenEin = 0;
100
int HoehenWert = 0;
99
int HoehenWert = 0;
101
int SollHoehe = 0;
100
int SollHoehe = 0;
102
int LageKorrekturRoll = 0,LageKorrekturNick = 0;
101
int LageKorrekturRoll = 0,LageKorrekturNick = 0;
103
float Ki =  FAKTOR_I;
102
float Ki =  FAKTOR_I;
104
unsigned char Looping_Nick = 0,Looping_Roll = 0;
103
unsigned char Looping_Nick = 0,Looping_Roll = 0;
105
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
104
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
106
 
105
 
107
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
106
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
108
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
107
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
109
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
108
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
110
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
109
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
111
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
110
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
112
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
111
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
113
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
112
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
114
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
113
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
115
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
114
unsigned char Parameter_I_Factor = 10;          // Wert : 1-20
116
unsigned char Parameter_UserParam1 = 0;
115
unsigned char Parameter_UserParam1 = 0;
117
unsigned char Parameter_UserParam2 = 0;
116
unsigned char Parameter_UserParam2 = 0;
118
unsigned char Parameter_UserParam3 = 0;
117
unsigned char Parameter_UserParam3 = 0;
119
unsigned char Parameter_UserParam4 = 0;
118
unsigned char Parameter_UserParam4 = 0;
120
unsigned char Parameter_UserParam5 = 0;
119
unsigned char Parameter_UserParam5 = 0;
121
unsigned char Parameter_UserParam6 = 0;
120
unsigned char Parameter_UserParam6 = 0;
122
unsigned char Parameter_UserParam7 = 0;
121
unsigned char Parameter_UserParam7 = 0;
123
unsigned char Parameter_UserParam8 = 0;
122
unsigned char Parameter_UserParam8 = 0;
124
unsigned char Parameter_ServoNickControl = 100;
123
unsigned char Parameter_ServoNickControl = 100;
125
unsigned char Parameter_LoopGasLimit = 70;
124
unsigned char Parameter_LoopGasLimit = 70;
126
unsigned char Parameter_AchsKopplung1 = 0;
125
unsigned char Parameter_AchsKopplung1 = 0;
127
unsigned char Parameter_AchsGegenKopplung1 = 0;
126
unsigned char Parameter_AchsGegenKopplung1 = 0;
128
unsigned char Parameter_DynamicStability = 100;
127
unsigned char Parameter_DynamicStability = 100;
129
 
128
 
130
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
129
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
131
int MaxStickNick = 0,MaxStickRoll = 0;
130
int MaxStickNick = 0,MaxStickRoll = 0;
132
 
131
 
133
void Piep(unsigned char Anzahl)
132
void Piep(unsigned char Anzahl)
134
{
133
{
135
 while(Anzahl--)
134
 while(Anzahl--)
136
 {
135
 {
137
  if(MotorenEin) return; //auf keinen Fall im Flug!
136
  if(MotorenEin) return; //auf keinen Fall im Flug!
138
  BeepTime = 100;
137
  BeepTime = 100;
139
  Delay_ms(250);
138
  Delay_ms(250);
140
 }
139
 }
141
}
140
}
142
 
141
 
143
//############################################################################
142
//############################################################################
144
//  Nullwerte ermitteln
143
//  Nullwerte ermitteln
145
void SetNeutral(void)
144
void SetNeutral(void)
146
//############################################################################
145
//############################################################################
147
{
146
{
148
        NeutralAccX = 0;
147
        NeutralAccX = 0;
149
        NeutralAccY = 0;
148
        NeutralAccY = 0;
150
        NeutralAccZ = 0;
149
        NeutralAccZ = 0;
151
    AdNeutralNick = 0;
150
    AdNeutralNick = 0;
152
        AdNeutralRoll = 0;
151
        AdNeutralRoll = 0;
153
        AdNeutralGier = 0;
152
        AdNeutralGier = 0;
154
    Parameter_AchsKopplung1 = 0;
153
    Parameter_AchsKopplung1 = 0;
155
    Parameter_AchsGegenKopplung1 = 0;
154
    Parameter_AchsGegenKopplung1 = 0;
156
    CalibrierMittelwert();
155
    CalibrierMittelwert();
157
    Delay_ms_Mess(100);
156
    Delay_ms_Mess(100);
158
        CalibrierMittelwert();
157
        CalibrierMittelwert();
159
    if((ParamSet.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
158
    if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL))  // Höhenregelung aktiviert?
160
     {
159
     {
161
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
160
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
162
     }
161
     }
163
 
162
 
164
     AdNeutralNick= AdValueGyrNick;
163
     AdNeutralNick= AdValueGyrNick;
165
         AdNeutralRoll= AdValueGyrRoll;
164
         AdNeutralRoll= AdValueGyrRoll;
166
         AdNeutralGier= AdValueGyrGier;
165
         AdNeutralGier= AdValueGyrGier;
167
     StartNeutralRoll = AdNeutralRoll;
166
     StartNeutralRoll = AdNeutralRoll;
168
     StartNeutralNick = AdNeutralNick;
167
     StartNeutralNick = AdNeutralNick;
169
    if(GetParamByte(PID_ACC_NICK) > 4)
168
    if(GetParamByte(PID_ACC_NICK) > 4)
170
    {
169
    {
171
      NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
170
      NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
172
          NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
171
          NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
173
          NeutralAccZ = Current_AccZ;
172
          NeutralAccZ = Current_AccZ;
174
    }
173
    }
175
    else
174
    else
176
    {
175
    {
177
      NeutralAccX = (int)GetParamByte(PID_ACC_NICK) * 256 + (int)GetParamByte(PID_ACC_NICK+1);
176
      NeutralAccX = (int)GetParamByte(PID_ACC_NICK) * 256 + (int)GetParamByte(PID_ACC_NICK+1);
178
          NeutralAccY = (int)GetParamByte(PID_ACC_ROLL) * 256 + (int)GetParamByte(PID_ACC_ROLL+1);
177
          NeutralAccY = (int)GetParamByte(PID_ACC_ROLL) * 256 + (int)GetParamByte(PID_ACC_ROLL+1);
179
          NeutralAccZ = (int)GetParamByte(PID_ACC_Z) * 256 + (int)GetParamByte(PID_ACC_Z+1);
178
          NeutralAccZ = (int)GetParamByte(PID_ACC_Z) * 256 + (int)GetParamByte(PID_ACC_Z+1);
180
    }
179
    }
181
 
180
 
182
        Mess_IntegralNick = 0;
181
        Mess_IntegralNick = 0;
183
    Mess_IntegralNick2 = 0;
182
    Mess_IntegralNick2 = 0;
184
    Mess_IntegralRoll = 0;
183
    Mess_IntegralRoll = 0;
185
    Mess_IntegralRoll2 = 0;
184
    Mess_IntegralRoll2 = 0;
186
    Mess_Integral_Gier = 0;
185
    Mess_Integral_Gier = 0;
187
    MesswertNick = 0;
186
    MesswertNick = 0;
188
    MesswertRoll = 0;
187
    MesswertRoll = 0;
189
    MesswertGier = 0;
188
    MesswertGier = 0;
190
    StartLuftdruck = Luftdruck;
189
    StartLuftdruck = Luftdruck;
191
    HoeheD = 0;
190
    HoeheD = 0;
192
    Mess_Integral_Hoch = 0;
191
    Mess_Integral_Hoch = 0;
193
    KompassStartwert = KompassValue;
192
    KompassStartwert = KompassValue;
194
    GPS_Neutral();
193
    GPS_Neutral();
195
    BeepTime = 50;
194
    BeepTime = 50;
196
        Umschlag180Nick = (long) ParamSet.WinkelUmschlagNick * 2500L;
195
        Umschlag180Nick = (long) ParamSet.WinkelUmschlagNick * 2500L;
197
        Umschlag180Roll = (long) ParamSet.WinkelUmschlagRoll * 2500L;
196
        Umschlag180Roll = (long) ParamSet.WinkelUmschlagRoll * 2500L;
198
    ExternHoehenValue = 0;
197
    ExternHoehenValue = 0;
199
}
198
}
200
 
199
 
201
//############################################################################
200
//############################################################################
202
// Bearbeitet die Messwerte
201
// Bearbeitet die Messwerte
203
void Mittelwert(void)
202
void Mittelwert(void)
204
//############################################################################
203
//############################################################################
205
{
204
{
206
    static signed long tmpl,tmpl2;
205
    static signed long tmpl,tmpl2;
207
    MesswertGier = (signed int) AdNeutralGier - AdValueGyrGier;
206
    MesswertGier = (signed int) AdNeutralGier - AdValueGyrGier;
208
    MesswertRoll = (signed int) AdValueGyrRoll - AdNeutralRoll;
207
    MesswertRoll = (signed int) AdValueGyrRoll - AdNeutralRoll;
209
    MesswertNick = (signed int) AdValueGyrNick - AdNeutralNick;
208
    MesswertNick = (signed int) AdValueGyrNick - AdNeutralNick;
210
 
209
 
211
//DebugOut.Analog[26] = MesswertNick;
210
//DebugOut.Analog[26] = MesswertNick;
212
DebugOut.Analog[28] = MesswertRoll;
211
DebugOut.Analog[28] = MesswertRoll;
213
 
212
 
214
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
213
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
215
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 1 + ((ACC_AMPLIFY * (long)AdValueAccNick))) / 2L;
214
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 1 + ((ACC_AMPLIFY * (long)AdValueAccNick))) / 2L;
216
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 1 + ((ACC_AMPLIFY * (long)AdValueAccRoll))) / 2L;
215
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 1 + ((ACC_AMPLIFY * (long)AdValueAccRoll))) / 2L;
217
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 1 + ((long)AdValueAccTop)) / 2L;
216
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 1 + ((long)AdValueAccTop)) / 2L;
218
    IntegralAccNick += ACC_AMPLIFY * AdValueAccNick;
217
    IntegralAccNick += ACC_AMPLIFY * AdValueAccNick;
219
    IntegralAccRoll += ACC_AMPLIFY * AdValueAccRoll;
218
    IntegralAccRoll += ACC_AMPLIFY * AdValueAccRoll;
220
    IntegralAccZ    += Current_AccZ - NeutralAccZ;
219
    IntegralAccZ    += Current_AccZ - NeutralAccZ;
221
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
220
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
222
            Mess_Integral_Gier +=  MesswertGier;
221
            Mess_Integral_Gier +=  MesswertGier;
223
            Mess_Integral_Gier2 += MesswertGier;
222
            Mess_Integral_Gier2 += MesswertGier;
224
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
223
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
225
      if(!Looping_Nick && !Looping_Roll && (ParamSet.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
224
      if(!Looping_Nick && !Looping_Roll && (ParamSet.GlobalConfig & CFG_AXIS_COUPLING_ACTIVE))
226
         {
225
         {
227
            tmpl = Mess_IntegralNick / 4096L;
226
            tmpl = Mess_IntegralNick / 4096L;
228
            tmpl *= MesswertGier;
227
            tmpl *= MesswertGier;
229
            tmpl *= Parameter_AchsKopplung1;  //125
228
            tmpl *= Parameter_AchsKopplung1;  //125
230
            tmpl /= 2048L;
229
            tmpl /= 2048L;
231
            tmpl2 = Mess_IntegralRoll / 4096L;
230
            tmpl2 = Mess_IntegralRoll / 4096L;
232
            tmpl2 *= MesswertGier;
231
            tmpl2 *= MesswertGier;
233
            tmpl2 *= Parameter_AchsKopplung1;
232
            tmpl2 *= Parameter_AchsKopplung1;
234
            tmpl2 /= 2048L;
233
            tmpl2 /= 2048L;
235
         }
234
         }
236
      else  tmpl = tmpl2 = 0;
235
      else  tmpl = tmpl2 = 0;
237
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
236
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
238
            MesswertRoll += tmpl;
237
            MesswertRoll += tmpl;
239
            MesswertRoll += (tmpl2*Parameter_AchsGegenKopplung1)/512L; //109
238
            MesswertRoll += (tmpl2*Parameter_AchsGegenKopplung1)/512L; //109
240
            Mess_IntegralRoll2 += MesswertRoll;
239
            Mess_IntegralRoll2 += MesswertRoll;
241
            Mess_IntegralRoll +=  MesswertRoll - LageKorrekturRoll;
240
            Mess_IntegralRoll +=  MesswertRoll - LageKorrekturRoll;
242
            if(Mess_IntegralRoll > Umschlag180Roll)
241
            if(Mess_IntegralRoll > Umschlag180Roll)
243
            {
242
            {
244
             Mess_IntegralRoll  = -(Umschlag180Roll - 10000L);
243
             Mess_IntegralRoll  = -(Umschlag180Roll - 10000L);
245
             Mess_IntegralRoll2 = Mess_IntegralRoll;
244
             Mess_IntegralRoll2 = Mess_IntegralRoll;
246
            }
245
            }
247
            if(Mess_IntegralRoll <-Umschlag180Roll)
246
            if(Mess_IntegralRoll <-Umschlag180Roll)
248
            {
247
            {
249
             Mess_IntegralRoll =  (Umschlag180Roll - 10000L);
248
             Mess_IntegralRoll =  (Umschlag180Roll - 10000L);
250
             Mess_IntegralRoll2 = Mess_IntegralRoll;
249
             Mess_IntegralRoll2 = Mess_IntegralRoll;
251
            }
250
            }
252
            if(AdValueGyrRoll < 15)   MesswertRoll = -1000;
251
            if(AdValueGyrRoll < 15)   MesswertRoll = -1000;
253
            if(AdValueGyrRoll <  7)   MesswertRoll = -2000;
252
            if(AdValueGyrRoll <  7)   MesswertRoll = -2000;
254
            if(BoardRelease == 10)
253
            if(BoardRelease == 10)
255
                         {
254
                         {
256
              if(AdValueGyrRoll > 1010) MesswertRoll = +1000;
255
              if(AdValueGyrRoll > 1010) MesswertRoll = +1000;
257
              if(AdValueGyrRoll > 1017) MesswertRoll = +2000;
256
              if(AdValueGyrRoll > 1017) MesswertRoll = +2000;
258
                         }
257
                         }
259
                         else
258
                         else
260
                         {
259
                         {
261
              if(AdValueGyrRoll > 2020) MesswertRoll = +1000;
260
              if(AdValueGyrRoll > 2020) MesswertRoll = +1000;
262
              if(AdValueGyrRoll > 2034) MesswertRoll = +2000;
261
              if(AdValueGyrRoll > 2034) MesswertRoll = +2000;
263
                         }
262
                         }
264
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
263
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
265
            MesswertNick -= tmpl2;
264
            MesswertNick -= tmpl2;
266
            MesswertNick -= (tmpl*Parameter_AchsGegenKopplung1)/512L;
265
            MesswertNick -= (tmpl*Parameter_AchsGegenKopplung1)/512L;
267
            Mess_IntegralNick2 += MesswertNick;
266
            Mess_IntegralNick2 += MesswertNick;
268
            Mess_IntegralNick  += MesswertNick - LageKorrekturNick;
267
            Mess_IntegralNick  += MesswertNick - LageKorrekturNick;
269
            if(Mess_IntegralNick > Umschlag180Nick)
268
            if(Mess_IntegralNick > Umschlag180Nick)
270
            {
269
            {
271
             Mess_IntegralNick = -(Umschlag180Nick - 10000L);
270
             Mess_IntegralNick = -(Umschlag180Nick - 10000L);
272
             Mess_IntegralNick2 = Mess_IntegralNick;
271
             Mess_IntegralNick2 = Mess_IntegralNick;
273
            }
272
            }
274
            if(Mess_IntegralNick <-Umschlag180Nick)
273
            if(Mess_IntegralNick <-Umschlag180Nick)
275
            {
274
            {
276
             Mess_IntegralNick =  (Umschlag180Nick - 10000L);
275
             Mess_IntegralNick =  (Umschlag180Nick - 10000L);
277
             Mess_IntegralNick2 = Mess_IntegralNick;
276
             Mess_IntegralNick2 = Mess_IntegralNick;
278
            }
277
            }
279
            if(AdValueGyrNick < 15)   MesswertNick = -1000;
278
            if(AdValueGyrNick < 15)   MesswertNick = -1000;
280
            if(AdValueGyrNick <  7)   MesswertNick = -2000;
279
            if(AdValueGyrNick <  7)   MesswertNick = -2000;
281
            if(BoardRelease == 10)
280
            if(BoardRelease == 10)
282
                         {
281
                         {
283
              if(AdValueGyrNick > 1010) MesswertNick = +1000;
282
              if(AdValueGyrNick > 1010) MesswertNick = +1000;
284
              if(AdValueGyrNick > 1017) MesswertNick = +2000;
283
              if(AdValueGyrNick > 1017) MesswertNick = +2000;
285
                         }
284
                         }
286
                         else
285
                         else
287
                         {
286
                         {
288
              if(AdValueGyrNick > 2020) MesswertNick = +1000;
287
              if(AdValueGyrNick > 2020) MesswertNick = +1000;
289
              if(AdValueGyrNick > 2034) MesswertNick = +2000;
288
              if(AdValueGyrNick > 2034) MesswertNick = +2000;
290
                         }
289
                         }
291
//++++++++++++++++++++++++++++++++++++++++++++++++
290
//++++++++++++++++++++++++++++++++++++++++++++++++
292
// ADC einschalten
291
// ADC einschalten
293
    ADC_Enable();
292
    ADC_Enable();
294
//++++++++++++++++++++++++++++++++++++++++++++++++
293
//++++++++++++++++++++++++++++++++++++++++++++++++
295
 
294
 
296
    Integral_Gier  = Mess_Integral_Gier;
295
    Integral_Gier  = Mess_Integral_Gier;
297
    IntegralNick = Mess_IntegralNick;
296
    IntegralNick = Mess_IntegralNick;
298
    IntegralRoll = Mess_IntegralRoll;
297
    IntegralRoll = Mess_IntegralRoll;
299
    IntegralNick2 = Mess_IntegralNick2;
298
    IntegralNick2 = Mess_IntegralNick2;
300
    IntegralRoll2 = Mess_IntegralRoll2;
299
    IntegralRoll2 = Mess_IntegralRoll2;
301
 
300
 
302
  if(ParamSet.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
301
  if(ParamSet.GlobalConfig & CFG_ROTARY_RATE_LIMITER && !Looping_Nick && !Looping_Roll)
303
  {
302
  {
304
    if(MesswertNick > 200)       MesswertNick += 4 * (MesswertNick - 200);
303
    if(MesswertNick > 200)       MesswertNick += 4 * (MesswertNick - 200);
305
    else if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
304
    else if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
306
    if(MesswertRoll > 200)       MesswertRoll += 4 * (MesswertRoll - 200);
305
    if(MesswertRoll > 200)       MesswertRoll += 4 * (MesswertRoll - 200);
307
    else if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
306
    else if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
308
  }
307
  }
309
    if(Poti1 < PPM_in[ParamSet.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[ParamSet.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
308
    if(Poti1 < PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110 && Poti1) Poti1--;
310
    if(Poti2 < PPM_in[ParamSet.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[ParamSet.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
309
    if(Poti2 < PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110 && Poti2) Poti2--;
311
    if(Poti3 < PPM_in[ParamSet.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[ParamSet.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
310
    if(Poti3 < PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110 && Poti3) Poti3--;
312
    if(Poti4 < PPM_in[ParamSet.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[ParamSet.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
311
    if(Poti4 < PPM_in[ParamSet.ChannelAssignment[CH_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[ParamSet.ChannelAssignment[CH_POTI4]] + 110 && Poti4) Poti4--;
313
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
312
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
314
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
313
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
315
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
314
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
316
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
315
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
317
}
316
}
318
 
317
 
319
//############################################################################
318
//############################################################################
320
// Messwerte beim Ermitteln der Nullage
319
// Messwerte beim Ermitteln der Nullage
321
void CalibrierMittelwert(void)
320
void CalibrierMittelwert(void)
322
//############################################################################
321
//############################################################################
323
{
322
{
324
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
323
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
325
        ADC_Disable();
324
        ADC_Disable();
326
        MesswertNick = AdValueGyrNick;
325
        MesswertNick = AdValueGyrNick;
327
        MesswertRoll = AdValueGyrRoll;
326
        MesswertRoll = AdValueGyrRoll;
328
        MesswertGier = AdValueGyrGier;
327
        MesswertGier = AdValueGyrGier;
329
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdValueAccNick;
328
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdValueAccNick;
330
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdValueAccRoll;
329
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdValueAccRoll;
331
        Mittelwert_AccHoch = (long)AdValueAccTop;
330
        Mittelwert_AccHoch = (long)AdValueAccTop;
332
   // ADC einschalten
331
   // ADC einschalten
333
    ADC_Enable();
332
    ADC_Enable();
334
    if(Poti1 < PPM_in[ParamSet.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[ParamSet.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
333
    if(Poti1 < PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110 && Poti1) Poti1--;
335
    if(Poti2 < PPM_in[ParamSet.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[ParamSet.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
334
    if(Poti2 < PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110 && Poti2) Poti2--;
336
    if(Poti3 < PPM_in[ParamSet.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[ParamSet.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
335
    if(Poti3 < PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110 && Poti3) Poti3--;
337
    if(Poti4 < PPM_in[ParamSet.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[ParamSet.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
336
    if(Poti4 < PPM_in[ParamSet.ChannelAssignment[CH_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[ParamSet.ChannelAssignment[CH_POTI4]] + 110 && Poti4) Poti4--;
338
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
337
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
339
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
338
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
340
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
339
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
341
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
340
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
342
 
341
 
343
        Umschlag180Nick = (long) ParamSet.WinkelUmschlagNick * 2500L;
342
        Umschlag180Nick = (long) ParamSet.WinkelUmschlagNick * 2500L;
344
        Umschlag180Roll = (long) ParamSet.WinkelUmschlagNick * 2500L;
343
        Umschlag180Roll = (long) ParamSet.WinkelUmschlagNick * 2500L;
345
}
344
}
346
 
345
 
347
//############################################################################
346
//############################################################################
348
// Senden der Motorwerte per I2C-Bus
347
// Senden der Motorwerte per I2C-Bus
349
void SendMotorData(void)
348
void SendMotorData(void)
350
//############################################################################
349
//############################################################################
351
{
350
{
352
    if(MOTOR_OFF || !MotorenEin)
351
    if(MOTOR_OFF || !MotorenEin)
353
        {
352
        {
354
        Motor_Hinten = 0;
353
        Motor_Hinten = 0;
355
        Motor_Vorne = 0;
354
        Motor_Vorne = 0;
356
        Motor_Rechts = 0;
355
        Motor_Rechts = 0;
357
        Motor_Links = 0;
356
        Motor_Links = 0;
358
        if(MotorTest[0]) Motor_Vorne = MotorTest[0];
357
        if(MotorTest[0]) Motor_Vorne = MotorTest[0];
359
        if(MotorTest[1]) Motor_Hinten = MotorTest[1];
358
        if(MotorTest[1]) Motor_Hinten = MotorTest[1];
360
        if(MotorTest[2]) Motor_Links = MotorTest[2];
359
        if(MotorTest[2]) Motor_Links = MotorTest[2];
361
        if(MotorTest[3]) Motor_Rechts = MotorTest[3];
360
        if(MotorTest[3]) Motor_Rechts = MotorTest[3];
362
        }
361
        }
363
 
362
 
364
    DebugOut.Analog[12] = Motor_Vorne;
363
    DebugOut.Analog[12] = Motor_Vorne;
365
    DebugOut.Analog[13] = Motor_Hinten;
364
    DebugOut.Analog[13] = Motor_Hinten;
366
    DebugOut.Analog[14] = Motor_Links;
365
    DebugOut.Analog[14] = Motor_Links;
367
    DebugOut.Analog[15] = Motor_Rechts;
366
    DebugOut.Analog[15] = Motor_Rechts;
368
 
367
 
369
    //Start I2C Interrupt Mode
368
    //Start I2C Interrupt Mode
370
    twi_state = 0;
369
    twi_state = 0;
371
    motor = 0;
370
    motor = 0;
372
    i2c_start();
371
    i2c_start();
373
}
372
}
374
 
373
 
375
 
374
 
376
 
375
 
377
//############################################################################
376
//############################################################################
378
// Trägt ggf. das Poti als Parameter ein
377
// Trägt ggf. das Poti als Parameter ein
379
void ParameterZuordnung(void)
378
void ParameterZuordnung(void)
380
//############################################################################
379
//############################################################################
381
{
380
{
382
 
381
 
383
 #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;}
382
 #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;}
384
 CHK_POTI(Parameter_MaxHoehe,ParamSet.MaxHoehe,0,255);
383
 CHK_POTI(Parameter_MaxHoehe,ParamSet.MaxHoehe,0,255);
385
 CHK_POTI(Parameter_Luftdruck_D,ParamSet.Luftdruck_D,0,100);
384
 CHK_POTI(Parameter_Luftdruck_D,ParamSet.Luftdruck_D,0,100);
386
 CHK_POTI(Parameter_Hoehe_P,ParamSet.Hoehe_P,0,100);
385
 CHK_POTI(Parameter_Hoehe_P,ParamSet.Hoehe_P,0,100);
387
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,ParamSet.Hoehe_ACC_Wirkung,0,255);
386
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,ParamSet.Hoehe_ACC_Wirkung,0,255);
388
 CHK_POTI(Parameter_KompassWirkung,ParamSet.KompassWirkung,0,255);
387
 CHK_POTI(Parameter_KompassWirkung,ParamSet.KompassWirkung,0,255);
389
 CHK_POTI(Parameter_Gyro_P,ParamSet.Gyro_P,10,255);
388
 CHK_POTI(Parameter_Gyro_P,ParamSet.Gyro_P,10,255);
390
 CHK_POTI(Parameter_Gyro_I,ParamSet.Gyro_I,0,255);
389
 CHK_POTI(Parameter_Gyro_I,ParamSet.Gyro_I,0,255);
391
 CHK_POTI(Parameter_I_Faktor,ParamSet.I_Faktor,0,255);
390
 CHK_POTI(Parameter_I_Factor,ParamSet.I_Factor,0,255);
392
 CHK_POTI(Parameter_UserParam1,ParamSet.UserParam1,0,255);
391
 CHK_POTI(Parameter_UserParam1,ParamSet.UserParam1,0,255);
393
 CHK_POTI(Parameter_UserParam2,ParamSet.UserParam2,0,255);
392
 CHK_POTI(Parameter_UserParam2,ParamSet.UserParam2,0,255);
394
 CHK_POTI(Parameter_UserParam3,ParamSet.UserParam3,0,255);
393
 CHK_POTI(Parameter_UserParam3,ParamSet.UserParam3,0,255);
395
 CHK_POTI(Parameter_UserParam4,ParamSet.UserParam4,0,255);
394
 CHK_POTI(Parameter_UserParam4,ParamSet.UserParam4,0,255);
396
 CHK_POTI(Parameter_UserParam5,ParamSet.UserParam5,0,255);
395
 CHK_POTI(Parameter_UserParam5,ParamSet.UserParam5,0,255);
397
 CHK_POTI(Parameter_UserParam6,ParamSet.UserParam6,0,255);
396
 CHK_POTI(Parameter_UserParam6,ParamSet.UserParam6,0,255);
398
 CHK_POTI(Parameter_UserParam7,ParamSet.UserParam7,0,255);
397
 CHK_POTI(Parameter_UserParam7,ParamSet.UserParam7,0,255);
399
 CHK_POTI(Parameter_UserParam8,ParamSet.UserParam8,0,255);
398
 CHK_POTI(Parameter_UserParam8,ParamSet.UserParam8,0,255);
400
 CHK_POTI(Parameter_ServoNickControl,ParamSet.ServoNickControl,0,255);
399
 CHK_POTI(Parameter_ServoNickControl,ParamSet.ServoNickControl,0,255);
401
 CHK_POTI(Parameter_LoopGasLimit,ParamSet.LoopGasLimit,0,255);
400
 CHK_POTI(Parameter_LoopGasLimit,ParamSet.LoopGasLimit,0,255);
402
 CHK_POTI(Parameter_AchsKopplung1,    ParamSet.AchsKopplung1,0,255);
401
 CHK_POTI(Parameter_AchsKopplung1,    ParamSet.AchsKopplung1,0,255);
403
 CHK_POTI(Parameter_AchsGegenKopplung1,ParamSet.AchsGegenKopplung1,0,255);
402
 CHK_POTI(Parameter_AchsGegenKopplung1,ParamSet.AchsGegenKopplung1,0,255);
404
 CHK_POTI(Parameter_DynamicStability,ParamSet.DynamicStability,0,255);
403
 CHK_POTI(Parameter_DynamicStability,ParamSet.DynamicStability,0,255);
405
 
404
 
406
 Ki = (float) Parameter_I_Faktor * 0.0001;
405
 Ki = (float) Parameter_I_Factor * 0.0001;
407
 MAX_GAS = ParamSet.Gas_Max;
406
 MAX_GAS = ParamSet.Gas_Max;
408
 MIN_GAS = ParamSet.Gas_Min;
407
 MIN_GAS = ParamSet.Gas_Min;
409
}
408
}
410
 
409
 
411
 
410
 
412
//############################################################################
411
//############################################################################
413
//
412
//
414
void MotorRegler(void)
413
void MotorRegler(void)
415
//############################################################################
414
//############################################################################
416
{
415
{
417
         int motorwert,pd_ergebnis,h,tmp_int;
416
         int motorwert,pd_ergebnis,h,tmp_int;
418
         int GierMischanteil,GasMischanteil;
417
         int GierMischanteil,GasMischanteil;
419
     static long SummeNick=0,SummeRoll=0;
418
     static long SummeNick=0,SummeRoll=0;
420
     static long sollGier = 0,tmp_long,tmp_long2;
419
     static long sollGier = 0,tmp_long,tmp_long2;
421
     static long IntegralFehlerNick = 0;
420
     static long IntegralFehlerNick = 0;
422
     static long IntegralFehlerRoll = 0;
421
     static long IntegralFehlerRoll = 0;
423
         static unsigned int RcLostTimer;
422
         static unsigned int RcLostTimer;
424
         static unsigned char delay_neutral = 0;
423
         static unsigned char delay_neutral = 0;
425
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
424
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
426
         static unsigned int  modell_fliegt = 0;
425
         static unsigned int  modell_fliegt = 0;
427
     static int hoehenregler = 0;
426
     static int hoehenregler = 0;
428
     static char TimerWerteausgabe = 0;
427
     static char TimerWerteausgabe = 0;
429
     static char NeueKompassRichtungMerken = 0;
428
     static char NeueKompassRichtungMerken = 0;
430
     static long ausgleichNick, ausgleichRoll;
429
     static long ausgleichNick, ausgleichRoll;
431
 
430
 
432
        Mittelwert();
431
        Mittelwert();
433
 
432
 
434
    GRN_ON;
433
    GRN_ON;
435
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
434
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
436
// Gaswert ermitteln
435
// Gaswert ermitteln
437
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
436
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
438
        GasMischanteil = StickGas;
437
        GasMischanteil = StickGas;
439
    if(GasMischanteil < 0) GasMischanteil = 0;
438
    if(GasMischanteil < 0) GasMischanteil = 0;
440
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
439
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
441
// Emfang schlecht
440
// Emfang schlecht
442
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
441
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
443
   if(SenderOkay < 100)
442
   if(SenderOkay < 100)
444
        {
443
        {
445
        if(!PcZugriff)
444
        if(!PcZugriff)
446
         {
445
         {
447
           if(BeepModulation == 0xFFFF)
446
           if(BeepModulation == 0xFFFF)
448
            {
447
            {
449
             BeepTime = 15000; // 1.5 seconds
448
             BeepTime = 15000; // 1.5 seconds
450
             BeepModulation = 0x0C00;
449
             BeepModulation = 0x0C00;
451
            }
450
            }
452
         }
451
         }
453
        if(RcLostTimer) RcLostTimer--;
452
        if(RcLostTimer) RcLostTimer--;
454
        else
453
        else
455
         {
454
         {
456
          MotorenEin = 0;
455
          MotorenEin = 0;
457
          Notlandung = 0;
456
          Notlandung = 0;
458
         }
457
         }
459
        ROT_ON;
458
        ROT_ON;
460
        if(modell_fliegt > 2000)  // wahrscheinlich in der Luft --> langsam absenken
459
        if(modell_fliegt > 2000)  // wahrscheinlich in der Luft --> langsam absenken
461
            {
460
            {
462
            GasMischanteil = ParamSet.NotGas;
461
            GasMischanteil = ParamSet.EmergencyGas;
463
            Notlandung = 1;
462
            Notlandung = 1;
464
            PPM_in[ParamSet.Kanalbelegung[K_NICK]] = 0;
463
            PPM_in[ParamSet.ChannelAssignment[CH_NICK]] = 0;
465
            PPM_in[ParamSet.Kanalbelegung[K_ROLL]] = 0;
464
            PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] = 0;
466
            PPM_in[ParamSet.Kanalbelegung[K_GIER]] = 0;
465
            PPM_in[ParamSet.ChannelAssignment[CH_GIER]] = 0;
467
            }
466
            }
468
         else MotorenEin = 0;
467
         else MotorenEin = 0;
469
        }
468
        }
470
        else
469
        else
471
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
470
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
472
// Emfang gut
471
// Emfang gut
473
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
472
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
474
        if(SenderOkay > 140)
473
        if(SenderOkay > 140)
475
            {
474
            {
476
            Notlandung = 0;
475
            Notlandung = 0;
477
            RcLostTimer = ParamSet.NotGasZeit * 50;
476
            RcLostTimer = ParamSet.EmergencyGasDuration * 50;
478
            if(GasMischanteil > 40)
477
            if(GasMischanteil > 40)
479
                {
478
                {
480
                if(modell_fliegt < 0xffff) modell_fliegt++;
479
                if(modell_fliegt < 0xffff) modell_fliegt++;
481
                }
480
                }
482
            if((modell_fliegt < 200) || (GasMischanteil < 40))
481
            if((modell_fliegt < 200) || (GasMischanteil < 40))
483
                {
482
                {
484
                SummeNick = 0;
483
                SummeNick = 0;
485
                SummeRoll = 0;
484
                SummeRoll = 0;
486
                Mess_Integral_Gier = 0;
485
                Mess_Integral_Gier = 0;
487
                Mess_Integral_Gier2 = 0;
486
                Mess_Integral_Gier2 = 0;
488
                }
487
                }
489
            if((PPM_in[ParamSet.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0)
488
            if((PPM_in[ParamSet.ChannelAssignment[CH_GAS]] > 80) && MotorenEin == 0)
490
                {
489
                {
491
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
490
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
492
// auf Nullwerte kalibrieren
491
// auf Nullwerte kalibrieren
493
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
492
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
494
                if(PPM_in[ParamSet.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
493
                if(PPM_in[ParamSet.ChannelAssignment[CH_GIER]] > 75)  // Neutralwerte
495
                    {
494
                    {
496
                    if(++delay_neutral > 200)  // nicht sofort
495
                    if(++delay_neutral > 200)  // nicht sofort
497
                        {
496
                        {
498
                        GRN_OFF;
497
                        GRN_OFF;
499
                        MotorenEin = 0;
498
                        MotorenEin = 0;
500
                        delay_neutral = 0;
499
                        delay_neutral = 0;
501
                        modell_fliegt = 0;
500
                        modell_fliegt = 0;
502
                        if(PPM_in[ParamSet.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[ParamSet.Kanalbelegung[K_ROLL]]) > 70)
501
                        if(PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > 70 || abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) > 70)
503
                        {
502
                        {
504
                         unsigned char setting=1;
503
                         unsigned char setting=1;
505
                         if(PPM_in[ParamSet.Kanalbelegung[K_ROLL]] > 70 && PPM_in[ParamSet.Kanalbelegung[K_NICK]] < 70) setting = 1;
504
                         if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > 70 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < 70) setting = 1;
506
                         if(PPM_in[ParamSet.Kanalbelegung[K_ROLL]] > 70 && PPM_in[ParamSet.Kanalbelegung[K_NICK]] > 70) setting = 2;
505
                         if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > 70 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > 70) setting = 2;
507
                         if(PPM_in[ParamSet.Kanalbelegung[K_ROLL]] < 70 && PPM_in[ParamSet.Kanalbelegung[K_NICK]] > 70) setting = 3;
506
                         if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < 70 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > 70) setting = 3;
508
                         if(PPM_in[ParamSet.Kanalbelegung[K_ROLL]] <-70 && PPM_in[ParamSet.Kanalbelegung[K_NICK]] > 70) setting = 4;
507
                         if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] <-70 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > 70) setting = 4;
509
                         if(PPM_in[ParamSet.Kanalbelegung[K_ROLL]] <-70 && PPM_in[ParamSet.Kanalbelegung[K_NICK]] < 70) setting = 5;
508
                         if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] <-70 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < 70) setting = 5;
510
                         SetActiveParamSet(setting);  // aktiven Datensatz merken
509
                         SetActiveParamSet(setting);  // aktiven Datensatz merken
511
                        }
510
                        }
512
                        if((ParamSet.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
511
                        if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL))  // Höhenregelung aktiviert?
513
                          {
512
                          {
514
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
513
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
515
                          }
514
                          }
516
                            ParamSet_ReadFromEEProm(GetActiveParamSet());
515
                            ParamSet_ReadFromEEProm(GetActiveParamSet());
517
                        SetNeutral();
516
                        SetNeutral();
518
                        Piep(GetActiveParamSet());
517
                        Piep(GetActiveParamSet());
519
                        }
518
                        }
520
                    }
519
                    }
521
                 else
520
                 else
522
                if(PPM_in[ParamSet.Kanalbelegung[K_GIER]] < -75)  // ACC Neutralwerte speichern
521
                if(PPM_in[ParamSet.ChannelAssignment[CH_GIER]] < -75)  // ACC Neutralwerte speichern
523
                    {
522
                    {
524
                    if(++delay_neutral > 200)  // nicht sofort
523
                    if(++delay_neutral > 200)  // nicht sofort
525
                        {
524
                        {
526
                        GRN_OFF;
525
                        GRN_OFF;
527
                        SetParamByte(PID_ACC_NICK,0xFF); // Werte löschen
526
                        SetParamByte(PID_ACC_NICK,0xFF); // Werte löschen
528
                        MotorenEin = 0;
527
                        MotorenEin = 0;
529
                        delay_neutral = 0;
528
                        delay_neutral = 0;
530
                        modell_fliegt = 0;
529
                        modell_fliegt = 0;
531
                        SetNeutral();
530
                        SetNeutral();
532
                        SetParamByte(PID_ACC_NICK, NeutralAccX / 256); // ACC-NeutralWerte speichern
531
                        SetParamByte(PID_ACC_NICK, NeutralAccX / 256); // ACC-NeutralWerte speichern
533
                        SetParamByte(PID_ACC_NICK+1,NeutralAccX % 256); // ACC-NeutralWerte speichern
532
                        SetParamByte(PID_ACC_NICK+1,NeutralAccX % 256); // ACC-NeutralWerte speichern
534
                        SetParamByte(PID_ACC_ROLL,NeutralAccY / 256);
533
                        SetParamByte(PID_ACC_ROLL,NeutralAccY / 256);
535
                        SetParamByte(PID_ACC_ROLL+1,NeutralAccY % 256);
534
                        SetParamByte(PID_ACC_ROLL+1,NeutralAccY % 256);
536
                        SetParamByte(PID_ACC_Z,(int)NeutralAccZ / 256);
535
                        SetParamByte(PID_ACC_Z,(int)NeutralAccZ / 256);
537
                        SetParamByte(PID_ACC_Z+1,(int)NeutralAccZ % 256);
536
                        SetParamByte(PID_ACC_Z+1,(int)NeutralAccZ % 256);
538
                        Piep(GetActiveParamSet());
537
                        Piep(GetActiveParamSet());
539
                        }
538
                        }
540
                    }
539
                    }
541
                 else delay_neutral = 0;
540
                 else delay_neutral = 0;
542
                }
541
                }
543
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
542
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
544
// Gas ist unten
543
// Gas ist unten
545
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
544
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
546
            if(PPM_in[ParamSet.Kanalbelegung[K_GAS]] < 35-120)
545
            if(PPM_in[ParamSet.ChannelAssignment[CH_GAS]] < 35-120)
547
                {
546
                {
548
                // Starten
547
                // Starten
549
                if(PPM_in[ParamSet.Kanalbelegung[K_GIER]] < -75)
548
                if(PPM_in[ParamSet.ChannelAssignment[CH_GIER]] < -75)
550
                    {
549
                    {
551
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
550
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
552
// Einschalten
551
// Einschalten
553
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
552
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
554
                    if(++delay_einschalten > 200)
553
                    if(++delay_einschalten > 200)
555
                        {
554
                        {
556
                        delay_einschalten = 200;
555
                        delay_einschalten = 200;
557
                        modell_fliegt = 1;
556
                        modell_fliegt = 1;
558
                        MotorenEin = 1;
557
                        MotorenEin = 1;
559
                        sollGier = 0;
558
                        sollGier = 0;
560
                        Mess_Integral_Gier = 0;
559
                        Mess_Integral_Gier = 0;
561
                        Mess_Integral_Gier2 = 0;
560
                        Mess_Integral_Gier2 = 0;
562
                        Mess_IntegralNick = 0;
561
                        Mess_IntegralNick = 0;
563
                        Mess_IntegralRoll = 0;
562
                        Mess_IntegralRoll = 0;
564
                        Mess_IntegralNick2 = IntegralNick;
563
                        Mess_IntegralNick2 = IntegralNick;
565
                        Mess_IntegralRoll2 = IntegralRoll;
564
                        Mess_IntegralRoll2 = IntegralRoll;
566
                        SummeNick = 0;
565
                        SummeNick = 0;
567
                        SummeRoll = 0;
566
                        SummeRoll = 0;
568
                        }
567
                        }
569
                    }
568
                    }
570
                    else delay_einschalten = 0;
569
                    else delay_einschalten = 0;
571
                //Auf Neutralwerte setzen
570
                //Auf Neutralwerte setzen
572
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
571
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
573
// Auschalten
572
// Auschalten
574
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
573
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
575
                if(PPM_in[ParamSet.Kanalbelegung[K_GIER]] > 75)
574
                if(PPM_in[ParamSet.ChannelAssignment[CH_GIER]] > 75)
576
                    {
575
                    {
577
                    if(++delay_ausschalten > 200)  // nicht sofort
576
                    if(++delay_ausschalten > 200)  // nicht sofort
578
                        {
577
                        {
579
                        MotorenEin = 0;
578
                        MotorenEin = 0;
580
                        delay_ausschalten = 200;
579
                        delay_ausschalten = 200;
581
                        modell_fliegt = 0;
580
                        modell_fliegt = 0;
582
                        }
581
                        }
583
                    }
582
                    }
584
                else delay_ausschalten = 0;
583
                else delay_ausschalten = 0;
585
                }
584
                }
586
            }
585
            }
587
 
586
 
588
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
587
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
589
// neue Werte von der Funke
588
// neue Werte von der Funke
590
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
589
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
591
 if(!NewPpmData-- || Notlandung)
590
 if(!NewPpmData-- || Notlandung)
592
  {
591
  {
593
    int tmp_int;
592
    int tmp_int;
594
        static int stick_nick,stick_roll;
593
        static int stick_nick,stick_roll;
595
    ParameterZuordnung();
594
    ParameterZuordnung();
596
    StickNick = (StickNick * 3 + PPM_in[ParamSet.Kanalbelegung[K_NICK]] * ParamSet.Stick_P) / 4;
595
    StickNick = (StickNick * 3 + PPM_in[ParamSet.ChannelAssignment[CH_NICK]] * ParamSet.Stick_P) / 4;
597
    StickNick += PPM_diff[ParamSet.Kanalbelegung[K_NICK]] * ParamSet.Stick_D;
596
    StickNick += PPM_diff[ParamSet.ChannelAssignment[CH_NICK]] * ParamSet.Stick_D;
598
    StickRoll = (StickRoll * 3 + PPM_in[ParamSet.Kanalbelegung[K_ROLL]] * ParamSet.Stick_P) / 4;
597
    StickRoll = (StickRoll * 3 + PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] * ParamSet.Stick_P) / 4;
599
    StickRoll += PPM_diff[ParamSet.Kanalbelegung[K_ROLL]] * ParamSet.Stick_D;
598
    StickRoll += PPM_diff[ParamSet.ChannelAssignment[CH_ROLL]] * ParamSet.Stick_D;
600
 
599
 
601
    StickGier = -PPM_in[ParamSet.Kanalbelegung[K_GIER]];
600
    StickGier = -PPM_in[ParamSet.ChannelAssignment[CH_GIER]];
602
        StickGas  = PPM_in[ParamSet.Kanalbelegung[K_GAS]] + 120;
601
        StickGas  = PPM_in[ParamSet.ChannelAssignment[CH_GAS]] + 120;
603
 
602
 
604
   if(abs(PPM_in[ParamSet.Kanalbelegung[K_NICK]]) > MaxStickNick)
603
   if(abs(PPM_in[ParamSet.ChannelAssignment[CH_NICK]]) > MaxStickNick)
605
     MaxStickNick = abs(PPM_in[ParamSet.Kanalbelegung[K_NICK]]); else MaxStickNick--;
604
     MaxStickNick = abs(PPM_in[ParamSet.ChannelAssignment[CH_NICK]]); else MaxStickNick--;
606
   if(abs(PPM_in[ParamSet.Kanalbelegung[K_ROLL]]) > MaxStickRoll)
605
   if(abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) > MaxStickRoll)
607
     MaxStickRoll = abs(PPM_in[ParamSet.Kanalbelegung[K_ROLL]]); else MaxStickRoll--;
606
     MaxStickRoll = abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]); else MaxStickRoll--;
608
   if(Notlandung)  {MaxStickNick = 0; MaxStickRoll = 0;}
607
   if(Notlandung)  {MaxStickNick = 0; MaxStickRoll = 0;}
609
 
608
 
610
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / 256.0;
609
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / 256.0;
611
    IntegralFaktor = ((float) Parameter_Gyro_I) / 44000;
610
    IntegralFaktor = ((float) Parameter_Gyro_I) / 44000;
612
 
611
 
613
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
612
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
614
//+ Digitale Steuerung per DubWise
613
//+ Digitale Steuerung per DubWise
615
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
614
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
616
#define KEY_VALUE (Parameter_UserParam1 * 4)  //(Poti3 * 8)
615
#define KEY_VALUE (Parameter_UserParam1 * 4)  //(Poti3 * 8)
617
if(DubWiseKeys[1]) BeepTime = 10;
616
if(DubWiseKeys[1]) BeepTime = 10;
618
    if(DubWiseKeys[1] & DUB_KEY_UP)    tmp_int = KEY_VALUE;   else
617
    if(DubWiseKeys[1] & DUB_KEY_UP)    tmp_int = KEY_VALUE;   else
619
    if(DubWiseKeys[1] & DUB_KEY_DOWN)  tmp_int = -KEY_VALUE;  else   tmp_int = 0;
618
    if(DubWiseKeys[1] & DUB_KEY_DOWN)  tmp_int = -KEY_VALUE;  else   tmp_int = 0;
620
    ExternStickNick = (ExternStickNick * 7 + tmp_int) / 8;
619
    ExternStickNick = (ExternStickNick * 7 + tmp_int) / 8;
621
    if(DubWiseKeys[1] & DUB_KEY_LEFT)  tmp_int = KEY_VALUE; else
620
    if(DubWiseKeys[1] & DUB_KEY_LEFT)  tmp_int = KEY_VALUE; else
622
    if(DubWiseKeys[1] & DUB_KEY_RIGHT) tmp_int = -KEY_VALUE; else tmp_int = 0;
621
    if(DubWiseKeys[1] & DUB_KEY_RIGHT) tmp_int = -KEY_VALUE; else tmp_int = 0;
623
    ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8;
622
    ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8;
624
 
623
 
625
    if(DubWiseKeys[0] & 8)  ExternStickGier = 50;else
624
    if(DubWiseKeys[0] & 8)  ExternStickGier = 50;else
626
    if(DubWiseKeys[0] & 4)  ExternStickGier =-50;else ExternStickGier = 0;
625
    if(DubWiseKeys[0] & 4)  ExternStickGier =-50;else ExternStickGier = 0;
627
    if(DubWiseKeys[0] & 2)  ExternHoehenValue++;
626
    if(DubWiseKeys[0] & 2)  ExternHoehenValue++;
628
    if(DubWiseKeys[0] & 16) ExternHoehenValue--;
627
    if(DubWiseKeys[0] & 16) ExternHoehenValue--;
629
 
628
 
630
    StickNick += ExternStickNick / 8;
629
    StickNick += ExternStickNick / 8;
631
    StickRoll += ExternStickRoll / 8;
630
    StickRoll += ExternStickRoll / 8;
632
    StickGier += ExternStickGier;
631
    StickGier += ExternStickGier;
633
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
632
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
634
//+ Analoge Steuerung per Seriell
633
//+ Analoge Steuerung per Seriell
635
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
634
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
636
   if(ExternControl.Config & 0x01 && Parameter_UserParam1 > 128)
635
   if(ExternControl.Config & 0x01 && Parameter_UserParam1 > 128)
637
    {
636
    {
638
         StickNick += (int) ExternControl.Nick * (int) ParamSet.Stick_P;
637
         StickNick += (int) ExternControl.Nick * (int) ParamSet.Stick_P;
639
         StickRoll += (int) ExternControl.Roll * (int) ParamSet.Stick_P;
638
         StickRoll += (int) ExternControl.Roll * (int) ParamSet.Stick_P;
640
         StickGier += ExternControl.Gier;
639
         StickGier += ExternControl.Gier;
641
     ExternHoehenValue =  (int) ExternControl.Hight * (int)ParamSet.Hoehe_Verstaerkung;
640
     ExternHoehenValue =  (int) ExternControl.Hight * (int)ParamSet.Hoehe_Verstaerkung;
642
     if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
641
     if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
643
    }
642
    }
644
 
643
 
645
    if(ParamSet.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
644
    if(ParamSet.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
646
    if(GyroFaktor < 0) GyroFaktor = 0;
645
    if(GyroFaktor < 0) GyroFaktor = 0;
647
    if(IntegralFaktor < 0) IntegralFaktor = 0;
646
    if(IntegralFaktor < 0) IntegralFaktor = 0;
648
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
647
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
649
// Looping?
648
// Looping?
650
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
649
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
651
  if((PPM_in[ParamSet.Kanalbelegung[K_ROLL]] > ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
650
  if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_LEFT)  Looping_Links = 1;
652
  else
651
  else
653
   {
652
   {
654
     {
653
     {
655
      if((PPM_in[ParamSet.Kanalbelegung[K_ROLL]] < (ParamSet.LoopThreshold - ParamSet.LoopHysterese))) Looping_Links = 0;
654
      if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < (ParamSet.LoopThreshold - ParamSet.LoopHysteresis))) Looping_Links = 0;
656
     }
655
     }
657
   }
656
   }
658
  if((PPM_in[ParamSet.Kanalbelegung[K_ROLL]] < -ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
657
  if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < -ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_RIGHT) Looping_Rechts = 1;
659
   else
658
   else
660
   {
659
   {
661
   if(Looping_Rechts) // Hysterese
660
   if(Looping_Rechts) // Hysterese
662
     {
661
     {
663
      if(PPM_in[ParamSet.Kanalbelegung[K_ROLL]] > -(ParamSet.LoopThreshold - ParamSet.LoopHysterese)) Looping_Rechts = 0;
662
      if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > -(ParamSet.LoopThreshold - ParamSet.LoopHysteresis)) Looping_Rechts = 0;
664
     }
663
     }
665
   }
664
   }
666
 
665
 
667
  if((PPM_in[ParamSet.Kanalbelegung[K_NICK]] > ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
666
  if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_UP) Looping_Oben = 1;
668
  else
667
  else
669
   {
668
   {
670
    if(Looping_Oben)  // Hysterese
669
    if(Looping_Oben)  // Hysterese
671
     {
670
     {
672
      if((PPM_in[ParamSet.Kanalbelegung[K_NICK]] < (ParamSet.LoopThreshold - ParamSet.LoopHysterese))) Looping_Oben = 0;
671
      if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < (ParamSet.LoopThreshold - ParamSet.LoopHysteresis))) Looping_Oben = 0;
673
     }
672
     }
674
   }
673
   }
675
  if((PPM_in[ParamSet.Kanalbelegung[K_NICK]] < -ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
674
  if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < -ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_DOWN) Looping_Unten = 1;
676
   else
675
   else
677
   {
676
   {
678
    if(Looping_Unten) // Hysterese
677
    if(Looping_Unten) // Hysterese
679
     {
678
     {
680
      if(PPM_in[ParamSet.Kanalbelegung[K_NICK]] > -(ParamSet.LoopThreshold - ParamSet.LoopHysterese)) Looping_Unten = 0;
679
      if(PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > -(ParamSet.LoopThreshold - ParamSet.LoopHysteresis)) Looping_Unten = 0;
681
     }
680
     }
682
   }
681
   }
683
 
682
 
684
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
683
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
685
   if(Looping_Oben  || Looping_Unten) {Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
684
   if(Looping_Oben  || Looping_Unten) {Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
686
  } // Ende neue Funken-Werte
685
  } // Ende neue Funken-Werte
687
 
686
 
688
  if(Looping_Roll) BeepTime = 100;
687
  if(Looping_Roll) BeepTime = 100;
689
  if(Looping_Roll || Looping_Nick)
688
  if(Looping_Roll || Looping_Nick)
690
   {
689
   {
691
    if(GasMischanteil > ParamSet.LoopGasLimit) GasMischanteil = ParamSet.LoopGasLimit;
690
    if(GasMischanteil > ParamSet.LoopGasLimit) GasMischanteil = ParamSet.LoopGasLimit;
692
   }
691
   }
693
 
692
 
694
 
693
 
695
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
694
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
696
// Bei Empfangsausfall im Flug
695
// Bei Empfangsausfall im Flug
697
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
696
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
698
   if(Notlandung)
697
   if(Notlandung)
699
    {
698
    {
700
     StickGier = 0;
699
     StickGier = 0;
701
     StickNick = 0;
700
     StickNick = 0;
702
     StickRoll = 0;
701
     StickRoll = 0;
703
     GyroFaktor  = 0.1;
702
     GyroFaktor  = 0.1;
704
     IntegralFaktor = 0.005;
703
     IntegralFaktor = 0.005;
705
     Looping_Roll = 0;
704
     Looping_Roll = 0;
706
     Looping_Nick = 0;
705
     Looping_Nick = 0;
707
    }
706
    }
708
 
707
 
709
 
708
 
710
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
709
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
711
// Integrale auf ACC-Signal abgleichen
710
// Integrale auf ACC-Signal abgleichen
712
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
711
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
713
#define ABGLEICH_ANZAHL 256L
712
#define ABGLEICH_ANZAHL 256L
714
 
713
 
715
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
714
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
716
 MittelIntegralRoll  += IntegralRoll;
715
 MittelIntegralRoll  += IntegralRoll;
717
 MittelIntegralNick2 += IntegralNick2;
716
 MittelIntegralNick2 += IntegralNick2;
718
 MittelIntegralRoll2 += IntegralRoll2;
717
 MittelIntegralRoll2 += IntegralRoll2;
719
 
718
 
720
 if(Looping_Nick || Looping_Roll)
719
 if(Looping_Nick || Looping_Roll)
721
  {
720
  {
722
    IntegralAccNick = 0;
721
    IntegralAccNick = 0;
723
    IntegralAccRoll = 0;
722
    IntegralAccRoll = 0;
724
    MittelIntegralNick = 0;
723
    MittelIntegralNick = 0;
725
    MittelIntegralRoll = 0;
724
    MittelIntegralRoll = 0;
726
    MittelIntegralNick2 = 0;
725
    MittelIntegralNick2 = 0;
727
    MittelIntegralRoll2 = 0;
726
    MittelIntegralRoll2 = 0;
728
    Mess_IntegralNick2 = Mess_IntegralNick;
727
    Mess_IntegralNick2 = Mess_IntegralNick;
729
    Mess_IntegralRoll2 = Mess_IntegralRoll;
728
    Mess_IntegralRoll2 = Mess_IntegralRoll;
730
    ZaehlMessungen = 0;
729
    ZaehlMessungen = 0;
731
    LageKorrekturNick = 0;
730
    LageKorrekturNick = 0;
732
    LageKorrekturRoll = 0;
731
    LageKorrekturRoll = 0;
733
  }
732
  }
734
 
733
 
735
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
734
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
736
  if(!Looping_Nick && !Looping_Roll)
735
  if(!Looping_Nick && !Looping_Roll)
737
  {
736
  {
738
   long tmp_long, tmp_long2;
737
   long tmp_long, tmp_long2;
739
    tmp_long = (long)(IntegralNick / ParamSet.GyroAccFaktor - (long)Mittelwert_AccNick);
738
    tmp_long = (long)(IntegralNick / ParamSet.GyroAccFaktor - (long)Mittelwert_AccNick);
740
    tmp_long2 = (long)(IntegralRoll / ParamSet.GyroAccFaktor - (long)Mittelwert_AccRoll);
739
    tmp_long2 = (long)(IntegralRoll / ParamSet.GyroAccFaktor - (long)Mittelwert_AccRoll);
741
    tmp_long /= 16;
740
    tmp_long /= 16;
742
    tmp_long2 /= 16;
741
    tmp_long2 /= 16;
743
   if((MaxStickNick > 15) || (MaxStickRoll > 15))
742
   if((MaxStickNick > 15) || (MaxStickRoll > 15))
744
    {
743
    {
745
    tmp_long  /= 3;
744
    tmp_long  /= 3;
746
    tmp_long2 /= 3;
745
    tmp_long2 /= 3;
747
    }
746
    }
748
   if(abs(PPM_in[ParamSet.Kanalbelegung[K_GIER]]) > 25)
747
   if(abs(PPM_in[ParamSet.ChannelAssignment[CH_GIER]]) > 25)
749
    {
748
    {
750
    tmp_long  /= 3;
749
    tmp_long  /= 3;
751
    tmp_long2 /= 3;
750
    tmp_long2 /= 3;
752
    }
751
    }
753
 
752
 
754
 #define AUSGLEICH 32
753
 #define AUSGLEICH 32
755
    if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
754
    if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
756
    if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
755
    if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
757
    if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
756
    if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
758
    if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
757
    if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
759
 
758
 
760
    Mess_IntegralNick -= tmp_long;
759
    Mess_IntegralNick -= tmp_long;
761
    Mess_IntegralRoll -= tmp_long2;
760
    Mess_IntegralRoll -= tmp_long2;
762
  }
761
  }
763
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
762
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
764
 
763
 
765
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
764
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
766
 {
765
 {
767
  static int cnt = 0;
766
  static int cnt = 0;
768
  static char last_n_p,last_n_n,last_r_p,last_r_n;
767
  static char last_n_p,last_n_n,last_r_p,last_r_n;
769
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
768
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
770
  if(!Looping_Nick && !Looping_Roll)
769
  if(!Looping_Nick && !Looping_Roll)
771
  {
770
  {
772
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
771
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
773
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
772
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
774
        IntegralAccNick = (ParamSet.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
773
        IntegralAccNick = (ParamSet.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
775
        IntegralAccRoll = (ParamSet.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
774
        IntegralAccRoll = (ParamSet.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
776
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
775
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
777
#define MAX_I 0//(Poti2/10)
776
#define MAX_I 0//(Poti2/10)
778
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
777
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
779
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
778
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
780
    ausgleichNick = IntegralFehlerNick / ParamSet.GyroAccAbgleich;
779
    ausgleichNick = IntegralFehlerNick / ParamSet.GyroAccAbgleich;
781
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++
780
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++
782
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
781
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
783
    ausgleichRoll = IntegralFehlerRoll / ParamSet.GyroAccAbgleich;
782
    ausgleichRoll = IntegralFehlerRoll / ParamSet.GyroAccAbgleich;
784
 
783
 
785
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
784
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
786
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
785
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
787
 
786
 
788
   if((MaxStickNick > 15) || (MaxStickRoll > 15) || (abs(PPM_in[ParamSet.Kanalbelegung[K_GIER]]) > 25))
787
   if((MaxStickNick > 15) || (MaxStickRoll > 15) || (abs(PPM_in[ParamSet.ChannelAssignment[CH_GIER]]) > 25))
789
    {
788
    {
790
     LageKorrekturNick /= 2;
789
     LageKorrekturNick /= 2;
791
     LageKorrekturNick /= 2;
790
     LageKorrekturNick /= 2;
792
    }
791
    }
793
 
792
 
794
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
793
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
795
// Gyro-Drift ermitteln
794
// Gyro-Drift ermitteln
796
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
795
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
797
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
796
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
798
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
797
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
799
    tmp_long  = IntegralNick2 - IntegralNick;
798
    tmp_long  = IntegralNick2 - IntegralNick;
800
    tmp_long2 = IntegralRoll2 - IntegralRoll;
799
    tmp_long2 = IntegralRoll2 - IntegralRoll;
801
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
800
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
802
 
801
 
803
    IntegralFehlerNick = tmp_long;
802
    IntegralFehlerNick = tmp_long;
804
    IntegralFehlerRoll = tmp_long2;
803
    IntegralFehlerRoll = tmp_long2;
805
    Mess_IntegralNick2 -= IntegralFehlerNick;
804
    Mess_IntegralNick2 -= IntegralFehlerNick;
806
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
805
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
807
 
806
 
808
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
807
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
809
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
808
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
810
 
809
 
811
 
810
 
812
DebugOut.Analog[17] = IntegralAccNick / 26;
811
DebugOut.Analog[17] = IntegralAccNick / 26;
813
DebugOut.Analog[18] = IntegralAccRoll / 26;
812
DebugOut.Analog[18] = IntegralAccRoll / 26;
814
DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
813
DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
815
DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
814
DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
816
DebugOut.Analog[21] = MittelIntegralNick / 26;
815
DebugOut.Analog[21] = MittelIntegralNick / 26;
817
DebugOut.Analog[22] = MittelIntegralRoll / 26;
816
DebugOut.Analog[22] = MittelIntegralRoll / 26;
818
//DebugOut.Analog[28] = ausgleichNick;
817
//DebugOut.Analog[28] = ausgleichNick;
819
DebugOut.Analog[29] = ausgleichRoll;
818
DebugOut.Analog[29] = ausgleichRoll;
820
DebugOut.Analog[30] = LageKorrekturRoll * 10;
819
DebugOut.Analog[30] = LageKorrekturRoll * 10;
821
 
820
 
822
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL * 4)
821
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL * 4)
823
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16)
822
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16)
824
#define BEWEGUNGS_LIMIT 20000
823
#define BEWEGUNGS_LIMIT 20000
825
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
824
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
826
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
825
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
827
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT)
826
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT)
828
        {
827
        {
829
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
828
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
830
         {
829
         {
831
           if(last_n_p)
830
           if(last_n_p)
832
           {
831
           {
833
            cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
832
            cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
834
            ausgleichNick = IntegralFehlerNick / 8;
833
            ausgleichNick = IntegralFehlerNick / 8;
835
            if(ausgleichNick > 5000) ausgleichNick = 5000;
834
            if(ausgleichNick > 5000) ausgleichNick = 5000;
836
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
835
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
837
           }
836
           }
838
           else last_n_p = 1;
837
           else last_n_p = 1;
839
         } else  last_n_p = 0;
838
         } else  last_n_p = 0;
840
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
839
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
841
         {
840
         {
842
           if(last_n_n)
841
           if(last_n_n)
843
            {
842
            {
844
             cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
843
             cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
845
             ausgleichNick = IntegralFehlerNick / 8;
844
             ausgleichNick = IntegralFehlerNick / 8;
846
             if(ausgleichNick < -5000) ausgleichNick = -5000;
845
             if(ausgleichNick < -5000) ausgleichNick = -5000;
847
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
846
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
848
            }
847
            }
849
           else last_n_n = 1;
848
           else last_n_n = 1;
850
         } else  last_n_n = 0;
849
         } else  last_n_n = 0;
851
        } else cnt = 0;
850
        } else cnt = 0;
852
        if(cnt > ParamSet.Driftkomp) cnt = ParamSet.Driftkomp;
851
        if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp;
853
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
852
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
854
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
853
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
855
 
854
 
856
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
855
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
857
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
856
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
858
 
857
 
859
        ausgleichRoll = 0;
858
        ausgleichRoll = 0;
860
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT)
859
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT)
861
        {
860
        {
862
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
861
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
863
         {
862
         {
864
           if(last_r_p)
863
           if(last_r_p)
865
           {
864
           {
866
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
865
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
867
            ausgleichRoll = IntegralFehlerRoll / 8;
866
            ausgleichRoll = IntegralFehlerRoll / 8;
868
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
867
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
869
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
868
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
870
           }
869
           }
871
           else last_r_p = 1;
870
           else last_r_p = 1;
872
         } else  last_r_p = 0;
871
         } else  last_r_p = 0;
873
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
872
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
874
         {
873
         {
875
           if(last_r_n)
874
           if(last_r_n)
876
           {
875
           {
877
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
876
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
878
            ausgleichRoll = IntegralFehlerRoll / 8;
877
            ausgleichRoll = IntegralFehlerRoll / 8;
879
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
878
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
880
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
879
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
881
           }
880
           }
882
           else last_r_n = 1;
881
           else last_r_n = 1;
883
         } else  last_r_n = 0;
882
         } else  last_r_n = 0;
884
        } else
883
        } else
885
        {
884
        {
886
         cnt = 0;
885
         cnt = 0;
887
        }
886
        }
888
 
887
 
889
        if(cnt > ParamSet.Driftkomp) cnt = ParamSet.Driftkomp;
888
        if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp;
890
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
889
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
891
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
890
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
892
DebugOut.Analog[27] = ausgleichRoll;
891
DebugOut.Analog[27] = ausgleichRoll;
893
DebugOut.Analog[23] = AdNeutralNick;//10*(AdNeutralNick - StartNeutralNick);
892
DebugOut.Analog[23] = AdNeutralNick;//10*(AdNeutralNick - StartNeutralNick);
894
DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll);
893
DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll);
895
  }
894
  }
896
  else
895
  else
897
  {
896
  {
898
   LageKorrekturRoll = 0;
897
   LageKorrekturRoll = 0;
899
   LageKorrekturNick = 0;
898
   LageKorrekturNick = 0;
900
  }
899
  }
901
 
900
 
902
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
901
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
903
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
902
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
904
   MittelIntegralNick_Alt = MittelIntegralNick;
903
   MittelIntegralNick_Alt = MittelIntegralNick;
905
   MittelIntegralRoll_Alt = MittelIntegralRoll;
904
   MittelIntegralRoll_Alt = MittelIntegralRoll;
906
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
905
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
907
    IntegralAccNick = 0;
906
    IntegralAccNick = 0;
908
    IntegralAccRoll = 0;
907
    IntegralAccRoll = 0;
909
    IntegralAccZ = 0;
908
    IntegralAccZ = 0;
910
    MittelIntegralNick = 0;
909
    MittelIntegralNick = 0;
911
    MittelIntegralRoll = 0;
910
    MittelIntegralRoll = 0;
912
    MittelIntegralNick2 = 0;
911
    MittelIntegralNick2 = 0;
913
    MittelIntegralRoll2 = 0;
912
    MittelIntegralRoll2 = 0;
914
    ZaehlMessungen = 0;
913
    ZaehlMessungen = 0;
915
 }
914
 }
916
//DebugOut.Analog[31] = StickRoll / (26*IntegralFaktor);
915
//DebugOut.Analog[31] = StickRoll / (26*IntegralFaktor);
917
 
916
 
918
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
917
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
919
//  Gieren
918
//  Gieren
920
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
919
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
921
    if(abs(StickGier) > 20) // war 35
920
    if(abs(StickGier) > 20) // war 35
922
     {
921
     {
923
      if(!(ParamSet.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1;
922
      if(!(ParamSet.GlobalConfig & CFG_COMPASS_FIX)) NeueKompassRichtungMerken = 1;
924
     }
923
     }
925
    tmp_int  = (long) ParamSet.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
924
    tmp_int  = (long) ParamSet.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
926
    tmp_int += (ParamSet.Gier_P * StickGier) / 4;
925
    tmp_int += (ParamSet.Gier_P * StickGier) / 4;
927
    sollGier = tmp_int;
926
    sollGier = tmp_int;
928
    Mess_Integral_Gier -= tmp_int;
927
    Mess_Integral_Gier -= tmp_int;
929
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
928
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
930
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
929
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
931
 
930
 
932
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
931
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
933
//  Kompass
932
//  Kompass
934
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
933
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
935
    if(KompassValue && (ParamSet.GlobalConfig & CFG_KOMPASS_AKTIV))
934
    if(KompassValue && (ParamSet.GlobalConfig & CFG_COMPASS_ACTIVE))
936
     {
935
     {
937
       int w,v;
936
       int w,v;
938
       static int SignalSchlecht = 0;
937
       static int SignalSchlecht = 0;
939
       w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
938
       w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
940
       v = abs(IntegralRoll /512);
939
       v = abs(IntegralRoll /512);
941
       if(v > w) w = v; // grösste Neigung ermitteln
940
       if(v > w) w = v; // grösste Neigung ermitteln
942
       if(w < 25 && NeueKompassRichtungMerken && !SignalSchlecht)
941
       if(w < 25 && NeueKompassRichtungMerken && !SignalSchlecht)
943
        {
942
        {
944
         KompassStartwert = KompassValue;
943
         KompassStartwert = KompassValue;
945
         NeueKompassRichtungMerken = 0;
944
         NeueKompassRichtungMerken = 0;
946
        }
945
        }
947
       w = (w * Parameter_KompassWirkung) / 64;           // auf die Wirkung normieren
946
       w = (w * Parameter_KompassWirkung) / 64;           // auf die Wirkung normieren
948
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
947
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
949
       if(w > 0)
948
       if(w > 0)
950
        {
949
        {
951
          if(!SignalSchlecht) Mess_Integral_Gier += (KompassRichtung * w) / 32;  // nach Kompass ausrichten
950
          if(!SignalSchlecht) Mess_Integral_Gier += (KompassRichtung * w) / 32;  // nach Kompass ausrichten
952
          if(SignalSchlecht) SignalSchlecht--;
951
          if(SignalSchlecht) SignalSchlecht--;
953
        }
952
        }
954
        else SignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek
953
        else SignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek
955
     }
954
     }
956
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
955
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
957
 
956
 
958
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
957
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
959
//  Debugwerte zuordnen
958
//  Debugwerte zuordnen
960
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
959
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
961
  if(!TimerWerteausgabe--)
960
  if(!TimerWerteausgabe--)
962
   {
961
   {
963
    TimerWerteausgabe = 24;
962
    TimerWerteausgabe = 24;
964
    DebugOut.Analog[0] = IntegralNick / ParamSet.GyroAccFaktor;
963
    DebugOut.Analog[0] = IntegralNick / ParamSet.GyroAccFaktor;
965
    DebugOut.Analog[1] = IntegralRoll / ParamSet.GyroAccFaktor;
964
    DebugOut.Analog[1] = IntegralRoll / ParamSet.GyroAccFaktor;
966
    DebugOut.Analog[2] = Mittelwert_AccNick;
965
    DebugOut.Analog[2] = Mittelwert_AccNick;
967
    DebugOut.Analog[3] = Mittelwert_AccRoll;
966
    DebugOut.Analog[3] = Mittelwert_AccRoll;
968
    DebugOut.Analog[4] = MesswertGier;
967
    DebugOut.Analog[4] = MesswertGier;
969
    DebugOut.Analog[5] = HoehenWert;
968
    DebugOut.Analog[5] = HoehenWert;
970
    DebugOut.Analog[6] =(Mess_Integral_Hoch / 512);
969
    DebugOut.Analog[6] =(Mess_Integral_Hoch / 512);
971
    DebugOut.Analog[8] = KompassValue;
970
    DebugOut.Analog[8] = KompassValue;
972
    DebugOut.Analog[9] = UBat;
971
    DebugOut.Analog[9] = UBat;
973
    DebugOut.Analog[10] = SenderOkay;
972
    DebugOut.Analog[10] = SenderOkay;
974
    DebugOut.Analog[16] = Mittelwert_AccHoch;
973
    DebugOut.Analog[16] = Mittelwert_AccHoch;
975
 
974
 
976
/*    DebugOut.Analog[16] = motor_rx[0];
975
/*    DebugOut.Analog[16] = motor_rx[0];
977
    DebugOut.Analog[17] = motor_rx[1];
976
    DebugOut.Analog[17] = motor_rx[1];
978
    DebugOut.Analog[18] = motor_rx[2];
977
    DebugOut.Analog[18] = motor_rx[2];
979
    DebugOut.Analog[19] = motor_rx[3];
978
    DebugOut.Analog[19] = motor_rx[3];
980
    DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3];
979
    DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3];
981
    DebugOut.Analog[20] /= 14;
980
    DebugOut.Analog[20] /= 14;
982
    DebugOut.Analog[21] = motor_rx[4];
981
    DebugOut.Analog[21] = motor_rx[4];
983
    DebugOut.Analog[22] = motor_rx[5];
982
    DebugOut.Analog[22] = motor_rx[5];
984
    DebugOut.Analog[23] = motor_rx[6];
983
    DebugOut.Analog[23] = motor_rx[6];
985
    DebugOut.Analog[24] = motor_rx[7];
984
    DebugOut.Analog[24] = motor_rx[7];
986
    DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
985
    DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
987
*/
986
*/
988
//    DebugOut.Analog[9] = MesswertNick;
987
//    DebugOut.Analog[9] = MesswertNick;
989
//    DebugOut.Analog[9] = SollHoehe;
988
//    DebugOut.Analog[9] = SollHoehe;
990
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
989
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
991
//    DebugOut.Analog[11] = KompassStartwert;
990
//    DebugOut.Analog[11] = KompassStartwert;
992
//    DebugOut.Analog[10] = Parameter_Gyro_I;
991
//    DebugOut.Analog[10] = Parameter_Gyro_I;
993
//    DebugOut.Analog[10] = ParamSet.Gyro_I;
992
//    DebugOut.Analog[10] = ParamSet.Gyro_I;
994
//    DebugOut.Analog[9] = KompassRichtung;
993
//    DebugOut.Analog[9] = KompassRichtung;
995
//    DebugOut.Analog[10] = GasMischanteil;
994
//    DebugOut.Analog[10] = GasMischanteil;
996
//    DebugOut.Analog[3] = HoeheD * 32;
995
//    DebugOut.Analog[3] = HoeheD * 32;
997
//    DebugOut.Analog[4] = hoehenregler;
996
//    DebugOut.Analog[4] = hoehenregler;
998
  }
997
  }
999
 
998
 
1000
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
999
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1001
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
1000
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
1002
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1001
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1003
//DebugOut.Analog[26] = MesswertNick;
1002
//DebugOut.Analog[26] = MesswertNick;
1004
//DebugOut.Analog[28] = MesswertRoll;
1003
//DebugOut.Analog[28] = MesswertRoll;
1005
 
1004
 
1006
    if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor;
1005
    if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor;
1007
    else             MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
1006
    else             MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
1008
    if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor;
1007
    if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor;
1009
    else             MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
1008
    else             MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
1010
    MesswertGier = MesswertGier * (2 * GyroFaktor) + Integral_Gier * IntegralFaktor / 2;
1009
    MesswertGier = MesswertGier * (2 * GyroFaktor) + Integral_Gier * IntegralFaktor / 2;
1011
 
1010
 
1012
DebugOut.Analog[25] = IntegralRoll * IntegralFaktor;
1011
DebugOut.Analog[25] = IntegralRoll * IntegralFaktor;
1013
DebugOut.Analog[31] = StickRoll;// / (26*IntegralFaktor);
1012
DebugOut.Analog[31] = StickRoll;// / (26*IntegralFaktor);
1014
DebugOut.Analog[28] = MesswertRoll;
1013
DebugOut.Analog[28] = MesswertRoll;
1015
 
1014
 
1016
    // Maximalwerte abfangen
1015
    // Maximalwerte abfangen
1017
    #define MAX_SENSOR  2048
1016
    #define MAX_SENSOR  2048
1018
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
1017
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
1019
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
1018
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
1020
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
1019
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
1021
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
1020
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
1022
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
1021
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
1023
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
1022
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
1024
 
1023
 
1025
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1024
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1026
// Höhenregelung
1025
// Höhenregelung
1027
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
1026
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
1028
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1027
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1029
//OCR0B = 180 - (Poti1 + 120) / 4;
1028
//OCR0B = 180 - (Poti1 + 120) / 4;
1030
//DruckOffsetSetting = OCR0B;
1029
//DruckOffsetSetting = OCR0B;
1031
 if((ParamSet.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
1030
 if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL))  // Höhenregelung
1032
  {
1031
  {
1033
    int tmp_int;
1032
    int tmp_int;
1034
    if(ParamSet.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1033
    if(ParamSet.GlobalConfig & CFG_HEIGHT_SWITCH)  // Regler wird über Schalter gesteuert
1035
    {
1034
    {
1036
     if(Parameter_MaxHoehe < 50)
1035
     if(Parameter_MaxHoehe < 50)
1037
      {
1036
      {
1038
       SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
1037
       SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
1039
       HoehenReglerAktiv = 0;
1038
       HoehenReglerAktiv = 0;
1040
      }
1039
      }
1041
      else
1040
      else
1042
        HoehenReglerAktiv = 1;
1041
        HoehenReglerAktiv = 1;
1043
    }
1042
    }
1044
    else
1043
    else
1045
    {
1044
    {
1046
     SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)ParamSet.Hoehe_Verstaerkung - 20;
1045
     SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)ParamSet.Hoehe_Verstaerkung - 20;
1047
     HoehenReglerAktiv = 1;
1046
     HoehenReglerAktiv = 1;
1048
    }
1047
    }
1049
 
1048
 
1050
    if(Notlandung) SollHoehe = 0;
1049
    if(Notlandung) SollHoehe = 0;
1051
    h = HoehenWert;
1050
    h = HoehenWert;
1052
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
1051
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
1053
     {      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil
1052
     {      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil
1054
      h = GasMischanteil - h;         // vom Gas abziehen
1053
      h = GasMischanteil - h;         // vom Gas abziehen
1055
      h -= (HoeheD * Parameter_Luftdruck_D)/8;    // D-Anteil
1054
      h -= (HoeheD * Parameter_Luftdruck_D)/8;    // D-Anteil
1056
      tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32;
1055
      tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32;
1057
      if(tmp_int > 50) tmp_int = 50;
1056
      if(tmp_int > 50) tmp_int = 50;
1058
      else if(tmp_int < -50) tmp_int = -50;
1057
      else if(tmp_int < -50) tmp_int = -50;
1059
      h -= tmp_int;
1058
      h -= tmp_int;
1060
      hoehenregler = (hoehenregler*15 + h) / 16;
1059
      hoehenregler = (hoehenregler*15 + h) / 16;
1061
      if(hoehenregler < ParamSet.Hoehe_MinGas) // nicht unter MIN
1060
      if(hoehenregler < ParamSet.Hoehe_MinGas) // nicht unter MIN
1062
       {
1061
       {
1063
         if(GasMischanteil >= ParamSet.Hoehe_MinGas) hoehenregler = ParamSet.Hoehe_MinGas;
1062
         if(GasMischanteil >= ParamSet.Hoehe_MinGas) hoehenregler = ParamSet.Hoehe_MinGas;
1064
         if(GasMischanteil < ParamSet.Hoehe_MinGas) hoehenregler = GasMischanteil;
1063
         if(GasMischanteil < ParamSet.Hoehe_MinGas) hoehenregler = GasMischanteil;
1065
       }
1064
       }
1066
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1065
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1067
      GasMischanteil = hoehenregler;
1066
      GasMischanteil = hoehenregler;
1068
     }
1067
     }
1069
  }
1068
  }
1070
  if(GasMischanteil > MAX_GAS - 20) GasMischanteil = MAX_GAS - 20;
1069
  if(GasMischanteil > MAX_GAS - 20) GasMischanteil = MAX_GAS - 20;
1071
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1070
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1072
// + Mischer und PI-Regler
1071
// + Mischer und PI-Regler
1073
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1072
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1074
  DebugOut.Analog[7] = GasMischanteil;
1073
  DebugOut.Analog[7] = GasMischanteil;
1075
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1074
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1076
// Gier-Anteil
1075
// Gier-Anteil
1077
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1076
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1078
#define MUL_G  1.0
1077
#define MUL_G  1.0
1079
    GierMischanteil = MesswertGier - sollGier;     // Regler für Gier
1078
    GierMischanteil = MesswertGier - sollGier;     // Regler für Gier
1080
// GierMischanteil = 0;
1079
// GierMischanteil = 0;
1081
 
1080
 
1082
    if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
1081
    if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
1083
    if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
1082
    if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
1084
    if(GierMischanteil > ((MAX_GAS - GasMischanteil))) GierMischanteil = ((MAX_GAS - GasMischanteil));
1083
    if(GierMischanteil > ((MAX_GAS - GasMischanteil))) GierMischanteil = ((MAX_GAS - GasMischanteil));
1085
    if(GierMischanteil < -((MAX_GAS - GasMischanteil))) GierMischanteil = -((MAX_GAS - GasMischanteil));
1084
    if(GierMischanteil < -((MAX_GAS - GasMischanteil))) GierMischanteil = -((MAX_GAS - GasMischanteil));
1086
 
1085
 
1087
    if(GasMischanteil < 20) GierMischanteil = 0;
1086
    if(GasMischanteil < 20) GierMischanteil = 0;
1088
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1087
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1089
// Nick-Achse
1088
// Nick-Achse
1090
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1089
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1091
    DiffNick = MesswertNick - (StickNick - GPS_Nick);   // Differenz bestimmen
1090
    DiffNick = MesswertNick - (StickNick - GPS_Nick);   // Differenz bestimmen
1092
    if(IntegralFaktor) SummeNick += IntegralNick * IntegralFaktor - (StickNick - GPS_Nick); // I-Anteil bei Winkelregelung
1091
    if(IntegralFaktor) SummeNick += IntegralNick * IntegralFaktor - (StickNick - GPS_Nick); // I-Anteil bei Winkelregelung
1093
    else  SummeNick += DiffNick; // I-Anteil bei HH
1092
    else  SummeNick += DiffNick; // I-Anteil bei HH
1094
    if(SummeNick >  16000) SummeNick =  16000;
1093
    if(SummeNick >  16000) SummeNick =  16000;
1095
    if(SummeNick < -16000) SummeNick = -16000;
1094
    if(SummeNick < -16000) SummeNick = -16000;
1096
    pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick
1095
    pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick
1097
    // Motor Vorn
1096
    // Motor Vorn
1098
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1097
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1099
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1098
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1100
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1099
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1101
 
1100
 
1102
    motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;   // Mischer
1101
    motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;   // Mischer
1103
        if ((motorwert < 0)) motorwert = 0;
1102
        if ((motorwert < 0)) motorwert = 0;
1104
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1103
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1105
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1104
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1106
        Motor_Vorne = motorwert;
1105
        Motor_Vorne = motorwert;
1107
    // Motor Heck
1106
    // Motor Heck
1108
        motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
1107
        motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
1109
        if ((motorwert < 0)) motorwert = 0;
1108
        if ((motorwert < 0)) motorwert = 0;
1110
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1109
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1111
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1110
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1112
        Motor_Hinten = motorwert;
1111
        Motor_Hinten = motorwert;
1113
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1112
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1114
// Roll-Achse
1113
// Roll-Achse
1115
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1114
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1116
        DiffRoll = MesswertRoll - (StickRoll  - GPS_Roll);      // Differenz bestimmen
1115
        DiffRoll = MesswertRoll - (StickRoll  - GPS_Roll);      // Differenz bestimmen
1117
    if(IntegralFaktor) SummeRoll += IntegralRoll * IntegralFaktor - (StickRoll  - GPS_Roll);// I-Anteil bei Winkelregelung
1116
    if(IntegralFaktor) SummeRoll += IntegralRoll * IntegralFaktor - (StickRoll  - GPS_Roll);// I-Anteil bei Winkelregelung
1118
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
1117
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
1119
    if(SummeRoll >  16000) SummeRoll =  16000;
1118
    if(SummeRoll >  16000) SummeRoll =  16000;
1120
    if(SummeRoll < -16000) SummeRoll = -16000;
1119
    if(SummeRoll < -16000) SummeRoll = -16000;
1121
    pd_ergebnis = DiffRoll + Ki * SummeRoll;    // PI-Regler für Roll
1120
    pd_ergebnis = DiffRoll + Ki * SummeRoll;    // PI-Regler für Roll
1122
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1121
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1123
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1122
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1124
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1123
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1125
    // Motor Links
1124
    // Motor Links
1126
    motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
1125
    motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
1127
#define GRENZE Poti1
1126
#define GRENZE Poti1
1128
 
1127
 
1129
        if ((motorwert < 0)) motorwert = 0;
1128
        if ((motorwert < 0)) motorwert = 0;
1130
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1129
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1131
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1130
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1132
    Motor_Links = motorwert;
1131
    Motor_Links = motorwert;
1133
    // Motor Rechts
1132
    // Motor Rechts
1134
        motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
1133
        motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
1135
 
1134
 
1136
        if ((motorwert < 0)) motorwert = 0;
1135
        if ((motorwert < 0)) motorwert = 0;
1137
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1136
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1138
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1137
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1139
    Motor_Rechts = motorwert;
1138
    Motor_Rechts = motorwert;
1140
   // +++++++++++++++++++++++++++++++++++++++++++++++
1139
   // +++++++++++++++++++++++++++++++++++++++++++++++
1141
}
1140
}
1142
 
1141
 
1143
 
1142