Rev 1960 | Rev 1963 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1960 | Rev 1961 | ||
---|---|---|---|
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
2 | // + Copyright (c) 04.2007 Holger Buss |
3 | // + Nur für den privaten Gebrauch |
3 | // + Nur für den privaten Gebrauch |
4 | // + www.MikroKopter.com |
4 | // + www.MikroKopter.com |
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
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. |
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 |
8 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
9 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
9 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
10 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
10 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
11 | // + Verkauf von Luftbildaufnahmen, usw. |
11 | // + Verkauf von Luftbildaufnahmen, usw. |
12 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
12 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
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 |
14 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
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" |
17 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
18 | // + eindeutig als Ursprung verlinkt werden |
18 | // + eindeutig als Ursprung verlinkt werden |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
20 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
21 | // + Benutzung auf eigene Gefahr |
21 | // + Benutzung auf eigene Gefahr |
22 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
22 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
24 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
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 |
25 | // + mit unserer Zustimmung zulässig |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
30 | // + this list of conditions and the following disclaimer. |
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 |
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. |
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 |
33 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
34 | // + for non-commercial use (directly or indirectly) |
34 | // + for non-commercial use (directly or indirectly) |
35 | // + Commercial use (for example: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
35 | // + Commercial use (for example: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
36 | // + with our written permission |
36 | // + with our written permission |
37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
38 | // + clearly linked as origin |
38 | // + clearly linked as origin |
39 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
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" |
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 |
41 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
42 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
42 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
43 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
43 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
44 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
44 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
45 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
45 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
46 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
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) |
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 |
48 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
49 | // + POSSIBILITY OF SUCH DAMAGE. |
49 | // + POSSIBILITY OF SUCH DAMAGE. |
50 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
50 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
51 | #include <util/delay.h> |
51 | #include <util/delay.h> |
52 | #include <stddef.h> |
52 | #include <stddef.h> |
53 | #include <string.h> |
53 | #include <string.h> |
54 | #include "configuration.h" |
54 | #include "configuration.h" |
55 | #include "sensors.h" |
55 | #include "sensors.h" |
56 | #include "rc.h" |
56 | #include "rc.h" |
57 | 57 | ||
58 | int16_t variables[8] = {0,0,0,0,0,0,0,0}; |
58 | int16_t variables[VARIABLE_COUNT]; |
59 | paramset_t staticParams; |
59 | paramset_t staticParams; |
60 | channelMap_t channelMap; |
60 | channelMap_t channelMap; |
61 | mixerMatrix_t mixerMatrix; |
61 | mixerMatrix_t mixerMatrix; |
62 | dynamicParam_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}; |
62 | dynamicParam_t dynamicParams; |
63 | uint8_t CPUType = ATMEGA644; |
63 | uint8_t CPUType = ATMEGA644; |
64 | uint8_t boardRelease = 13; |
64 | uint8_t boardRelease = 13; |
65 | uint8_t requiredMotors; |
65 | uint8_t requiredMotors; |
66 | /************************************************************************ |
66 | /************************************************************************ |
67 | * Map the parameter to pot values |
67 | * Map the parameter to pot values |
68 | * Replacing this code by the code below saved almost 1 kbyte. |
68 | * Replacing this code by the code below saved almost 1 kbyte. |
69 | ************************************************************************/ |
69 | ************************************************************************/ |
70 | 70 | ||
71 | void configuration_applyVariablesToParams(void) { |
71 | void configuration_applyVariablesToParams(void) { |
72 | uint8_t i; |
72 | uint8_t i; |
73 | #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;} |
73 | #define SET_POT_MM(b,a,min,max) {if (a<255) {if (a>=255-VARIABLE_COUNT) b=variables[a+VARIABLE_COUNT-255]; else b=a;} if(b<=min) b=min; else if(b>=max) b=max;} |
74 | #define SET_POT(b,a) { if (a<255) {if (a>=251) b=variables[a-251]; else b=a;}} |
74 | #define SET_POT(b,a) { if (a<255) {if (a>=255-VARIABLE_COUNT) b=variables[a+VARIABLE_COUNT-255]; else b=a;}} |
75 | SET_POT_MM(dynamicParams.gyroP, staticParams.gyroP, 5, 200); |
75 | SET_POT_MM(dynamicParams.gyroP, staticParams.gyroP, 5, 200); |
76 | SET_POT(dynamicParams.gyroI, staticParams.gyroI); |
76 | SET_POT(dynamicParams.gyroI, staticParams.gyroI); |
77 | SET_POT(dynamicParams.gyroD, staticParams.gyroD); |
77 | SET_POT(dynamicParams.gyroD, staticParams.gyroD); |
78 | SET_POT(dynamicParams.IFactor, staticParams.IFactor); |
78 | SET_POT(dynamicParams.IFactor, staticParams.IFactor); |
79 | SET_POT(dynamicParams.yawIFactor, staticParams.yawIFactor); |
79 | SET_POT(dynamicParams.yawIFactor, staticParams.yawIFactor); |
80 | SET_POT(dynamicParams.compassYawEffect,staticParams.compassYawEffect); |
80 | SET_POT(dynamicParams.compassYawEffect,staticParams.compassYawEffect); |
81 | 81 | ||
82 | SET_POT(dynamicParams.externalControl, staticParams.externalControl); |
82 | SET_POT(dynamicParams.externalControl, staticParams.externalControl); |
83 | SET_POT(dynamicParams.axisCoupling1, staticParams.axisCoupling1); |
83 | SET_POT(dynamicParams.axisCoupling1, staticParams.axisCoupling1); |
84 | SET_POT(dynamicParams.axisCoupling2, staticParams.axisCoupling2); |
84 | SET_POT(dynamicParams.axisCoupling2, staticParams.axisCoupling2); |
85 | SET_POT(dynamicParams.axisCouplingYawCorrection, staticParams.axisCouplingYawCorrection); |
85 | SET_POT(dynamicParams.axisCouplingYawCorrection, staticParams.axisCouplingYawCorrection); |
86 | SET_POT(dynamicParams.dynamicStability,staticParams.dynamicStability); |
86 | SET_POT(dynamicParams.dynamicStability,staticParams.dynamicStability); |
87 | SET_POT(dynamicParams.maxControlActivityForAcc,staticParams.maxControlActivityForAcc); |
87 | SET_POT(dynamicParams.maxControlActivityForAcc,staticParams.maxControlActivityForAcc); |
88 | 88 | ||
89 | SET_POT_MM(dynamicParams.heightP, staticParams.heightP,0,100); |
89 | SET_POT_MM(dynamicParams.heightP, staticParams.heightP,0,100); |
90 | SET_POT_MM(dynamicParams.heightD, staticParams.heightD,0,100); |
90 | SET_POT_MM(dynamicParams.heightD, staticParams.heightD,0,100); |
91 | SET_POT(dynamicParams.heightSetting,staticParams.heightSetting); |
91 | SET_POT(dynamicParams.heightSetting,staticParams.heightSetting); |
92 | SET_POT(dynamicParams.heightACCEffect,staticParams.heightACCEffect); |
92 | SET_POT(dynamicParams.heightACCEffect,staticParams.heightACCEffect); |
93 | SET_POT(dynamicParams.attitudeControl,staticParams.attitudeControl); |
93 | SET_POT(dynamicParams.attitudeControl,staticParams.attitudeControl); |
94 | 94 | ||
95 | for (i=0; i<sizeof(staticParams.userParams); i++) { |
95 | for (i=0; i<sizeof(staticParams.userParams); i++) { |
96 | SET_POT(dynamicParams.userParams[i],staticParams.userParams[i]); |
96 | SET_POT(dynamicParams.userParams[i],staticParams.userParams[i]); |
97 | } |
97 | } |
98 | 98 | ||
99 | SET_POT(dynamicParams.servoManualControl[0], staticParams.servoConfigurations[0].manualControl); |
99 | SET_POT(dynamicParams.servoManualControl[0], staticParams.servoConfigurations[0].manualControl); |
100 | SET_POT(dynamicParams.servoManualControl[1], staticParams.servoConfigurations[1].manualControl); |
100 | SET_POT(dynamicParams.servoManualControl[1], staticParams.servoConfigurations[1].manualControl); |
101 | 101 | ||
102 | SET_POT_MM(dynamicParams.output0Timing, staticParams.outputFlash[0].timing,1,255); |
102 | SET_POT_MM(dynamicParams.output0Timing, staticParams.outputFlash[0].timing,1,255); |
103 | SET_POT_MM(dynamicParams.output1Timing, staticParams.outputFlash[1].timing,1,255); |
103 | SET_POT_MM(dynamicParams.output1Timing, staticParams.outputFlash[1].timing,1,255); |
104 | } |
104 | } |
105 | 105 | ||
106 | const XLATION XLATIONS[] = { |
106 | const XLATION XLATIONS[] = { |
107 | // {offsetof(paramset_t, MaxHeight), offsetof(dynamicParam_t, MaxHeight)}, |
107 | {offsetof(paramset_t, heightSetting), offsetof(dynamicParam_t, heightSetting)}, |
108 | }; |
108 | }; |
109 | 109 | ||
110 | const MMXLATION MMXLATIONS[] = { |
110 | const MMXLATION MMXLATIONS[] = { |
111 | // {offsetof(paramset_t, HeightD), offsetof(dynamicParam_t, HeightD),0,100}, |
111 | {offsetof(paramset_t, heightD), offsetof(dynamicParam_t, heightD),0,100}, |
112 | }; |
112 | }; |
113 | 113 | ||
114 | uint8_t configuration_applyVariableToParam(uint8_t src, uint8_t min, uint8_t max) { |
114 | uint8_t configuration_applyVariableToParam(uint8_t src, uint8_t min, uint8_t max) { |
115 | uint8_t result; |
115 | uint8_t result; |
116 | if (src>=251) result = variables[src-251]; |
116 | if (src>=251) result = variables[src-251]; |
117 | else result = src; |
117 | else result = src; |
118 | if (result < min) result = min; |
118 | if (result < min) result = min; |
119 | else if (result > max) result = max; |
119 | else if (result > max) result = max; |
120 | return result; |
120 | return result; |
121 | } |
121 | } |
122 | 122 | ||
123 | void configuration_applyVariablesToParams_dead(void) { |
123 | void configuration_applyVariablesToParams_dead(void) { |
124 | uint8_t i, src; |
124 | uint8_t i, src; |
125 | uint8_t* pointerToTgt; |
125 | uint8_t* pointerToTgt; |
126 | for(i=0; i<sizeof(XLATIONS)/sizeof(XLATION); i++) { |
126 | for(i=0; i<sizeof(XLATIONS)/sizeof(XLATION); i++) { |
127 | src = *((uint8_t*)(&staticParams + XLATIONS[i].sourceIdx)); |
127 | src = *((uint8_t*)(&staticParams + XLATIONS[i].sourceIdx)); |
128 | pointerToTgt = (uint8_t*)(&dynamicParams + XLATIONS[i].targetIdx); |
128 | pointerToTgt = (uint8_t*)(&dynamicParams + XLATIONS[i].targetIdx); |
129 | if (src < 255) { |
129 | if (src < 255) { |
130 | *pointerToTgt = configuration_applyVariableToParam(src, 0, 255); |
130 | *pointerToTgt = configuration_applyVariableToParam(src, 0, 255); |
131 | } |
131 | } |
132 | } |
132 | } |
133 | 133 | ||
134 | for(i=0; i<sizeof(MMXLATIONS)/sizeof(MMXLATION); i++) { |
134 | for(i=0; i<sizeof(MMXLATIONS)/sizeof(MMXLATION); i++) { |
135 | src = *((uint8_t*)(&staticParams + MMXLATIONS[i].sourceIdx)); |
135 | src = *((uint8_t*)(&staticParams + MMXLATIONS[i].sourceIdx)); |
136 | pointerToTgt = (uint8_t*)(&dynamicParams + XLATIONS[i].targetIdx); |
136 | pointerToTgt = (uint8_t*)(&dynamicParams + XLATIONS[i].targetIdx); |
137 | if (src < 255) { |
137 | if (src < 255) { |
138 | *pointerToTgt = configuration_applyVariableToParam(src, MMXLATIONS[i].min, MMXLATIONS[i].max); |
138 | *pointerToTgt = configuration_applyVariableToParam(src, MMXLATIONS[i].min, MMXLATIONS[i].max); |
139 | } |
139 | } |
140 | } |
140 | } |
141 | 141 | ||
142 | for (i=0; i<sizeof(staticParams.userParams); i++) { |
142 | for (i=0; i<sizeof(staticParams.userParams); i++) { |
143 | src = *((uint8_t*)(&staticParams + offsetof(paramset_t, userParams) + i)); |
143 | src = *((uint8_t*)(&staticParams + offsetof(paramset_t, userParams) + i)); |
144 | pointerToTgt = (uint8_t*)(&dynamicParams + offsetof(dynamicParam_t, userParams) + i); |
144 | pointerToTgt = (uint8_t*)(&dynamicParams + offsetof(dynamicParam_t, userParams) + i); |
145 | if (src < 255) { |
145 | if (src < 255) { |
146 | *pointerToTgt = configuration_applyVariableToParam(src, 0, 255); |
146 | *pointerToTgt = configuration_applyVariableToParam(src, 0, 255); |
147 | } |
147 | } |
148 | } |
148 | } |
149 | } |
149 | } |
150 | 150 | ||
151 | uint8_t getCPUType(void) { // works only after reset or power on when the registers have default values |
151 | uint8_t getCPUType(void) { // works only after reset or power on when the registers have default values |
152 | uint8_t CPUType = ATMEGA644; |
152 | uint8_t CPUType = ATMEGA644; |
153 | if( (UCSR1A == 0x20) && (UCSR1C == 0x06) ) CPUType = ATMEGA644P; // initial Values for 644P after reset |
153 | //if((UCSR1A == 0x20) && (UCSR1C == 0x06)) CPUType = ATMEGA644P; // initial Values for 644P after reset |
154 | return CPUType; |
154 | return CPUType; |
155 | } |
155 | } |
156 | 156 | ||
157 | /* |
157 | /* |
158 | * Automatic detection of hardware components is not supported in this development-oriented |
158 | * Automatic detection of hardware components is not supported in this development-oriented |
159 | * FC firmware. It would go against the point of it: To enable alternative hardware |
159 | * FC firmware. It would go against the point of it: To enable alternative hardware |
160 | * configurations with otherwise unsupported components. Instead, one should write |
160 | * configurations with otherwise unsupported components. Instead, one should write |
161 | * custom code + adjust constants for the new hardware, and include the relevant code |
161 | * custom code + adjust constants for the new hardware, and include the relevant code |
162 | * from the makefile. |
162 | * from the makefile. |
163 | * However - we still do detect the board release. Reason: Otherwise it would be too |
163 | * However - we still do detect the board release. Reason: Otherwise it would be too |
164 | * tedious to have to modify the code for how to turn on and off LEDs when deploying |
164 | * tedious to have to modify the code for how to turn on and off LEDs when deploying |
165 | * on different HW version.... |
165 | * on different HW version.... |
166 | */ |
166 | */ |
167 | 167 | ||
168 | uint8_t getBoardRelease(void) { |
168 | uint8_t getBoardRelease(void) { |
169 | uint8_t boardRelease = 13; |
169 | uint8_t boardRelease = 13; |
170 | // the board release is coded via the pull up or down the 2 status LED |
170 | // the board release is coded via the pull up or down the 2 status LED |
171 | 171 | ||
172 | PORTB &= ~((1 << PORTB1)|(1 << PORTB0)); // set tristate |
172 | PORTB &= ~((1 << PORTB1)|(1 << PORTB0)); // set tristate |
173 | DDRB &= ~((1 << DDB0)|(1 << DDB0)); // set port direction as input |
173 | DDRB &= ~((1 << DDB0)|(1 << DDB0)); // set port direction as input |
174 | 174 | ||
175 | _delay_loop_2(1000); // make some delay |
175 | _delay_loop_2(1000); // make some delay |
176 | 176 | ||
177 | switch( PINB & ((1<<PINB1)|(1<<PINB0))) { |
177 | switch( PINB & ((1<<PINB1)|(1<<PINB0))) { |
178 | case 0x00: |
178 | case 0x00: |
179 | boardRelease = 10; // 1.0 |
179 | boardRelease = 10; // 1.0 |
180 | break; |
180 | break; |
181 | case 0x01: |
181 | case 0x01: |
182 | boardRelease = 11; // 1.1 or 1.2 |
182 | boardRelease = 11; // 1.1 or 1.2 |
183 | break; |
183 | break; |
184 | case 0x02: |
184 | case 0x02: |
185 | boardRelease = 20; // 2.0 |
185 | boardRelease = 20; // 2.0 |
186 | break; |
186 | break; |
187 | case 0x03: |
187 | case 0x03: |
188 | boardRelease = 13; // 1.3 |
188 | boardRelease = 13; // 1.3 |
189 | break; |
189 | break; |
190 | default: |
190 | default: |
191 | break; |
191 | break; |
192 | } |
192 | } |
193 | // set LED ports as output |
193 | // set LED ports as output |
194 | DDRB |= (1<<DDB1)|(1<<DDB0); |
194 | DDRB |= (1<<DDB1)|(1<<DDB0); |
195 | RED_ON; |
195 | RED_ON; |
196 | GRN_OFF; |
196 | GRN_OFF; |
197 | return boardRelease; |
197 | return boardRelease; |
198 | } |
198 | } |
199 | 199 | ||
200 | void setOtherDefaults(void) { |
200 | void setOtherDefaults(void) { |
201 | // Height Control |
201 | // Height Control |
202 | staticParams.heightP = 10; |
202 | staticParams.heightP = 10; |
203 | staticParams.heightD = 30; |
203 | staticParams.heightD = 30; |
204 | staticParams.heightSetting = 251; |
204 | staticParams.heightSetting = 251; |
205 | staticParams.heightMaxThrottleChange = 10; |
205 | staticParams.heightControlMaxThrottleChange = 10; |
206 | staticParams.heightSlewRate = 4; |
206 | staticParams.heightSlewRate = 4; |
207 | staticParams.heightACCEffect = 30; |
- | |
208 | 207 | ||
209 | // Control |
208 | // Control |
210 | staticParams.stickP = 8; |
209 | staticParams.stickP = 8; |
211 | staticParams.stickD = 12; |
210 | staticParams.stickD = 12; |
212 | staticParams.stickYawP = 12; |
211 | staticParams.stickYawP = 12; |
213 | staticParams.stickThrottleD = 12; |
212 | staticParams.stickThrottleD = 12; |
214 | staticParams.minThrottle = 8; |
213 | staticParams.minThrottle = 8; |
215 | staticParams.maxThrottle = 230; |
214 | staticParams.maxThrottle = 230; |
216 | staticParams.externalControl = 0; |
215 | staticParams.externalControl = 0; |
217 | 216 | ||
218 | // IMU |
217 | // IMU |
219 | staticParams.gyroPIDFilterConstant = 1; |
218 | staticParams.gyroPIDFilterConstant = 1; |
220 | staticParams.gyroATTFilterConstant = 1; |
219 | staticParams.gyroATTFilterConstant = 1; |
221 | staticParams.gyroDFilterConstant = 1; |
220 | staticParams.gyroDFilterConstant = 1; |
222 | staticParams.accFilterConstant = 4; |
221 | staticParams.accFilterConstant = 4; |
223 | 222 | ||
224 | staticParams.gyroP = 60; |
223 | staticParams.gyroP = 60; |
225 | staticParams.gyroI = 80; |
224 | staticParams.gyroI = 80; |
226 | staticParams.gyroD = 4; |
225 | staticParams.gyroD = 4; |
227 | 226 | ||
228 | // set by gyro code. |
227 | // set by gyro-specific code: gyro_setDefaults(). |
229 | // staticParams.zerothOrderCorrection = |
228 | // staticParams.zerothOrderCorrection = |
230 | // staticParams.driftCompDivider = |
229 | // staticParams.driftCompDivider = |
231 | // staticParams.driftCompLimit = |
230 | // staticParams.driftCompLimit = |
232 | 231 | ||
233 | staticParams.axisCoupling1 = 90; |
232 | staticParams.axisCoupling1 = 90; |
234 | staticParams.axisCoupling2 = 67; |
233 | staticParams.axisCoupling2 = 67; |
235 | staticParams.axisCouplingYawCorrection = 0; |
234 | staticParams.axisCouplingYawCorrection = 0; |
236 | staticParams.dynamicStability = 50; |
235 | staticParams.dynamicStability = 50; |
237 | staticParams.IFactor = 32; |
236 | staticParams.IFactor = 32; |
238 | staticParams.compassYawEffect = 128; |
237 | staticParams.compassYawEffect = 128; |
239 | 238 | ||
240 | // Servos |
239 | // Servos |
241 | for (uint8_t i=0; i<2; i++) { |
240 | for (uint8_t i=0; i<2; i++) { |
242 | staticParams.servoConfigurations[i].manualControl = 128; |
241 | staticParams.servoConfigurations[i].manualControl = 128; |
243 | staticParams.servoConfigurations[i].compensationFactor = 0; |
242 | staticParams.servoConfigurations[i].compensationFactor = 0; |
244 | staticParams.servoConfigurations[i].minValue = 64; |
243 | staticParams.servoConfigurations[i].minValue = 64; |
245 | staticParams.servoConfigurations[i].maxValue = 192; |
244 | staticParams.servoConfigurations[i].maxValue = 192; |
246 | staticParams.servoConfigurations[i].flags = 0; |
245 | staticParams.servoConfigurations[i].flags = 0; |
247 | } |
246 | } |
248 | staticParams.servoCount = 4; |
247 | staticParams.servoCount = 4; |
249 | 248 | ||
250 | // Battery warning and emergency flight |
249 | // Battery warning and emergency flight |
251 | staticParams.batteryVoltageWarning = 101; // 3.7 each for 3S |
250 | staticParams.batteryVoltageWarning = 101; // 3.7 each for 3S |
252 | staticParams.emergencyThrottle = 35; |
251 | staticParams.emergencyThrottle = 35; |
253 | staticParams.emergencyFlightDuration = 30; |
252 | staticParams.emergencyFlightDuration = 30; |
254 | 253 | ||
255 | // Outputs |
254 | // Outputs |
256 | staticParams.outputFlash[0].bitmask = 0b01011111; |
255 | staticParams.outputFlash[0].bitmask = 1; //0b01011111; |
257 | staticParams.outputFlash[0].timing = 15; |
256 | staticParams.outputFlash[0].timing = 15; |
258 | staticParams.outputFlash[1].bitmask = 0b11110011; |
257 | staticParams.outputFlash[1].bitmask = 3; //0b11110011; |
259 | staticParams.outputFlash[1].timing = 15; |
258 | staticParams.outputFlash[1].timing = 15; |
260 | 259 | ||
261 | staticParams.outputFlags = 0; |
260 | staticParams.outputFlags = 0; |
262 | } |
261 | } |
263 | 262 | ||
264 | /***************************************************/ |
263 | /***************************************************/ |
265 | /* Default Values for parameter set 1 */ |
264 | /* Default Values for parameter set 1 */ |
266 | /***************************************************/ |
265 | /***************************************************/ |
267 | void paramSet_default(uint8_t setnumber) { |
266 | void paramSet_default(uint8_t setnumber) { |
268 | setOtherDefaults(); |
267 | setOtherDefaults(); |
269 | gyro_setDefaults(); |
268 | gyro_setDefaults(); |
270 | 269 | ||
271 | for (uint8_t i=0; i<8; i++) { |
270 | for (uint8_t i=0; i<8; i++) { |
272 | staticParams.userParams[i] = 0; |
271 | staticParams.userParams[i] = 0; |
273 | } |
272 | } |
274 | 273 | ||
275 | staticParams.bitConfig = |
274 | staticParams.bitConfig = |
276 | CFG_GYRO_SATURATION_PREVENTION | |
275 | CFG_GYRO_SATURATION_PREVENTION | CFG_HEADING_HOLD; |
277 | CFG_HEADING_HOLD; |
- | |
278 | staticParams.bitConfig2 = 0; |
- | |
279 | 276 | ||
280 | memcpy(staticParams.name, "Default\0", 6); |
277 | memcpy(staticParams.name, "Default\0", 6); |
281 | } |
278 | } |
282 | 279 | ||
283 | /***************************************************/ |
280 | /***************************************************/ |
284 | /* Default Values for Mixer Table */ |
281 | /* Default Values for Mixer Table */ |
285 | /***************************************************/ |
282 | /***************************************************/ |
286 | void mixerMatrix_default(void) { // Quadro |
283 | void mixerMatrix_default(void) { // Quadro |
287 | uint8_t i; |
284 | uint8_t i; |
288 | // mixerMatric.revision = EEMIXER_REVISION; |
285 | // mixerMatric.revision = EEMIXER_REVISION; |
289 | // clear mixer table (but preset throttle) |
286 | // clear mixer table (but preset throttle) |
290 | for (i = 0; i < 16; i++) { |
287 | for (i = 0; i < 16; i++) { |
291 | mixerMatrix.motor[i][MIX_THROTTLE] = i < 4 ? 64 : 0; |
288 | mixerMatrix.motor[i][MIX_THROTTLE] = i < 4 ? 64 : 0; |
292 | mixerMatrix.motor[i][MIX_PITCH] = 0; |
289 | mixerMatrix.motor[i][MIX_PITCH] = 0; |
293 | mixerMatrix.motor[i][MIX_ROLL] = 0; |
290 | mixerMatrix.motor[i][MIX_ROLL] = 0; |
294 | mixerMatrix.motor[i][MIX_YAW] = 0; |
291 | mixerMatrix.motor[i][MIX_YAW] = 0; |
295 | } |
292 | } |
296 | // default = Quadro |
293 | // default = Quadro |
297 | mixerMatrix.motor[0][MIX_PITCH] = +64; |
294 | mixerMatrix.motor[0][MIX_PITCH] = +64; |
298 | mixerMatrix.motor[0][MIX_YAW] = +64; |
295 | mixerMatrix.motor[0][MIX_YAW] = +64; |
299 | mixerMatrix.motor[1][MIX_PITCH] = -64; |
296 | mixerMatrix.motor[1][MIX_PITCH] = -64; |
300 | mixerMatrix.motor[1][MIX_YAW] = +64; |
297 | mixerMatrix.motor[1][MIX_YAW] = +64; |
301 | mixerMatrix.motor[2][MIX_ROLL] = -64; |
298 | mixerMatrix.motor[2][MIX_ROLL] = -64; |
302 | mixerMatrix.motor[2][MIX_YAW] = -64; |
299 | mixerMatrix.motor[2][MIX_YAW] = -64; |
303 | mixerMatrix.motor[3][MIX_ROLL] = +64; |
300 | mixerMatrix.motor[3][MIX_ROLL] = +64; |
304 | mixerMatrix.motor[3][MIX_YAW] = -64; |
301 | mixerMatrix.motor[3][MIX_YAW] = -64; |
305 | memcpy(mixerMatrix.name, "Quadro\0", 7); |
302 | memcpy(mixerMatrix.name, "Quadro\0", 7); |
306 | } |
303 | } |
307 | 304 | ||
308 | void channelMap_default(void) { |
305 | void channelMap_default(void) { |
309 | channelMap.channels[CH_PITCH] = 2; |
306 | channelMap.channels[CH_PITCH] = 2; |
310 | channelMap.channels[CH_ROLL] = 1; |
307 | channelMap.channels[CH_ROLL] = 1; |
311 | channelMap.channels[CH_THROTTLE] = 3; |
308 | channelMap.channels[CH_THROTTLE] = 3; |
312 | channelMap.channels[CH_YAW] = 4; |
309 | channelMap.channels[CH_YAW] = 4; |
313 | channelMap.channels[CH_POTS + 0] = 5; |
310 | channelMap.channels[CH_POTS + 0] = 5; |
314 | channelMap.channels[CH_POTS + 1] = 6; |
311 | channelMap.channels[CH_POTS + 1] = 6; |
315 | channelMap.channels[CH_POTS + 2] = 7; |
312 | channelMap.channels[CH_POTS + 2] = 7; |
316 | channelMap.channels[CH_POTS + 3] = 8; |
313 | channelMap.channels[CH_POTS + 3] = 8; |
317 | } |
314 | } |
318 | 315 | ||
319 | 316 |