Subversion Repositories FlightCtrl

Rev

Rev 1874 | Rev 1961 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1874 Rev 1908
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 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
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
        /*
94
        /*
95
         * While we are still using userparams for flight parameters, do set
95
         * While we are still using userparams for flight parameters, do set
96
         * some safe & meaningful default values.
96
         * some safe & meaningful default values.
97
         */
97
         */
98
        staticParams.UserParams1[3] = 8; // Throttle stick D=8
98
        staticParams.UserParams1[3] = 12; // Throttle stick D=12
99
        staticParams.UserParams2[0] = 0b11010101; // All gyro filter constants 2; acc. 4
99
        staticParams.UserParams2[0] = 0b11010101; // All gyro filter constants 2; acc. 4
100
        staticParams.UserParams2[1] = 2; // H&I motor smoothing.
100
        staticParams.UserParams2[1] = 2; // H&I motor smoothing.
101
        staticParams.UserParams2[2] = 120; // Yaw I factor
101
        staticParams.UserParams2[2] = 120; // Yaw I factor
102
        staticParams.UserParams2[3] = 100; // Max Z acceleration for acc. correction of angles.
102
        staticParams.UserParams2[3] = 100; // Max Z acceleration for acc. correction of angles.
103
}
103
}
104
 
104
 
