Subversion Repositories FlightCtrl

Rev

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

Rev 2157 Rev 2158
1
#ifndef _CONFIGURATION_H
1
#ifndef _CONFIGURATION_H
2
#define _CONFIGURATION_H
2
#define _CONFIGURATION_H
3
 
3
 
4
#include <inttypes.h>
4
#include <inttypes.h>
5
#include <avr/io.h>
5
#include <avr/io.h>
6
 
6
 
7
#define MAX_CHANNELS 10
7
#define MAX_CHANNELS 10
8
#define MAX_MOTORS 12
8
#define MAX_MOTORS 12
9
 
9
 
10
// bitmask for VersionInfo_t.HardwareError[0]
10
// bitmask for VersionInfo_t.HardwareError[0]
11
#define FC_ERROR0_GYRO_PITCH    0x01
11
#define FC_ERROR0_GYRO_PITCH    0x01
12
#define FC_ERROR0_GYRO_ROLL     0x02
12
#define FC_ERROR0_GYRO_ROLL     0x02
13
#define FC_ERROR0_GYRO_YAW              0x04
13
#define FC_ERROR0_GYRO_YAW              0x04
14
#define FC_ERROR0_ACC_X                 0x08
14
#define FC_ERROR0_ACC_X                 0x08
15
#define FC_ERROR0_ACC_Y                 0x10
15
#define FC_ERROR0_ACC_Y                 0x10
16
#define FC_ERROR0_ACC_Z                 0x20
16
#define FC_ERROR0_ACC_Z                 0x20
17
#define FC_ERROR0_PRESSURE              0x40
17
#define FC_ERROR0_PRESSURE              0x40
18
#define FC_ERROR1_RES0                  0x80
18
#define FC_ERROR1_RES0                  0x80
19
// bitmask for VersionInfo_t.HardwareError[1]
19
// bitmask for VersionInfo_t.HardwareError[1]
20
#define FC_ERROR1_I2C                   0x01
20
#define FC_ERROR1_I2C                   0x01
21
#define FC_ERROR1_BL_MISSING    0x02
21
#define FC_ERROR1_BL_MISSING    0x02
22
#define FC_ERROR1_SPI_RX                0x04
22
#define FC_ERROR1_SPI_RX                0x04
23
#define FC_ERROR1_PPM                   0x08
23
#define FC_ERROR1_PPM                   0x08
24
#define FC_ERROR1_MIXER                 0x10
24
#define FC_ERROR1_MIXER                 0x10
25
#define FC_ERROR1_RES1                  0x20
25
#define FC_ERROR1_RES1                  0x20
26
#define FC_ERROR1_RES2                  0x40
26
#define FC_ERROR1_RES2                  0x40
27
#define FC_ERROR1_RES3                  0x80
27
#define FC_ERROR1_RES3                  0x80
28
 
28
 
29
typedef struct {
29
typedef struct {
30
        uint8_t SWMajor;
30
        uint8_t SWMajor;
31
        uint8_t SWMinor;
31
        uint8_t SWMinor;
32
        uint8_t protoMajor;
32
        uint8_t protoMajor;
33
        uint8_t protoMinor;
33
        uint8_t protoMinor;
34
        uint8_t SWPatch;
34
        uint8_t SWPatch;
35
        uint8_t hardwareErrors[5];
35
        uint8_t hardwareErrors[5];
36
}__attribute__((packed)) VersionInfo_t;
36
}__attribute__((packed)) VersionInfo_t;
37
 
37
 
38
extern VersionInfo_t versionInfo;
38
extern VersionInfo_t versionInfo;
39
 
39
 
