Subversion Repositories FlightCtrl

Rev

Rev 2160 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2160 Rev 2189
Line 2... Line 2...
2
#define _CONFIGURATION_H
2
#define _CONFIGURATION_H
Line 3... Line 3...
3
 
3
 
4
#include <inttypes.h>
4
#include <inttypes.h>
Line -... Line 5...
-
 
5
#include <avr/io.h>
5
#include <avr/io.h>
6
 
6
 
7
#define MAX_CONTROLCHANNELS 8
Line 7... Line 8...
7
#define MAX_CHANNELS 10
8
#define MAX_I2CCHANNELS 8
8
#define MAX_MOTORS 12
9
#define MAX_PWMCHANNELS 8
9
 
10
 
10
// bitmask for VersionInfo_t.HardwareError[0]
11
// bitmask for VersionInfo_t.HardwareError[0]
11
#define FC_ERROR0_GYRO_PITCH    0x01
12
#define FC_ERROR0_GYRO_X                0x01
12
#define FC_ERROR0_GYRO_ROLL     0x02
13
#define FC_ERROR0_GYRO_Y                0x02
13
#define FC_ERROR0_GYRO_YAW              0x04
14
#define FC_ERROR0_GYRO_Z                0x04
14
#define FC_ERROR0_ACC_X                 0x08
15
#define FC_ERROR0_ACCEL_X               0x08
15
#define FC_ERROR0_ACC_Y                 0x10
16
#define FC_ERROR0_ACCEL_Y               0x10
16
#define FC_ERROR0_ACC_Z                 0x20
17
#define FC_ERROR0_ACCEL_Z               0x20
17
#define FC_ERROR0_PRESSURE              0x40
18
#define FC_ERROR0_PRESSURE              0x40
18
#define FC_ERROR1_RES0                  0x80
19
#define FC_ERROR1_RES0                  0x80
Line 24... Line 25...
24
#define FC_ERROR1_MIXER                 0x10
25
#define FC_ERROR1_MIXER                 0x10
25
#define FC_ERROR1_RES1                  0x20
26
#define FC_ERROR1_RES1                  0x20
26
#define FC_ERROR1_RES2                  0x40
27
#define FC_ERROR1_RES2                  0x40
27
#define FC_ERROR1_RES3                  0x80
28
#define FC_ERROR1_RES3                  0x80
Line -... Line 29...
-
 
29
 
-
 
30
#define PID_NORMAL_VALUE 100
28
 
31
 
29
typedef struct {
32
typedef struct {
30
        uint8_t SWMajor;
33
        uint8_t SWMajor;
-
 
34
        uint8_t SWMinor;
31
        uint8_t SWMinor;
35
        uint8_t SWPatch;
32
        uint8_t protoMajor;
36
        uint8_t protoMajor;
33
        uint8_t protoMinor;
-
 
34
        uint8_t SWPatch;
37
        uint8_t protoMinor;
35
        uint8_t hardwareErrors[5];
38
        uint8_t hardwareErrors[5];
Line 36... Line 39...
36
}__attribute__((packed)) VersionInfo_t;
39
}__attribute__((packed)) VersionInfo_t;
Line 37... Line 40...
37
 
40
 
38
extern VersionInfo_t versionInfo;
41
extern VersionInfo_t versionInfo;
-
 
42
 
-
 
