Subversion Repositories FlightCtrl

Rev

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

Rev 1963 Rev 1964
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
#include <util/delay.h>
52
#include <util/delay.h>
53
#include <stddef.h>
53
#include <stddef.h>
54
#include <string.h>
54
#include <string.h>
55
#include "configuration.h"
55
#include "configuration.h"
56
#include "sensors.h"
56
#include "sensors.h"
57
#include "rc.h"
57
#include "rc.h"
58
 
58
 
59
int16_t variables[VARIABLE_COUNT];
59
int16_t variables[VARIABLE_COUNT];
60
paramset_t staticParams;
60
paramset_t staticParams;
61
channelMap_t channelMap;
61
channelMap_t channelMap;
62
mixerMatrix_t mixerMatrix;
62
mixerMatrix_t mixerMatrix;
63
dynamicParam_t dynamicParams;
63
dynamicParam_t dynamicParams;
64
uint8_t CPUType = ATMEGA644;
64
uint8_t CPUType = ATMEGA644;
65
uint8_t boardRelease = 13;
65
uint8_t boardRelease = 13;
66
uint8_t requiredMotors;
66
uint8_t requiredMotors;
67
 
67
 
68
// MK flags. TODO: Replace by enum. State machine.
68
// MK flags. TODO: Replace by enum. State machine.
69
uint16_t isFlying = 0;
69
uint16_t isFlying = 0;
70
volatile uint8_t MKFlags = 0;
70
volatile uint8_t MKFlags = 0;
71
 
71
 
72
/************************************************************************
72
/************************************************************************
73
 * Map the parameter to pot values                                    
73
 * Map the parameter to pot values                                    
74
 * Replacing this code by the code below saved almost 1 kbyte.
74
 * Replacing this code by the code below saved almost 1 kbyte.
75
 ************************************************************************/
75
 ************************************************************************/
76
 
76
 