105
void setOtherDefaults(void) {
105
void setOtherDefaults(void) {
106
        /* Channel assignments were changed to the normal:
106
        /* Channel assignments were changed to the normal:
107
         * Aileron/roll=1, elevator/pitch=2, throttle=3, yaw/rudder=4
107
         * Aileron/roll=1, elevator/pitch=2, throttle=3, yaw/rudder=4
108
         */
108
         */
109
        staticParams.ChannelAssignment[CH_PITCH] = 2;
109
        staticParams.ChannelAssignment[CH_PITCH] = 2;
110
        staticParams.ChannelAssignment[CH_ROLL] = 1;
110
        staticParams.ChannelAssignment[CH_ROLL] = 1;
111
        staticParams.ChannelAssignment[CH_THROTTLE] = 3;
111
        staticParams.ChannelAssignment[CH_THROTTLE] = 3;
112
        staticParams.ChannelAssignment[CH_YAW] = 4;
112
        staticParams.ChannelAssignment[CH_YAW] = 4;
113
        staticParams.ChannelAssignment[CH_POTS + 0] = 5;
113
        staticParams.ChannelAssignment[CH_POTS + 0] = 5;
114
        staticParams.ChannelAssignment[CH_POTS + 1] = 6;
114
        staticParams.ChannelAssignment[CH_POTS + 1] = 6;
115
        staticParams.ChannelAssignment[CH_POTS + 2] = 7;
115
        staticParams.ChannelAssignment[CH_POTS + 2] = 7;
116
        staticParams.ChannelAssignment[CH_POTS + 3] = 8;
116
        staticParams.ChannelAssignment[CH_POTS + 3] = 8;
117
        staticParams.GlobalConfig = /* CFG_AXIS_COUPLING_ACTIVE | */ CFG_HEADING_HOLD; // CFG_COMPASS_ACTIVE | CFG_GPS_ACTIVE;//CFG_HEIGHT_CONTROL | CFG_HEIGHT_SWITCH | CFG_COMPASS_FIX;
117
        staticParams.GlobalConfig = /* CFG_AXIS_COUPLING_ACTIVE | */ CFG_HEADING_HOLD; // CFG_COMPASS_ACTIVE | CFG_GPS_ACTIVE;//CFG_HEIGHT_CONTROL | CFG_HEIGHT_SWITCH | CFG_COMPASS_FIX;
118
        staticParams.HeightMinGas = 30;
118
        staticParams.HeightMinGas = 30;
119
        staticParams.MaxHeight = 251;
119
        staticParams.MaxHeight = 251;
120
        staticParams.HeightP = 10;
120
        staticParams.HeightP = 10;
121
        staticParams.HeightD = 30;
121
        staticParams.HeightD = 30;
122
        staticParams.Height_ACC_Effect = 30;
122
        staticParams.Height_ACC_Effect = 30;
123
        staticParams.Height_Gain = 4;
123
        staticParams.Height_Gain = 4;
124
        staticParams.StickP = 8;
124
        staticParams.StickP = 8;
125
        staticParams.StickD = 12;
125
        staticParams.StickD = 12;
126
        staticParams.StickYawP = 12;
126
        staticParams.StickYawP = 12;
127
        staticParams.MinThrottle = 8;
127
        staticParams.MinThrottle = 8;
128
        staticParams.MaxThrottle = 230;
128
        staticParams.MaxThrottle = 230;
129
        staticParams.CompassYawEffect = 128;
129
        staticParams.CompassYawEffect = 128;
130
        staticParams.GyroP = 80;
130
        staticParams.GyroP = 80;
131
        staticParams.GyroI = 100;
131
        staticParams.GyroI = 100;
132
        staticParams.LowVoltageWarning = 95;
132
        staticParams.LowVoltageWarning = 101;  // 3.7 each for 3S
133
        staticParams.EmergencyGas = 35;
133
        staticParams.EmergencyGas = 35;
134
        staticParams.EmergencyGasDuration = 30;
134
        staticParams.EmergencyGasDuration = 30;
135
        staticParams.Unused0 = 0;
135
        staticParams.Unused0 = 0;
136
        staticParams.IFactor = 32;
136
        staticParams.IFactor = 32;
137
        staticParams.ServoPitchControl = 100;
137
        staticParams.ServoPitchControl = 100;
138
        staticParams.ServoPitchComp = 40;
138
        staticParams.ServoPitchComp = 40;
139
        staticParams.ServoPitchCompInvert = 0;
139
        staticParams.ServoPitchCompInvert = 0;
140
        staticParams.ServoPitchMin = 50;
140
        staticParams.ServoPitchMin = 50;
141
        staticParams.ServoPitchMax = 150;
141
        staticParams.ServoPitchMax = 150;
142
        staticParams.ServoRefresh = 5;
142
        staticParams.ServoRefresh = 5;
143
        staticParams.LoopGasLimit = 50;
143
        staticParams.LoopGasLimit = 50;
144
        staticParams.LoopThreshold = 90;
144
        staticParams.LoopThreshold = 90;
145
        staticParams.LoopHysteresis = 50;
145
        staticParams.LoopHysteresis = 50;
146
        staticParams.BitConfig = 0;
146
        staticParams.BitConfig = 0;
147
        staticParams.AxisCoupling1 = 90;
147
        staticParams.AxisCoupling1 = 90;
148
        staticParams.AxisCoupling2 = 67;
148
        staticParams.AxisCoupling2 = 67;
149
        staticParams.AxisCouplingYawCorrection = 0;
149
        staticParams.AxisCouplingYawCorrection = 0;
150
        staticParams.DynamicStability = 50;
150
        staticParams.DynamicStability = 50;
151
        staticParams.J16Bitmask = 95;
151
        staticParams.J16Bitmask = 95;
152
        staticParams.J17Bitmask = 243;
152
        staticParams.J17Bitmask = 243;
153
        staticParams.J16Timing = 15;
153
        staticParams.J16Timing = 15;
154
        staticParams.J17Timing = 15;
154
        staticParams.J17Timing = 15;
155
        staticParams.NaviGpsModeControl = 253;
155
        staticParams.NaviGpsModeControl = 253;
156
        staticParams.NaviGpsGain = 100;
156
        staticParams.NaviGpsGain = 100;
157
        staticParams.NaviGpsP = 90;
157
        staticParams.NaviGpsP = 90;
158
        staticParams.NaviGpsI = 90;
158
        staticParams.NaviGpsI = 90;
159
        staticParams.NaviGpsD = 90;
159
        staticParams.NaviGpsD = 90;
160
        staticParams.NaviGpsPLimit = 75;
160
        staticParams.NaviGpsPLimit = 75;
161
        staticParams.NaviGpsILimit = 75;
161
        staticParams.NaviGpsILimit = 75;
162
        staticParams.NaviGpsDLimit = 75;
162
        staticParams.NaviGpsDLimit = 75;
163
        staticParams.NaviGpsACC = 0;
163
        staticParams.NaviGpsACC = 0;
164
        staticParams.NaviGpsMinSat = 6;
164
        staticParams.NaviGpsMinSat = 6;
165
        staticParams.NaviStickThreshold = 8;
165
        staticParams.NaviStickThreshold = 8;
166
        staticParams.NaviWindCorrection = 90;
166
        staticParams.NaviWindCorrection = 90;
167
        staticParams.NaviSpeedCompensation = 30;
167
        staticParams.NaviSpeedCompensation = 30;
168
        staticParams.NaviOperatingRadius = 100;
168
        staticParams.NaviOperatingRadius = 100;
169
        staticParams.NaviAngleLimitation = 100;
169
        staticParams.NaviAngleLimitation = 100;
170
        staticParams.NaviPHLoginTime = 4;
170
        staticParams.NaviPHLoginTime = 4;
171
}
171
}
172
 