40
typedef struct {
40
typedef struct {
41
  /*PMM*/uint8_t gyroP;
41
  /*PMM*/uint8_t gyroP;
42
  /* P */uint8_t gyroI;
42
  /* P */uint8_t gyroI;
43
  /* P */uint8_t gyroD;
43
  /* P */uint8_t gyroD;
44
  /* P */uint8_t compassControlHeading;
44
  /* P */uint8_t compassControlHeading;
45
 
45
 
46
  // Control
46
  // Control
47
  /* P */uint8_t externalControl;
47
  /* P */uint8_t externalControl;
48
  /* P */uint8_t dynamicStability;
48
  /* P */uint8_t dynamicStability;
49
 
49
 
50
  // Height control
50
  // Height control
51
  /*PMM*/uint8_t heightP;
51
  /*PMM*/uint8_t heightP;
52
  /* P */uint8_t heightI;
52
  /* P */uint8_t heightI;
53
  /*PMM*/uint8_t heightD;
53
  /*PMM*/uint8_t heightD;
54
  /* P */uint8_t heightSetting;
54
  /* P */uint8_t heightSetting;
55
 
55
 
56
  uint8_t attitudeControl;
56
  uint8_t attitudeControl;
57
 
57
 
58
  // Output and servo
58
  // Output and servo
59
  /*PMM*/uint8_t output0Timing;
59
  /*PMM*/uint8_t output0Timing;
60
  /*PMM*/uint8_t output1Timing;
60
  /*PMM*/uint8_t output1Timing;
61
 
61
 
62
  uint8_t servoManualControl[2];
62
  uint8_t servoManualControl[2];
63
 
63
 
64
  // Correction
64
  // Correction
65
  uint8_t levelCorrection[2];
65
  uint8_t levelCorrection[2];
66
 
66
 
67
  // Simple direct navigation
67
  // Simple direct navigation
68
  uint8_t naviMode;
68
  uint8_t naviMode;
69
 
69
 
70
  /* P */uint8_t userParams[8];
70
  /* P */uint8_t userParams[8];
71
} DynamicParams_t;
71
} DynamicParams_t;
72
 
72
 
73
extern volatile DynamicParams_t dynamicParams;
73
extern volatile DynamicParams_t dynamicParams;
74
 
74
 
75
typedef struct {
75
typedef struct {
76
  uint8_t sourceIdx, targetIdx;
76
  uint8_t sourceIdx, targetIdx;
77
  uint8_t min, max;
77
  uint8_t min, max;
78
} MMXLATION;
78
} MMXLATION;
79
 
79
 
80
/*
80
/*
81
typedef struct {
81
typedef struct {
82
  uint8_t sourceIdx, targetIdx;
82
  uint8_t sourceIdx, targetIdx;
83
} XLATION;
83
} XLATION;
84
*/
84
*/
85
 
85
 
86
typedef struct {
86
typedef struct {
87
        uint8_t trim;
87
        uint8_t trim;
88
        uint8_t variableOffset;
88
        uint8_t variableOffset;
89
  uint8_t channels[MAX_CHANNELS];
89
  uint8_t channels[MAX_CHANNELS];
90
} ChannelMap_t;
90
} ChannelMap_t;
91
extern ChannelMap_t channelMap;
91
extern ChannelMap_t channelMap;
92
 
92
 
93
typedef struct {
93
typedef struct {
94
  char name[12];
94
  char name[12];
95
  int8_t motor[MAX_MOTORS][4];
95
  int8_t matrix[MAX_MOTORS][5];
-
 
96
  //int8_t oppositeMotor[MAX_MOTORS];
96
}__attribute__((packed)) MixerMatrix_t;
97
}__attribute__((packed)) MotorMixer_t;
97
extern MixerMatrix_t mixerMatrix;
98
extern MotorMixer_t motorMixer;
98
 
99
 
99
typedef struct {
100
typedef struct {
100
  int16_t offsets[3];
101
  int16_t offsets[3];
101
} sensorOffset_t;
102
} sensorOffset_t;
102
 
103
 