77
void configuration_applyVariablesToParams(void) {
77
void configuration_applyVariablesToParams(void) {
78
  uint8_t i;
78
  uint8_t i;
79
#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;}
79
#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;}
80
#define SET_POT(b,a) { if (a<255) {if (a>=255-VARIABLE_COUNT) b=variables[a+VARIABLE_COUNT-255]; else b=a;}}
80
#define SET_POT(b,a) { if (a<255) {if (a>=255-VARIABLE_COUNT) b=variables[a+VARIABLE_COUNT-255]; else b=a;}}
81
  SET_POT_MM(dynamicParams.gyroP, staticParams.gyroP, 5, 200);
81
  SET_POT_MM(dynamicParams.gyroP, staticParams.gyroP, 5, 200);
82
  SET_POT(dynamicParams.gyroI, staticParams.gyroI);
82
  SET_POT(dynamicParams.gyroI, staticParams.gyroI);
83
  SET_POT(dynamicParams.gyroD, staticParams.gyroD);
83
  SET_POT(dynamicParams.gyroD, staticParams.gyroD);
84
  SET_POT(dynamicParams.IFactor, staticParams.IFactor);
84
  SET_POT(dynamicParams.IFactor, staticParams.IFactor);
85
  SET_POT(dynamicParams.yawIFactor, staticParams.yawIFactor);
85
  SET_POT(dynamicParams.yawIFactor, staticParams.yawIFactor);
86
  SET_POT(dynamicParams.compassYawEffect,staticParams.compassYawEffect);
86
  SET_POT(dynamicParams.compassYawEffect,staticParams.compassYawEffect);
87
 
87
 
88
  SET_POT(dynamicParams.externalControl, staticParams.externalControl);
88
  SET_POT(dynamicParams.externalControl, staticParams.externalControl);
89
  SET_POT(dynamicParams.axisCoupling1, staticParams.axisCoupling1);
89
  SET_POT(dynamicParams.axisCoupling1, staticParams.axisCoupling1);
90
  SET_POT(dynamicParams.axisCoupling2, staticParams.axisCoupling2);
90
  SET_POT(dynamicParams.axisCoupling2, staticParams.axisCoupling2);
91
  SET_POT(dynamicParams.axisCouplingYawCorrection, staticParams.axisCouplingYawCorrection);
91
  SET_POT(dynamicParams.axisCouplingYawCorrection, staticParams.axisCouplingYawCorrection);
92
  SET_POT(dynamicParams.dynamicStability,staticParams.dynamicStability);
92
  SET_POT(dynamicParams.dynamicStability,staticParams.dynamicStability);
93
  SET_POT(dynamicParams.maxControlActivityForAcc,staticParams.maxControlActivityForAcc);
93
  SET_POT(dynamicParams.maxControlActivityForAcc,staticParams.maxControlActivityForAcc);
94
 
94
 
95
  SET_POT_MM(dynamicParams.heightP, staticParams.heightP,0,100);
95
  SET_POT_MM(dynamicParams.heightP, staticParams.heightP,0,100);
96
  SET_POT_MM(dynamicParams.heightD, staticParams.heightD,0,100);
96
  SET_POT_MM(dynamicParams.heightD, staticParams.heightD,0,100);
97
  SET_POT(dynamicParams.heightSetting,staticParams.heightSetting);
97
  SET_POT(dynamicParams.heightSetting,staticParams.heightSetting);
98
  SET_POT(dynamicParams.heightACCEffect,staticParams.heightACCEffect);
98
  SET_POT(dynamicParams.heightACCEffect,staticParams.heightACCEffect);
99
  SET_POT(dynamicParams.attitudeControl,staticParams.attitudeControl);
99
  SET_POT(dynamicParams.attitudeControl,staticParams.attitudeControl);
100
 
100
 
101
  for (i=0; i<sizeof(staticParams.userParams); i++) {
101
  for (i=0; i<sizeof(staticParams.userParams); i++) {
102
    SET_POT(dynamicParams.userParams[i],staticParams.userParams[i]);
102
    SET_POT(dynamicParams.userParams[i],staticParams.userParams[i]);
103
  }
103
  }
104
 
104
 
105
  SET_POT(dynamicParams.servoManualControl[0], staticParams.servoConfigurations[0].manualControl);
105
  SET_POT(dynamicParams.servoManualControl[0], staticParams.servoConfigurations[0].manualControl);
106
  SET_POT(dynamicParams.servoManualControl[1], staticParams.servoConfigurations[1].manualControl);
106
  SET_POT(dynamicParams.servoManualControl[1], staticParams.servoConfigurations[1].manualControl);
107
 
107
 
108
  SET_POT_MM(dynamicParams.output0Timing, staticParams.outputFlash[0].timing,1,255);
108
  SET_POT_MM(dynamicParams.output0Timing, staticParams.outputFlash[0].timing,1,255);
109
  SET_POT_MM(dynamicParams.output1Timing, staticParams.outputFlash[1].timing,1,255);
109
  SET_POT_MM(dynamicParams.output1Timing, staticParams.outputFlash[1].timing,1,255);
110
}
110
}
111
 
111
 
112
const XLATION XLATIONS[] = {
112
const XLATION XLATIONS[] = {
113
  {offsetof(paramset_t, heightSetting), offsetof(dynamicParam_t, heightSetting)},
113
  {offsetof(paramset_t, heightSetting), offsetof(dynamicParam_t, heightSetting)},
114
};
114
};
115
 
115
 
116
const MMXLATION MMXLATIONS[] = {
116
const MMXLATION MMXLATIONS[] = {
117
  {offsetof(paramset_t, heightD), offsetof(dynamicParam_t, heightD),0,100},
117
  {offsetof(paramset_t, heightD), offsetof(dynamicParam_t, heightD),0,100},
118
};
118
};
119
 
119
 
120
uint8_t configuration_applyVariableToParam(uint8_t src, uint8_t min, uint8_t max) {
120
uint8_t configuration_applyVariableToParam(uint8_t src, uint8_t min, uint8_t max) {
121
  uint8_t result;
121
  uint8_t result;
122
  if (src>=251) result = variables[src-251];
122
  if (src>=251) result = variables[src-251];
123
  else result = src;
123
  else result = src;
124
  if (result < min) result = min;
124
  if (result < min) result = min;
125
  else if (result > max) result = max;
125
  else if (result > max) result = max;
126
  return result;
126
  return result;
127
}
127
}
128
 
128
 
