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