103
typedef struct {
104
typedef struct {
104
  uint8_t manualControl;
105
  uint8_t manualControl;
105
  uint8_t stabilizationFactor;
106
  uint8_t stabilizationFactor;
106
  uint8_t minValue;
107
  uint8_t minValue;
107
  uint8_t maxValue;
108
  uint8_t maxValue;
108
  uint8_t flags;
109
  uint8_t flags;
109
} Servo_t;
110
} Servo_t;
110
 
111
 
111
#define SERVO_STABILIZATION_REVERSE 1
112
#define SERVO_STABILIZATION_REVERSE 1
112
 
113
 
113
typedef struct {
114
typedef struct {
114
  uint8_t bitmask;
115
  uint8_t bitmask;
115
  uint8_t timing;
116
  uint8_t timing;
116
} output_flash_t;
117
} output_flash_t;
117
 
118
 
118
typedef struct {
119
typedef struct {
119
  uint8_t gyroQuadrant;
120
  uint8_t gyroQuadrant;
120
  uint8_t accQuadrant;
121
  uint8_t accQuadrant;
121
  uint8_t imuReversedFlags;
122
  uint8_t imuReversedFlags;
122
 
123
 
123
  uint8_t gyroPIDFilterConstant;
124
  uint8_t gyroPIDFilterConstant;
124
  uint8_t gyroDWindowLength;
125
  uint8_t gyroDWindowLength;
125
  uint8_t gyroDFilterConstant;
126
  // uint8_t gyroDFilterConstant;
126
  uint8_t accFilterConstant;
127
  uint8_t accFilterConstant;
127
 
128
 
128
  uint8_t zerothOrderCorrection;
129
  uint8_t zerothOrderCorrection;
129
  uint8_t rateTolerance;
130
  uint8_t rateTolerance;
130
 
131
 
131
  uint8_t gyroActivityDamping;
132
  uint8_t gyroActivityDamping;
132
  uint8_t driftCompDivider; // 1/k  (Koppel_ACC_Wirkung)
133
  uint8_t driftCompDivider; // 1/k  (Koppel_ACC_Wirkung)
133
  uint8_t driftCompLimit;   // limit for gyrodrift compensation
134
  uint8_t driftCompLimit;   // limit for gyrodrift compensation
134
} IMUConfig_t;
135
} IMUConfig_t;
135
 
136
 
136
extern IMUConfig_t IMUConfig;
137
extern IMUConfig_t IMUConfig;
137
 
138
 