129
void configuration_applyVariablesToParams_dead(void) {
129
void configuration_applyVariablesToParams_dead(void) {
130
  uint8_t i, src;
130
  uint8_t i, src;
131
  uint8_t* pointerToTgt;
131
  uint8_t* pointerToTgt;
132
  for(i=0; i<sizeof(XLATIONS)/sizeof(XLATION); i++) {
132
  for(i=0; i<sizeof(XLATIONS)/sizeof(XLATION); i++) {
133
    src = *((uint8_t*)(&staticParams + XLATIONS[i].sourceIdx));
133
    src = *((uint8_t*)(&staticParams + XLATIONS[i].sourceIdx));
134
    pointerToTgt = (uint8_t*)(&dynamicParams + XLATIONS[i].targetIdx);
134
    pointerToTgt = (uint8_t*)(&dynamicParams + XLATIONS[i].targetIdx);
135
    if (src < 255) {
135
    if (src < 255) {
136
      *pointerToTgt = configuration_applyVariableToParam(src, 0, 255);
136
      *pointerToTgt = configuration_applyVariableToParam(src, 0, 255);
137
    }
137
    }
138
  }
138
  }
139
 
139
 
140
  for(i=0; i<sizeof(MMXLATIONS)/sizeof(MMXLATION); i++) {
140
  for(i=0; i<sizeof(MMXLATIONS)/sizeof(MMXLATION); i++) {
141
    src = *((uint8_t*)(&staticParams + MMXLATIONS[i].sourceIdx));
141
    src = *((uint8_t*)(&staticParams + MMXLATIONS[i].sourceIdx));
142
    pointerToTgt = (uint8_t*)(&dynamicParams + XLATIONS[i].targetIdx);
142
    pointerToTgt = (uint8_t*)(&dynamicParams + XLATIONS[i].targetIdx);
143
    if (src < 255) {
143
    if (src < 255) {
144
      *pointerToTgt = configuration_applyVariableToParam(src, MMXLATIONS[i].min, MMXLATIONS[i].max);
144
      *pointerToTgt = configuration_applyVariableToParam(src, MMXLATIONS[i].min, MMXLATIONS[i].max);
145
    }
145
    }
146
  }
146
  }
147
 
147
 
148
  for (i=0; i<sizeof(staticParams.userParams); i++) {
148
  for (i=0; i<sizeof(staticParams.userParams); i++) {
149
    src = *((uint8_t*)(&staticParams + offsetof(paramset_t, userParams) + i));
149
    src = *((uint8_t*)(&staticParams + offsetof(paramset_t, userParams) + i));
150
    pointerToTgt = (uint8_t*)(&dynamicParams + offsetof(dynamicParam_t, userParams) + i);
150
    pointerToTgt = (uint8_t*)(&dynamicParams + offsetof(dynamicParam_t, userParams) + i);
151
    if (src < 255) {
151
    if (src < 255) {
152
      *pointerToTgt = configuration_applyVariableToParam(src, 0, 255);
152
      *pointerToTgt = configuration_applyVariableToParam(src, 0, 255);
153
    }    
153
    }    
154
  }
154
  }
155
}
155
}
156
 
156
 
157
uint8_t getCPUType(void) {   // works only after reset or power on when the registers have default values
157
uint8_t getCPUType(void) {   // works only after reset or power on when the registers have default values
158
  uint8_t CPUType = ATMEGA644;
158
  uint8_t CPUType = ATMEGA644;
159
  //if((UCSR1A == 0x20) && (UCSR1C == 0x06)) CPUType = ATMEGA644P;  // initial Values for 644P after reset
159
  //if((UCSR1A == 0x20) && (UCSR1C == 0x06)) CPUType = ATMEGA644P;  // initial Values for 644P after reset
160
  return CPUType;
160
  return CPUType;
161
}
161
}
162
 
162
 
163
/*
163
/*
164
 * Automatic detection of hardware components is not supported in this development-oriented
164
 * Automatic detection of hardware components is not supported in this development-oriented
165
 * FC firmware. It would go against the point of it: To enable alternative hardware
165
 * FC firmware. It would go against the point of it: To enable alternative hardware
166
 * configurations with otherwise unsupported components. Instead, one should write
166
 * configurations with otherwise unsupported components. Instead, one should write
167
 * custom code + adjust constants for the new hardware, and include the relevant code
167
 * custom code + adjust constants for the new hardware, and include the relevant code
168
 * from the makefile.
168
 * from the makefile.
169
 * However - we still do detect the board release. Reason: Otherwise it would be too
169
 * However - we still do detect the board release. Reason: Otherwise it would be too
170
 * tedious to have to modify the code for how to turn on and off LEDs when deploying
170
 * tedious to have to modify the code for how to turn on and off LEDs when deploying
171
 * on different HW version....
171
 * on different HW version....
172
 */
