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; |
62 | number--; |
||
1 | ingob | 63 | eeprom_read_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * number], length); |
921 | hbuss | 64 | LED_Init(); |
1 | ingob | 65 | } |
66 | |||
67 | // -- Parametersatz ins EEPROM schreiben --- |
||
1051 | killagreg | 68 | // number [1..5] |
1 | ingob | 69 | void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
70 | { |
||
1051 | killagreg | 71 | if(number > 5) number = 5; |
993 | hbuss | 72 | if(number < 1) return; |
73 | number--; |
||
1 | ingob | 74 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * number], length); |
75 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number); // diesen Parametersatz als aktuell merken |
||
921 | hbuss | 76 | LED_Init(); |
1 | ingob | 77 | } |
78 | |||
79 | unsigned char GetActiveParamSetNumber(void) |
||
80 | { |
||
173 | holgerb | 81 | unsigned char set; |
82 | set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]); |
||
1051 | killagreg | 83 | if(set > 5) |
84 | { |
||
85 | set = 2; |
||
173 | holgerb | 86 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], set); // diesen Parametersatz als aktuell merken |
1051 | killagreg | 87 | } |
173 | holgerb | 88 | return(set); |
1 | ingob | 89 | } |
90 | |||
819 | hbuss | 91 | void CalMk3Mag(void) |
92 | { |
||
93 | static unsigned char stick = 1; |
||
94 | |||
95 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0; |
||
96 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick) |
||
97 | { |
||
98 | stick = 1; |
||
99 | WinkelOut.CalcState++; |
||
1051 | killagreg | 100 | if(WinkelOut.CalcState > 4) |
101 | { |
||
819 | hbuss | 102 | // WinkelOut.CalcState = 0; // in Uart.c |
103 | beeptime = 1000; |
||
1051 | killagreg | 104 | } |
819 | hbuss | 105 | else Piep(WinkelOut.CalcState); |
106 | } |
||
107 | DebugOut.Analog[19] = WinkelOut.CalcState; |
||
108 | } |
||
109 | |||
1 | ingob | 110 | //############################################################################ |
111 | //Hauptprogramm |
||
112 | int main (void) |
||
113 | //############################################################################ |
||
114 | { |
||
819 | hbuss | 115 | unsigned int timer; |
296 | holgerb | 116 | |
304 | ingob | 117 | //unsigned int timer2 = 0; |
1051 | killagreg | 118 | DDRB = 0x00; |
119 | PORTB = 0x00; |
||
188 | holgerb | 120 | for(timer = 0; timer < 1000; timer++); // verzögern |
1051 | killagreg | 121 | if(PINB & 0x01) |
918 | hbuss | 122 | { |
1051 | killagreg | 123 | if(PINB & 0x02) PlatinenVersion = 13; |
124 | else PlatinenVersion = 11; |
||
918 | hbuss | 125 | } |
1051 | killagreg | 126 | else |
1021 | hbuss | 127 | { |
1051 | killagreg | 128 | if(PINB & 0x02) PlatinenVersion = 20; |
129 | else PlatinenVersion = 10; |
||
1021 | hbuss | 130 | } |
131 | |||
173 | holgerb | 132 | DDRC = 0x81; // SCL |
1036 | hbuss | 133 | DDRC |=0x40; // HEF4017 Reset |
1 | ingob | 134 | PORTC = 0xff; // Pullup SDA |
135 | DDRB = 0x1B; // LEDs und Druckoffset |
||
136 | PORTB = 0x01; // LED_Rot |
||
137 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
||
1036 | hbuss | 138 | DDRD |=0x80; // J7 -> Servo signal |
139 | PORTD = 0x77; // LED |
||
1051 | killagreg | 140 | |
141 | |||
1 | ingob | 142 | MCUSR &=~(1<<WDRF); |
143 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
||
144 | WDTCSR = 0; |
||
145 | |||
146 | beeptime = 2000; |
||
147 | |||
148 | StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0; |
||
149 | |||
150 | ROT_OFF; |
||
1051 | killagreg | 151 | |
1 | ingob | 152 | Timer_Init(); |
153 | UART_Init(); |
||
154 | rc_sum_init(); |
||
155 | ADC_Init(); |
||
156 | i2c_init(); |
||
597 | ingob | 157 | SPI_MasterInit(); |
1051 | killagreg | 158 | |
1 | ingob | 159 | sei(); |
160 | |||
1051 | killagreg | 161 | 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 | 162 | printf("\n\r=============================="); |
918 | hbuss | 163 | |
1 | ingob | 164 | GRN_ON; |
165 | |||
1058 | killagreg | 166 | |
993 | hbuss | 167 | ReadParameterSet(0, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 9); // read only the first bytes |
168 | // valid Stick-Settings? |
||
1058 | killagreg | 169 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) == 255 || eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) < EE_DATENREVISION || |
993 | hbuss | 170 | EE_Parameter.Kanalbelegung[0] > 9 || EE_Parameter.Kanalbelegung[1] > 9 || EE_Parameter.Kanalbelegung[2] > 9 || EE_Parameter.Kanalbelegung[3] > 9) |
1051 | killagreg | 171 | { |
993 | hbuss | 172 | printf("\n\rInit. EEPROM: Generating Default-Parameter and Stick-Settings..."); |
173 | DefaultStickMapping(); |
||
174 | } |
||
175 | else if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) printf("\n\rInit. EEPROM: Generating Default-Parameter using old Stick Settings"); |
||
1051 | killagreg | 176 | |
177 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) |
||
178 | { |
||
1 | ingob | 179 | DefaultKonstanten1(); |
1051 | killagreg | 180 | for (unsigned char i=1;i<6;i++) |
1 | ingob | 181 | { |
395 | hbuss | 182 | if(i==2) DefaultKonstanten2(); // Kamera |
183 | if(i==3) DefaultKonstanten3(); // Beginner |
||
184 | if(i>3) DefaultKonstanten2(); // Kamera |
||
1 | ingob | 185 | WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
1051 | killagreg | 186 | } |
395 | hbuss | 187 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], 3); // default-Setting |
173 | holgerb | 188 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION); |
1 | ingob | 189 | } |
513 | hbuss | 190 | |
1051 | killagreg | 191 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4) |
513 | hbuss | 192 | { |
193 | printf("\n\rACC nicht abgeglichen!"); |
||
194 | } |
||
1051 | killagreg | 195 | |
1 | ingob | 196 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
197 | printf("\n\rBenutze Parametersatz %d", GetActiveParamSetNumber()); |
||
198 | |||
1051 | killagreg | 199 | |
1 | ingob | 200 | if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
1051 | killagreg | 201 | { |
1 | ingob | 202 | printf("\n\rAbgleich Luftdrucksensor.."); |
1051 | killagreg | 203 | timer = SetDelay(1000); |
1 | ingob | 204 | SucheLuftruckOffset(); |
205 | while (!CheckDelay(timer)); |
||
206 | printf("OK\n\r"); |
||
207 | } |
||
1051 | killagreg | 208 | |
1 | ingob | 209 | SetNeutral(); |
210 | |||
211 | ROT_OFF; |
||
1051 | killagreg | 212 | |
1 | ingob | 213 | beeptime = 2000; |
1051 | killagreg | 214 | ExternControl.Digital[0] = 0x55; |
1 | ingob | 215 | |
1051 | killagreg | 216 | |
1 | ingob | 217 | printf("\n\rSteuerung: "); |
218 | if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
||
219 | else printf("Neutral"); |
||
1051 | killagreg | 220 | |
1 | ingob | 221 | printf("\n\n\r"); |
1051 | killagreg | 222 | |
1 | ingob | 223 | LcdClear(); |
173 | holgerb | 224 | I2CTimeout = 5000; |
819 | hbuss | 225 | WinkelOut.Orientation = 1; |
1 | ingob | 226 | while (1) |
227 | { |
||
1051 | killagreg | 228 | |
720 | ingob | 229 | if(UpdateMotor) // ReglerIntervall |
1051 | killagreg | 230 | { |
231 | UpdateMotor=0; |
||
419 | hbuss | 232 | //PORTD |= 0x08; |
819 | hbuss | 233 | if(WinkelOut.CalcState) CalMk3Mag(); |
1051 | killagreg | 234 | else MotorRegler(); |
419 | hbuss | 235 | //PORTD &= ~0x08; |
1 | ingob | 236 | SendMotorData(); |
237 | ROT_OFF; |
||
1051 | killagreg | 238 | if(PcZugriff) PcZugriff--; |
239 | else |
||
492 | hbuss | 240 | { |
595 | hbuss | 241 | ExternControl.Config = 0; |
492 | hbuss | 242 | ExternStickNick = 0; |
243 | ExternStickRoll = 0; |
||
244 | ExternStickGier = 0; |
||
245 | } |
||
1 | ingob | 246 | if(SenderOkay) SenderOkay--; |
173 | holgerb | 247 | if(!I2CTimeout) |
248 | { |
||
249 | I2CTimeout = 5; |
||
250 | i2c_reset(); |
||
1051 | killagreg | 251 | if((BeepMuster == 0xffff) && MotorenEin) |
252 | { |
||
173 | holgerb | 253 | beeptime = 10000; |
254 | BeepMuster = 0x0080; |
||
1051 | killagreg | 255 | } |
1 | ingob | 256 | } |
1051 | killagreg | 257 | else |
1 | ingob | 258 | { |
173 | holgerb | 259 | I2CTimeout--; |
1051 | killagreg | 260 | ROT_OFF; |
1 | ingob | 261 | } |
805 | hbuss | 262 | if(SIO_DEBUG && (!UpdateMotor || !MotorenEin)) |
1 | ingob | 263 | { |
264 | DatenUebertragung(); |
||
265 | BearbeiteRxDaten(); |
||
266 | } |
||
267 | else BearbeiteRxDaten(); |
||
173 | holgerb | 268 | if(CheckDelay(timer)) |
1051 | killagreg | 269 | { |
173 | holgerb | 270 | if(UBat < EE_Parameter.UnterspannungsWarnung) |
1051 | killagreg | 271 | { |
272 | if(BeepMuster == 0xffff) |
||
273 | { |
||
173 | holgerb | 274 | beeptime = 6000; |
275 | BeepMuster = 0x0300; |
||
1051 | killagreg | 276 | } |
173 | holgerb | 277 | } |
1051 | killagreg | 278 | /* if(SendVersionToNavi) |
723 | hbuss | 279 | { |
280 | SPI_StartTransmitPacket(SPI_CMD_VERSION);//# |
||
281 | SendVersionToNavi = 0; |
||
282 | } |
||
283 | else SPI_StartTransmitPacket(SPI_CMD_VALUE);//# |
||
284 | */ |
||
823 | ingob | 285 | SPI_StartTransmitPacket();//# |
723 | hbuss | 286 | |
287 | SendSPI = 4; |
||
1051 | killagreg | 288 | timer = SetDelay(20); |
289 | } |
||
623 | hbuss | 290 | //if(UpdateMotor) DebugOut.Analog[26]++; |
921 | hbuss | 291 | LED_Update(); |
604 | hbuss | 292 | } |
723 | hbuss | 293 | if(!SendSPI) { SPI_TransmitByte(); } |
1 | ingob | 294 | } |
295 | return (1); |
||
296 | } |
||
297 |