Rev 1775 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1612 | dongfang | 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 (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 sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
||
18 | // + eindeutig als Ursprung verlinkt 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 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
||
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// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
48 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
49 | // + POSSIBILITY OF SUCH DAMAGE. |
||
50 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
51 | #include <util/delay.h> |
||
52 | #include <avr/eeprom.h> |
||
53 | #include "configuration.h" |
||
54 | #include "eeprom.h" |
||
55 | #include "timer0.h" |
||
56 | |||
57 | int16_t variables[8] = {0,0,0,0,0,0,0,0}; |
||
58 | fc_param_t dynamicParams = {48,251,16,58,64,8,150,150,2,10,{0,0,0,0,0,0,0,0},100,70,90,65,64,100,0,0,0}; |
||
59 | uint8_t CPUType = ATMEGA644; |
||
60 | uint8_t BoardRelease = 13; |
||
61 | |||
62 | /************************************************************************ |
||
63 | * Map the parameter to pot values |
||
64 | ************************************************************************/ |
||
65 | void configuration_applyVariablesToParams(void) { |
||
66 | uint8_t i; |
||
67 | #define SET_POT_MM(b,a,min,max) { if (a<255) {if (a>=251) b=variables[a-251]; else b=a;} if(b<=min) b=min; else if(b>=max) b=max;} |
||
68 | #define SET_POT(b,a) { if (a<255) {if (a>=251) b=variables[a-251]; else b=a;}} |
||
69 | SET_POT(dynamicParams.MaxHeight,staticParams.MaxHeight); |
||
70 | SET_POT_MM(dynamicParams.HeightD,staticParams.HeightD,0,100); |
||
71 | SET_POT_MM(dynamicParams.HeightP,staticParams.HeightP,0,100); |
||
72 | SET_POT(dynamicParams.Height_ACC_Effect,staticParams.Height_ACC_Effect); |
||
73 | SET_POT(dynamicParams.CompassYawEffect,staticParams.CompassYawEffect); |
||
74 | SET_POT_MM(dynamicParams.GyroP,staticParams.GyroP,10,255); |
||
75 | SET_POT(dynamicParams.GyroI,staticParams.GyroI); |
||
76 | SET_POT(dynamicParams.GyroD,staticParams.GyroD); |
||
77 | SET_POT(dynamicParams.IFactor,staticParams.IFactor); |
||
78 | for (i=0; i<sizeof(staticParams.UserParams1); i++) { |
||
79 | SET_POT(dynamicParams.UserParams[i],staticParams.UserParams1[i]); |
||
80 | } |
||
81 | for (i=0; i<sizeof(staticParams.UserParams2); i++) { |
||
82 | SET_POT(dynamicParams.UserParams[i + sizeof(staticParams.UserParams1)], staticParams.UserParams2[i]); |
||
83 | } |
||
84 | SET_POT(dynamicParams.ServoPitchControl,staticParams.ServoPitchControl); |
||
85 | SET_POT(dynamicParams.LoopGasLimit,staticParams.LoopGasLimit); |
||
86 | SET_POT(dynamicParams.AxisCoupling1,staticParams.AxisCoupling1); |
||
87 | SET_POT(dynamicParams.AxisCoupling2,staticParams.AxisCoupling2); |
||
88 | SET_POT(dynamicParams.AxisCouplingYawCorrection,staticParams.AxisCouplingYawCorrection); |
||
89 | SET_POT(dynamicParams.DynamicStability,staticParams.DynamicStability); |
||
90 | SET_POT_MM(dynamicParams.J16Timing,staticParams.J16Timing,1,255); |
||
91 | SET_POT_MM(dynamicParams.J17Timing,staticParams.J17Timing,1,255); |
||
92 | #if defined (USE_MK3MAG) |
||
93 | SET_POT(dynamicParams.NaviGpsModeControl,staticParams.NaviGpsModeControl); |
||
94 | SET_POT(dynamicParams.NaviGpsGain,staticParams.NaviGpsGain); |
||
95 | SET_POT(dynamicParams.NaviGpsP,staticParams.NaviGpsP); |
||
96 | SET_POT(dynamicParams.NaviGpsI,staticParams.NaviGpsI); |
||
97 | SET_POT(dynamicParams.NaviGpsD,staticParams.NaviGpsD); |
||
98 | SET_POT(dynamicParams.NaviGpsACC,staticParams.NaviGpsACC); |
||
99 | SET_POT_MM(dynamicParams.NaviOperatingRadius,staticParams.NaviOperatingRadius,10, 255); |
||
100 | SET_POT(dynamicParams.NaviWindCorrection,staticParams.NaviWindCorrection); |
||
101 | SET_POT(dynamicParams.NaviSpeedCompensation,staticParams.NaviSpeedCompensation); |
||
102 | #endif |
||
103 | SET_POT(dynamicParams.ExternalControl,staticParams.ExternalControl); |
||
104 | } |
||
105 | |||
106 | uint8_t getCPUType(void) { // works only after reset or power on when the registers have default values |
||
107 | uint8_t CPUType = ATMEGA644; |
||
108 | if( (UCSR1A == 0x20) && (UCSR1C == 0x06) ) CPUType = ATMEGA644P; // initial Values for 644P after reset |
||
109 | return CPUType; |
||
110 | } |
||
111 | |||
112 | /* |
||
113 | * Automatic detection of hardware components is not supported in this development-oriented |
||
114 | * FC firmware. It would go against the point of it: To enable alternative hardware |
||
115 | * configurations with otherwise unsupported components. Instead, one should write |
||
116 | * custom code + adjust constants for the new hardware, and include the relevant code |
||
117 | * from the makefile. |
||
118 | * However - we still do detect the board release. Reason: Otherwise it would be too |
||
119 | * tedious to have to modify the code for how to turn on and off LEDs when deploying |
||
120 | * on different HW version.... |
||
121 | */ |
||
122 | |||
123 | uint8_t getBoardRelease(void) { |
||
124 | uint8_t BoardRelease = 13; |
||
125 | // the board release is coded via the pull up or down the 2 status LED |
||
126 | |||
127 | PORTB &= ~((1 << PORTB1)|(1 << PORTB0)); // set tristate |
||
128 | DDRB &= ~((1 << DDB0)|(1 << DDB0)); // set port direction as input |
||
129 | |||
130 | _delay_loop_2(1000); // make some delay |
||
131 | |||
132 | switch( PINB & ((1<<PINB1)|(1<<PINB0))) { |
||
133 | case 0x00: |
||
134 | BoardRelease = 10; // 1.0 |
||
135 | break; |
||
136 | case 0x01: |
||
137 | BoardRelease = 11; // 1.1 or 1.2 |
||
138 | break; |
||
139 | case 0x02: |
||
140 | BoardRelease = 20; // 2.0 |
||
141 | break; |
||
142 | case 0x03: |
||
143 | BoardRelease = 13; // 1.3 |
||
144 | break; |
||
145 | default: |
||
146 | break; |
||
147 | } |
||
148 | // set LED ports as output |
||
149 | DDRB |= (1<<DDB1)|(1<<DDB0); |
||
150 | RED_ON; |
||
151 | GRN_OFF; |
||
152 | return BoardRelease; |
||
153 | } |
||
154 | |||
155 | void beep(uint16_t millis) { |
||
156 | BeepTime = millis; |
||
157 | } |
||
158 | |||
159 | /* |
||
160 | * Make [numbeeps] beeps. |
||
161 | */ |
||
162 | void beepNumber(uint8_t numbeeps) { |
||
163 | while(numbeeps--) { |
||
164 | if(MKFlags & MKFLAG_MOTOR_RUN) return; //auf keinen Fall bei laufenden Motoren! |
||
165 | beep(100); // 0.1 second |
||
166 | Delay_ms(250); // blocks 250 ms as pause to next beep, |
||
167 | // this will block the flight control loop, |
||
168 | // therefore do not use this function if motors are running |
||
169 | } |
||
170 | } |
||
171 | |||
172 | /* |
||
173 | * Beep the R/C alarm signal |
||
174 | */ |
||
175 | void beepRCAlarm(void) { |
||
176 | if(BeepModulation == 0xFFFF) { // If not already beeping an alarm signal (?) |
||
177 | BeepTime = 15000; // 1.5 seconds |
||
178 | BeepModulation = 0x0C00; |
||
179 | } |
||
180 | } |
||
181 | |||
182 | /* |
||
183 | * Beep the I2C bus error signal |
||
184 | */ |
||
185 | void beepI2CAlarm(void) { |
||
186 | if((BeepModulation == 0xFFFF) && (MKFlags & MKFLAG_MOTOR_RUN)) { |
||
187 | BeepTime = 10000; // 1 second |
||
188 | BeepModulation = 0x0080; |
||
189 | } |
||
190 | } |
||
191 | |||
192 | /* |
||
193 | * Beep the battery low alarm signal |
||
194 | */ |
||
195 | void beepBatteryAlarm(void) { |
||
196 | BeepModulation = 0x0300; |
||
197 | if(!BeepTime) { |
||
198 | BeepTime = 6000; // 0.6 seconds |
||
199 | } |
||
200 | } |
||
201 | |||
202 | /* |
||
203 | * Beep the EEPROM checksum alarm |
||
204 | */ |
||
205 | void beepEEPROMAlarm(void) { |
||
206 | BeepModulation = 0x0007; |
||
207 | if(!BeepTime) { |
||
208 | BeepTime = 6000; // 0.6 seconds |
||
209 | } |
||
210 | } |