172
 */
173
 
173
 
174
uint8_t getBoardRelease(void) {
174
uint8_t getBoardRelease(void) {
175
  uint8_t boardRelease = 13;
175
  uint8_t boardRelease = 13;
176
  // the board release is coded via the pull up or down the 2 status LED
176
  // the board release is coded via the pull up or down the 2 status LED
177
 
177
 
178
  PORTB &= ~((1 << PORTB1)|(1 << PORTB0)); // set tristate
178
  PORTB &= ~((1 << PORTB1)|(1 << PORTB0)); // set tristate
179
  DDRB  &= ~((1 << DDB0)|(1 << DDB0)); // set port direction as input
179
  DDRB  &= ~((1 << DDB0)|(1 << DDB0)); // set port direction as input
180
 
180
 
181
  _delay_loop_2(1000); // make some delay
181
  _delay_loop_2(1000); // make some delay
182
 
182
 
183
  switch( PINB & ((1<<PINB1)|(1<<PINB0))) {
183
  switch( PINB & ((1<<PINB1)|(1<<PINB0))) {
184
    case 0x00:
184
    case 0x00:
185
      boardRelease = 10; // 1.0
185
      boardRelease = 10; // 1.0
186
      break;
186
      break;
187
    case 0x01:
187
    case 0x01:
188
      boardRelease = 11; // 1.1 or 1.2
188
      boardRelease = 11; // 1.1 or 1.2
189
      break;
189
      break;
190
    case 0x02:
190
    case 0x02:
191
      boardRelease = 20; // 2.0
191
      boardRelease = 20; // 2.0
192
      break;
192
      break;
193
    case 0x03:
193
    case 0x03:
194
      boardRelease = 13; // 1.3
194
      boardRelease = 13; // 1.3
195
      break;
195
      break;
196
    default:
196
    default:
197
      break;
197
      break;
198
    }
198
    }
199
  // set LED ports as output
199
  // set LED ports as output
200
  DDRB |= (1<<DDB1)|(1<<DDB0);
200
  DDRB |= (1<<DDB1)|(1<<DDB0);
201
  RED_ON;
201
  RED_OFF;
202
  GRN_OFF;
202
  GRN_OFF;
203
  return boardRelease;
203
  return boardRelease;
204
}
204
}
205
 
205
 