172
 
173
/***************************************************/
173
/***************************************************/
174
/*    Default Values for parameter set 1           */
174
/*    Default Values for parameter set 1           */
175
/***************************************************/
175
/***************************************************/
176
void ParamSet_DefaultSet1(void) { // sport
176
void ParamSet_DefaultSet1(void) { // sport
177
        setOtherDefaults();
177
        setOtherDefaults();
178
        gyro_setDefaults();
178
        gyro_setDefaults();
179
        setDefaultUserParams();
179
        setDefaultUserParams();
180
        staticParams.GlobalConfig = CFG_ROTARY_RATE_LIMITER
180
        staticParams.GlobalConfig = CFG_ROTARY_RATE_LIMITER
181
                        /* | CFG_AXIS_COUPLING_ACTIVE*/;
181
                        /* | CFG_AXIS_COUPLING_ACTIVE*/;
182
    staticParams.EmergencyGasDuration = 200;
182
    staticParams.EmergencyGasDuration = 200;
183
    staticParams.J16Timing = 10;
183
    staticParams.J16Timing = 10;
184
    staticParams.J17Timing = 10;
184
    staticParams.J17Timing = 10;
185
        memcpy(staticParams.Name, "Sport\0", 6);
185
        memcpy(staticParams.Name, "Sport\0", 6);
186
}
186
}
187
 
187
 
188
/***************************************************/
188
/***************************************************/
189
/*    Default Values for parameter set 2           */
189
/*    Default Values for parameter set 2           */
190
/***************************************************/
190
/***************************************************/
191
void ParamSet_DefaultSet2(void) { // normal
191
void ParamSet_DefaultSet2(void) { // normal
192
        setOtherDefaults();
192
        setOtherDefaults();
193
        gyro_setDefaults();
193
        gyro_setDefaults();
194
        setDefaultUserParams();
194
        setDefaultUserParams();
195
        staticParams.GlobalConfig = CFG_ROTARY_RATE_LIMITER
195
        staticParams.GlobalConfig = CFG_ROTARY_RATE_LIMITER
196
                        /* | CFG_AXIS_COUPLING_ACTIVE*/ ;
196
                        /* | CFG_AXIS_COUPLING_ACTIVE*/ ;
197
        staticParams.Height_Gain = 3;
197
        staticParams.Height_Gain = 3;
198
    staticParams.EmergencyGasDuration = 200;
198
    staticParams.EmergencyGasDuration = 200;
199
        staticParams.J16Timing = 20;
199
        staticParams.J16Timing = 20;
200
        staticParams.J17Timing = 20;
200
        staticParams.J17Timing = 20;
201
        memcpy(staticParams.Name, "Normal\0", 7);
201
        memcpy(staticParams.Name, "Normal\0", 7);
202
}
202
}
203
 
203
 
204
/***************************************************/
204
/***************************************************/
205
/*    Default Values for parameter set 3           */
205
/*    Default Values for parameter set 3           */
206
/***************************************************/
206
/***************************************************/
207
void ParamSet_DefaultSet3(void) { // beginner
207
void ParamSet_DefaultSet3(void) { // beginner
208
        setOtherDefaults();
208
        setOtherDefaults();
209
        gyro_setDefaults();
209
        gyro_setDefaults();
210
        setDefaultUserParams();
210
        setDefaultUserParams();
211
        staticParams.GlobalConfig = CFG_ROTARY_RATE_LIMITER
211
        staticParams.GlobalConfig = CFG_ROTARY_RATE_LIMITER
212
                        /* | CFG_AXIS_COUPLING_ACTIVE */;
212
                        /* | CFG_AXIS_COUPLING_ACTIVE */;
213
        staticParams.Height_Gain = 3;
213
        staticParams.Height_Gain = 3;
214
        staticParams.EmergencyGasDuration = 200;
214
        staticParams.EmergencyGasDuration = 200;
215
        staticParams.J16Timing = 30;
215
        staticParams.J16Timing = 30;
216
        staticParams.J17Timing = 30;
216
        staticParams.J17Timing = 30;
217
        memcpy(staticParams.Name, "Beginner\0", 9);
217
        memcpy(staticParams.Name, "Beginner\0", 9);
218
}
218
}
219
 
