Rev 130 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 130 | Rev 243 | ||
---|---|---|---|
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 |
50 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
51 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
51 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
52 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
52 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
53 | // + POSSIBILITY OF SUCH DAMAGE. |
53 | // + POSSIBILITY OF SUCH DAMAGE. |
54 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
54 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | 55 | ||
56 | #include "main.h" |
56 | #include "main.h" |
57 | 57 | ||
58 | unsigned char h,m,s; |
58 | unsigned char h,m,s; |
59 | volatile unsigned char Timeout = 0; |
59 | volatile unsigned int I2CTimeout = 100; |
60 | volatile int MesswertNick,MesswertRoll,MesswertGier; |
60 | volatile int MesswertNick,MesswertRoll,MesswertGier; |
61 | volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0; |
61 | volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0; |
62 | volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0; |
62 | volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0; |
63 | volatile float NeutralAccZ = 0; |
63 | volatile float NeutralAccZ = 0; |
64 | unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0; |
64 | unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0; |
65 | volatile long IntegralNick = 0,IntegralNick2 = 0; |
65 | volatile long IntegralNick = 0,IntegralNick2 = 0; |
66 | volatile long IntegralRoll = 0,IntegralRoll2 = 0; |
66 | volatile long IntegralRoll = 0,IntegralRoll2 = 0; |
67 | volatile long Integral_Gier = 0; |
67 | volatile long Integral_Gier = 0; |
68 | volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0; |
68 | volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0; |
69 | volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0; |
69 | volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0; |
70 | volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; |
70 | volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; |
71 | volatile long Mess_Integral_Hoch = 0; |
71 | volatile long Mess_Integral_Hoch = 0; |
72 | volatile int KompassValue = 0; |
72 | volatile int KompassValue = 0; |
73 | volatile int KompassStartwert = 0; |
73 | volatile int KompassStartwert = 0; |
74 | volatile int KompassRichtung = 0; |
74 | volatile int KompassRichtung = 0; |
75 | unsigned char MAX_GAS,MIN_GAS; |
75 | unsigned char MAX_GAS,MIN_GAS; |
76 | unsigned char Notlandung = 0; |
76 | unsigned char Notlandung = 0; |
77 | unsigned char HoehenReglerAktiv = 0; |
77 | unsigned char HoehenReglerAktiv = 0; |
78 | 78 | ||
79 | float GyroFaktor; |
79 | float GyroFaktor; |
80 | float IntegralFaktor; |
80 | float IntegralFaktor; |
81 | 81 | ||
82 | volatile int DiffNick,DiffRoll; |
82 | volatile int DiffNick,DiffRoll; |
83 | int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0; |
83 | int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0; |
84 | volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count; |
84 | volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count; |
85 | unsigned char MotorWert[5]; |
85 | unsigned char MotorWert[5]; |
86 | volatile unsigned char SenderOkay = 0; |
86 | volatile unsigned char SenderOkay = 0; |
87 | int StickNick = 0,StickRoll = 0,StickGier = 0; |
87 | int StickNick = 0,StickRoll = 0,StickGier = 0; |
88 | char MotorenEin = 0; |
88 | char MotorenEin = 0; |
89 | int HoehenWert = 0; |
89 | int HoehenWert = 0; |
90 | int SollHoehe = 0; |
90 | int SollHoehe = 0; |
- | 91 | unsigned char Looping_Nick = 0,Looping_Roll = 0; |
|
91 | 92 | ||
92 | float Kp = FAKTOR_P; |
93 | float Kp = FAKTOR_P; |
93 | float Ki = FAKTOR_I; |
94 | float Ki = FAKTOR_I; |
94 | 95 | ||
95 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
96 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
96 | unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250 |
97 | unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250 |
97 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
98 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
98 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
99 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
99 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
100 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
100 | unsigned char Parameter_Gyro_P = 50; // Wert : 10-250 |
101 | unsigned char Parameter_Gyro_P = 150; // Wert : 10-250 |
101 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
102 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
102 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
103 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
103 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
104 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
104 | unsigned char Parameter_UserParam1 = 0; |
105 | unsigned char Parameter_UserParam1 = 0; |
105 | unsigned char Parameter_UserParam2 = 0; |
106 | unsigned char Parameter_UserParam2 = 0; |
106 | unsigned char Parameter_UserParam3 = 0; |
107 | unsigned char Parameter_UserParam3 = 0; |
107 | unsigned char Parameter_UserParam4 = 0; |
108 | unsigned char Parameter_UserParam4 = 0; |
108 | unsigned char Parameter_ServoNickControl = 100; |
109 | unsigned char Parameter_ServoNickControl = 100; |
- | 110 | unsigned char Parameter_LoopGasLimit = 70; |
|
109 | struct mk_param_struct EE_Parameter; |
111 | struct mk_param_struct EE_Parameter; |
110 | 112 | ||
111 | void Piep(unsigned char Anzahl) |
113 | void Piep(unsigned char Anzahl) |
112 | { |
114 | { |
113 | while(Anzahl--) |
115 | while(Anzahl--) |
114 | { |
116 | { |
115 | if(MotorenEin) return; //auf keinen Fall im Flug! |
117 | if(MotorenEin) return; //auf keinen Fall im Flug! |
116 | beeptime = 100; |
118 | beeptime = 100; |
117 | Delay_ms(250); |
119 | Delay_ms(250); |
118 | } |
120 | } |
119 | } |
121 | } |
120 | 122 | ||
121 | //############################################################################ |
123 | //############################################################################ |
122 | // Nullwerte ermitteln |
124 | // Nullwerte ermitteln |
123 | void SetNeutral(void) |
125 | void SetNeutral(void) |
124 | //############################################################################ |
126 | //############################################################################ |
125 | { |
127 | { |
126 | unsigned int timer; |
128 | unsigned int timer; |
127 | NeutralAccX = 0; |
129 | NeutralAccX = 0; |
128 | NeutralAccY = 0; |
130 | NeutralAccY = 0; |
129 | NeutralAccZ = 0; |
131 | NeutralAccZ = 0; |
130 | AdNeutralNick = 0; |
132 | AdNeutralNick = 0; |
131 | AdNeutralRoll = 0; |
133 | AdNeutralRoll = 0; |
132 | AdNeutralGier = 0; |
134 | AdNeutralGier = 0; |
133 | CalibrierMittelwert(); |
135 | CalibrierMittelwert(); |
134 | timer = SetDelay(5); |
136 | timer = SetDelay(5); |
135 | while (!CheckDelay(timer)); |
137 | while (!CheckDelay(timer)); |
136 | CalibrierMittelwert(); |
138 | CalibrierMittelwert(); |
137 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
139 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
138 | { |
140 | { |
139 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
141 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
140 | } |
142 | } |
- | 143 | ||
- | 144 | if(PlatinenVersion == 10) |
|
- | 145 | { |
|
141 | AdNeutralNick= abs(MesswertNick); |
146 | AdNeutralNick= abs(MesswertNick); |
142 | AdNeutralRoll= abs(MesswertRoll); |
147 | AdNeutralRoll= abs(MesswertRoll); |
143 | AdNeutralGier= abs(MesswertGier); |
148 | AdNeutralGier= abs(MesswertGier); |
- | 149 | } |
|
- | 150 | else |
|
- | 151 | { |
|
- | 152 | AdNeutralNick= abs(MesswertNick) / 2; |
|
- | 153 | AdNeutralRoll= abs(MesswertRoll) / 2; |
|
- | 154 | AdNeutralGier= abs(MesswertGier) / 2; |
|
- | 155 | } |
|
144 | NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY; |
156 | NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY; |
145 | NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY; |
157 | NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY; |
146 | NeutralAccZ = Aktuell_az; |
158 | NeutralAccZ = Aktuell_az; |
147 | 159 | ||
148 | Mess_IntegralNick = 0; |
160 | Mess_IntegralNick = 0; |
149 | Mess_IntegralNick2 = 0; |
161 | Mess_IntegralNick2 = 0; |
150 | Mess_IntegralRoll = 0; |
162 | Mess_IntegralRoll = 0; |
151 | Mess_IntegralRoll2 = 0; |
163 | Mess_IntegralRoll2 = 0; |
152 | Mess_Integral_Gier = 0; |
164 | Mess_Integral_Gier = 0; |
153 | MesswertNick = 0; |
165 | MesswertNick = 0; |
154 | MesswertRoll = 0; |
166 | MesswertRoll = 0; |
155 | MesswertGier = 0; |
167 | MesswertGier = 0; |
156 | StartLuftdruck = Luftdruck; |
168 | StartLuftdruck = Luftdruck; |
157 | HoeheD = 0; |
169 | HoeheD = 0; |
158 | Mess_Integral_Hoch = 0; |
170 | Mess_Integral_Hoch = 0; |
159 | KompassStartwert = KompassValue; |
171 | KompassStartwert = KompassValue; |
- | 172 | //GPS_Neutral(); |
|
160 | beeptime = 50; |
173 | beeptime = 50; |
161 | } |
174 | } |
162 | 175 | ||
163 | //############################################################################ |
176 | //############################################################################ |
164 | // Bildet den Mittelwert aus den Messwerten |
177 | // Bildet den Mittelwert aus den Messwerten |
165 | void Mittelwert(void) |
178 | void Mittelwert(void) |
166 | //############################################################################ |
179 | //############################################################################ |
167 | { |
180 | { |
168 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
181 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
169 | ANALOG_OFF; |
182 | ANALOG_OFF; |
170 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
183 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
171 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
184 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
172 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
185 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
173 | if(messanzahl_AccNick) Mittelwert_AccNick = ((long)Mittelwert_AccNick * 7 + ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick)) / 8L; |
186 | if(messanzahl_AccNick) Mittelwert_AccNick = ((long)Mittelwert_AccNick * 7 + ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick)) / 8L; |
174 | if(messanzahl_AccRoll) Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 7 + ((ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll)) / 8L; |
187 | if(messanzahl_AccRoll) Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 7 + ((ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll)) / 8L; |
175 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 7 + ((long)accumulate_AccHoch) / messanzahl_AccHoch) / 8L; |
188 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 7 + ((long)accumulate_AccHoch) / messanzahl_AccHoch) / 8L; |
176 | AccumulateNick = 0; MessanzahlNick = 0; |
189 | AccumulateNick = 0; MessanzahlNick = 0; |
177 | AccumulateRoll = 0; MessanzahlRoll = 0; |
190 | AccumulateRoll = 0; MessanzahlRoll = 0; |
178 | AccumulateGier = 0; MessanzahlGier = 0; |
191 | AccumulateGier = 0; MessanzahlGier = 0; |
179 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
192 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
180 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
193 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
181 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
194 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
182 | Integral_Gier = Mess_Integral_Gier; |
195 | Integral_Gier = Mess_Integral_Gier; |
183 | // Integral_Gier2 = Mess_Integral_Gier2; |
196 | // Integral_Gier2 = Mess_Integral_Gier2; |
184 | IntegralNick = Mess_IntegralNick; |
197 | IntegralNick = Mess_IntegralNick; |
185 | IntegralRoll = Mess_IntegralRoll; |
198 | IntegralRoll = Mess_IntegralRoll; |
186 | IntegralNick2 = Mess_IntegralNick2; |
199 | IntegralNick2 = Mess_IntegralNick2; |
187 | IntegralRoll2 = Mess_IntegralRoll2; |
200 | IntegralRoll2 = Mess_IntegralRoll2; |
188 | // ADC einschalten |
201 | // ADC einschalten |
189 | ANALOG_ON; |
202 | ANALOG_ON; |
- | 203 | ||
190 | 204 | /* |
|
191 | //------------------------------------------------------------------------------ |
205 | //------------------------------------------------------------------------------ |
192 | if(MesswertNick > 200) MesswertNick += 4 * (MesswertNick - 200); |
206 | if(MesswertNick > 200) MesswertNick += 4 * (MesswertNick - 200); |
193 | else |
207 | else |
194 | if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200); |
208 | if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200); |
195 | - | ||
196 | if(MesswertRoll > 200) MesswertRoll += 4 * (MesswertRoll - 200); |
209 | if(MesswertRoll > 200) MesswertRoll += 4 * (MesswertRoll - 200); |
197 | else |
210 | else |
198 | if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200); |
211 | if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200); |
199 | //------------------------------------------------------------------------------ |
212 | //------------------------------------------------------------------------------ |
- | 213 | */ |
|
200 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
214 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
201 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
215 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
202 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
216 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
203 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
217 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
204 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
218 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
205 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
219 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
206 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
220 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
207 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
221 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
208 | } |
222 | } |
209 | 223 | ||
210 | //############################################################################ |
224 | //############################################################################ |
211 | // Messwerte beim Ermitteln der Nullage |
225 | // Messwerte beim Ermitteln der Nullage |
212 | void CalibrierMittelwert(void) |
226 | void CalibrierMittelwert(void) |
213 | //############################################################################ |
227 | //############################################################################ |
214 | { |
228 | { |
215 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
229 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
216 | ANALOG_OFF; |
230 | ANALOG_OFF; |
217 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
231 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
218 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
232 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
219 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
233 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
220 | if(messanzahl_AccNick) Mittelwert_AccNick = ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick); |
234 | if(messanzahl_AccNick) Mittelwert_AccNick = ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick); |
221 | if(messanzahl_AccRoll) Mittelwert_AccRoll = (ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll; |
235 | if(messanzahl_AccRoll) Mittelwert_AccRoll = (ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll; |
222 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)accumulate_AccHoch) / messanzahl_AccHoch; |
236 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)accumulate_AccHoch) / messanzahl_AccHoch; |
223 | AccumulateNick = 0; MessanzahlNick = 0; |
237 | AccumulateNick = 0; MessanzahlNick = 0; |
224 | AccumulateRoll = 0; MessanzahlRoll = 0; |
238 | AccumulateRoll = 0; MessanzahlRoll = 0; |
225 | AccumulateGier = 0; MessanzahlGier = 0; |
239 | AccumulateGier = 0; MessanzahlGier = 0; |
226 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
240 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
227 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
241 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
228 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
242 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
229 | // ADC einschalten |
243 | // ADC einschalten |
230 | ANALOG_ON; |
244 | ANALOG_ON; |
231 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
245 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
232 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
246 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
233 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
247 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
234 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
248 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
235 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
249 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
236 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
250 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
237 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
251 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
238 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
252 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
239 | } |
253 | } |
240 | 254 | ||
241 | //############################################################################ |
255 | //############################################################################ |
242 | // Senden der Motorwerte per I2C-Bus |
256 | // Senden der Motorwerte per I2C-Bus |
243 | void SendMotorData(void) |
257 | void SendMotorData(void) |
244 | //############################################################################ |
258 | //############################################################################ |
245 | { |
259 | { |
246 | if(MOTOR_OFF || !MotorenEin) |
260 | if(MOTOR_OFF || !MotorenEin) |
247 | { |
261 | { |
248 | Motor_Hinten = 0; |
262 | Motor_Hinten = 0; |
249 | Motor_Vorne = 0; |
263 | Motor_Vorne = 0; |
250 | Motor_Rechts = 0; |
264 | Motor_Rechts = 0; |
251 | Motor_Links = 0; |
265 | Motor_Links = 0; |
252 | if(MotorTest[0]) Motor_Vorne = MotorTest[0]; |
266 | if(MotorTest[0]) Motor_Vorne = MotorTest[0]; |
253 | if(MotorTest[1]) Motor_Hinten = MotorTest[1]; |
267 | if(MotorTest[1]) Motor_Hinten = MotorTest[1]; |
254 | if(MotorTest[2]) Motor_Links = MotorTest[2]; |
268 | if(MotorTest[2]) Motor_Links = MotorTest[2]; |
255 | if(MotorTest[3]) Motor_Rechts = MotorTest[3]; |
269 | if(MotorTest[3]) Motor_Rechts = MotorTest[3]; |
256 | } |
270 | } |
257 | 271 | ||
258 | DebugOut.Analog[12] = Motor_Vorne; |
272 | DebugOut.Analog[12] = Motor_Vorne; |
259 | DebugOut.Analog[13] = Motor_Hinten; |
273 | DebugOut.Analog[13] = Motor_Hinten; |
260 | DebugOut.Analog[14] = Motor_Links; |
274 | DebugOut.Analog[14] = Motor_Links; |
261 | DebugOut.Analog[15] = Motor_Rechts; |
275 | DebugOut.Analog[15] = Motor_Rechts; |
262 | 276 | ||
263 | //Start I2C Interrupt Mode |
277 | //Start I2C Interrupt Mode |
264 | twi_state = 0; |
278 | twi_state = 0; |
265 | motor = 0; |
279 | motor = 0; |
266 | i2c_start(); |
280 | i2c_start(); |
267 | } |
281 | } |
268 | 282 | ||
269 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
283 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
270 | // + Konstanten |
284 | // + Konstanten |
271 | // + 0-250 -> normale Werte |
285 | // + 0-250 -> normale Werte |
272 | // + 251 -> Poti1 |
286 | // + 251 -> Poti1 |
273 | // + 252 -> Poti2 |
287 | // + 252 -> Poti2 |
274 | // + 253 -> Poti3 |
288 | // + 253 -> Poti3 |
275 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
289 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
276 | void DefaultKonstanten1(void) |
290 | void DefaultKonstanten1(void) |
277 | { |
291 | { |
278 | EE_Parameter.Kanalbelegung[K_NICK] = 1; |
292 | EE_Parameter.Kanalbelegung[K_NICK] = 1; |
279 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
293 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
280 | EE_Parameter.Kanalbelegung[K_GAS] = 3; |
294 | EE_Parameter.Kanalbelegung[K_GAS] = 3; |
281 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
295 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
282 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
296 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
283 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
297 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
284 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
298 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
285 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
299 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
286 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV | CFG_KOMPASS_FIX;//0x01; |
300 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV | CFG_KOMPASS_FIX;//0x01; |
287 | EE_Parameter.Hoehe_MinGas = 30; |
301 | EE_Parameter.Hoehe_MinGas = 30; |
288 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
302 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
289 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
303 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
290 | EE_Parameter.Luftdruck_D = 70; // Wert : 0-250 |
304 | EE_Parameter.Luftdruck_D = 50; // Wert : 0-250 |
291 | EE_Parameter.Hoehe_ACC_Wirkung = 30; // Wert : 0-250 |
305 | EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250 |
292 | EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50 |
306 | EE_Parameter.Hoehe_Verstaerkung = 4; // Wert : 0-50 |
293 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
307 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
294 | EE_Parameter.Stick_D = 8; //8 // Wert : 0-64 |
308 | EE_Parameter.Stick_D = 8; //8 // Wert : 0-64 |
295 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
309 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
296 | EE_Parameter.Gas_Min = 15; // Wert : 0-32 |
310 | EE_Parameter.Gas_Min = 15; // Wert : 0-32 |
297 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
311 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
298 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
312 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
299 | EE_Parameter.KompassWirkung = 128; // Wert : 0-250 |
313 | EE_Parameter.KompassWirkung = 128; // Wert : 0-250 |
300 | EE_Parameter.Gyro_P = 120; //80 // Wert : 0-250 |
314 | EE_Parameter.Gyro_P = 120; //80 // Wert : 0-250 |
301 | EE_Parameter.Gyro_I = 150; // Wert : 0-250 |
315 | EE_Parameter.Gyro_I = 150; // Wert : 0-250 |
302 | EE_Parameter.UnterspannungsWarnung = 90; // Wert : 0-250 |
316 | EE_Parameter.UnterspannungsWarnung = 94; // Wert : 0-250 |
303 | EE_Parameter.NotGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
317 | EE_Parameter.NotGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
304 | EE_Parameter.NotGasZeit = 20; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
318 | EE_Parameter.NotGasZeit = 20; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
305 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
319 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
306 | EE_Parameter.I_Faktor = 5; |
320 | EE_Parameter.I_Faktor = 0; |
307 | EE_Parameter.UserParam1 = 0; //zur freien Verwendung |
321 | EE_Parameter.UserParam1 = 0; //zur freien Verwendung |
308 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
322 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
309 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
323 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
310 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
324 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
311 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
325 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
312 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
326 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
313 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
327 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
314 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
328 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
315 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
329 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
316 | EE_Parameter.ServoNickRefresh = 5; |
330 | EE_Parameter.ServoNickRefresh = 5; |
- | 331 | EE_Parameter.LoopGasLimit = 50; |
|
- | 332 | EE_Parameter.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag |
|
- | 333 | EE_Parameter.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts / wird getrennt behandelt |
|
317 | memcpy(EE_Parameter.Name, "Normal\0", 12); |
334 | memcpy(EE_Parameter.Name, "Sport\0", 12); |
318 | } |
335 | } |
319 | 336 | ||
320 | void DefaultKonstanten2(void) |
337 | void DefaultKonstanten2(void) |
321 | { |
338 | { |
322 | EE_Parameter.Kanalbelegung[K_NICK] = 1; |
339 | EE_Parameter.Kanalbelegung[K_NICK] = 1; |
323 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
340 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
324 | EE_Parameter.Kanalbelegung[K_GAS] = 3; |
341 | EE_Parameter.Kanalbelegung[K_GAS] = 3; |
325 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
342 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
326 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
343 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
327 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
344 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
328 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
345 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
- | 346 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
|
329 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV;//0x01; |
347 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV;//0x01; |
330 | EE_Parameter.Hoehe_MinGas = 30; |
348 | EE_Parameter.Hoehe_MinGas = 30; |
331 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
349 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
332 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
350 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
333 | EE_Parameter.Luftdruck_D = 50; // Wert : 0-250 |
351 | EE_Parameter.Luftdruck_D = 50; // Wert : 0-250 |
334 | EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250 |
352 | EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250 |
335 | EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50 |
353 | EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50 |
336 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
354 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
337 | EE_Parameter.Stick_D = 0; //8 // Wert : 0-64 |
355 | EE_Parameter.Stick_D = 0; //8 // Wert : 0-64 |
338 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
356 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
339 | EE_Parameter.Gas_Min = 15; // Wert : 0-32 |
357 | EE_Parameter.Gas_Min = 15; // Wert : 0-32 |
340 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
358 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
341 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
359 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
342 | EE_Parameter.KompassWirkung = 128; // Wert : 0-250 |
360 | EE_Parameter.KompassWirkung = 128; // Wert : 0-250 |
343 | EE_Parameter.Gyro_P = 175; //80 // Wert : 0-250 |
361 | EE_Parameter.Gyro_P = 175; //80 // Wert : 0-250 |
344 | EE_Parameter.Gyro_I = 175; // Wert : 0-250 |
362 | EE_Parameter.Gyro_I = 175; // Wert : 0-250 |
345 | EE_Parameter.UnterspannungsWarnung = 90; // Wert : 0-250 |
363 | EE_Parameter.UnterspannungsWarnung = 94; // Wert : 0-250 |
346 | EE_Parameter.NotGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
364 | EE_Parameter.NotGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
347 | EE_Parameter.NotGasZeit = 20; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
365 | EE_Parameter.NotGasZeit = 20; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
348 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
366 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
349 | EE_Parameter.I_Faktor = 5; |
367 | EE_Parameter.I_Faktor = 0; |
350 | EE_Parameter.UserParam1 = 0; //zur freien Verwendung |
368 | EE_Parameter.UserParam1 = 0; //zur freien Verwendung |
351 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
369 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
352 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
370 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
353 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
371 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
354 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
- | |
355 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
- | |
356 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
372 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
357 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
373 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
358 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
374 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
359 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
375 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
360 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
376 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
361 | EE_Parameter.ServoNickRefresh = 5; |
377 | EE_Parameter.ServoNickRefresh = 5; |
- | 378 | EE_Parameter.LoopGasLimit = 50; |
|
- | 379 | EE_Parameter.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag |
|
- | 380 | EE_Parameter.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts |
|
362 | memcpy(EE_Parameter.Name, "Kamera\0", 12); |
381 | memcpy(EE_Parameter.Name, "Kamera\0", 12); |
363 | } |
382 | } |
364 | 383 | ||
365 | 384 | ||
366 | //############################################################################ |
385 | //############################################################################ |
367 | // Trägt ggf. das Poti als Parameter ein |
386 | // Trägt ggf. das Poti als Parameter ein |
368 | void ParameterZuordnung(void) |
387 | void ParameterZuordnung(void) |
369 | //############################################################################ |
388 | //############################################################################ |
370 | { |
389 | { |
371 | 390 | ||
372 | #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;} |
391 | #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;} |
373 | CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255); |
392 | CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255); |
374 | CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
393 | CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
375 | CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
394 | CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
376 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255); |
395 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255); |
377 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255); |
396 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255); |
378 | CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
397 | CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
379 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255); |
398 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255); |
380 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255); |
399 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255); |
381 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255); |
400 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255); |
382 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255); |
401 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255); |
383 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255); |
402 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255); |
384 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255); |
403 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255); |
385 | - | ||
386 | unsigned char ServoNickComp; // Wert : 0-250 // Einfluss Gyro/Servo |
- | |
387 | unsigned char ServoNickCompInvert; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
- | |
388 | unsigned char ServoNickMin; // Wert : 0-250 // Anschlag |
- | |
389 | unsigned char ServoNickMax; // Wert : 0-250 // Anschlag |
- | |
390 | - | ||
391 | - | ||
392 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
404 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
393 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
405 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
394 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
406 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
- | 407 | CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255); |
|
395 | 408 | ||
396 | Ki = (float) Parameter_I_Faktor * 0.0001; |
409 | Ki = (float) Parameter_I_Faktor * 0.0001; |
397 | MAX_GAS = EE_Parameter.Gas_Max; |
410 | MAX_GAS = EE_Parameter.Gas_Max; |
398 | MIN_GAS = EE_Parameter.Gas_Min; |
411 | MIN_GAS = EE_Parameter.Gas_Min; |
399 | } |
412 | } |
400 | 413 | ||
401 | 414 | ||
402 | //############################################################################ |
415 | //############################################################################ |
403 | // |
416 | // |
404 | void MotorRegler(void) |
417 | void MotorRegler(void) |
405 | //############################################################################ |
418 | //############################################################################ |
406 | { |
419 | { |
407 | int motorwert,pd_ergebnis,h,tmp_int; |
420 | int motorwert,pd_ergebnis,h,tmp_int; |
408 | int GierMischanteil,GasMischanteil; |
421 | int GierMischanteil,GasMischanteil; |
409 | static long SummeNick=0,SummeRoll=0; |
422 | static long SummeNick=0,SummeRoll=0; |
410 | static long sollGier = 0,tmp_long,tmp_long2; |
423 | static long sollGier = 0,tmp_long,tmp_long2; |
411 | static int IntegralFehlerNick = 0; |
424 | long IntegralFehlerNick = 0; |
412 | static int IntegralFehlerRoll = 0; |
425 | long IntegralFehlerRoll = 0; |
413 | static unsigned int RcLostTimer; |
426 | static unsigned int RcLostTimer; |
414 | static unsigned char delay_neutral = 0; |
427 | static unsigned char delay_neutral = 0; |
415 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
428 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
416 | static unsigned int modell_fliegt = 0; |
429 | static unsigned int modell_fliegt = 0; |
417 | static int hoehenregler = 0; |
430 | static int hoehenregler = 0; |
418 | static char TimerWerteausgabe = 0; |
431 | static char TimerWerteausgabe = 0; |
419 | static char NeueKompassRichtungMerken = 0; |
432 | static char NeueKompassRichtungMerken = 0; |
420 | Mittelwert(); |
433 | Mittelwert(); |
421 | 434 | ||
422 | GRN_ON; |
435 | GRN_ON; |
423 | 436 | ||
424 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
437 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
425 | // Gaswert ermitteln |
438 | // Gaswert ermitteln |
426 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
439 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
427 | GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
440 | GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
428 | if(GasMischanteil < 0) GasMischanteil = 0; |
441 | if(GasMischanteil < 0) GasMischanteil = 0; |
429 | - | ||
430 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
442 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
431 | // Emfang schlecht |
443 | // Emfang schlecht |
432 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
444 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
433 | if(SenderOkay < 100) |
445 | if(SenderOkay < 100) |
434 | { |
446 | { |
- | 447 | if(!PcZugriff) |
|
- | 448 | { |
|
- | 449 | if(BeepMuster == 0xffff) |
|
- | 450 | { |
|
435 | if(!PcZugriff) beeptime = 500; |
451 | beeptime = 15000; |
- | 452 | BeepMuster = 0x0c00; |
|
- | 453 | } |
|
- | 454 | } |
|
436 | if(RcLostTimer) RcLostTimer--; |
455 | if(RcLostTimer) RcLostTimer--; |
437 | else |
456 | else |
438 | { |
457 | { |
439 | MotorenEin = 0; |
458 | MotorenEin = 0; |
440 | Notlandung = 0; |
459 | Notlandung = 0; |
441 | } |
460 | } |
442 | ROT_ON; |
461 | ROT_ON; |
443 | if(modell_fliegt > 2000) // wahrscheinlich in der Luft --> langsam absenken |
462 | if(modell_fliegt > 2000) // wahrscheinlich in der Luft --> langsam absenken |
444 | { |
463 | { |
445 | GasMischanteil = EE_Parameter.NotGas; |
464 | GasMischanteil = EE_Parameter.NotGas; |
446 | Notlandung = 1; |
465 | Notlandung = 1; |
447 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
466 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
448 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
467 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
449 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
468 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
450 | /* Poti1 = 65; |
- | |
451 | Poti2 = 48; |
- | |
452 | Poti3 = 0; |
- | |
453 | */ } |
469 | } |
454 | else MotorenEin = 0; |
470 | else MotorenEin = 0; |
455 | } |
471 | } |
456 | else |
472 | else |
457 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
473 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
458 | // Emfang gut |
474 | // Emfang gut |
459 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
475 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
460 | if(SenderOkay > 140) |
476 | if(SenderOkay > 140) |
461 | { |
477 | { |
462 | Notlandung = 0; |
478 | Notlandung = 0; |
463 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
479 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
464 | if(GasMischanteil > 40) |
480 | if(GasMischanteil > 40) |
465 | { |
481 | { |
466 | if(modell_fliegt < 0xffff) modell_fliegt++; |
482 | if(modell_fliegt < 0xffff) modell_fliegt++; |
467 | } |
483 | } |
468 | if((modell_fliegt < 200) || (GasMischanteil < 40)) |
484 | if((modell_fliegt < 200) || (GasMischanteil < 40)) |
469 | { |
485 | { |
470 | SummeNick = 0; |
486 | SummeNick = 0; |
471 | SummeRoll = 0; |
487 | SummeRoll = 0; |
472 | Mess_Integral_Gier = 0; |
488 | Mess_Integral_Gier = 0; |
473 | Mess_Integral_Gier2 = 0; |
489 | Mess_Integral_Gier2 = 0; |
474 | } |
490 | } |
475 | if((GasMischanteil > 200) && MotorenEin == 0) |
491 | if((GasMischanteil > 200) && MotorenEin == 0) |
476 | { |
492 | { |
477 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
493 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
478 | // auf Nullwerte kalibrieren |
494 | // auf Nullwerte kalibrieren |
479 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
495 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
480 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
496 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
481 | { |
497 | { |
482 | unsigned char setting; |
498 | unsigned char setting; |
483 | if(++delay_neutral > 200) // nicht sofort |
499 | if(++delay_neutral > 200) // nicht sofort |
484 | { |
500 | { |
485 | GRN_OFF; |
501 | GRN_OFF; |
486 | SetNeutral(); |
- | |
487 | MotorenEin = 0; |
502 | MotorenEin = 0; |
488 | delay_neutral = 0; |
503 | delay_neutral = 0; |
489 | modell_fliegt = 0; |
504 | modell_fliegt = 0; |
490 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
505 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
491 | { |
506 | { |
492 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
507 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
493 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
508 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
494 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
509 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
495 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
510 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
496 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
511 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
497 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting); // aktiven Datensatz merken |
512 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting); // aktiven Datensatz merken |
498 | } |
513 | } |
499 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
- | |
500 | Piep(GetActiveParamSetNumber()); |
- | |
501 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
514 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
502 | { |
515 | { |
503 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
516 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
504 | } |
517 | } |
- | 518 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
|
- | 519 | SetNeutral(); |
|
- | 520 | Piep(GetActiveParamSetNumber()); |
|
505 | } |
521 | } |
506 | } |
522 | } |
507 | else delay_neutral = 0; |
523 | else delay_neutral = 0; |
508 | } |
524 | } |
509 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
525 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
510 | // Gas ist unten |
526 | // Gas ist unten |
511 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
527 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
512 | if(GasMischanteil < 35) |
528 | if(GasMischanteil < 35) |
513 | { |
529 | { |
514 | // Starten |
530 | // Starten |
515 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
531 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
516 | { |
532 | { |
517 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
533 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
518 | // Einschalten |
534 | // Einschalten |
519 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
535 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
520 | if(++delay_einschalten > 200) |
536 | if(++delay_einschalten > 200) |
521 | { |
537 | { |
522 | delay_einschalten = 200; |
538 | delay_einschalten = 200; |
523 | modell_fliegt = 1; |
539 | modell_fliegt = 1; |
524 | MotorenEin = 1; |
540 | MotorenEin = 1; |
525 | sollGier = 0; |
541 | sollGier = 0; |
526 | Mess_Integral_Gier = 0; |
542 | Mess_Integral_Gier = 0; |
527 | Mess_Integral_Gier2 = 0; |
543 | Mess_Integral_Gier2 = 0; |
528 | Mess_IntegralNick = 0; |
544 | Mess_IntegralNick = 0; |
529 | Mess_IntegralRoll = 0; |
545 | Mess_IntegralRoll = 0; |
530 | Mess_IntegralNick2 = IntegralNick; |
546 | Mess_IntegralNick2 = IntegralNick; |
531 | Mess_IntegralRoll2 = IntegralRoll; |
547 | Mess_IntegralRoll2 = IntegralRoll; |
532 | SummeNick = 0; |
548 | SummeNick = 0; |
533 | SummeRoll = 0; |
549 | SummeRoll = 0; |
534 | } |
550 | } |
535 | } |
551 | } |
536 | else delay_einschalten = 0; |
552 | else delay_einschalten = 0; |
537 | //Auf Neutralwerte setzen |
553 | //Auf Neutralwerte setzen |
538 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
554 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
539 | // Auschalten |
555 | // Auschalten |
540 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
556 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
541 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
557 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
542 | { |
558 | { |
543 | if(++delay_ausschalten > 200) // nicht sofort |
559 | if(++delay_ausschalten > 200) // nicht sofort |
544 | { |
560 | { |
545 | MotorenEin = 0; |
561 | MotorenEin = 0; |
546 | delay_ausschalten = 200; |
562 | delay_ausschalten = 200; |
547 | modell_fliegt = 0; |
563 | modell_fliegt = 0; |
548 | } |
564 | } |
549 | } |
565 | } |
550 | else delay_ausschalten = 0; |
566 | else delay_ausschalten = 0; |
551 | } |
567 | } |
552 | } |
568 | } |
553 | 569 | ||
554 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
570 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
555 | // neue Werte von der Funke |
571 | // neue Werte von der Funke |
556 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
572 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
557 | if(!NewPpmData-- || Notlandung) |
573 | if(!NewPpmData-- || Notlandung) |
558 | { |
574 | { |
559 | ParameterZuordnung(); |
575 | ParameterZuordnung(); |
560 | StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P; |
576 | StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P; |
561 | StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
577 | StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
562 | StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P; |
578 | StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P; |
563 | StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
579 | StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
564 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
580 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
565 | - | ||
566 | GyroFaktor = ((float)Parameter_Gyro_P + 10.0) / 256.0; |
581 | GyroFaktor = ((float)Parameter_Gyro_P + 10.0) / 256.0; |
567 | IntegralFaktor = ((float) Parameter_Gyro_I) / 44000; |
582 | IntegralFaktor = ((float) Parameter_Gyro_I) / 44000; |
568 | 583 | ||
569 | if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
584 | if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
570 | if(GyroFaktor < 0) GyroFaktor = 0; |
585 | if(GyroFaktor < 0) GyroFaktor = 0; |
571 | if(IntegralFaktor < 0) IntegralFaktor = 0; |
586 | if(IntegralFaktor < 0) IntegralFaktor = 0; |
- | 587 | // greift in den Stick ein, um ungewolltes überschlagen zu verhindern |
|
- | 588 | if(!(EE_Parameter.LoopConfig & CFG_LOOP_LINKS) && !(EE_Parameter.LoopConfig & CFG_LOOP_RECHTS)) |
|
- | 589 | { |
|
- | 590 | if(IntegralNick > 60000) |
|
- | 591 | { |
|
- | 592 | StickNick -= 8 * EE_Parameter.Stick_P; |
|
- | 593 | if(IntegralNick > 80000) StickNick -= 16 * EE_Parameter.Stick_P; |
|
- | 594 | } |
|
- | 595 | else |
|
- | 596 | if(IntegralNick < -60000) |
|
- | 597 | { |
|
- | 598 | StickNick += 8 * EE_Parameter.Stick_P; |
|
- | 599 | if(IntegralNick > 80000) StickNick -= 16 * EE_Parameter.Stick_P; |
|
- | 600 | } |
|
- | 601 | if(IntegralRoll > 60000) |
|
- | 602 | { |
|
- | 603 | StickRoll -= 8 * EE_Parameter.Stick_P; |
|
- | 604 | if(IntegralRoll > 80000) StickRoll -= 16 * EE_Parameter.Stick_P; |
|
- | 605 | } |
|
- | 606 | else |
|
- | 607 | if(IntegralRoll < -60000) |
|
- | 608 | { |
|
- | 609 | StickRoll += 8 * EE_Parameter.Stick_P; |
|
- | 610 | if(IntegralRoll > 80000) StickRoll -= 16 * EE_Parameter.Stick_P; |
|
- | 611 | } |
|
- | 612 | } |
|
- | 613 | ||
572 | } |
614 | } |
- | 615 | ||
- | 616 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 617 | // Looping? |
|
- | 618 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 619 | if(((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_LINKS) || |
|
- | 620 | ((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_RECHTS)) |
|
- | 621 | { |
|
- | 622 | Looping_Roll = 1; |
|
- | 623 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
|
- | 624 | } |
|
- | 625 | else Looping_Roll = 0; |
|
- | 626 | ||
- | 627 | if(((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_OBEN) || |
|
- | 628 | ((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_UNTEN)) |
|
- | 629 | { |
|
- | 630 | Looping_Nick = 1; |
|
- | 631 | Looping_Roll = 0; |
|
- | 632 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
|
- | 633 | } |
|
- | 634 | else Looping_Nick = 0; |
|
- | 635 | ||
- | 636 | ||
573 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
637 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
574 | // Bei Empfangsausfall im Flug |
638 | // Bei Empfangsausfall im Flug |
575 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
639 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
576 | if(Notlandung) |
640 | if(Notlandung) |
577 | { |
641 | { |
578 | StickGier = 0; |
642 | StickGier = 0; |
579 | StickNick = 0; |
643 | StickNick = 0; |
580 | StickRoll = 0; |
644 | StickRoll = 0; |
581 | GyroFaktor = 0.1; |
645 | GyroFaktor = 0.1; |
582 | IntegralFaktor = 0.005; |
646 | IntegralFaktor = 0.005; |
- | 647 | Looping_Roll = 0; |
|
- | 648 | Looping_Nick = 0; |
|
583 | } |
649 | } |
584 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
650 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
585 | // Gyro-Drift kompensieren |
651 | // Gyro-Drift kompensieren |
586 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
652 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
587 | #define DRIFT_FAKTOR 3 |
653 | #define DRIFT_FAKTOR 3 |
588 | if(ZaehlMessungen >= 1000 / DRIFT_FAKTOR) |
654 | if(ZaehlMessungen >= 1000 / DRIFT_FAKTOR) |
589 | { |
655 | { |
590 | IntegralFehlerNick = IntegralNick2 - IntegralNick; |
656 | IntegralFehlerNick = IntegralNick2 - IntegralNick; |
591 | IntegralFehlerRoll = IntegralRoll2 - IntegralRoll; |
657 | IntegralFehlerRoll = IntegralRoll2 - IntegralRoll; |
592 | ZaehlMessungen = 0; |
658 | ZaehlMessungen = 0; |
593 | if(IntegralFehlerNick > 500/DRIFT_FAKTOR) AdNeutralNick++; |
659 | if(IntegralFehlerNick > 500/DRIFT_FAKTOR) AdNeutralNick++; |
594 | if(IntegralFehlerNick < -500/DRIFT_FAKTOR) AdNeutralNick--; |
660 | if(IntegralFehlerNick < -500/DRIFT_FAKTOR) AdNeutralNick--; |
595 | if(IntegralFehlerRoll > 500/DRIFT_FAKTOR) AdNeutralRoll++; |
661 | if(IntegralFehlerRoll > 500/DRIFT_FAKTOR) AdNeutralRoll++; |
596 | if(IntegralFehlerRoll < -500/DRIFT_FAKTOR) AdNeutralRoll--; |
662 | if(IntegralFehlerRoll < -500/DRIFT_FAKTOR) AdNeutralRoll--; |
597 | if(Mess_Integral_Gier2 > 500/DRIFT_FAKTOR) AdNeutralGier--; |
663 | // if(Mess_Integral_Gier2 > 500/DRIFT_FAKTOR) AdNeutralGier--; // macht nur mit Referenz (Kompass Sinn) |
598 | if(Mess_Integral_Gier2 <-500/DRIFT_FAKTOR) AdNeutralGier++; |
664 | // if(Mess_Integral_Gier2 <-500/DRIFT_FAKTOR) AdNeutralGier++; // macht nur mit Referenz (Kompass Sinn) |
599 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
665 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
600 | Mess_IntegralNick2 = IntegralNick; |
666 | Mess_IntegralNick2 = IntegralNick; |
601 | Mess_IntegralRoll2 = IntegralRoll; |
667 | Mess_IntegralRoll2 = IntegralRoll; |
602 | Mess_Integral_Gier2 = Integral_Gier; |
668 | Mess_Integral_Gier2 = Integral_Gier; |
603 | ANALOG_ON; // ADC einschalten |
669 | ANALOG_ON; // ADC einschalten |
604 | } |
670 | } |
605 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
671 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
606 | // Integrale auf ACC-Signal abgleichen |
672 | // Integrale auf ACC-Signal abgleichen |
607 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
673 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | 674 | ||
- | 675 | ||
- | 676 | if(EE_Parameter.GlobalConfig & CFG_GPS_AKTIV){ |
|
- | 677 | ||
608 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick) / 16; |
678 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick) / 16; |
609 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll) / 16; |
679 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll) / 16; |
610 | #define AUSGLEICH 500 |
680 | #define AUSGLEICH 500 |
611 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
681 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
612 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
682 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
613 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
683 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
614 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
684 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
615 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
685 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
616 | Mess_IntegralNick -= tmp_long; |
686 | Mess_IntegralNick -= tmp_long; |
617 | Mess_IntegralRoll -= tmp_long2; |
687 | Mess_IntegralRoll -= tmp_long2; |
- | 688 | }else{ |
|
- | 689 | ||
- | 690 | if(IntegralFaktor && !Looping_Nick && !Looping_Roll) |
|
- | 691 | { |
|
- | 692 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
|
- | 693 | if(labs(Mittelwert_AccNick) < 200) tmp_long /= 8; |
|
- | 694 | else tmp_long /= 16; |
|
- | 695 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
|
- | 696 | if(labs(Mittelwert_AccRoll) < 200) tmp_long2 /= 8; |
|
- | 697 | else tmp_long2 /= 16; |
|
- | 698 | ||
- | 699 | #define AUSGLEICH 500 |
|
- | 700 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
|
- | 701 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
|
- | 702 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
|
- | 703 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
|
- | 704 | } |
|
- | 705 | else |
|
- | 706 | { |
|
- | 707 | tmp_long = 0; |
|
- | 708 | tmp_long2 = 0; |
|
- | 709 | } |
|
- | 710 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
|
- | 711 | Mess_IntegralNick -= tmp_long; |
|
- | 712 | Mess_IntegralRoll -= tmp_long2;} |
|
- | 713 | ||
618 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
714 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
619 | // Gieren |
715 | // Gieren |
620 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
716 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
621 | sollGier = StickGier; |
- | |
622 | if(abs(StickGier) > 35) |
717 | if(abs(StickGier) > 20) // war 35 |
623 | { |
718 | { |
624 | if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1; |
719 | if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1; |
625 | } |
720 | } |
626 | tmp_int = EE_Parameter.Gier_P * (sollGier * abs(sollGier)) / 256; // expo |
721 | tmp_int = EE_Parameter.Gier_P * (StickGier * abs(StickGier)) / 512; // expo y = ax + bx² |
- | 722 | tmp_int += (EE_Parameter.Gier_P * StickGier) / 4; |
|
- | 723 | sollGier = tmp_int; |
|
627 | Mess_Integral_Gier -= tmp_int; |
724 | Mess_Integral_Gier -= tmp_int; |
628 | if(Mess_Integral_Gier > 30000) Mess_Integral_Gier = 30000; // begrenzen |
725 | if(Mess_Integral_Gier > 25000) Mess_Integral_Gier = 25000; // begrenzen |
629 | if(Mess_Integral_Gier <-30000) Mess_Integral_Gier =-30000; |
726 | if(Mess_Integral_Gier <-25000) Mess_Integral_Gier =-25000; |
630 | 727 | ||
631 | ANALOG_ON; // ADC einschalten |
728 | ANALOG_ON; // ADC einschalten |
632 | 729 | ||
633 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
730 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
634 | // Kompass |
731 | // Kompass |
635 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
732 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
636 | //KompassValue = 12; |
- | |
637 | if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)) |
733 | if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)) |
638 | { |
734 | { |
639 | int w,v; |
735 | int w,v; |
640 | static int SignalSchlecht = 0; |
736 | static int SignalSchlecht = 0; |
641 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
737 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
642 | v = abs(IntegralRoll /512); |
738 | v = abs(IntegralRoll /512); |
643 | if(v > w) w = v; // grösste Neigung ermitteln |
739 | if(v > w) w = v; // grösste Neigung ermitteln |
644 | if(w < 25 && NeueKompassRichtungMerken && !SignalSchlecht) |
740 | if(w < 25 && NeueKompassRichtungMerken && !SignalSchlecht) |
645 | { |
741 | { |
646 | KompassStartwert = KompassValue; |
742 | KompassStartwert = KompassValue; |
647 | NeueKompassRichtungMerken = 0; |
743 | NeueKompassRichtungMerken = 0; |
648 | } |
744 | } |
649 | w = (w * Parameter_KompassWirkung) / 64; // auf die Wirkung normieren |
745 | w = (w * Parameter_KompassWirkung) / 64; // auf die Wirkung normieren |
650 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
746 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
651 | if(w > 0) |
747 | if(w > 0) |
652 | { |
748 | { |
653 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
749 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
654 | if(!SignalSchlecht) Mess_Integral_Gier += (KompassRichtung * w) / 32; // nach Kompass ausrichten |
750 | if(!SignalSchlecht) Mess_Integral_Gier += (KompassRichtung * w) / 32; // nach Kompass ausrichten |
655 | ANALOG_ON; // ADC einschalten |
751 | ANALOG_ON; // ADC einschalten |
656 | if(SignalSchlecht) SignalSchlecht--; |
752 | if(SignalSchlecht) SignalSchlecht--; |
657 | } |
753 | } |
658 | else SignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek |
754 | else SignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek |
659 | } |
755 | } |
660 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
756 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
661 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
662 | 757 | ||
663 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
758 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
664 | // GPS |
759 | // GPS |
665 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
760 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
666 | if(EE_Parameter.GlobalConfig & CFG_GPS_AKTIV) |
- | |
667 | { |
761 | |
668 | gps_p = Parameter_UserParam1; |
762 | gps_p = Parameter_UserParam1; |
669 | gps_d = Parameter_UserParam2; |
763 | gps_d = Parameter_UserParam2; |
- | 764 | skal = Parameter_UserParam3; |
|
- | 765 | komp_dreh = Parameter_UserParam4*45; |
|
- | 766 | ||
- | 767 | if(EE_Parameter.GlobalConfig & CFG_GPS_AKTIV){ |
|
- | 768 | ||
- | 769 | gpsmax=40; //maximale GPS Steuerausschläge |
|
- | 770 | ||
- | 771 | if (MotorenEin == 1 && gps_gethome == 0 && actualPos.state != 0){ //speichert GPS-Home-Position |
|
- | 772 | gps_home_x = actualPos.northing; |
|
- | 773 | gps_home_y = actualPos.easting; |
|
- | 774 | home_height = HoehenWert+50; //30 |
|
670 | 775 | ||
- | 776 | beeptime = 80; |
|
671 | gps_main(); |
777 | gps_gethome = 1; |
- | 778 | } |
|
- | 779 | ||
- | 780 | if (MotorenEin ==0 && gps_gethome ==1) |
|
672 | } |
781 | {gps_gethome=0;} |
673 | else |
782 | |
- | 783 | ||
- | 784 | if (Poti1>0) { |
|
- | 785 | ||
- | 786 | gps_main(); |
|
- | 787 | }else if (Poti1>0 && actualPos.state==0){beeptime = 80;} |
|
- | 788 | if (Poti1==0){ |
|
674 | { |
789 | gps_getpos=5; |
675 | GPS_Nick = 0; |
790 | GPS_Nick=0; |
- | 791 | GPS_Roll=0; |
|
- | 792 | } |
|
676 | GPS_Roll = 0; |
793 | if (Poti2==0){homing_state=0;} |
677 | } |
794 | } |
678 | 795 | ||
- | 796 | ||
- | 797 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 798 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
679 | 799 | ||
680 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
800 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
681 | // Debugwerte zuordnen |
801 | // Debugwerte zuordnen |
682 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
802 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
683 | DebugOut.Sekunden++; |
- | |
684 | if(!TimerWerteausgabe--) |
803 | if(!TimerWerteausgabe--) |
685 | { |
804 | { |
686 | TimerWerteausgabe = 49; |
805 | TimerWerteausgabe = 49; |
687 | // DebugOut.Analog[0] = MesswertNick; |
- | |
688 | // DebugOut.Analog[1] = MesswertRoll; |
- | |
689 | // DebugOut.Analog[2] = MesswertGier; |
- | |
690 | DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor; |
806 | DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor; |
691 | DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor; |
807 | DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor; |
692 | DebugOut.Analog[2] = Mittelwert_AccNick; |
808 | DebugOut.Analog[2] = Mittelwert_AccNick; |
693 | DebugOut.Analog[3] = Mittelwert_AccRoll; |
809 | DebugOut.Analog[3] = Mittelwert_AccRoll; |
694 | DebugOut.Analog[4] = MesswertGier; |
810 | DebugOut.Analog[4] = MesswertGier; |
695 | DebugOut.Analog[5] = HoehenWert; |
811 | DebugOut.Analog[5] = HoehenWert; |
696 | DebugOut.Analog[6] = (Mess_Integral_Hoch / 512); |
812 | DebugOut.Analog[6] = (Mess_Integral_Hoch / 512); |
697 | DebugOut.Analog[7] = GasMischanteil; |
- | |
698 | DebugOut.Analog[8] = KompassValue; |
813 | DebugOut.Analog[8] = KompassValue; |
- | 814 | DebugOut.Analog[10] = gps_h_d1; |
|
- | 815 | DebugOut.Analog[11] = gps_h_d2; |
|
- | 816 | ||
- | 817 | /* DebugOut.Analog[16] = motor_rx[0]; |
|
- | 818 | DebugOut.Analog[17] = motor_rx[1]; |
|
- | 819 | DebugOut.Analog[18] = motor_rx[2]; |
|
- | 820 | DebugOut.Analog[19] = motor_rx[3]; |
|
- | 821 | DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3]; |
|
- | 822 | DebugOut.Analog[20] /= 14; |
|
- | 823 | DebugOut.Analog[21] = motor_rx[4]; |
|
- | 824 | DebugOut.Analog[22] = motor_rx[5]; |
|
- | 825 | DebugOut.Analog[23] = motor_rx[6]; |
|
- | 826 | DebugOut.Analog[24] = motor_rx[7]; |
|
- | 827 | DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7]; |
|
- | 828 | */ |
|
- | 829 | // DebugOut.Analog[9] = MesswertNick; |
|
699 | // DebugOut.Analog[9] = SollHoehe; |
830 | // DebugOut.Analog[9] = SollHoehe; |
700 | // DebugOut.Analog[10] = Mess_Integral_Gier / 128; |
831 | // DebugOut.Analog[10] = Mess_Integral_Gier / 128; |
701 | // DebugOut.Analog[11] = KompassStartwert; |
832 | // DebugOut.Analog[11] = KompassStartwert; |
702 | // DebugOut.Analog[10] = Parameter_Gyro_I; |
833 | // DebugOut.Analog[10] = Parameter_Gyro_I; |
703 | // DebugOut.Analog[10] = EE_Parameter.Gyro_I; |
834 | // DebugOut.Analog[10] = EE_Parameter.Gyro_I; |
704 | // DebugOut.Analog[9] = KompassRichtung; |
835 | // DebugOut.Analog[9] = KompassRichtung; |
705 | // DebugOut.Analog[10] = GasMischanteil; |
836 | // DebugOut.Analog[10] = GasMischanteil; |
706 | // DebugOut.Analog[3] = HoeheD * 32; |
837 | // DebugOut.Analog[3] = HoeheD * 32; |
707 | // DebugOut.Analog[4] = hoehenregler; |
838 | // DebugOut.Analog[4] = hoehenregler; |
708 | } |
839 | } |
709 | - | ||
710 | 840 | ||
711 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
841 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
712 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
842 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
713 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
843 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | 844 | if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor; |
|
714 | MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor; |
845 | else MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor; |
- | 846 | if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor; |
|
715 | MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor; |
847 | else MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor; |
716 | MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor; |
848 | // MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor; |
- | 849 | MesswertGier = MesswertGier * (GyroFaktor) + Integral_Gier * IntegralFaktor/2; |
|
717 | 850 | ||
718 | // Maximalwerte abfangen |
851 | // Maximalwerte abfangen |
719 | #define MAX_SENSOR 2048 |
852 | #define MAX_SENSOR 2048 |
720 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
853 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
721 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
854 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
722 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
855 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
723 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
856 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
724 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
857 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
725 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
858 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
726 | 859 | ||
727 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
860 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
728 | // Höhenregelung |
861 | // Höhenregelung |
729 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
862 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
730 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
863 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
731 | //OCR0B = 180 - (Poti1 + 120) / 4; |
864 | //OCR0B = 180 - (Poti1 + 120) / 4; |
732 | //DruckOffsetSetting = OCR0B; |
865 | //DruckOffsetSetting = OCR0B; |
733 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung |
866 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung |
734 | { |
867 | { |
735 | int tmp_int; |
868 | int tmp_int; |
736 | if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
869 | if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
737 | { |
870 | { |
738 | if(Parameter_MaxHoehe < 50) |
871 | if(Parameter_MaxHoehe < 50) |
739 | { |
872 | { |
740 | SollHoehe = HoehenWert - 20; // Parameter_MaxHoehe ist der PPM-Wert des Schalters |
873 | SollHoehe = HoehenWert - 20; // Parameter_MaxHoehe ist der PPM-Wert des Schalters |
741 | HoehenReglerAktiv = 0; |
874 | HoehenReglerAktiv = 0; |
742 | } |
875 | } |
743 | else |
876 | else |
744 | HoehenReglerAktiv = 1; |
877 | HoehenReglerAktiv = 1; |
745 | } |
878 | } |
746 | else |
879 | else |
747 | { |
880 | { |
748 | SollHoehe = Parameter_MaxHoehe * EE_Parameter.Hoehe_Verstaerkung - 20; |
881 | SollHoehe = Parameter_MaxHoehe * EE_Parameter.Hoehe_Verstaerkung - 20; |
749 | HoehenReglerAktiv = 1; |
882 | HoehenReglerAktiv = 1; |
750 | } |
883 | } |
751 | 884 | ||
752 | if(Notlandung) SollHoehe = 0; |
885 | if(Notlandung) SollHoehe = 0; |
753 | h = HoehenWert; |
886 | h = HoehenWert; |
754 | if((h > SollHoehe) && HoehenReglerAktiv) // zu hoch --> drosseln |
887 | if((h > SollHoehe) && HoehenReglerAktiv) // zu hoch --> drosseln |
755 | { h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil |
888 | { h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil |
756 | h = GasMischanteil - h; // vom Gas abziehen |
889 | h = GasMischanteil - h; // vom Gas abziehen |
757 | h -= (HoeheD * Parameter_Luftdruck_D)/8; // D-Anteil |
890 | h -= (HoeheD * Parameter_Luftdruck_D)/8; // D-Anteil |
758 | tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32; |
891 | tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32; |
759 | if(tmp_int > 50) tmp_int = 50; |
892 | if(tmp_int > 50) tmp_int = 50; |
760 | else if(tmp_int < -50) tmp_int = -50; |
893 | else if(tmp_int < -50) tmp_int = -50; |
761 | h -= tmp_int; |
894 | h -= tmp_int; |
762 | hoehenregler = (hoehenregler*15 + h) / 16; |
895 | hoehenregler = (hoehenregler*15 + h) / 16; |
763 | if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN |
896 | if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN |
764 | { |
897 | { |
765 | if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas; |
898 | if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas; |
766 | if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil; |
899 | if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil; |
767 | } |
900 | } |
768 | if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas |
901 | if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas |
769 | GasMischanteil = hoehenregler; |
902 | GasMischanteil = hoehenregler; |
770 | } |
903 | } |
771 | } |
904 | } |
772 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
905 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
773 | // + Mischer und PI-Regler |
906 | // + Mischer und PI-Regler |
774 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
907 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | 908 | DebugOut.Analog[7] = GasMischanteil; |
|
775 | 909 | ||
776 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
910 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
777 | // Gier-Anteil |
911 | // Gier-Anteil |
778 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
912 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | 913 | #define MUL_G 1.0 |
|
779 | GierMischanteil = MesswertGier - sollGier; // Regler für Gier |
914 | GierMischanteil = MesswertGier - sollGier; // Regler für Gier |
- | 915 | //GierMischanteil = 0; |
|
- | 916 | if(GierMischanteil > (MUL_G * GasMischanteil)) GierMischanteil = MUL_G * GasMischanteil; |
|
- | 917 | if(GierMischanteil < -(MUL_G * GasMischanteil)) GierMischanteil = -(MUL_G * GasMischanteil); |
|
780 | if(GierMischanteil > 100) GierMischanteil = 100; |
918 | if(GierMischanteil > 100) GierMischanteil = 100; |
781 | if(GierMischanteil < -100) GierMischanteil = -100; |
919 | if(GierMischanteil < -100) GierMischanteil = -100; |
- | 920 | ||
- | 921 | if(GasMischanteil < 20) GierMischanteil = 0; |
|
782 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
922 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
783 | // Nick-Achse |
923 | // Nick-Achse |
784 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
924 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | 925 | ||
785 | DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick)); // Differenz bestimmen |
926 | DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick)); // Differenz bestimmen |
786 | SummeNick += DiffNick; // I-Anteil |
927 | SummeNick += DiffNick; // I-Anteil |
787 | if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1; |
928 | if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1; |
788 | if(SummeNick > 16000) SummeNick = 16000; |
929 | if(SummeNick > 16000) SummeNick = 16000; |
789 | if(SummeNick < -16000) SummeNick = -16000; |
930 | if(SummeNick < -16000) SummeNick = -16000; |
790 | pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick |
931 | pd_ergebnis = DiffNick;// + Ki * SummeNick; // PI-Regler für Nick |
791 | // Motor Vorn |
932 | // Motor Vorn |
- | 933 | #define MUL 2 |
|
- | 934 | if(pd_ergebnis > MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = MUL * (GasMischanteil + abs(GierMischanteil)); |
|
- | 935 | if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil)); |
|
- | 936 | ||
792 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; // Mischer |
937 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; // Mischer |
793 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
938 | if ((motorwert < 0)) motorwert = 0; |
794 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
939 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
795 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
940 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
796 | Motor_Vorne = motorwert; |
941 | Motor_Vorne = motorwert; |
797 | // Motor Heck |
942 | // Motor Heck |
798 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
943 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
799 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
944 | if ((motorwert < 0)) motorwert = 0; |
800 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
945 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
801 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
946 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
802 | Motor_Hinten = motorwert; |
947 | Motor_Hinten = motorwert; |
803 | - | ||
804 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
948 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
805 | // Roll-Achse |
949 | // Roll-Achse |
806 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
950 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
807 | DiffRoll = Kp * (MesswertRoll - (StickRoll - GPS_Roll)); // Differenz bestimmen |
951 | DiffRoll = Kp * (MesswertRoll - (StickRoll - GPS_Roll)); // Differenz bestimmen |
808 | SummeRoll += DiffRoll; // I-Anteil |
952 | SummeRoll += DiffRoll; // I-Anteil |
809 | if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1; |
953 | if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1; |
810 | if(SummeRoll > 16000) SummeRoll = 16000; |
954 | if(SummeRoll > 16000) SummeRoll = 16000; |
811 | if(SummeRoll < -16000) SummeRoll = -16000; |
955 | if(SummeRoll < -16000) SummeRoll = -16000; |
812 | pd_ergebnis = DiffRoll + Ki * SummeRoll; // PI-Regler für Roll |
956 | pd_ergebnis = DiffRoll;// + Ki * SummeRoll; // PI-Regler für Roll |
- | 957 | if(pd_ergebnis > MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = MUL * (GasMischanteil + abs(GierMischanteil)); |
|
- | 958 | if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil)); |
|
813 | // Motor Links |
959 | // Motor Links |
814 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
960 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
815 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
961 | if ((motorwert < 0)) motorwert = 0; |
816 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
962 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
817 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
963 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
818 | Motor_Links = motorwert; |
964 | Motor_Links = motorwert; |
819 | // Motor Rechts |
965 | // Motor Rechts |
820 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
966 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
821 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
967 | if ((motorwert < 0)) motorwert = 0; |
822 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
968 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
823 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
969 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
824 | Motor_Rechts = motorwert; |
970 | Motor_Rechts = motorwert; |
825 | // +++++++++++++++++++++++++++++++++++++++++++++++ |
971 | // +++++++++++++++++++++++++++++++++++++++++++++++ |
826 | - | ||
827 | } |
972 | } |
828 | 973 | ||
829 | 974 |