206
void setOtherDefaults(void) {
206
void setOtherDefaults(void) {
207
  // Height Control
207
  // Height Control
208
  staticParams.heightP = 10;
208
  staticParams.heightP = 10;
209
  staticParams.heightD = 30;
209
  staticParams.heightD = 30;
210
  staticParams.heightSetting = 251;
210
  staticParams.heightSetting = 251;
211
  staticParams.heightControlMaxThrottleChange = 10;
211
  staticParams.heightControlMaxThrottleChange = 10;
212
  staticParams.heightSlewRate = 4;
212
  staticParams.heightSlewRate = 4;
213
 
213
 
214
  // Control
214
  // Control
215
  staticParams.stickP = 8;
215
  staticParams.stickP = 8;
216
  staticParams.stickD = 12;
216
  staticParams.stickD = 12;
217
  staticParams.stickYawP = 12;
217
  staticParams.stickYawP = 12;
218
  staticParams.stickThrottleD = 12;
218
  staticParams.stickThrottleD = 12;
219
  staticParams.minThrottle = 8;
219
  staticParams.minThrottle = 8;
220
  staticParams.maxThrottle = 230;
220
  staticParams.maxThrottle = 230;
221
  staticParams.externalControl = 0;
221
  staticParams.externalControl = 0;
222
 
222
 
223
  // IMU
223
  // IMU
224
  staticParams.gyroPIDFilterConstant = 1;
224
  staticParams.gyroPIDFilterConstant = 1;
225
  staticParams.gyroATTFilterConstant = 1;
225
  staticParams.gyroATTFilterConstant = 1;
226
  staticParams.gyroDFilterConstant = 1;
226
  staticParams.gyroDFilterConstant = 1;
227
  staticParams.accFilterConstant = 4;
227
  staticParams.accFilterConstant = 4;
228
 
228
 
229
  staticParams.gyroP = 60;
229
  staticParams.gyroP = 60;
230
  staticParams.gyroI = 80;
230
  staticParams.gyroI = 80;
231
  staticParams.gyroD = 4;
231
  staticParams.gyroD = 4;
232
 
232
 
233
  // set by gyro-specific code: gyro_setDefaults().
233
  // set by gyro-specific code: gyro_setDefaults().
234
  // staticParams.zerothOrderCorrection = 
234
  // staticParams.zerothOrderCorrection = 
235
  // staticParams.driftCompDivider = 
235
  // staticParams.driftCompDivider = 
236
  // staticParams.driftCompLimit = 
236
  // staticParams.driftCompLimit = 
237
 
237
 
238
  staticParams.axisCoupling1 = 90;
238
  staticParams.axisCoupling1 = 90;
239
  staticParams.axisCoupling2 = 67;
239
  staticParams.axisCoupling2 = 67;
240
  staticParams.axisCouplingYawCorrection = 0;
240
  staticParams.axisCouplingYawCorrection = 0;
241
  staticParams.dynamicStability = 50;
241
  staticParams.dynamicStability = 50;
242
  staticParams.IFactor = 32;  
242
  staticParams.IFactor = 32;  
243
  staticParams.compassYawEffect = 128;
243
  staticParams.compassYawEffect = 128;
244
 
244
 
245
  // Servos
245
  // Servos
246
  for (uint8_t i=0; i<2; i++) {
246
  for (uint8_t i=0; i<2; i++) {
247
    staticParams.servoConfigurations[i].manualControl = 128;
247
    staticParams.servoConfigurations[i].manualControl = 128;
248
    staticParams.servoConfigurations[i].compensationFactor = 0;
248
    staticParams.servoConfigurations[i].compensationFactor = 0;
249
    staticParams.servoConfigurations[i].minValue = 64;
249
    staticParams.servoConfigurations[i].minValue = 64;
250
    staticParams.servoConfigurations[i].maxValue = 192;
250
    staticParams.servoConfigurations[i].maxValue = 192;
251
    staticParams.servoConfigurations[i].flags = 0;
251
    staticParams.servoConfigurations[i].flags = 0;
252
  }
252
  }
253
  staticParams.servoCount = 4;
253
  staticParams.servoCount = 4;
254
 
254
 
255
  // Battery warning and emergency flight
255
  // Battery warning and emergency flight
256
  staticParams.batteryVoltageWarning = 101;  // 3.7 each for 3S
256
  staticParams.batteryVoltageWarning = 101;  // 3.7 each for 3S
257
  staticParams.emergencyThrottle = 35;
257
  staticParams.emergencyThrottle = 35;
258
  staticParams.emergencyFlightDuration = 30;
258
  staticParams.emergencyFlightDuration = 30;
259
 
259
 
260
  // Outputs
260
  // Outputs
261
  staticParams.outputFlash[0].bitmask = 1; //0b01011111;
261
  staticParams.outputFlash[0].bitmask = 1; //0b01011111;
262
  staticParams.outputFlash[0].timing = 15;
262
  staticParams.outputFlash[0].timing = 15;
263
  staticParams.outputFlash[1].bitmask = 3; //0b11110011;
263
  staticParams.outputFlash[1].bitmask = 3; //0b11110011;
264
  staticParams.outputFlash[1].timing = 15;
264
  staticParams.outputFlash[1].timing = 15;
-
 
265
 
265
 
266
  staticParams.outputDebugMask = 16;
266
  staticParams.outputFlags = 0;
267
  staticParams.outputOptions = 8;
267
}
268
}
268
 
269
 
269
/***************************************************/
270
/***************************************************/
270
/*    Default Values for parameter set 1           */
271
/*    Default Values for parameter set 1           */
271
/***************************************************/
272
/***************************************************/
272
void paramSet_default(uint8_t setnumber) {
273
void paramSet_default(uint8_t setnumber) {
273
  setOtherDefaults();
274
  setOtherDefaults();
274
  gyro_setDefaults();
275
  gyro_setDefaults();
275
 
276
 
276
  for (uint8_t i=0; i<8; i++) {
277
  for (uint8_t i=0; i<8; i++) {
277
    staticParams.userParams[i] = 0;
278
    staticParams.userParams[i] = 0;
278
  }
279
  }
279
 
280
 
280
  staticParams.bitConfig =
281
  staticParams.bitConfig =
281
    CFG_GYRO_SATURATION_PREVENTION | CFG_HEADING_HOLD;
282
    CFG_GYRO_SATURATION_PREVENTION | CFG_HEADING_HOLD;
282
 
283
 
283
  memcpy(staticParams.name, "Default\0", 6);
284
  memcpy(staticParams.name, "Default\0", 6);
284
}
285
}
285
 