219
 
220
/***************************************************/
220
/***************************************************/
221
/*       Read Parameter from EEPROM as byte        */
221
/*       Read Parameter from EEPROM as byte        */
222
/***************************************************/
222
/***************************************************/
223
uint8_t GetParamByte(uint16_t param_id) {
223
uint8_t GetParamByte(uint16_t param_id) {
224
        return eeprom_read_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id]);
224
        return eeprom_read_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id]);
225
}
225
}
226
 
226
 
227
/***************************************************/
227
/***************************************************/
228
/*       Write Parameter to EEPROM as byte         */
228
/*       Write Parameter to EEPROM as byte         */
229
/***************************************************/
229
/***************************************************/
230
void SetParamByte(uint16_t param_id, uint8_t value) {
230
void SetParamByte(uint16_t param_id, uint8_t value) {
231
        eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value);
231
        eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value);
232
}
232
}
233
 
233
 
234
/***************************************************/
234
/***************************************************/
235
/*       Read Parameter from EEPROM as word        */
235
/*       Read Parameter from EEPROM as word        */
236
/***************************************************/
236
/***************************************************/
237
uint16_t GetParamWord(uint16_t param_id) {
237
uint16_t GetParamWord(uint16_t param_id) {
238
        return eeprom_read_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN
238
        return eeprom_read_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN
239
                        + param_id]);
239
                        + param_id]);
240
}
240
}
241
 
241
 
242
/***************************************************/
242
/***************************************************/
243
/*       Write Parameter to EEPROM as word         */
243
/*       Write Parameter to EEPROM as word         */
244
/***************************************************/
244
/***************************************************/
245
void SetParamWord(uint16_t param_id, uint16_t value) {
245
void SetParamWord(uint16_t param_id, uint16_t value) {
246
        eeprom_write_word(
246
        eeprom_write_word(
247
                        (uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value);
247
                        (uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value);
248
}
248
}
249
 
249
 
250
/***************************************************/
250
/***************************************************/
251
/*       Read Parameter Set from EEPROM            */
251
/*       Read Parameter Set from EEPROM            */
252
/***************************************************/
252
/***************************************************/
253
// number [1..5]
253
// number [1..5]
254
void ParamSet_ReadFromEEProm(uint8_t setnumber) {
254
void ParamSet_ReadFromEEProm(uint8_t setnumber) {
255
        if ((1 > setnumber) || (setnumber > 5))
255
        if ((1 > setnumber) || (setnumber > 5))
256
                setnumber = 3;
256
                setnumber = 3;
257
        eeprom_read_block((uint8_t *) &staticParams.ChannelAssignment[0],
257
        eeprom_read_block((uint8_t *) &staticParams.ChannelAssignment[0],
258
                        &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * (setnumber
258
                        &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * (setnumber
259
                                        - 1)], PARAMSET_STRUCT_LEN);
259
                                        - 1)], PARAMSET_STRUCT_LEN);
260
        output_init();
260
        output_init();
261
}
261
}
262
 
262
 
263
/***************************************************/
263
/***************************************************/
264
/*        Write Parameter Set to EEPROM            */
264
/*        Write Parameter Set to EEPROM            */
265
/***************************************************/
265
/***************************************************/
266
// number [1..5]
266
// number [1..5]
267
void ParamSet_WriteToEEProm(uint8_t setnumber) {
267
void ParamSet_WriteToEEProm(uint8_t setnumber) {
268
        if (setnumber > 5)
268
        if (setnumber > 5)
269
                setnumber = 5;
269
                setnumber = 5;
270
        if (setnumber < 1)
270
        if (setnumber < 1)
271
                return;
271
                return;
272
        eeprom_write_block((uint8_t *) &staticParams.ChannelAssignment[0],
272
        eeprom_write_block((uint8_t *) &staticParams.ChannelAssignment[0],
273
                        &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * (setnumber
273
                        &EEPromArray[EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * (setnumber
274
                                        - 1)], PARAMSET_STRUCT_LEN);
274
                                        - 1)], PARAMSET_STRUCT_LEN);
275
        eeprom_write_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAMSET_LENGTH],