43
typedef struct {
-
 
44
  uint8_t flightMode;
-
 
45
 
-
 
46
  uint8_t attGyroP;     // Attitude mode Proportional (attitude error to control)
-
 
47
  uint8_t attGyroI;     // Attitude mode Integral (attitude error integral to control. Serves to eliminate permanent attitude errors)
-
 
48
  uint8_t attGyroD;     // Attitude mode rate
-
 
49
 
-
 
50
  uint8_t rateGyroP;    // Rate mode Proportional
39
 
51
  uint8_t rateGyroI;    // Rate mode Integral (serves to eliminate slow rotation errors in rate mode)
40
typedef struct {
52
  uint8_t rateGyroD;    // Rate mode Differential (GyroD)
41
  /*PMM*/uint8_t gyroP;
53
 
42
  /* P */uint8_t gyroI;
54
  uint8_t yawGyroP;
43
  /* P */uint8_t gyroD;
55
  uint8_t yawGyroI;
44
  /* P */uint8_t compassControlHeading;
56
  uint8_t yawGyroD;
45
 
57
 
46
  // Control
58
  // Control
47
  /* P */uint8_t externalControl;
59
  uint8_t externalControl;
48
  /* P */uint8_t dynamicStability;
60
  uint8_t attitudeControl;
49
 
61
 
50
  // Height control
62
  // Height control
51
  /*PMM*/uint8_t heightP;
63
  uint8_t heightP;
Line 52... Line -...
52
  /* P */uint8_t heightI;
-
 
Line 53... Line 64...
53
  /*PMM*/uint8_t heightD;
64
  uint8_t heightI;
54
  /* P */uint8_t heightSetting;
65
  uint8_t heightD;
55
 
66
  uint8_t heightSetting;
Line 56... Line 67...
56
  uint8_t attitudeControl;
67
 
Line 57... Line 68...
57
 
68
 
58
  // Output and servo
69
  // Output and servo
Line 85... Line 96...
85
 
96
 
86
typedef struct {
97
typedef struct {
87
    uint8_t RCPolarity; // 1=positive, 0=negative. Use positive with Futaba receiver, negative with FrSky.
98
    uint8_t RCPolarity; // 1=positive, 0=negative. Use positive with Futaba receiver, negative with FrSky.
88
        uint8_t HWTrim;
99
        uint8_t HWTrim;
89
        uint8_t variableOffset;
100
        uint8_t variableOffset;
90
    uint8_t channels[MAX_CHANNELS];
101
    uint8_t channels[MAX_CONTROLCHANNELS];
Line 91... Line 102...
91
} ChannelMap_t;
102
} ChannelMap_t;
Line -... Line 103...
-
 
103
 
-
 
104
extern ChannelMap_t channelMap;
-
 
105
 
-
 
106
#define LOG_MOTOR_MIXER_UNIT 6
-
 
107
#define LOG_DYNAMIC_STABILITY_SCALER 6
-
 
108
 
-
 
109
typedef enum {
-
 
110
  MIXER_SOURCE_ROLL = 0,
-
 
111
  MIXER_SOURCE_PITCH = 1,
-
 
112
  MIXER_SOURCE_THROTTLE = 2,
-
 
113
  MIXER_SOURCE_YAW = 3
-
 
114
} MixerSource_Control;
-
 
115
 
-
 
116
typedef enum {
-
 
117
  MIXER_SOURCE_AUX_GIMBAL_ROLL = 0,
-
 
118
  MIXER_SOURCE_AUX_GIMBAL_PITCH = 1,
-
 
119
  MIXER_SOURCE_AUX_RCCHANNEL = 2,
-
 
120
  MIXER_SOURCE_AUX_END = 2 + MAX_CONTROLCHANNELS
-
 
121
} MixerSourceAux;
-
 
122
 
-
 
123
typedef enum {
-
 
124
  I2C0 = 0,
-
 
125
  I2C1 = 1,
-
 
126
  I2C2 = 2,
-
 
127
  I2C3 = 3,
-
 
128
  I2C4 = 4,
-
 
129
  I2C5 = 5,
-
 
130
  I2C6 = 6,
-
 
131
  I2C7 = 7,
-
 
132
  SERVO0 = MAX_I2CCHANNELS,
92
 
133
  NUM_OUTPUTS = 8 + MAX_PWMCHANNELS
-
 
134
} MixerDestination;
93
extern ChannelMap_t channelMap;
135
 
94
 
136
typedef struct {
95
typedef struct {
137
  uint8_t outputType;
-
 
138
  uint8_t minValue;
-
 
139
  uint8_t maxValue;
96
  char name[12];
140
  int8_t  flightControls[4];
-
 
141
  uint8_t auxSource;     // for selecting a gimbal axis or an RC channel.
-
 
142
  uint8_t oppositeMotor; // only relevant where used to control a multicopter motor.
97
  int8_t matrix[MAX_MOTORS][5];
143
}__attribute__((packed)) MixerMatrixRow_t;
-
 
144
 
-
 
145
typedef MixerMatrixRow_t OutputMixer_t[NUM_OUTPUTS];
-
 
146
extern OutputMixer_t outputMixer;
-
 
147
 
-
 
148
typedef enum {
-
 
149
  OUTPUT_TYPE_UNDEFINED,
Line 98... Line 150...
98
  //int8_t oppositeMotor[MAX_MOTORS];
150
  OUTPUT_TYPE_MOTOR,
99
}__attribute__((packed)) MotorMixer_t;
151
  OUTPUT_TYPE_SERVO
100
extern MotorMixer_t motorMixer;
152
} outputTypes;
Line 101... Line 153...
101
 
153
 
102
typedef struct {
154
typedef struct {
103
  int16_t offsets[3];
155
  int16_t offsets[3];
104
} sensorOffset_t;
-
 
105
 
-
 
106
typedef struct {
156
} sensorOffset_t;
107
  uint8_t manualControl;
157
 
Line 108... Line 158...
108
  uint8_t stabilizationFactor;
158
typedef struct {
Line 117... Line 167...
117
  uint8_t bitmask;
167
  uint8_t bitmask;
118
  uint8_t timing;
168
  uint8_t timing;
119
} output_flash_t;
169
} output_flash_t;
Line 120... Line 170...
120
 
170
 
-
 
171
typedef struct {
-
 
172
  /* Set up so that
-
 
173
   * Nose-up is positive on pitch
-
 
174
   * Roll-right is positive on roll
-
 
175
   * Turn-ccw is positive on yaw
121
typedef struct {
176
   */
-
 
177
  uint8_t gyroQuadrant;
-
 
178
  /*
-
 
179
   * Set up so that:
-
 
180
   * Acc. Z is +1g in normal attitude
-
 
181
   * Acc. X gets positive in a left roll
-
 
182
   * Acc. Y gets positive in a nose-up attitude.
122
  uint8_t gyroQuadrant;
183
   */
123
  uint8_t accQuadrant;
184
  uint8_t accQuadrant;
124
  uint8_t imuReversedFlags;
-
 
125
 
185
  uint8_t imuReversedFlags;
126
  uint8_t gyroPIDFilterConstant;
186
  uint8_t gyroPIDFilterConstant;
127
  uint8_t gyroDWindowLength;
-
 
128
  // uint8_t gyroDFilterConstant;
187
  uint8_t gyroDWindowLength;
Line 129... Line -...
129
  uint8_t accFilterConstant;
-
 
130
 
-
 
131
  uint8_t zerothOrderCorrection;
-
 
132
  uint8_t rateTolerance;
-
 
133
 
-
 
134
  uint8_t gyroActivityDamping;
-
 
135
  uint8_t driftCompDivider; // 1/k  (Koppel_ACC_Wirkung)
188
  uint8_t accFilterConstant;
Line 136... Line 189...
136
  uint8_t driftCompLimit;   // limit for gyrodrift compensation
189
 
Line 137... Line 190...
137
} IMUConfig_t;
190
} IMUConfig_t;
138
 
191
 
139
extern IMUConfig_t IMUConfig;
192
extern IMUConfig_t IMUConfig;
140
 
193
 
Line -... Line 194...
-
 
194
// values above 250 representing poti1 to poti4
-
 
195
typedef struct {
141
// values above 250 representing poti1 to poti4
196
  // Global bitflags
142
typedef struct {
197
  uint8_t bitConfig;  // see upper defines for bitcoding
143
  // Global bitflags
198
 
Line 144... Line 199...
144
  uint8_t bitConfig;  // see upper defines for bitcoding
199
  uint8_t flightMode;
Line 145... Line 200...
145
 
200
 
-
 
201
  // uint8_t axisCoupling1; // Value: 0-250  Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung)
-
 
202
  // uint8_t axisCoupling2; // Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
-
 
203
  // uint8_t axisCouplingYawCorrection;// Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
-
 
204
 
-
 
205
  uint8_t levelCorrection[2];
-
 
206
 
-
 
207
  // Control
-
 
208
  uint8_t attGyroP;     // Attitude mode Proportional (attitude error to control)
-
 
209
  uint8_t attGyroI;     // Attitude mode Integral (attitude error integral to control. Serves to eliminate permanent attitude errors)
-
 
210
  uint8_t attGyroIMax;  // Attitude mode Integral max. limit
146
  // uint8_t axisCoupling1; // Value: 0-250  Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung)
211
  uint8_t attGyroD;     // Attitude mode rate
147
  // uint8_t axisCoupling2; // Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
212
 
148
  // uint8_t axisCouplingYawCorrection;// Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
213
  uint8_t rateGyroP;    // Rate mode Proportional
149
 
214
  uint8_t rateGyroI;    // Rate mode Integral (serves to eliminate slow rotation errors in rate mode)
-
 
215
  uint8_t rateGyroIMax; // Rate mode Integral max. limit
150
  uint8_t levelCorrection[2];
216
  uint8_t rateGyroD;    // Rate mode Differential (GyroD)
-
 
217
 
Line 151... Line 218...
151
 
218
  uint8_t yawGyroP;
152
  // Control
219
  uint8_t yawGyroI;
153
  uint8_t gyroP;
220
  uint8_t yawGyroD;
154
  uint8_t gyroI;
221
 
Line -... Line 222...
-
 
222
  uint8_t externalControl; // for serial Control
155
  uint8_t gyroD;
223
  uint8_t attitudeControl;
-
 
224
  uint8_t dynamicStability;
156
 
225
 
Line 157... Line -...
157
  uint8_t attitudeControl;
-
 
158
 
-
 
159
  uint8_t stickP;
-
 
160
  uint8_t stickD;
-
 
161
  uint8_t stickYawP;
-
 
162
  uint8_t stickThrottleD;
-
 
163
 
-
 
164
  uint8_t minThrottle;
226
  uint8_t stickP;
165
  uint8_t maxThrottle;
227
  uint8_t stickD;
166
 
228
  uint8_t stickYawP;
167
  uint8_t externalControl; // for serial Control
229
  uint8_t stickThrottleD;
Line 228... Line 290...
228
} ParamSet_t;
290
} ParamSet_t;
Line 229... Line 291...
229
 
291
 
Line 230... Line 292...
230
extern ParamSet_t staticParams;
292
extern ParamSet_t staticParams;
231
 
293
 
232
// MKFlags
294
// MKFlags
233
#define MKFLAG_MOTOR_RUN        (1<<0)
295
#define MKFLAG_MOTOR_RUN            (1<<0)
234
//#define MKFLAG_FLY            (1<<1)
-
 
235
#define MKFLAG_CALIBRATE        (1<<2)
296
//#define MKFLAG_FLY            (1<<1)
236
#define MKFLAG_START            (1<<3)
297
//#define MKFLAG_CALIBRATE          (1<<2)
237
#define MKFLAG_EMERGENCY_FLIGHT (1<<4)
298
#define MKFLAG_EMERGENCY_FLIGHT (1<<4)
238
#define MKFLAG_LOWBAT           (1<<5)
299
#define MKFLAG_LOWBAT               (1<<5)
Line 239... Line 300...
239
#define MKFLAG_RESERVE2         (1<<6)
300
//#define MKFLAG_RESERVE2                   (1<<6)
240
#define MKFLAG_RESERVE3         (1<<7)
301
//#define MKFLAG_RESERVE3                   (1<<7)
241
 
302
 
242
// bit mask for staticParams.bitConfig
303
// bit mask for staticParams.bitConfig
243
#define CFG_SIMPLE_HEIGHT_CONTROL               (1<<0)
304
#define CFG_SIMPLE_HEIGHT_CONTROL               (1<<0)
244
#define CFG_SIMPLE_HC_HOLD_SWITCH       (1<<1)
305
#define CFG_SIMPLE_HC_HOLD_SWITCH       (1<<1)
245
#define CFG_HEADING_HOLD                        (1<<2)
306
#define CFG_UNUSED                              (1<<2)
246
#define CFG_COMPASS_ENABLED             (1<<3)
307
#define CFG_COMPASS_ENABLED             (1<<3)
247
#define CFG_UNUSED                              (1<<4)
308
#define CFG_UNUSED2                             (1<<4)
Line 248... Line 309...
248
#define CFG_NAVI_ENABLED                        (1<<5)
309
#define CFG_NAVI_ENABLED                        (1<<5)
249
#define CFG_AXIS_COUPLING_ENABLED       (1<<6)
310
#define CFG_UNUSED3                     (1<<6)
250
#define CFG_GYRO_SATURATION_PREVENTION  (1<<7)
311
#define CFG_GYRO_SATURATION_PREVENTION  (1<<7)
251
 
312
 
Line 252... Line 313...
252
#define IMU_REVERSE_GYRO_PR                             (1<<0)
313
#define IMU_REVERSE_GYRO_XY                             (1<<0)
253
#define IMU_REVERSE_GYRO_YAW                    (1<<1)
314
#define IMU_REVERSE_GYRO_Z                              (1<<1)
254
#define IMU_REVERSE_ACC_XY                              (1<<2)
-
 
Line 255... Line 315...
255
#define IMU_REVERSE_ACC_Z                               (1<<3)
315
#define IMU_REVERSE_ACCEL_XY                    (1<<2)
256
 
316
#define IMU_REVERSE_ACCEL_Z                             (1<<3)
257
#define ATMEGA644       0
317
 
258
#define ATMEGA644P      1
318
#define ATMEGA644       0
259
#define SYSCLK F_CPU
319
#define ATMEGA644P      1
260
 
320
 
261
// Not really a part of configuration, but LEDs and HW s test are the same.
321
// Not really a part of configuration, but LEDs and HW s test are the same.
Line 262... Line 322...
262
#define RED_OFF   {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else  PORTB |= (1<<PORTB0);}
322
#define RED_OFF   {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else  PORTB |= (1<<PORTB0);}
263
#define RED_ON    {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else  PORTB &=~(1<<PORTB0);}
-
 
264
#define RED_FLASH PORTB ^= (1<<PORTB0)
-
 
265
#define GRN_OFF   {if(boardRelease  < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);}
-
 
266
#define GRN_ON    {if(boardRelease  < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);}
-
 
267
#define GRN_FLASH PORTB ^= (1<<PORTB1)
-
 
Line 268... Line 323...
268
 
323
#define RED_ON    {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else  PORTB &=~(1<<PORTB0);}
Line 269... Line 324...
269
// Mixer table
324
#define RED_FLASH PORTB ^= (1<<PORTB0)
270
#define MIX_PITCH               0
-
 
271
#define MIX_ROLL                1
325
#define GRN_OFF   {if(boardRelease  < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);}
272
#define MIX_THROTTLE        2
326
#define GRN_ON    {if(boardRelease  < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);}
273
#define MIX_YAW             3
327
#define GRN_FLASH PORTB ^= (1<<PORTB1)
Line 274... Line 328...
274
#define MIX_OPPOSITE_MOTOR  4
328
 
275
 
329
// Mixer table
Line 276... Line 330...
276
#define VARIABLE_COUNT  8
330
 
277
 
331
#define VARIABLE_COUNT  8
278
extern volatile uint8_t MKFlags;
332
 
279
extern uint8_t requiredMotors;
333
extern volatile uint8_t MKFlags;
Line 280... Line 334...
280
extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s.
334
extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s.
281
extern uint8_t boardRelease;
335
extern uint8_t boardRelease;
282
extern uint8_t CPUType;
336
extern uint8_t CPUType;
Line 283... Line 337...
283
 
337
 
284
extern volatile uint8_t MKFlags;
338
extern volatile uint8_t MKFlags;