Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
||
3 | // + Nur für den privaten Gebrauch |
||
4 | // + www.MikroKopter.com |
||
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1051 | killagreg | 6 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
7 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten und nicht-kommerziellen Gebrauch zulässig ist. |
||
8 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
||
9 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
||
1 | ingob | 10 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
11 | // + Verkauf von Luftbildaufnahmen, usw. |
||
12 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1051 | killagreg | 13 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
1 | ingob | 14 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
16 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
||
17 | // + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
||
18 | // + eindeutig als Ursprung verlinkt und genannt werden |
||
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
20 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
||
21 | // + Benutzung auf eigene Gefahr |
||
22 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
||
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1051 | killagreg | 24 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
1 | ingob | 25 | // + mit unserer Zustimmung zulässig |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
||
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1051 | killagreg | 29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
1 | ingob | 30 | // + this list of conditions and the following disclaimer. |
31 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
||
32 | // + from this software without specific prior written permission. |
||
1051 | killagreg | 33 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
1 | ingob | 34 | // + for non-commercial use (directly or indirectly) |
1051 | killagreg | 35 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
1 | ingob | 36 | // + with our written permission |
1051 | killagreg | 37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
38 | // + clearly linked as origin |
||
1 | ingob | 39 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
40 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
41 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
42 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
43 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
44 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
45 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
46 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
47 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
48 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
49 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
1051 | killagreg | 50 | // + POSSIBILITY OF SUCH DAMAGE. |
1 | ingob | 51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
52 | #include "main.h" |
||
53 | |||
54 | unsigned char EEPromArray[E2END+1] EEMEM; |
||
173 | holgerb | 55 | unsigned char PlatinenVersion = 10; |
723 | hbuss | 56 | unsigned char SendVersionToNavi = 1; |
1 | ingob | 57 | // -- Parametersatz aus EEPROM lesen --- |
1051 | killagreg | 58 | // number [1..5] |
1 | ingob | 59 | void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
60 | { |
||
993 | hbuss | 61 | if((number > 5)||(number < 1)) number = 3; |
1063 | killagreg | 62 | eeprom_read_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
921 | hbuss | 63 | LED_Init(); |
1 | ingob | 64 | } |
65 | |||
66 | // -- Parametersatz ins EEPROM schreiben --- |
||
1051 | killagreg | 67 | // number [1..5] |
1 | ingob | 68 | void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
69 | { |
||
1051 | killagreg | 70 | if(number > 5) number = 5; |
993 | hbuss | 71 | if(number < 1) return; |
1063 | killagreg | 72 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
73 | SetActiveParamSetNumber(number); |
||
921 | hbuss | 74 | LED_Init(); |
1 | ingob | 75 | } |
76 | |||
77 | unsigned char GetActiveParamSetNumber(void) |
||
78 | { |
||
1063 | killagreg | 79 | unsigned char set; |
80 | set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]); |
||
81 | if((set > 5) || (set < 1)) |
||
82 | { |
||
83 | set = 3; |
||
84 | SetActiveParamSetNumber(set); // diesen Parametersatz als aktuell merken |
||
85 | } |
||
86 | return(set); |
||
1 | ingob | 87 | } |
88 | |||
1063 | killagreg | 89 | |
90 | void SetActiveParamSetNumber(unsigned char number) |
||
91 | { |
||
92 | if(number > 5) number = 5; |
||
93 | if(number < 1) return; |
||
94 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number); // diesen Parametersatz als aktuell merken |
||
95 | } |
||
96 | |||
97 | |||
819 | hbuss | 98 | void CalMk3Mag(void) |
99 | { |
||
100 | static unsigned char stick = 1; |
||
101 | |||
102 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0; |
||
103 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick) |
||
104 | { |
||
105 | stick = 1; |
||
106 | WinkelOut.CalcState++; |
||
1051 | killagreg | 107 | if(WinkelOut.CalcState > 4) |
108 | { |
||
819 | hbuss | 109 | // WinkelOut.CalcState = 0; // in Uart.c |
110 | beeptime = 1000; |
||
1051 | killagreg | 111 | } |
819 | hbuss | 112 | else Piep(WinkelOut.CalcState); |
113 | } |
||
114 | DebugOut.Analog[19] = WinkelOut.CalcState; |
||
115 | } |
||
116 | |||
1 | ingob | 117 | //############################################################################ |
118 | //Hauptprogramm |
||
119 | int main (void) |
||
120 | //############################################################################ |
||
121 | { |
||
819 | hbuss | 122 | unsigned int timer; |
1051 | killagreg | 123 | DDRB = 0x00; |
124 | PORTB = 0x00; |
||
188 | holgerb | 125 | for(timer = 0; timer < 1000; timer++); // verzögern |
1051 | killagreg | 126 | if(PINB & 0x01) |
918 | hbuss | 127 | { |
1051 | killagreg | 128 | if(PINB & 0x02) PlatinenVersion = 13; |
129 | else PlatinenVersion = 11; |
||
918 | hbuss | 130 | } |
1051 | killagreg | 131 | else |
1021 | hbuss | 132 | { |
1051 | killagreg | 133 | if(PINB & 0x02) PlatinenVersion = 20; |
134 | else PlatinenVersion = 10; |
||
1021 | hbuss | 135 | } |
136 | |||
173 | holgerb | 137 | DDRC = 0x81; // SCL |
1036 | hbuss | 138 | DDRC |=0x40; // HEF4017 Reset |
1 | ingob | 139 | PORTC = 0xff; // Pullup SDA |
140 | DDRB = 0x1B; // LEDs und Druckoffset |
||
141 | PORTB = 0x01; // LED_Rot |
||
142 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
||
1036 | hbuss | 143 | DDRD |=0x80; // J7 -> Servo signal |
1153 | hbuss | 144 | PORTD = 0x47; // LED |
1051 | killagreg | 145 | |
1 | ingob | 146 | MCUSR &=~(1<<WDRF); |
147 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
||
148 | WDTCSR = 0; |
||
149 | |||
150 | beeptime = 2000; |
||
151 | |||
152 | StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0; |
||
1111 | hbuss | 153 | if(PlatinenVersion >= 20) GIER_GRAD_FAKTOR = 1160; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC |
1 | ingob | 154 | ROT_OFF; |
1051 | killagreg | 155 | |
1 | ingob | 156 | Timer_Init(); |
1156 | hbuss | 157 | TIMER2_Init(); |
1 | ingob | 158 | UART_Init(); |
159 | rc_sum_init(); |
||
160 | ADC_Init(); |
||
161 | i2c_init(); |
||
597 | ingob | 162 | SPI_MasterInit(); |
1051 | killagreg | 163 | |
1 | ingob | 164 | sei(); |
165 | |||
1051 | killagreg | 166 | printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",PlatinenVersion/10,PlatinenVersion%10, VERSION_MAJOR, VERSION_MINOR,VERSION_PATCH + 'a'); |
1 | ingob | 167 | printf("\n\r=============================="); |
918 | hbuss | 168 | |
1 | ingob | 169 | GRN_ON; |
170 | |||
1063 | killagreg | 171 | ReadParameterSet(3, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 9); // read only the first bytes |
993 | hbuss | 172 | // valid Stick-Settings? |
1058 | killagreg | 173 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) == 255 || eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) < EE_DATENREVISION || |
993 | hbuss | 174 | EE_Parameter.Kanalbelegung[0] > 9 || EE_Parameter.Kanalbelegung[1] > 9 || EE_Parameter.Kanalbelegung[2] > 9 || EE_Parameter.Kanalbelegung[3] > 9) |
1051 | killagreg | 175 | { |
1155 | hbuss | 176 | printf("\n\rInit. EEPROM"); |
993 | hbuss | 177 | DefaultStickMapping(); |
178 | } |
||
179 | else if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) printf("\n\rInit. EEPROM: Generating Default-Parameter using old Stick Settings"); |
||
1051 | killagreg | 180 | |
181 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) |
||
182 | { |
||
1 | ingob | 183 | DefaultKonstanten1(); |
1051 | killagreg | 184 | for (unsigned char i=1;i<6;i++) |
1 | ingob | 185 | { |
395 | hbuss | 186 | if(i==2) DefaultKonstanten2(); // Kamera |
187 | if(i==3) DefaultKonstanten3(); // Beginner |
||
188 | if(i>3) DefaultKonstanten2(); // Kamera |
||
1111 | hbuss | 189 | if(PlatinenVersion >= 20) |
190 | { |
||
1120 | hbuss | 191 | EE_Parameter.Gyro_D = 8; |
1111 | hbuss | 192 | EE_Parameter.Driftkomp = 0; |
193 | EE_Parameter.GyroAccFaktor = 27; |
||
194 | EE_Parameter.WinkelUmschlagNick = 78; |
||
195 | EE_Parameter.WinkelUmschlagRoll = 78; |
||
196 | |||
197 | } |
||
1 | ingob | 198 | WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
1051 | killagreg | 199 | } |
1063 | killagreg | 200 | SetActiveParamSetNumber(3); // default-Setting |
173 | holgerb | 201 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION); |
1 | ingob | 202 | } |
513 | hbuss | 203 | |
1051 | killagreg | 204 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4) |
513 | hbuss | 205 | { |
206 | printf("\n\rACC nicht abgeglichen!"); |
||
207 | } |
||
1051 | killagreg | 208 | |
1 | ingob | 209 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
210 | printf("\n\rBenutze Parametersatz %d", GetActiveParamSetNumber()); |
||
211 | |||
1051 | killagreg | 212 | |
1 | ingob | 213 | if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
1051 | killagreg | 214 | { |
1 | ingob | 215 | printf("\n\rAbgleich Luftdrucksensor.."); |
1051 | killagreg | 216 | timer = SetDelay(1000); |
1 | ingob | 217 | SucheLuftruckOffset(); |
218 | while (!CheckDelay(timer)); |
||
219 | printf("OK\n\r"); |
||
220 | } |
||
1051 | killagreg | 221 | |
1 | ingob | 222 | SetNeutral(); |
223 | |||
224 | ROT_OFF; |
||
1051 | killagreg | 225 | |
1 | ingob | 226 | beeptime = 2000; |
1051 | killagreg | 227 | ExternControl.Digital[0] = 0x55; |
1 | ingob | 228 | |
1051 | killagreg | 229 | |
1 | ingob | 230 | printf("\n\rSteuerung: "); |
231 | if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
||
232 | else printf("Neutral"); |
||
1051 | killagreg | 233 | |
1 | ingob | 234 | printf("\n\n\r"); |
1051 | killagreg | 235 | |
1 | ingob | 236 | LcdClear(); |
173 | holgerb | 237 | I2CTimeout = 5000; |
819 | hbuss | 238 | WinkelOut.Orientation = 1; |
1 | ingob | 239 | while (1) |
240 | { |
||
1155 | hbuss | 241 | if(UpdateMotor && AdReady) // ReglerIntervall |
1051 | killagreg | 242 | { |
1166 | hbuss | 243 | J3High; |
1051 | killagreg | 244 | UpdateMotor=0; |
819 | hbuss | 245 | if(WinkelOut.CalcState) CalMk3Mag(); |
1051 | killagreg | 246 | else MotorRegler(); |
1 | ingob | 247 | SendMotorData(); |
248 | ROT_OFF; |
||
1166 | hbuss | 249 | J3Low; |
1051 | killagreg | 250 | if(PcZugriff) PcZugriff--; |
251 | else |
||
492 | hbuss | 252 | { |
595 | hbuss | 253 | ExternControl.Config = 0; |
492 | hbuss | 254 | ExternStickNick = 0; |
255 | ExternStickRoll = 0; |
||
256 | ExternStickGier = 0; |
||
257 | } |
||
1 | ingob | 258 | if(SenderOkay) SenderOkay--; |
173 | holgerb | 259 | if(!I2CTimeout) |
260 | { |
||
261 | I2CTimeout = 5; |
||
262 | i2c_reset(); |
||
1051 | killagreg | 263 | if((BeepMuster == 0xffff) && MotorenEin) |
264 | { |
||
173 | holgerb | 265 | beeptime = 10000; |
266 | BeepMuster = 0x0080; |
||
1051 | killagreg | 267 | } |
1 | ingob | 268 | } |
1051 | killagreg | 269 | else |
1 | ingob | 270 | { |
173 | holgerb | 271 | I2CTimeout--; |
1051 | killagreg | 272 | ROT_OFF; |
1 | ingob | 273 | } |
805 | hbuss | 274 | if(SIO_DEBUG && (!UpdateMotor || !MotorenEin)) |
1 | ingob | 275 | { |
276 | DatenUebertragung(); |
||
277 | BearbeiteRxDaten(); |
||
278 | } |
||
279 | else BearbeiteRxDaten(); |
||
173 | holgerb | 280 | if(CheckDelay(timer)) |
1051 | killagreg | 281 | { |
173 | holgerb | 282 | if(UBat < EE_Parameter.UnterspannungsWarnung) |
1051 | killagreg | 283 | { |
284 | if(BeepMuster == 0xffff) |
||
285 | { |
||
173 | holgerb | 286 | beeptime = 6000; |
287 | BeepMuster = 0x0300; |
||
1051 | killagreg | 288 | } |
173 | holgerb | 289 | } |
1153 | hbuss | 290 | SPI_StartTransmitPacket(); |
723 | hbuss | 291 | |
292 | SendSPI = 4; |
||
1051 | killagreg | 293 | timer = SetDelay(20); |
294 | } |
||
921 | hbuss | 295 | LED_Update(); |
604 | hbuss | 296 | } |
723 | hbuss | 297 | if(!SendSPI) { SPI_TransmitByte(); } |
1 | ingob | 298 | } |
299 | return (1); |
||
300 | } |
||
301 |