275
        eeprom_write_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAMSET_LENGTH],
276
                        PARAMSET_STRUCT_LEN);
276
                        PARAMSET_STRUCT_LEN);
277
        eeprom_write_block(&staticParams.ChannelAssignment[0],
277
        eeprom_write_block(&staticParams.ChannelAssignment[0],
278
                        &EEPromArray[EEPROM_ADR_CHANNELS], 8); // backup the first 8 bytes that is the rc channel mapping
278
                        &EEPromArray[EEPROM_ADR_CHANNELS], 8); // backup the first 8 bytes that is the rc channel mapping
279
        // set this parameter set to active set
279
        // set this parameter set to active set
280
        setActiveParamSet(setnumber);
280
        setActiveParamSet(setnumber);
281
        output_init();
281
        output_init();
282
}
282
}
283
 
283
 
284
/***************************************************/
284
/***************************************************/
285
/*       Get active parameter set                  */
285
/*       Get active parameter set                  */
286
/***************************************************/
286
/***************************************************/
287
uint8_t getActiveParamSet(void) {
287
uint8_t getActiveParamSet(void) {
288
        uint8_t setnumber;
288
        uint8_t setnumber;
289
        setnumber = eeprom_read_byte(&EEPromArray[PID_ACTIVE_SET]);
289
        setnumber = eeprom_read_byte(&EEPromArray[PID_ACTIVE_SET]);
290
        if (setnumber > 5) {
290
        if (setnumber > 5) {
291
                setnumber = 3;
291
                setnumber = 3;
292
                eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber);
292
                eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber);
293
        }
293
        }
294
        return (setnumber);
294
        return (setnumber);
295
}
295
}
296
 
296
 
297
/***************************************************/
297
/***************************************************/
298
/*       Set active parameter set                  */
298
/*       Set active parameter set                  */
299
/***************************************************/
299
/***************************************************/
300
void setActiveParamSet(uint8_t setnumber) {
300
void setActiveParamSet(uint8_t setnumber) {
301
        if (setnumber > 5)
301
        if (setnumber > 5)
302
                setnumber = 5;
302
                setnumber = 5;
303
        if (setnumber < 1)
303
        if (setnumber < 1)
304
                setnumber = 1;
304
                setnumber = 1;
305
        eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber);
305
        eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber);
306
}
306
}
307
 
307
 
308
/***************************************************/
308
/***************************************************/
309
/*          Read MixerTable from EEPROM            */
309
/*          Read MixerTable from EEPROM            */
310
/***************************************************/
310
/***************************************************/
311
uint8_t MixerTable_ReadFromEEProm(void) {
311
uint8_t MixerTable_ReadFromEEProm(void) {
312
        if (eeprom_read_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE])
312
        if (eeprom_read_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE])
313
                        == EEMIXER_REVISION) {
313
                        == EEMIXER_REVISION) {
314
                eeprom_read_block((uint8_t *) &Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE],
314
                eeprom_read_block((uint8_t *) &Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE],
315
                                sizeof(Mixer));
315
                                sizeof(Mixer));
316
                return 1;
316
                return 1;
317
        } else
317
        } else
318
                return 0;
318
                return 0;
319
}
319
}
320
 
320
 
321
/***************************************************/
321
/***************************************************/
322
/*          Write Mixer Table to EEPROM            */
322
/*          Write Mixer Table to EEPROM            */
323
/***************************************************/
323
/***************************************************/
324
uint8_t MixerTable_WriteToEEProm(void) {
324
uint8_t MixerTable_WriteToEEProm(void) {
325
        if (Mixer.Revision == EEMIXER_REVISION) {
325
        if (Mixer.Revision == EEMIXER_REVISION) {
326
                eeprom_write_block((uint8_t *) &Mixer,
326
                eeprom_write_block((uint8_t *) &Mixer,
327
                                &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer));
327
                                &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer));
328
                return 1;
328
                return 1;
329
        } else
329
        } else