286
 
286
/***************************************************/
287
/***************************************************/
287
/*    Default Values for Mixer Table               */
288
/*    Default Values for Mixer Table               */
288
/***************************************************/
289
/***************************************************/
289
void mixerMatrix_default(void) { // Quadro 
290
void mixerMatrix_default(void) { // Quadro 
290
  uint8_t i;
291
  uint8_t i;
291
  // mixerMatric.revision = EEMIXER_REVISION;
292
  // mixerMatric.revision = EEMIXER_REVISION;
292
  // clear mixer table (but preset throttle)
293
  // clear mixer table (but preset throttle)
293
  for (i = 0; i < 16; i++) {
294
  for (i = 0; i < 16; i++) {
294
    mixerMatrix.motor[i][MIX_THROTTLE] = i < 4 ? 64 : 0;
295
    mixerMatrix.motor[i][MIX_THROTTLE] = i < 4 ? 64 : 0;
295
    mixerMatrix.motor[i][MIX_PITCH] = 0;
296
    mixerMatrix.motor[i][MIX_PITCH] = 0;
296
    mixerMatrix.motor[i][MIX_ROLL] = 0;
297
    mixerMatrix.motor[i][MIX_ROLL] = 0;
297
    mixerMatrix.motor[i][MIX_YAW] = 0;
298
    mixerMatrix.motor[i][MIX_YAW] = 0;
298
  }
299
  }
299
  // default = Quadro
300
  // default = Quadro
300
  mixerMatrix.motor[0][MIX_PITCH] = +64;
301
  mixerMatrix.motor[0][MIX_PITCH] = +64;
301
  mixerMatrix.motor[0][MIX_YAW] = +64;
302
  mixerMatrix.motor[0][MIX_YAW] = +64;
302
  mixerMatrix.motor[1][MIX_PITCH] = -64;
303
  mixerMatrix.motor[1][MIX_PITCH] = -64;
303
  mixerMatrix.motor[1][MIX_YAW] = +64;
304
  mixerMatrix.motor[1][MIX_YAW] = +64;
304
  mixerMatrix.motor[2][MIX_ROLL] = -64;
305
  mixerMatrix.motor[2][MIX_ROLL] = -64;
305
  mixerMatrix.motor[2][MIX_YAW] = -64;
306
  mixerMatrix.motor[2][MIX_YAW] = -64;
306
  mixerMatrix.motor[3][MIX_ROLL] = +64;
307
  mixerMatrix.motor[3][MIX_ROLL] = +64;
307
  mixerMatrix.motor[3][MIX_YAW] = -64;
308
  mixerMatrix.motor[3][MIX_YAW] = -64;
308
  memcpy(mixerMatrix.name, "Quadro\0", 7);
309
  memcpy(mixerMatrix.name, "Quadro\0", 7);
309
}
310
}
310
 
311
 
311
void channelMap_default(void) {
312
void channelMap_default(void) {
312
  channelMap.channels[CH_PITCH] = 2;
313
  channelMap.channels[CH_PITCH] = 2;
313
  channelMap.channels[CH_ROLL] = 1;
314
  channelMap.channels[CH_ROLL] = 1;
314
  channelMap.channels[CH_THROTTLE] = 3;
315
  channelMap.channels[CH_THROTTLE] = 3;
315
  channelMap.channels[CH_YAW] = 4;
316
  channelMap.channels[CH_YAW] = 4;
316
  channelMap.channels[CH_POTS + 0] = 5;
317
  channelMap.channels[CH_POTS + 0] = 5;
317
  channelMap.channels[CH_POTS + 1] = 6;
318
  channelMap.channels[CH_POTS + 1] = 6;
318
  channelMap.channels[CH_POTS + 2] = 7;
319
  channelMap.channels[CH_POTS + 2] = 7;
319
  channelMap.channels[CH_POTS + 3] = 8;
320
  channelMap.channels[CH_POTS + 3] = 8;
320
}
321
}
321
 
322
 
322
 
323