138
// values above 250 representing poti1 to poti4
139
// values above 250 representing poti1 to poti4
139
typedef struct {
140
typedef struct {
140
  // Global bitflags
141
  // Global bitflags
141
  uint8_t bitConfig;  // see upper defines for bitcoding
142
  uint8_t bitConfig;  // see upper defines for bitcoding
142
 
143
 
143
  // uint8_t axisCoupling1; // Value: 0-250  Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung)
144
  // uint8_t axisCoupling1; // Value: 0-250  Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung)
144
  // uint8_t axisCoupling2; // Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
145
  // uint8_t axisCoupling2; // Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
145
  // uint8_t axisCouplingYawCorrection;// Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
146
  // uint8_t axisCouplingYawCorrection;// Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
146
 
147
 
147
  uint8_t levelCorrection[2];
148
  uint8_t levelCorrection[2];
148
 
149
 
149
  // Control
150
  // Control
150
  uint8_t gyroP;
151
  uint8_t gyroP;
151
  uint8_t gyroI;
152
  uint8_t gyroI;
152
  uint8_t gyroD;
153
  uint8_t gyroD;
153
 
154
 
154
  uint8_t attitudeControl;
155
  uint8_t attitudeControl;
155
 
156
 
156
  uint8_t stickP;
157
  uint8_t stickP;
157
  uint8_t stickD;
158
  uint8_t stickD;
158
  uint8_t stickYawP;
159
  uint8_t stickYawP;
159
  uint8_t stickThrottleD;
160
  uint8_t stickThrottleD;
160
 
161
 
161
  uint8_t minThrottle;
162
  uint8_t minThrottle;
162
  uint8_t maxThrottle;
163
  uint8_t maxThrottle;
163
 
164
 
164
  uint8_t externalControl; // for serial Control
165
  uint8_t externalControl; // for serial Control
165
  uint8_t motorSmoothing;
166
  uint8_t motorSmoothing;
166
  uint8_t dynamicStability; // PID limit for Attitude controller
167
  uint8_t dynamicStability; // PID limit for Attitude controller
167
 
168
 
168
  uint8_t IFactor;
169
  uint8_t IFactor;
169
  uint8_t yawIFactor;
170
  uint8_t yawIFactor;
170
 
171
 
171
  uint8_t compassMode;      // bitflag thing.
172
  uint8_t compassMode;      // bitflag thing.
172
  uint8_t compassYawCorrection;
173
  uint8_t compassYawCorrection;
173
  uint8_t compassBendingReturnSpeed;
174
  uint8_t compassBendingReturnSpeed;
174
  uint8_t compassP;
175
  uint8_t compassP;
175
 
176
 
176
  uint8_t batteryVoltageWarning;
177
  uint8_t batteryVoltageWarning;
177
  uint8_t emergencyThrottle;
178
  uint8_t emergencyThrottle;
178
  uint8_t emergencyFlightDuration;
179
  uint8_t emergencyFlightDuration;
179
 
180
 
180
  // Height Control
181
  // Height Control
181
  uint8_t airpressureFilterConstant;
182
  uint8_t airpressureFilterConstant;
182
  uint8_t airpressureWindowLength; // 0 means: Use filter.
183
  uint8_t airpressureWindowLength; // 0 means: Use filter.
183
  uint8_t airpressureDWindowLength; // values 1..5 are legal.
184
  uint8_t airpressureDWindowLength; // values 1..5 are legal.
184
  uint8_t airpressureAccZCorrection;
185
  uint8_t airpressureAccZCorrection;
185
 
186
 
186
  uint8_t heightP;
187
  uint8_t heightP;
187
  uint8_t heightI;
188
  uint8_t heightI;
188
  uint8_t heightD;
189
  uint8_t heightD;
189
 
190
 
190
  uint8_t heightSetting;
191
  uint8_t heightSetting;
191
  uint8_t heightControlMaxIntegralIn;
192
  uint8_t heightControlMaxIntegralIn;
192
  uint8_t heightControlMaxIntegralOut;
193
  uint8_t heightControlMaxIntegralOut;
193
  uint8_t heightControlMaxThrottleChange;
194
  uint8_t heightControlMaxThrottleChange;
194
 
195
 
195
  uint8_t heightControlTestOscPeriod;
196
  uint8_t heightControlTestOscPeriod;
196
  uint8_t heightControlTestOscAmplitude;
197
  uint8_t heightControlTestOscAmplitude;
197
 
198
 
198
  // Servos
199
  // Servos
199
  uint8_t servoCount;
200
  uint8_t servoCount;
200
  uint8_t servoManualMaxSpeed;
201
  uint8_t servoManualMaxSpeed;
201
  Servo_t servoConfigurations[2]; // [PITCH, ROLL]
202
  Servo_t servoConfigurations[2]; // [PITCH, ROLL]
202
 
203
 
203
  // Outputs
204
  // Outputs
204
  output_flash_t outputFlash[2];
205
  output_flash_t outputFlash[2];
205
  uint8_t outputDebugMask;
206
  uint8_t outputDebugMask;
206
  uint8_t outputFlags;
207
  uint8_t outputFlags;
207
 
208
 
208
 // Shared for both modes of navigation
209
 // Shared for both modes of navigation
209
  uint8_t naviMode;
210
  uint8_t naviMode;
210
  uint8_t naviStickThreshold;
211
  uint8_t naviStickThreshold;
211
  uint8_t naviStickLimit;
212
  uint8_t naviStickLimit;
212
  uint8_t GPSMininumSatellites;
213
  uint8_t GPSMininumSatellites;
213
  uint8_t naviP;
214
  uint8_t naviP;
214
  uint8_t naviI;
215
  uint8_t naviI;
215
  uint8_t naviD;
216
  uint8_t naviD;
216
 
217
 
217
  uint8_t naviTestOscPeriod;
218
  uint8_t naviTestOscPeriod;
218
  uint8_t naviTestOscAmplitude;
219
  uint8_t naviTestOscAmplitude;
219
 
220
 
220
  // User params
221
  // User params
221
  uint8_t userParams[8];
222
  uint8_t userParams[8];
222
 
223
 
223
  // Name
224
  // Name
224
  char name[12];
225
  char name[12];
225
} ParamSet_t;
226
} ParamSet_t;
226
 