330
                return 0;
330
                return 0;
331
}
331
}
332
 
332
 
333
/***************************************************/
333
/***************************************************/
334
/*    Default Values for Mixer Table               */
334
/*    Default Values for Mixer Table               */
335
/***************************************************/
335
/***************************************************/
336
void MixerTable_Default(void) { // Quadro 
336
void MixerTable_Default(void) { // Quadro 
337
        uint8_t i;
337
        uint8_t i;
338
        Mixer.Revision = EEMIXER_REVISION;
338
        Mixer.Revision = EEMIXER_REVISION;
339
        // clear mixer table (but preset throttle)
339
        // clear mixer table (but preset throttle)
340
        for (i = 0; i < 16; i++) {
340
        for (i = 0; i < 16; i++) {
341
                Mixer.Motor[i][MIX_THROTTLE] = i < 4 ? 64 : 0;
341
                Mixer.Motor[i][MIX_THROTTLE] = i < 4 ? 64 : 0;
342
                Mixer.Motor[i][MIX_PITCH] = 0;
342
                Mixer.Motor[i][MIX_PITCH] = 0;
343
                Mixer.Motor[i][MIX_ROLL] = 0;
343
                Mixer.Motor[i][MIX_ROLL] = 0;
344
                Mixer.Motor[i][MIX_YAW] = 0;
344
                Mixer.Motor[i][MIX_YAW] = 0;
345
        }
345
        }
346
        // default = Quadro
346
        // default = Quadro
347
        Mixer.Motor[0][MIX_PITCH] = +64;
347
        Mixer.Motor[0][MIX_PITCH] = +64;
348
        Mixer.Motor[0][MIX_YAW] = +64;
348
        Mixer.Motor[0][MIX_YAW] = +64;
349
        Mixer.Motor[1][MIX_PITCH] = -64;
349
        Mixer.Motor[1][MIX_PITCH] = -64;
350
        Mixer.Motor[1][MIX_YAW] = +64;
350
        Mixer.Motor[1][MIX_YAW] = +64;
351
        Mixer.Motor[2][MIX_ROLL] = -64;
351
        Mixer.Motor[2][MIX_ROLL] = -64;
352
        Mixer.Motor[2][MIX_YAW] = -64;
352
        Mixer.Motor[2][MIX_YAW] = -64;
353
        Mixer.Motor[3][MIX_ROLL] = +64;
353
        Mixer.Motor[3][MIX_ROLL] = +64;
354
        Mixer.Motor[3][MIX_YAW] = -64;
354
        Mixer.Motor[3][MIX_YAW] = -64;
355
        memcpy(Mixer.Name, "Quadro\0", 7);
355
        memcpy(Mixer.Name, "Quadro\0", 7);
356
}
356
}
357
 
357
 
358
/***************************************************/
358
/***************************************************/
359
/*       Initialize EEPROM Parameter Sets          */
359
/*       Initialize EEPROM Parameter Sets          */
360
/***************************************************/
360
/***************************************************/
361
void ParamSet_Init(void) {
361
void ParamSet_Init(void) {
362
        uint8_t Channel_Backup = 1, i, j;
362
        uint8_t Channel_Backup = 1, i, j;
363
        // parameter version  check
363
        // parameter version  check
364
        if (eeprom_read_byte(&EEPromArray[PID_PARAM_REVISION]) != EEPARAM_REVISION) {
364
        if (eeprom_read_byte(&EEPromArray[PID_PARAM_REVISION]) != EEPARAM_REVISION) {
365
                // if version check faild
365
                // if version check faild
366
                printf("\n\rInit Parameter in EEPROM");
366
                printf("\n\rInit Parameter in EEPROM");
367
                eeprom_write_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE], 0xFF); // reset also mixer table
367
                eeprom_write_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE], 0xFF); // reset also mixer table
368
                // check if channel mapping backup is valid
368
                // check if channel mapping backup is valid
369
                for (j = 0; j < 4 && Channel_Backup; j++) {
369
                for (j = 0; j < 4 && Channel_Backup; j++) {
370
                        if (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS + 0]) >= 12)
