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 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
683 | 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 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
683 | 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 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
683 | 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 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
683 | 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. |
||
683 | 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) |
683 | killagreg | 35 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
1 | ingob | 36 | // + with our written permission |
683 | 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 |
||
683 | killagreg | 50 | // + POSSIBILITY OF SUCH DAMAGE. |
1 | ingob | 51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
687 | killagreg | 52 | #include <avr/boot.h> |
53 | |||
54 | #include <avr/io.h> |
||
55 | #include <avr/interrupt.h> |
||
56 | |||
1 | ingob | 57 | #include "main.h" |
685 | killagreg | 58 | #include "timer0.h" |
59 | #include "timer2.h" |
||
60 | #include "uart.h" |
||
61 | #include "uart1.h" |
||
62 | #include "menu.h" |
||
724 | killagreg | 63 | #include "ubx.h" |
685 | killagreg | 64 | #include "fc.h" |
65 | #include "rc.h" |
||
66 | #include "analog.h" |
||
67 | #include "printf_P.h" |
||
694 | killagreg | 68 | //#include "spi.h" |
69 | #include "mm3.h" |
||
685 | killagreg | 70 | #include "twimaster.h" |
71 | #include "eeprom.h" |
||
72 | #include "_Settings.h" |
||
1 | ingob | 73 | |
74 | |||
687 | killagreg | 75 | |
685 | killagreg | 76 | uint8_t BoardRelease = 10; |
77 | |||
1 | ingob | 78 | |
79 | //############################################################################ |
||
80 | //Hauptprogramm |
||
81 | int main (void) |
||
82 | //############################################################################ |
||
83 | { |
||
84 | unsigned int timer; |
||
296 | holgerb | 85 | |
683 | killagreg | 86 | // disable interrupts global |
87 | cli(); |
||
88 | |||
712 | killagreg | 89 | // get board release |
683 | killagreg | 90 | DDRB = 0x00; |
91 | PORTB = 0x00; |
||
732 | killagreg | 92 | for(timer = 0; timer < 1000; timer++); // make some delay |
685 | killagreg | 93 | if(PINB & 0x01) BoardRelease = 11; |
94 | else BoardRelease = 10; |
||
95 | |||
732 | killagreg | 96 | // set LED ports as output |
712 | killagreg | 97 | DDRB |= (1<<DDB1)|(1<<DDB0); |
98 | ROT_ON; |
||
99 | GRN_OFF; |
||
683 | killagreg | 100 | |
750 | killagreg | 101 | // set PC2 & PC3 as output (ctrl J16 & J17) |
102 | DDRC |= (1<<DDC2)|(1<<DDC3); |
||
103 | J16_OFF; |
||
104 | J17_OFF; |
||
105 | |||
106 | // disable watchdog |
||
1 | ingob | 107 | MCUSR &=~(1<<WDRF); |
108 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
||
109 | WDTCSR = 0; |
||
110 | |||
683 | killagreg | 111 | BeepTime = 2000; |
1 | ingob | 112 | |
707 | killagreg | 113 | PPM_in[CH_THRUST] = 0; |
701 | killagreg | 114 | StickYaw = 0; |
683 | killagreg | 115 | StickRoll = 0; |
701 | killagreg | 116 | StickPitch = 0; |
1 | ingob | 117 | |
118 | ROT_OFF; |
||
683 | killagreg | 119 | |
712 | killagreg | 120 | // initalize modules |
683 | killagreg | 121 | TIMER0_Init(); |
122 | TIMER2_Init(); |
||
123 | USART0_Init(); |
||
752 | killagreg | 124 | #if defined (__AVR_ATmega644p__) |
125 | if (BoardRelease != 10) USART1_Init(); |
||
126 | #endif |
||
712 | killagreg | 127 | RC_Init(); |
1 | ingob | 128 | ADC_Init(); |
726 | killagreg | 129 | I2C_Init(); |
130 | MM3_Init(); |
||
683 | killagreg | 131 | //SPI_MasterInit(); |
132 | |||
133 | // enable interrupts global |
||
1 | ingob | 134 | sei(); |
135 | |||
735 | killagreg | 136 | VersionInfo.Major = VERSION_MAJOR; |
137 | VersionInfo.Minor = VERSION_MINOR; |
||
138 | VersionInfo.PCCompatible = VERSION_COMPATIBLE; |
||
683 | killagreg | 139 | |
735 | killagreg | 140 | printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",BoardRelease/10,BoardRelease%10, VERSION_MAJOR, VERSION_MINOR,VERSION_INDEX + 'a'); |
1 | ingob | 141 | printf("\n\r=============================="); |
142 | GRN_ON; |
||
143 | |||
687 | killagreg | 144 | // Parameter set handling |
145 | ParamSet_Init(); |
||
513 | hbuss | 146 | |
731 | killagreg | 147 | if(GetParamWord(PID_ACC_PITCH) > 1023) |
513 | hbuss | 148 | { |
727 | killagreg | 149 | printf("\n\rACC not calibrated!"); |
513 | hbuss | 150 | } |
683 | killagreg | 151 | |
731 | killagreg | 152 | //wait for a short time (otherwise the RC channel check won't work below) |
694 | killagreg | 153 | timer = SetDelay(500); |
154 | while(!CheckDelay(timer)); |
||
1 | ingob | 155 | |
694 | killagreg | 156 | //Compass calibration? |
707 | killagreg | 157 | if(PPM_in[ParamSet.ChannelAssignment[CH_THRUST]] > 100 && PPM_in[ParamSet.ChannelAssignment[CH_YAW]] > 100) |
694 | killagreg | 158 | { |
159 | printf("\n\rCalibrating Compass"); |
||
726 | killagreg | 160 | MM3_Calibrate(); |
694 | killagreg | 161 | } |
162 | |||
163 | |||
690 | killagreg | 164 | if(ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL) |
683 | killagreg | 165 | { |
727 | killagreg | 166 | printf("\n\rCalibrating air pressure sensor.."); |
683 | killagreg | 167 | timer = SetDelay(1000); |
701 | killagreg | 168 | SearchAirPressureOffset(); |
1 | ingob | 169 | while (!CheckDelay(timer)); |
170 | printf("OK\n\r"); |
||
171 | } |
||
683 | killagreg | 172 | |
1 | ingob | 173 | SetNeutral(); |
174 | |||
175 | ROT_OFF; |
||
176 | |||
683 | killagreg | 177 | BeepTime = 2000; |
178 | ExternControl.Digital[0] = 0x55; |
||
179 | |||
180 | |||
727 | killagreg | 181 | printf("\n\rControl: "); |
687 | killagreg | 182 | if (ParamSet.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
1 | ingob | 183 | else printf("Neutral"); |
683 | killagreg | 184 | |
1 | ingob | 185 | printf("\n\n\r"); |
683 | killagreg | 186 | |
685 | killagreg | 187 | LCD_Clear(); |
702 | killagreg | 188 | |
173 | holgerb | 189 | I2CTimeout = 5000; |
1 | ingob | 190 | while (1) |
191 | { |
||
712 | killagreg | 192 | if(UpdateMotor) // control interval |
683 | killagreg | 193 | { |
694 | killagreg | 194 | //SPI_TransmitByte(); //# |
712 | killagreg | 195 | UpdateMotor=0; // reset Flag, is enabled every 2 ms by isr of timer0 |
419 | hbuss | 196 | //PORTD |= 0x08; |
712 | killagreg | 197 | MotorControl(); |
604 | hbuss | 198 | |
419 | hbuss | 199 | //PORTD &= ~0x08; |
1 | ingob | 200 | SendMotorData(); |
201 | ROT_OFF; |
||
706 | killagreg | 202 | if(PcAccess) PcAccess--; |
712 | killagreg | 203 | else |
492 | hbuss | 204 | { |
683 | killagreg | 205 | DubWiseKeys[0] = 0; |
492 | hbuss | 206 | DubWiseKeys[1] = 0; |
595 | hbuss | 207 | ExternControl.Config = 0; |
701 | killagreg | 208 | ExternStickPitch= 0; |
492 | hbuss | 209 | ExternStickRoll = 0; |
701 | killagreg | 210 | ExternStickYaw = 0; |
492 | hbuss | 211 | } |
688 | killagreg | 212 | if(SenderOkay) SenderOkay--; |
213 | if(!I2CTimeout) |
||
173 | holgerb | 214 | { |
215 | I2CTimeout = 5; |
||
726 | killagreg | 216 | I2C_Reset(); |
701 | killagreg | 217 | if((BeepModulation == 0xFFFF) && MotorsOn) |
683 | killagreg | 218 | { |
219 | BeepTime = 10000; // 1 second |
||
220 | BeepModulation = 0x0080; |
||
221 | } |
||
1 | ingob | 222 | } |
683 | killagreg | 223 | else |
1 | ingob | 224 | { |
173 | holgerb | 225 | I2CTimeout--; |
683 | killagreg | 226 | ROT_OFF; |
1 | ingob | 227 | } |
604 | hbuss | 228 | if(SIO_DEBUG && !UpdateMotor) |
1 | ingob | 229 | { |
735 | killagreg | 230 | TransmitTxData(); |
231 | ProcessRxData(); |
||
1 | ingob | 232 | } |
735 | killagreg | 233 | else ProcessRxData(); |
173 | holgerb | 234 | if(CheckDelay(timer)) |
683 | killagreg | 235 | { |
690 | killagreg | 236 | if(UBat < ParamSet.LowVoltageWarning) |
683 | killagreg | 237 | { |
238 | if(BeepModulation == 0xFFFF) |
||
239 | { |
||
240 | BeepTime = 6000; // 0.6 seconds |
||
241 | } |
||
173 | holgerb | 242 | } |
694 | killagreg | 243 | //SPI_StartTransmitPacket();//# |
683 | killagreg | 244 | timer = SetDelay(100); |
245 | } |
||
604 | hbuss | 246 | } |
1 | ingob | 247 | } |
248 | return (1); |
||
249 | } |
||
250 |