Rev 1163 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1152 | grottenfli | 1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
||
3 | // + Nur für den privaten Gebrauch |
||
4 | // + www.MikroKopter.com |
||
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
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. |
||
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 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
13 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
||
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 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
24 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
||
25 | // + mit unserer Zustimmung zulässig |
||
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1163 | krheinwald | 27 | // + Die Funktion printf_P() und das Modul rcdsl.c unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
1152 | grottenfli | 28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
||
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. |
||
33 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
||
34 | // + for non-commercial use (directly or indirectly) |
||
35 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
||
36 | // + with our written permission |
||
37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
||
38 | // + clearly linked as origin |
||
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 |
||
50 | // + POSSIBILITY OF SUCH DAMAGE. |
||
51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
52 | #include "main.h" |
||
53 | #include "rcdsl.h" |
||
54 | #include "parameter.h" |
||
55 | |||
56 | unsigned char EEPromArray[E2END+1] EEMEM; |
||
57 | unsigned char PlatinenVersion = 10; |
||
58 | unsigned char SendVersionToNavi = 1; |
||
59 | // -- Parametersatz aus EEPROM lesen --- |
||
60 | // number [1..5] |
||
61 | void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
||
62 | { |
||
63 | if((number > 5)||(number < 1)) number = 3; |
||
64 | eeprom_read_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
||
65 | LED_Init(); |
||
66 | } |
||
67 | |||
68 | // -- Parametersatz ins EEPROM schreiben --- |
||
69 | // number [1..5] |
||
70 | void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
||
71 | { |
||
72 | if(number > 5) number = 5; |
||
73 | if(number < 1) return; |
||
74 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
||
75 | SetActiveParamSetNumber(number); |
||
76 | LED_Init(); |
||
77 | } |
||
78 | |||
79 | unsigned char GetActiveParamSetNumber(void) |
||
80 | { |
||
81 | unsigned char set; |
||
82 | set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]); |
||
83 | if((set > 5) || (set < 1)) |
||
84 | { |
||
85 | set = 3; |
||
86 | SetActiveParamSetNumber(set); // diesen Parametersatz als aktuell merken |
||
87 | } |
||
88 | return(set); |
||
89 | } |
||
90 | |||
91 | |||
92 | void SetActiveParamSetNumber(unsigned char number) |
||
93 | { |
||
94 | if(number > 5) number = 5; |
||
95 | if(number < 1) return; |
||
96 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number); // diesen Parametersatz als aktuell merken |
||
97 | } |
||
98 | |||
99 | |||
100 | void CalMk3Mag(void) |
||
101 | { |
||
102 | static unsigned char stick = 1; |
||
103 | |||
104 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0; |
||
105 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick) |
||
106 | { |
||
107 | stick = 1; |
||
108 | WinkelOut.CalcState++; |
||
109 | if(WinkelOut.CalcState > 4) |
||
110 | { |
||
111 | // WinkelOut.CalcState = 0; // in Uart.c |
||
112 | beeptime = 1000; |
||
113 | } |
||
114 | else Piep(WinkelOut.CalcState); |
||
115 | } |
||
116 | DebugOut.Analog[19] = WinkelOut.CalcState; |
||
117 | } |
||
118 | |||
119 | //############################################################################ |
||
120 | //Hauptprogramm |
||
121 | int main (void) |
||
122 | //############################################################################ |
||
123 | { |
||
124 | unsigned int timer; |
||
125 | |||
126 | //unsigned int timer2 = 0; |
||
127 | DDRB = 0x00; |
||
128 | PORTB = 0x00; |
||
129 | for(timer = 0; timer < 1000; timer++); // verz?gern |
||
130 | if(PINB & 0x01) |
||
131 | { |
||
132 | if(PINB & 0x02) PlatinenVersion = 13; |
||
133 | else PlatinenVersion = 11; |
||
134 | } |
||
135 | else |
||
136 | { |
||
137 | if(PINB & 0x02) PlatinenVersion = 20; |
||
138 | else PlatinenVersion = 10; |
||
139 | } |
||
140 | |||
141 | DDRC = 0x81; // SCL |
||
142 | DDRC |=0x40; // HEF4017 Reset |
||
143 | PORTC = 0xff; // Pullup SDA |
||
144 | DDRB = 0x1B; // LEDs und Druckoffset |
||
145 | PORTB = 0x01; // LED_Rot |
||
146 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
||
147 | DDRD |=0x80; // J7 -> Servo signal |
||
148 | PORTD = 0x77; // LED |
||
149 | |||
150 | |||
151 | MCUSR &=~(1<<WDRF); |
||
152 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
||
153 | WDTCSR = 0; |
||
154 | |||
155 | beeptime = 2000; |
||
156 | |||
157 | StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0; |
||
158 | |||
159 | ROT_OFF; |
||
160 | |||
161 | Timer_Init(); |
||
162 | UART_Init(); |
||
163 | ADC_Init(); |
||
164 | i2c_init(); |
||
165 | SPI_MasterInit(); |
||
166 | |||
167 | sei(); |
||
168 | |||
169 | printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",PlatinenVersion/10,PlatinenVersion%10, VERSION_MAJOR, VERSION_MINOR,VERSION_PATCH + 'a'); |
||
170 | printf("\n\r=============================="); |
||
171 | |||
172 | GRN_ON; |
||
173 | |||
174 | |||
175 | ReadParameterSet(3, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 9); // read only the first bytes |
||
176 | // valid Stick-Settings? |
||
177 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) == 255 || eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) < EE_DATENREVISION || |
||
178 | EE_Parameter.Kanalbelegung[0] > 9 || EE_Parameter.Kanalbelegung[1] > 9 || EE_Parameter.Kanalbelegung[2] > 9 || EE_Parameter.Kanalbelegung[3] > 9) |
||
179 | { |
||
180 | printf("\n\rInit. EEPROM: Generating Default-Parameter and Stick-Settings..."); |
||
181 | DefaultStickMapping(); |
||
182 | } |
||
183 | else if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) printf("\n\rInit. EEPROM: Generating Default-Parameter using old Stick Settings"); |
||
184 | |||
185 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) |
||
186 | { |
||
187 | DefaultKonstanten1(); |
||
188 | for (unsigned char i=1;i<6;i++) |
||
189 | { |
||
190 | if(i==2) DefaultKonstanten2(); // Kamera |
||
191 | if(i==3) DefaultKonstanten3(); // Beginner |
||
192 | if(i>3) DefaultKonstanten2(); // Kamera |
||
193 | WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
194 | } |
||
195 | SetActiveParamSetNumber(3); // default-Setting |
||
196 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION); |
||
197 | } |
||
198 | |||
199 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4) |
||
200 | { |
||
201 | printf("\n\rACC nicht abgeglichen!"); |
||
202 | } |
||
203 | |||
204 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
1208 | krheinwald | 205 | printf("\n\rBenutze Parametersatz %d", GetActiveParamSetNumber()); |
1152 | grottenfli | 206 | |
1208 | krheinwald | 207 | if (PARAM_USE_DSL_RC) |
208 | rcdsl_init(); |
||
209 | else |
||
210 | rc_sum_init(); |
||
1152 | grottenfli | 211 | |
1208 | krheinwald | 212 | printf("\n\rUsing %s", (PARAM_USE_DSL_RC ? "DSL" : "PPM")); |
213 | |||
1152 | grottenfli | 214 | if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
215 | { |
||
216 | printf("\n\rAbgleich Luftdrucksensor.."); |
||
217 | timer = SetDelay(1000); |
||
1208 | krheinwald | 218 | SucheLuftruckOffset(); |
1152 | grottenfli | 219 | while (!CheckDelay(timer)); |
220 | |||
1163 | krheinwald | 221 | printf("\n\rOK\n\r"); |
1152 | grottenfli | 222 | } |
223 | |||
224 | SetNeutral(); |
||
225 | |||
226 | ROT_OFF; |
||
227 | |||
228 | beeptime = 2000; |
||
229 | ExternControl.Digital[0] = 0x55; |
||
230 | |||
231 | |||
232 | printf("\n\rSteuerung: "); |
||
233 | if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
||
234 | else printf("Neutral"); |
||
235 | |||
236 | printf("\n\n\r"); |
||
237 | |||
238 | LcdClear(); |
||
239 | I2CTimeout = 5000; |
||
240 | WinkelOut.Orientation = 1; |
||
241 | while (1) |
||
242 | { |
||
243 | |||
244 | if(UpdateMotor) // ReglerIntervall |
||
245 | { |
||
246 | UpdateMotor=0; |
||
247 | //PORTD |= 0x08; |
||
248 | if(WinkelOut.CalcState) CalMk3Mag(); |
||
249 | else MotorRegler(); |
||
250 | //PORTD &= ~0x08; |
||
251 | SendMotorData(); |
||
252 | ROT_OFF; |
||
253 | if(PcZugriff) PcZugriff--; |
||
254 | else |
||
255 | { |
||
256 | ExternControl.Config = 0; |
||
257 | ExternStickNick = 0; |
||
258 | ExternStickRoll = 0; |
||
259 | ExternStickGier = 0; |
||
260 | } |
||
261 | if(SenderOkay) SenderOkay--; |
||
262 | if(!I2CTimeout) |
||
263 | { |
||
264 | I2CTimeout = 5; |
||
265 | i2c_reset(); |
||
266 | if((BeepMuster == 0xffff) && MotorenEin) |
||
267 | { |
||
268 | beeptime = 10000; |
||
269 | BeepMuster = 0x0080; |
||
270 | } |
||
271 | } |
||
272 | else |
||
273 | { |
||
274 | I2CTimeout--; |
||
275 | ROT_OFF; |
||
276 | } |
||
277 | if(SIO_DEBUG && (!UpdateMotor || !MotorenEin)) |
||
278 | { |
||
279 | DatenUebertragung(); |
||
280 | BearbeiteRxDaten(); |
||
281 | } |
||
282 | else BearbeiteRxDaten(); |
||
283 | if(CheckDelay(timer)) |
||
284 | { |
||
285 | if(UBat < EE_Parameter.UnterspannungsWarnung) |
||
286 | { |
||
287 | if(BeepMuster == 0xffff) |
||
288 | { |
||
289 | beeptime = 6000; |
||
290 | BeepMuster = 0x0300; |
||
291 | } |
||
292 | } |
||
293 | /* if(SendVersionToNavi) |
||
294 | { |
||
295 | SPI_StartTransmitPacket(SPI_CMD_VERSION);//# |
||
296 | SendVersionToNavi = 0; |
||
297 | } |
||
298 | else SPI_StartTransmitPacket(SPI_CMD_VALUE);//# |
||
299 | */ |
||
300 | SPI_StartTransmitPacket();//# |
||
301 | |||
302 | SendSPI = 4; |
||
303 | timer = SetDelay(20); |
||
304 | } |
||
305 | //if(UpdateMotor) DebugOut.Analog[26]++; |
||
306 | LED_Update(); |
||
307 | } |
||
308 | if(!SendSPI) { SPI_TransmitByte(); } |
||
309 | } |
||
310 | return (1); |
||
311 | } |
||
312 |