227
 
227
extern ParamSet_t staticParams;
228
extern ParamSet_t staticParams;
228
 
229
 
229
// MKFlags
230
// MKFlags
230
#define MKFLAG_MOTOR_RUN        (1<<0)
231
#define MKFLAG_MOTOR_RUN        (1<<0)
231
//#define MKFLAG_FLY            (1<<1)
232
//#define MKFLAG_FLY            (1<<1)
232
#define MKFLAG_CALIBRATE        (1<<2)
233
#define MKFLAG_CALIBRATE        (1<<2)
233
#define MKFLAG_START            (1<<3)
234
#define MKFLAG_START            (1<<3)
234
#define MKFLAG_EMERGENCY_FLIGHT (1<<4)
235
#define MKFLAG_EMERGENCY_FLIGHT (1<<4)
235
#define MKFLAG_LOWBAT           (1<<5)
236
#define MKFLAG_LOWBAT           (1<<5)
236
#define MKFLAG_RESERVE2         (1<<6)
237
#define MKFLAG_RESERVE2         (1<<6)
237
#define MKFLAG_RESERVE3         (1<<7)
238
#define MKFLAG_RESERVE3         (1<<7)
238
 
239
 
239
// bit mask for staticParams.bitConfig
240
// bit mask for staticParams.bitConfig
240
#define CFG_SIMPLE_HEIGHT_CONTROL               (1<<0)
241
#define CFG_SIMPLE_HEIGHT_CONTROL               (1<<0)
241
#define CFG_SIMPLE_HC_HOLD_SWITCH       (1<<1)
242
#define CFG_SIMPLE_HC_HOLD_SWITCH       (1<<1)
242
#define CFG_HEADING_HOLD                        (1<<2)
243
#define CFG_HEADING_HOLD                        (1<<2)
243
#define CFG_COMPASS_ENABLED             (1<<3)
244
#define CFG_COMPASS_ENABLED             (1<<3)
244
#define CFG_UNUSED                              (1<<4)
245
#define CFG_UNUSED                              (1<<4)
245
#define CFG_NAVI_ENABLED                        (1<<5)
246
#define CFG_NAVI_ENABLED                        (1<<5)
246
#define CFG_AXIS_COUPLING_ENABLED       (1<<6)
247
#define CFG_AXIS_COUPLING_ENABLED       (1<<6)
247
#define CFG_GYRO_SATURATION_PREVENTION  (1<<7)
248
#define CFG_GYRO_SATURATION_PREVENTION  (1<<7)
248
 
249
 
249
#define IMU_REVERSE_GYRO_PR                             (1<<0)
250
#define IMU_REVERSE_GYRO_PR                             (1<<0)
250
#define IMU_REVERSE_GYRO_YAW                    (1<<1)
251
#define IMU_REVERSE_GYRO_YAW                    (1<<1)
251
#define IMU_REVERSE_ACC_XY                              (1<<2)
252
#define IMU_REVERSE_ACC_XY                              (1<<2)
252
#define IMU_REVERSE_ACC_Z                               (1<<3)
253
#define IMU_REVERSE_ACC_Z                               (1<<3)
253
 
