Rev 1623 | Rev 1646 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1623 | Rev 1635 | ||
---|---|---|---|
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 und nicht-kommerziellen Gebrauch zulässig ist. |
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 |
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 Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
17 | // + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
18 | // + eindeutig als Ursprung verlinkt und genannt werden |
18 | // + eindeutig als Ursprung verlinkt und genannt 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 excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
35 | // + Commercial use (for excample: 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 |
47 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
48 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
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 |
49 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
50 | // + POSSIBILITY OF SUCH DAMAGE. |
50 | // + POSSIBILITY OF SUCH DAMAGE. |
51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
52 | 52 | ||
53 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
53 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
54 | // + Contant Values |
54 | // + Contant Values |
55 | // + 0-250 -> normale Values |
55 | // + 0-250 -> normale Values |
56 | // + 251 -> Poti1 |
56 | // + 251 -> Poti1 |
57 | // + 252 -> Poti2 |
57 | // + 252 -> Poti2 |
58 | // + 253 -> Poti3 |
58 | // + 253 -> Poti3 |
59 | // + 254 -> Poti4 |
59 | // + 254 -> Poti4 |
60 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
60 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
61 | 61 | ||
62 | #ifndef EEMEM |
62 | #ifndef EEMEM |
63 | #define EEMEM __attribute__ ((section (".eeprom"))) |
63 | #define EEMEM __attribute__ ((section (".eeprom"))) |
64 | #endif |
64 | #endif |
65 | 65 | ||
66 | #include <avr/eeprom.h> |
66 | #include <avr/eeprom.h> |
67 | #include <string.h> |
67 | #include <string.h> |
68 | #include "eeprom.h" |
68 | #include "eeprom.h" |
69 | #include "printf_P.h" |
69 | #include "printf_P.h" |
70 | #include "output.h" |
70 | #include "output.h" |
71 | // TODO: Get rid of these. They have nothing to do with eeprom. |
71 | // TODO: Get rid of these. They have nothing to do with eeprom. |
72 | #include "flight.h" |
72 | #include "flight.h" |
73 | #include "rc.h" |
73 | #include "rc.h" |
74 | #include "sensors.h" |
74 | #include "sensors.h" |
75 | 75 | ||
76 | // byte array in eeprom |
76 | // byte array in eeprom |
77 | uint8_t EEPromArray[E2END+1] EEMEM; |
77 | uint8_t EEPromArray[E2END+1] EEMEM; |
78 | 78 | ||
79 | paramset_t staticParams; |
79 | paramset_t staticParams; |
80 | MixerTable_t Mixer; |
80 | MixerTable_t Mixer; |
81 | 81 | ||
82 | /* |
82 | /* |
83 | * Default for your own experiments here, so you don't have to reset them |
83 | * Default for your own experiments here, so you don't have to reset them |
84 | * from MK-Tool all the time. |
84 | * from MK-Tool all the time. |
85 | */ |
85 | */ |
86 | void setDefaultUserParams(void) { |
86 | void setDefaultUserParams(void) { |
87 | uint8_t i; |
87 | uint8_t i; |
88 | for (i=0; i<sizeof(staticParams.UserParams1); i++) { |
88 | for (i=0; i<sizeof(staticParams.UserParams1); i++) { |
89 | staticParams.UserParams1[i] = 0; |
89 | staticParams.UserParams1[i] = 0; |
90 | } |
90 | } |
91 | for (i=0; i<sizeof(staticParams.UserParams2); i++) { |
91 | for (i=0; i<sizeof(staticParams.UserParams2); i++) { |
92 | staticParams.UserParams2[i] = 0; |
92 | staticParams.UserParams2[i] = 0; |
93 | } |
93 | } |
- | 94 | /* |
|
- | 95 | * While we are still using userparams for flight parameters, do set |
|
- | 96 | * some safe & meaningful default values. |
|
- | 97 | */ |
|
- | 98 | staticParams.UserParams1[4] = 0b01010101; |
|
- | 99 | staticParams.UserParams1[5] = 2; // H&I motor smoothing. |
|
- | 100 | staticParams.UserParams1[6] = 120; |
|
- | 101 | staticParams.UserParams1[7] = 5; |
|
94 | } |
102 | } |
95 | 103 | ||
96 | void setOtherDefaults(void) { |
104 | void setOtherDefaults(void) { |
97 | /* Channel assignments were changed to the normal: |
105 | /* Channel assignments were changed to the normal: |
98 | * Aileron/roll=1, elevator/pitch=2, throttle=3, yaw/rudder=4 |
106 | * Aileron/roll=1, elevator/pitch=2, throttle=3, yaw/rudder=4 |
99 | */ |
107 | */ |
100 | staticParams.ChannelAssignment[CH_PITCH] = 2; |
108 | staticParams.ChannelAssignment[CH_PITCH] = 2; |
101 | staticParams.ChannelAssignment[CH_ROLL] = 1; |
109 | staticParams.ChannelAssignment[CH_ROLL] = 1; |
102 | staticParams.ChannelAssignment[CH_THROTTLE] = 3; |
110 | staticParams.ChannelAssignment[CH_THROTTLE] = 3; |
103 | staticParams.ChannelAssignment[CH_YAW] = 4; |
111 | staticParams.ChannelAssignment[CH_YAW] = 4; |
104 | staticParams.ChannelAssignment[CH_POTS+0] = 5; |
112 | staticParams.ChannelAssignment[CH_POTS+0] = 5; |
105 | staticParams.ChannelAssignment[CH_POTS+1] = 6; |
113 | staticParams.ChannelAssignment[CH_POTS+1] = 6; |
106 | staticParams.ChannelAssignment[CH_POTS+2] = 7; |
114 | staticParams.ChannelAssignment[CH_POTS+2] = 7; |
107 | staticParams.ChannelAssignment[CH_POTS+3] = 8; |
115 | staticParams.ChannelAssignment[CH_POTS+3] = 8; |
108 | staticParams.GlobalConfig = CFG_AXIS_COUPLING_ACTIVE | CFG_COMPASS_ACTIVE | CFG_GPS_ACTIVE;//CFG_HEIGHT_CONTROL | CFG_HEIGHT_SWITCH | CFG_COMPASS_FIX; |
116 | staticParams.GlobalConfig = CFG_AXIS_COUPLING_ACTIVE | CFG_COMPASS_ACTIVE | CFG_GPS_ACTIVE;//CFG_HEIGHT_CONTROL | CFG_HEIGHT_SWITCH | CFG_COMPASS_FIX; |
109 | staticParams.HeightMinGas = 30; |
117 | staticParams.HeightMinGas = 30; |
110 | staticParams.MaxHeight = 251; |
118 | staticParams.MaxHeight = 251; |
111 | staticParams.HeightP = 10; |
119 | staticParams.HeightP = 10; |
112 | staticParams.HeightD = 30; |
120 | staticParams.HeightD = 30; |
113 | staticParams.Height_ACC_Effect = 30; |
121 | staticParams.Height_ACC_Effect = 30; |
114 | staticParams.Height_Gain = 4; |
122 | staticParams.Height_Gain = 4; |
115 | staticParams.StickP = 12; |
123 | staticParams.StickP = 12; |
116 | staticParams.StickD = 16; |
124 | staticParams.StickD = 16; |
117 | staticParams.StickYawP = 12; |
125 | staticParams.StickYawP = 12; |
118 | staticParams.MinThrottle = 8; |
126 | staticParams.MinThrottle = 8; |
119 | staticParams.MaxThrottle = 230; |
127 | staticParams.MaxThrottle = 230; |
120 | staticParams.CompassYawEffect = 128; |
128 | staticParams.CompassYawEffect = 128; |
121 | staticParams.GyroP = 80; |
129 | staticParams.GyroP = 80; |
122 | staticParams.GyroI = 100; |
130 | staticParams.GyroI = 100; |
123 | staticParams.LowVoltageWarning = 94; |
131 | staticParams.LowVoltageWarning = 94; |
124 | staticParams.EmergencyGas = 35; |
132 | staticParams.EmergencyGas = 35; |
125 | staticParams.EmergencyGasDuration = 30; |
133 | staticParams.EmergencyGasDuration = 30; |
126 | staticParams.UfoArrangement = 0; |
134 | staticParams.UfoArrangement = 0; |
127 | staticParams.IFactor = 32; |
135 | staticParams.IFactor = 32; |
128 | staticParams.ServoPitchControl = 100; |
136 | staticParams.ServoPitchControl = 100; |
129 | staticParams.ServoPitchComp = 40; |
137 | staticParams.ServoPitchComp = 40; |
130 | staticParams.ServoPitchCompInvert = 0; |
138 | staticParams.ServoPitchCompInvert = 0; |
131 | staticParams.ServoPitchMin = 50; |
139 | staticParams.ServoPitchMin = 50; |
132 | staticParams.ServoPitchMax = 150; |
140 | staticParams.ServoPitchMax = 150; |
133 | staticParams.ServoRefresh = 5; |
141 | staticParams.ServoRefresh = 5; |
134 | staticParams.LoopGasLimit = 50; |
142 | staticParams.LoopGasLimit = 50; |
135 | staticParams.LoopThreshold = 90; |
143 | staticParams.LoopThreshold = 90; |
136 | staticParams.LoopHysteresis = 50; |
144 | staticParams.LoopHysteresis = 50; |
137 | staticParams.BitConfig = 0; |
145 | staticParams.BitConfig = 0; |
138 | staticParams.AxisCoupling1 = 90; |
146 | staticParams.AxisCoupling1 = 90; |
139 | staticParams.AxisCoupling2 = 67; |
147 | staticParams.AxisCoupling2 = 67; |
140 | staticParams.AxisCouplingYawCorrection = 0; |
148 | staticParams.AxisCouplingYawCorrection = 0; |
141 | staticParams.GyroAccTrim = 2; |
149 | staticParams.GyroAccTrim = 2; |
142 | staticParams.DynamicStability = 50; |
150 | staticParams.DynamicStability = 50; |
143 | staticParams.J16Bitmask = 95; |
151 | staticParams.J16Bitmask = 95; |
144 | staticParams.J17Bitmask = 243; |
152 | staticParams.J17Bitmask = 243; |
145 | staticParams.J16Timing = 15; |
153 | staticParams.J16Timing = 15; |
146 | staticParams.J17Timing = 15; |
154 | staticParams.J17Timing = 15; |
147 | staticParams.NaviGpsModeControl = 253; |
155 | staticParams.NaviGpsModeControl = 253; |
148 | staticParams.NaviGpsGain = 100; |
156 | staticParams.NaviGpsGain = 100; |
149 | staticParams.NaviGpsP = 90; |
157 | staticParams.NaviGpsP = 90; |
150 | staticParams.NaviGpsI = 90; |
158 | staticParams.NaviGpsI = 90; |
151 | staticParams.NaviGpsD = 90; |
159 | staticParams.NaviGpsD = 90; |
152 | staticParams.NaviGpsPLimit = 75; |
160 | staticParams.NaviGpsPLimit = 75; |
153 | staticParams.NaviGpsILimit = 75; |
161 | staticParams.NaviGpsILimit = 75; |
154 | staticParams.NaviGpsDLimit = 75; |
162 | staticParams.NaviGpsDLimit = 75; |
155 | staticParams.NaviGpsACC = 0; |
163 | staticParams.NaviGpsACC = 0; |
156 | staticParams.NaviGpsMinSat = 6; |
164 | staticParams.NaviGpsMinSat = 6; |
157 | staticParams.NaviStickThreshold = 8; |
165 | staticParams.NaviStickThreshold = 8; |
158 | staticParams.NaviWindCorrection = 90; |
166 | staticParams.NaviWindCorrection = 90; |
159 | staticParams.NaviSpeedCompensation = 30; |
167 | staticParams.NaviSpeedCompensation = 30; |
160 | staticParams.NaviOperatingRadius = 100; |
168 | staticParams.NaviOperatingRadius = 100; |
161 | staticParams.NaviAngleLimitation = 100; |
169 | staticParams.NaviAngleLimitation = 100; |
162 | staticParams.NaviPHLoginTime = 4; |
170 | staticParams.NaviPHLoginTime = 4; |
163 | } |
171 | } |
164 | 172 | ||
165 | /***************************************************/ |
173 | /***************************************************/ |
166 | /* Default Values for parameter set 1 */ |
174 | /* Default Values for parameter set 1 */ |
167 | /***************************************************/ |
175 | /***************************************************/ |
168 | void ParamSet_DefaultSet1(void) { // sport |
176 | void ParamSet_DefaultSet1(void) { // sport |
169 | gyro_setDefaults(); |
177 | gyro_setDefaults(); |
170 | setDefaultUserParams(); |
178 | setDefaultUserParams(); |
171 | setOtherDefaults(); |
179 | setOtherDefaults(); |
172 | memcpy(staticParams.Name, "Sport\0",6); |
180 | memcpy(staticParams.Name, "Sport\0",6); |
173 | } |
181 | } |
174 | 182 | ||
175 | /***************************************************/ |
183 | /***************************************************/ |
176 | /* Default Values for parameter set 2 */ |
184 | /* Default Values for parameter set 2 */ |
177 | /***************************************************/ |
185 | /***************************************************/ |
178 | void ParamSet_DefaultSet2(void) { // normal |
186 | void ParamSet_DefaultSet2(void) { // normal |
179 | gyro_setDefaults(); |
187 | gyro_setDefaults(); |
180 | setDefaultUserParams(); |
188 | setDefaultUserParams(); |
181 | setOtherDefaults(); |
189 | setOtherDefaults(); |
182 | staticParams.Height_Gain = 3; |
190 | staticParams.Height_Gain = 3; |
183 | staticParams.GyroAccTrim = 32; |
191 | staticParams.GyroAccTrim = 32; |
184 | staticParams.J16Timing = 20; |
192 | staticParams.J16Timing = 20; |
185 | staticParams.J17Timing = 20; |
193 | staticParams.J17Timing = 20; |
186 | memcpy(staticParams.Name, "Normal\0", 7); |
194 | memcpy(staticParams.Name, "Normal\0", 7); |
187 | } |
195 | } |
188 | 196 | ||
189 | /***************************************************/ |
197 | /***************************************************/ |
190 | /* Default Values for parameter set 3 */ |
198 | /* Default Values for parameter set 3 */ |
191 | /***************************************************/ |
199 | /***************************************************/ |
192 | void ParamSet_DefaultSet3(void) { // beginner |
200 | void ParamSet_DefaultSet3(void) { // beginner |
193 | gyro_setDefaults(); |
201 | gyro_setDefaults(); |
194 | setDefaultUserParams(); |
202 | setDefaultUserParams(); |
195 | setOtherDefaults(); |
203 | setOtherDefaults(); |
196 | staticParams.GlobalConfig = CFG_ROTARY_RATE_LIMITER | CFG_AXIS_COUPLING_ACTIVE | CFG_COMPASS_ACTIVE | CFG_GPS_ACTIVE;//CFG_HEIGHT_CONTROL | CFG_HEIGHT_SWITCH | CFG_COMPASS_FIX; |
204 | staticParams.GlobalConfig = CFG_ROTARY_RATE_LIMITER | CFG_AXIS_COUPLING_ACTIVE | CFG_COMPASS_ACTIVE | CFG_GPS_ACTIVE;//CFG_HEIGHT_CONTROL | CFG_HEIGHT_SWITCH | CFG_COMPASS_FIX; |
197 | staticParams.Height_Gain = 3; |
205 | staticParams.Height_Gain = 3; |
198 | staticParams.EmergencyGasDuration = 20; |
206 | staticParams.EmergencyGasDuration = 20; |
199 | staticParams.AxisCouplingYawCorrection = 70; |
207 | staticParams.AxisCouplingYawCorrection = 70; |
200 | staticParams.GyroAccTrim = 32; |
208 | staticParams.GyroAccTrim = 32; |
201 | staticParams.J16Timing = 30; |
209 | staticParams.J16Timing = 30; |
202 | staticParams.J17Timing = 30; |
210 | staticParams.J17Timing = 30; |
203 | memcpy(staticParams.Name, "Beginner\0", 9); |
211 | memcpy(staticParams.Name, "Beginner\0", 9); |
204 | } |
212 | } |
205 | 213 | ||
206 | /***************************************************/ |
214 | /***************************************************/ |
207 | /* Read Parameter from EEPROM as byte */ |
215 | /* Read Parameter from EEPROM as byte */ |
208 | /***************************************************/ |
216 | /***************************************************/ |
209 | uint8_t GetParamByte(uint16_t param_id) { |
217 | uint8_t GetParamByte(uint16_t param_id) { |
210 | return eeprom_read_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id]); |
218 | return eeprom_read_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id]); |
211 | } |
219 | } |
212 | 220 | ||
213 | /***************************************************/ |
221 | /***************************************************/ |
214 | /* Write Parameter to EEPROM as byte */ |
222 | /* Write Parameter to EEPROM as byte */ |
215 | /***************************************************/ |
223 | /***************************************************/ |
216 | void SetParamByte(uint16_t param_id, uint8_t value) { |
224 | void SetParamByte(uint16_t param_id, uint8_t value) { |
217 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value); |
225 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value); |
218 | } |
226 | } |
219 | 227 | ||
220 | /***************************************************/ |
228 | /***************************************************/ |
221 | /* Read Parameter from EEPROM as word */ |
229 | /* Read Parameter from EEPROM as word */ |
222 | /***************************************************/ |
230 | /***************************************************/ |
223 | uint16_t GetParamWord(uint16_t param_id) { |
231 | uint16_t GetParamWord(uint16_t param_id) { |
224 | return eeprom_read_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id]); |
232 | return eeprom_read_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id]); |
225 | } |
233 | } |
226 | 234 | ||
227 | /***************************************************/ |
235 | /***************************************************/ |
228 | /* Write Parameter to EEPROM as word */ |
236 | /* Write Parameter to EEPROM as word */ |
229 | /***************************************************/ |
237 | /***************************************************/ |
230 | void SetParamWord(uint16_t param_id, uint16_t value) { |
238 | void SetParamWord(uint16_t param_id, uint16_t value) { |
231 | eeprom_write_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value); |
239 | eeprom_write_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value); |
232 | } |
240 | } |
233 | 241 | ||
234 | /***************************************************/ |
242 | /***************************************************/ |
235 | /* Read Parameter Set from EEPROM */ |
243 | /* Read Parameter Set from EEPROM */ |
236 | /***************************************************/ |
244 | /***************************************************/ |
237 | // number [1..5] |
245 | // number [1..5] |
238 | void ParamSet_ReadFromEEProm(uint8_t setnumber) { |
246 | void ParamSet_ReadFromEEProm(uint8_t setnumber) { |
239 | if((1 > setnumber) || (setnumber > 5)) setnumber = 3; |
247 | if((1 > setnumber) || (setnumber > 5)) setnumber = 3; |
240 | eeprom_read_block((uint8_t *) &staticParams.ChannelAssignment[0], &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * (setnumber - 1)], PARAMSET_STRUCT_LEN); |
248 | eeprom_read_block((uint8_t *) &staticParams.ChannelAssignment[0], &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * (setnumber - 1)], PARAMSET_STRUCT_LEN); |
241 | output_init(); |
249 | output_init(); |
242 | } |
250 | } |
243 | 251 | ||
244 | /***************************************************/ |
252 | /***************************************************/ |
245 | /* Write Parameter Set to EEPROM */ |
253 | /* Write Parameter Set to EEPROM */ |
246 | /***************************************************/ |
254 | /***************************************************/ |
247 | // number [1..5] |
255 | // number [1..5] |
248 | void ParamSet_WriteToEEProm(uint8_t setnumber) { |
256 | void ParamSet_WriteToEEProm(uint8_t setnumber) { |
249 | if(setnumber > 5) setnumber = 5; |
257 | if(setnumber > 5) setnumber = 5; |
250 | if(setnumber < 1) return; |
258 | if(setnumber < 1) return; |
251 | eeprom_write_block((uint8_t *) &staticParams.ChannelAssignment[0], &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * (setnumber - 1)], PARAMSET_STRUCT_LEN); |
259 | eeprom_write_block((uint8_t *) &staticParams.ChannelAssignment[0], &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * (setnumber - 1)], PARAMSET_STRUCT_LEN); |
252 | eeprom_write_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAMSET_LENGTH], PARAMSET_STRUCT_LEN); |
260 | eeprom_write_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAMSET_LENGTH], PARAMSET_STRUCT_LEN); |
253 | eeprom_write_block( &staticParams.ChannelAssignment[0], &EEPromArray[EEPROM_ADR_CHANNELS], 8); // backup the first 8 bytes that is the rc channel mapping |
261 | eeprom_write_block( &staticParams.ChannelAssignment[0], &EEPromArray[EEPROM_ADR_CHANNELS], 8); // backup the first 8 bytes that is the rc channel mapping |
254 | // set this parameter set to active set |
262 | // set this parameter set to active set |
255 | setActiveParamSet(setnumber); |
263 | setActiveParamSet(setnumber); |
256 | output_init(); |
264 | output_init(); |
257 | } |
265 | } |
258 | 266 | ||
259 | 267 | ||
260 | /***************************************************/ |
268 | /***************************************************/ |
261 | /* Get active parameter set */ |
269 | /* Get active parameter set */ |
262 | /***************************************************/ |
270 | /***************************************************/ |
263 | uint8_t getActiveParamSet(void) { |
271 | uint8_t getActiveParamSet(void) { |
264 | uint8_t setnumber; |
272 | uint8_t setnumber; |
265 | setnumber = eeprom_read_byte(&EEPromArray[PID_ACTIVE_SET]); |
273 | setnumber = eeprom_read_byte(&EEPromArray[PID_ACTIVE_SET]); |
266 | if(setnumber > 5) { |
274 | if(setnumber > 5) { |
267 | setnumber = 3; |
275 | setnumber = 3; |
268 | eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber); |
276 | eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber); |
269 | } |
277 | } |
270 | return(setnumber); |
278 | return(setnumber); |
271 | } |
279 | } |
272 | 280 | ||
273 | /***************************************************/ |
281 | /***************************************************/ |
274 | /* Set active parameter set */ |
282 | /* Set active parameter set */ |
275 | /***************************************************/ |
283 | /***************************************************/ |
276 | void setActiveParamSet(uint8_t setnumber) { |
284 | void setActiveParamSet(uint8_t setnumber) { |
277 | if(setnumber > 5) setnumber = 5; |
285 | if(setnumber > 5) setnumber = 5; |
278 | if(setnumber < 1) setnumber = 1; |
286 | if(setnumber < 1) setnumber = 1; |
279 | eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber); |
287 | eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber); |
280 | } |
288 | } |
281 | 289 | ||
282 | /***************************************************/ |
290 | /***************************************************/ |
283 | /* Read MixerTable from EEPROM */ |
291 | /* Read MixerTable from EEPROM */ |
284 | /***************************************************/ |
292 | /***************************************************/ |
285 | uint8_t MixerTable_ReadFromEEProm(void) { |
293 | uint8_t MixerTable_ReadFromEEProm(void) { |
286 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE]) == EEMIXER_REVISION) { |
294 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE]) == EEMIXER_REVISION) { |
287 | eeprom_read_block((uint8_t *) &Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
295 | eeprom_read_block((uint8_t *) &Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
288 | return 1; |
296 | return 1; |
289 | } |
297 | } |
290 | else return 0; |
298 | else return 0; |
291 | } |
299 | } |
292 | 300 | ||
293 | /***************************************************/ |
301 | /***************************************************/ |
294 | /* Write Mixer Table to EEPROM */ |
302 | /* Write Mixer Table to EEPROM */ |
295 | /***************************************************/ |
303 | /***************************************************/ |
296 | uint8_t MixerTable_WriteToEEProm(void) { |
304 | uint8_t MixerTable_WriteToEEProm(void) { |
297 | if(Mixer.Revision == EEMIXER_REVISION) { |
305 | if(Mixer.Revision == EEMIXER_REVISION) { |
298 | eeprom_write_block((uint8_t *) &Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
306 | eeprom_write_block((uint8_t *) &Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
299 | return 1; |
307 | return 1; |
300 | } |
308 | } |
301 | else return 0; |
309 | else return 0; |
302 | } |
310 | } |
303 | 311 | ||
304 | /***************************************************/ |
312 | /***************************************************/ |
305 | /* Default Values for Mixer Table */ |
313 | /* Default Values for Mixer Table */ |
306 | /***************************************************/ |
314 | /***************************************************/ |
307 | void MixerTable_Default(void) { // Quadro |
315 | void MixerTable_Default(void) { // Quadro |
308 | uint8_t i; |
316 | uint8_t i; |
309 | Mixer.Revision = EEMIXER_REVISION; |
317 | Mixer.Revision = EEMIXER_REVISION; |
310 | // clear mixer table (but preset throttle) |
318 | // clear mixer table (but preset throttle) |
311 | for(i = 0; i < 16; i++) { |
319 | for(i = 0; i < 16; i++) { |
312 | Mixer.Motor[i][MIX_THROTTLE] = i < 4 ? 64 : 0; |
320 | Mixer.Motor[i][MIX_THROTTLE] = i < 4 ? 64 : 0; |
313 | Mixer.Motor[i][MIX_PITCH] = 0; |
321 | Mixer.Motor[i][MIX_PITCH] = 0; |
314 | Mixer.Motor[i][MIX_ROLL] = 0; |
322 | Mixer.Motor[i][MIX_ROLL] = 0; |
315 | Mixer.Motor[i][MIX_YAW] = 0; |
323 | Mixer.Motor[i][MIX_YAW] = 0; |
316 | } |
324 | } |
317 | // default = Quadro |
325 | // default = Quadro |
318 | Mixer.Motor[0][MIX_PITCH] = +64; Mixer.Motor[0][MIX_YAW] = +64; |
326 | Mixer.Motor[0][MIX_PITCH] = +64; Mixer.Motor[0][MIX_YAW] = +64; |
319 | Mixer.Motor[1][MIX_PITCH] = -64; Mixer.Motor[1][MIX_YAW] = +64; |
327 | Mixer.Motor[1][MIX_PITCH] = -64; Mixer.Motor[1][MIX_YAW] = +64; |
320 | Mixer.Motor[2][MIX_ROLL] = -64; Mixer.Motor[2][MIX_YAW] = -64; |
328 | Mixer.Motor[2][MIX_ROLL] = -64; Mixer.Motor[2][MIX_YAW] = -64; |
321 | Mixer.Motor[3][MIX_ROLL] = +64; Mixer.Motor[3][MIX_YAW] = -64; |
329 | Mixer.Motor[3][MIX_ROLL] = +64; Mixer.Motor[3][MIX_YAW] = -64; |
322 | memcpy(Mixer.Name, "Quadro\0", 7); |
330 | memcpy(Mixer.Name, "Quadro\0", 7); |
323 | } |
331 | } |
324 | 332 | ||
325 | /***************************************************/ |
333 | /***************************************************/ |
326 | /* Initialize EEPROM Parameter Sets */ |
334 | /* Initialize EEPROM Parameter Sets */ |
327 | /***************************************************/ |
335 | /***************************************************/ |
328 | void ParamSet_Init(void) { |
336 | void ParamSet_Init(void) { |
329 | uint8_t Channel_Backup = 0, i; |
337 | uint8_t Channel_Backup = 0, i; |
330 | // parameter version check |
338 | // parameter version check |
331 | if(eeprom_read_byte(&EEPromArray[PID_PARAM_REVISION]) != EEPARAM_REVISION) { |
339 | if(eeprom_read_byte(&EEPromArray[PID_PARAM_REVISION]) != EEPARAM_REVISION) { |
332 | // if version check faild |
340 | // if version check faild |
333 | printf("\n\rInit Parameter in EEPROM"); |
341 | printf("\n\rInit Parameter in EEPROM"); |
334 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE], 0xFF); // reset also mixer table |
342 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE], 0xFF); // reset also mixer table |
335 | // check if channel mapping backup is valid |
343 | // check if channel mapping backup is valid |
336 | if( (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+0]) < 12) |
344 | if( (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+0]) < 12) |
337 | && (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]) < 12) |
345 | && (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]) < 12) |
338 | && (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]) < 12) |
346 | && (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]) < 12) |
339 | && (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]) < 12) |
347 | && (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]) < 12) |
340 | ) |
348 | ) |
341 | { |
349 | { |
342 | Channel_Backup = 1; |
350 | Channel_Backup = 1; |
343 | } |
351 | } |
344 | // fill all 5 parameter settings |
352 | // fill all 5 parameter settings |
345 | for (i=1; i<6; i++) { |
353 | for (i=1; i<6; i++) { |
346 | switch(i) { |
354 | switch(i) { |
347 | case 1: |
355 | case 1: |
348 | ParamSet_DefaultSet1(); // Fill staticParams Structure to default parameter set 1 (Sport) |
356 | ParamSet_DefaultSet1(); // Fill staticParams Structure to default parameter set 1 (Sport) |
349 | break; |
357 | break; |
350 | case 2: |
358 | case 2: |
351 | ParamSet_DefaultSet2(); // Kamera |
359 | ParamSet_DefaultSet2(); // Kamera |
352 | break; |
360 | break; |
353 | case 3: |
361 | case 3: |
354 | ParamSet_DefaultSet3(); // Beginner |
362 | ParamSet_DefaultSet3(); // Beginner |
355 | break; |
363 | break; |
356 | default: |
364 | default: |
357 | ParamSet_DefaultSet2(); // Kamera |
365 | ParamSet_DefaultSet2(); // Kamera |
358 | break; |
366 | break; |
359 | } |
367 | } |
360 | if(Channel_Backup) { // if we have a rc channel mapping backup in eeprom |
368 | if(Channel_Backup) { // if we have a rc channel mapping backup in eeprom |
361 | // restore it |
369 | // restore it |
362 | staticParams.ChannelAssignment[0] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+0]); |
370 | staticParams.ChannelAssignment[0] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+0]); |
363 | staticParams.ChannelAssignment[1] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]); |
371 | staticParams.ChannelAssignment[1] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]); |
364 | staticParams.ChannelAssignment[2] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]); |
372 | staticParams.ChannelAssignment[2] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]); |
365 | staticParams.ChannelAssignment[3] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]); |
373 | staticParams.ChannelAssignment[3] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]); |
366 | staticParams.ChannelAssignment[4] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+4]); |
374 | staticParams.ChannelAssignment[4] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+4]); |
367 | staticParams.ChannelAssignment[5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+5]); |
375 | staticParams.ChannelAssignment[5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+5]); |
368 | staticParams.ChannelAssignment[6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+6]); |
376 | staticParams.ChannelAssignment[6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+6]); |
369 | staticParams.ChannelAssignment[7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+7]); |
377 | staticParams.ChannelAssignment[7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+7]); |
370 | } |
378 | } |
371 | ParamSet_WriteToEEProm(i); |
379 | ParamSet_WriteToEEProm(i); |
372 | } |
380 | } |
373 | // default-Setting is parameter set 3 |
381 | // default-Setting is parameter set 3 |
374 | setActiveParamSet(1); |
382 | setActiveParamSet(1); |
375 | // update version info |
383 | // update version info |
376 | SetParamByte(PID_PARAM_REVISION, EEPARAM_REVISION); |
384 | SetParamByte(PID_PARAM_REVISION, EEPARAM_REVISION); |
377 | } |
385 | } |
378 | // read active parameter set to staticParams stucture |
386 | // read active parameter set to staticParams stucture |
379 | ParamSet_ReadFromEEProm(getActiveParamSet()); |
387 | ParamSet_ReadFromEEProm(getActiveParamSet()); |
380 | printf("\n\rUsing Parameter Set %d", getActiveParamSet()); |
388 | printf("\n\rUsing Parameter Set %d", getActiveParamSet()); |
381 | 389 | ||
382 | // load mixer table |
390 | // load mixer table |
383 | if(!MixerTable_ReadFromEEProm()) { |
391 | if(!MixerTable_ReadFromEEProm()) { |
384 | printf("\n\rGenerating default Mixer Table"); |
392 | printf("\n\rGenerating default Mixer Table"); |
385 | MixerTable_Default(); // Quadro |
393 | MixerTable_Default(); // Quadro |
386 | MixerTable_WriteToEEProm(); |
394 | MixerTable_WriteToEEProm(); |
387 | } |
395 | } |
388 | // determine motornumber |
396 | // determine motornumber |
389 | RequiredMotors = 0; |
397 | RequiredMotors = 0; |
390 | for(i = 0; i < 16; i++) { |
398 | for(i = 0; i < 16; i++) { |
391 | if(Mixer.Motor[i][MIX_THROTTLE] > 0) RequiredMotors++; |
399 | if(Mixer.Motor[i][MIX_THROTTLE] > 0) RequiredMotors++; |
392 | } |
400 | } |
393 | 401 | ||
394 | printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name, RequiredMotors); |
402 | printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name, RequiredMotors); |
395 | printf("\n\r=============================="); |
403 | printf("\n\r=============================="); |
396 | } |
404 | } |
397 | 405 |