370
                        if (eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS + 0]) >= 12)
371
                                Channel_Backup = 0;
371
                                Channel_Backup = 0;
372
                }
372
                }
373
                // fill all 5 parameter settings
373
                // fill all 5 parameter settings
374
                for (i = 1; i < 6; i++) {
374
                for (i = 1; i < 6; i++) {
375
                        switch (i) {
375
                        switch (i) {
376
                        case 1:
376
                        case 1:
377
                                ParamSet_DefaultSet1(); // Fill staticParams Structure to default parameter set 1 (Sport)
377
                                ParamSet_DefaultSet1(); // Fill staticParams Structure to default parameter set 1 (Sport)
378
                                break;
378
                                break;
379
                        case 2:
379
                        case 2:
380
                                ParamSet_DefaultSet2(); // Kamera
380
                                ParamSet_DefaultSet2(); // Kamera
381
                                break;
381
                                break;
382
                        case 3:
382
                        case 3:
383
                                ParamSet_DefaultSet3(); // Beginner
383
                                ParamSet_DefaultSet3(); // Beginner
384
                                break;
384
                                break;
385
                        default:
385
                        default:
386
                                ParamSet_DefaultSet2(); // Kamera
386
                                ParamSet_DefaultSet2(); // Kamera
387
                                break;
387
                                break;
388
                        }
388
                        }
389
                        if (Channel_Backup) { // if we have a rc channel mapping backup in eeprom
389
                        if (Channel_Backup) { // if we have a rc channel mapping backup in eeprom
390
                                // restore it
390
                                // restore it
391
                                for (j = 0; j < 8; j++) {
391
                                for (j = 0; j < 8; j++) {
392
                                        staticParams.ChannelAssignment[j] = eeprom_read_byte(
392
                                        staticParams.ChannelAssignment[j] = eeprom_read_byte(
393
                                                        &EEPromArray[EEPROM_ADR_CHANNELS + j]);
393
                                                        &EEPromArray[EEPROM_ADR_CHANNELS + j]);
394
                                }
394
                                }
395
                        }
395
                        }
396
                        ParamSet_WriteToEEProm(i);
396
                        ParamSet_WriteToEEProm(i);
397
                }
397
                }
398
                // default-Setting is parameter set 3
398
                // default-Setting is parameter set 3
399
                setActiveParamSet(1);
399
                setActiveParamSet(1);
400
                // update version info
400
                // update version info
401
                SetParamByte(PID_PARAM_REVISION, EEPARAM_REVISION);
401
                SetParamByte(PID_PARAM_REVISION, EEPARAM_REVISION);
402
        }
402
        }
403
        // read active parameter set to staticParams stucture
403
        // read active parameter set to staticParams stucture
404
        ParamSet_ReadFromEEProm(getActiveParamSet());
404
        ParamSet_ReadFromEEProm(getActiveParamSet());
405
        printf("\n\rUsing Parameter Set %d", getActiveParamSet());
405
        printf("\n\rUsing Parameter Set %d", getActiveParamSet());
406
 
406
 
407
        // load mixer table
407
        // load mixer table
408
        if (!MixerTable_ReadFromEEProm()) {
408
        if (!MixerTable_ReadFromEEProm()) {
409
                printf("\n\rGenerating default Mixer Table");
409
                printf("\n\rGenerating default Mixer Table");
410
                MixerTable_Default(); // Quadro
410
                MixerTable_Default(); // Quadro
411
                MixerTable_WriteToEEProm();
411
                MixerTable_WriteToEEProm();
412
        }
412
        }
413
        // determine motornumber
413
        // determine motornumber
414
        RequiredMotors = 0;
414
        RequiredMotors = 0;
415
        for (i = 0; i < 16; i++) {
415
        for (i = 0; i < 16; i++) {
416
                if (Mixer.Motor[i][MIX_THROTTLE] > 0)
416
                if (Mixer.Motor[i][MIX_THROTTLE] > 0)
417
                        RequiredMotors++;
417
                        RequiredMotors++;
418
        }
418
        }
419
 
419
 
420
        printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name, RequiredMotors);
420
        printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name, RequiredMotors);
421
        printf("\n\r==============================");
421
        printf("\n\r==============================");
422
}
422
}
423
 
423