254
 
254
#define ATMEGA644       0
255
#define ATMEGA644       0
255
#define ATMEGA644P      1
256
#define ATMEGA644P      1
256
#define SYSCLK F_CPU
257
#define SYSCLK F_CPU
257
 
258
 
258
// Not really a part of configuration, but LEDs and HW s test are the same.
259
// Not really a part of configuration, but LEDs and HW s test are the same.
259
#define RED_OFF   {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else  PORTB |= (1<<PORTB0);}
260
#define RED_OFF   {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else  PORTB |= (1<<PORTB0);}
260
#define RED_ON    {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else  PORTB &=~(1<<PORTB0);}
261
#define RED_ON    {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else  PORTB &=~(1<<PORTB0);}
261
#define RED_FLASH PORTB ^= (1<<PORTB0)
262
#define RED_FLASH PORTB ^= (1<<PORTB0)
262
#define GRN_OFF   {if(boardRelease  < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);}
263
#define GRN_OFF   {if(boardRelease  < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);}
263
#define GRN_ON    {if(boardRelease  < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);}
264
#define GRN_ON    {if(boardRelease  < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);}
264
#define GRN_FLASH PORTB ^= (1<<PORTB1)
265
#define GRN_FLASH PORTB ^= (1<<PORTB1)
265
 
266
 
266
// Mixer table
267
// Mixer table
267
#define MIX_THROTTLE    0
268
#define MIX_PITCH               0
268
#define MIX_PITCH       1
269
#define MIX_ROLL                1
269
#define MIX_ROLL        2
270
#define MIX_THROTTLE        2
270
#define MIX_YAW         3
271
#define MIX_YAW             3
-
 
272
#define MIX_OPPOSITE_MOTOR  4
271
 
273
 
272
#define VARIABLE_COUNT 8
274
#define VARIABLE_COUNT  8
273
 
275
 
274
extern volatile uint8_t MKFlags;
276
extern volatile uint8_t MKFlags;
275
extern uint8_t requiredMotors;
277
extern uint8_t requiredMotors;
276
extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s.
278
extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s.
277
extern uint8_t boardRelease;
279
extern uint8_t boardRelease;
278
extern uint8_t CPUType;
280
extern uint8_t CPUType;
279
 
281
 
280
extern volatile uint8_t MKFlags;
282
extern volatile uint8_t MKFlags;
281
extern uint16_t isFlying;
283
extern uint16_t isFlying;
282
 
284
 
283
void IMUConfig_default(void);
285
void IMUConfig_default(void);
284
void channelMap_default(void);
286
void channelMap_default(void);
285
void paramSet_default(uint8_t setnumber);
287
void paramSet_default(uint8_t setnumber);
286
void mixerMatrix_default(void);
288
void motorMixer_default(void);
287
 
289
 
288
void configuration_setNormalFlightParameters(void);
290
void configuration_setNormalFlightParameters(void);
289
void configuration_setFailsafeFlightParameters(void);
291
void configuration_setFailsafeFlightParameters(void);
290
void configuration_applyVariablesToParams(void);
292
void configuration_applyVariablesToParams(void);
291
 
293
 
292
void setCPUType(void);
294
void setCPUType(void);
293
void setBoardRelease(void);
295
void setBoardRelease(void);
294
 
296
 
295
// Called after a change in configuration parameters, as a hook for modules to take over changes.
297
// Called after a change in configuration parameters, as a hook for modules to take over changes.
296
void configuration_paramSetDidChange(void);
298
void configuration_paramSetDidChange(void);
297
#endif // _CONFIGURATION_H
299
#endif // _CONFIGURATION_H
298
 
300