Subversion Repositories FlightCtrl

Rev

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

Rev 2158 Rev 2160
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 RCPolarity; // 1=positive, 0=negative. Use positive with Futaba receiver, negative with FrSky.
87
        uint8_t trim;
88
        uint8_t HWTrim;
88
        uint8_t variableOffset;
89
        uint8_t variableOffset;
89
  uint8_t channels[MAX_CHANNELS];
90
    uint8_t channels[MAX_CHANNELS];
90
} ChannelMap_t;
91
} ChannelMap_t;
-
 
92
 
91
extern ChannelMap_t channelMap;
93
extern ChannelMap_t channelMap;
92
 
94
 
93
typedef struct {
95
typedef struct {
94
  char name[12];
96
  char name[12];
95
  int8_t matrix[MAX_MOTORS][5];
97
  int8_t matrix[MAX_MOTORS][5];
96
  //int8_t oppositeMotor[MAX_MOTORS];
98
  //int8_t oppositeMotor[MAX_MOTORS];
97
}__attribute__((packed)) MotorMixer_t;
99
}__attribute__((packed)) MotorMixer_t;
98
extern MotorMixer_t motorMixer;
100
extern MotorMixer_t motorMixer;
99
 
101
 
100
typedef struct {
102
typedef struct {
101
  int16_t offsets[3];
103
  int16_t offsets[3];
102
} sensorOffset_t;
104
} sensorOffset_t;
103
 
105
 
104
typedef struct {
106
typedef struct {
105
  uint8_t manualControl;
107
  uint8_t manualControl;
106
  uint8_t stabilizationFactor;
108
  uint8_t stabilizationFactor;
107
  uint8_t minValue;
109
  uint8_t minValue;
108
  uint8_t maxValue;
110
  uint8_t maxValue;
109
  uint8_t flags;
111
  uint8_t flags;
110
} Servo_t;
112
} Servo_t;
111
 
113
 
112
#define SERVO_STABILIZATION_REVERSE 1
114
#define SERVO_STABILIZATION_REVERSE 1
113
 
115
 
114
typedef struct {
116
typedef struct {
115
  uint8_t bitmask;
117
  uint8_t bitmask;
116
  uint8_t timing;
118
  uint8_t timing;
117
} output_flash_t;
119
} output_flash_t;
118
 
120
 
119
typedef struct {
121
typedef struct {
120
  uint8_t gyroQuadrant;
122
  uint8_t gyroQuadrant;
121
  uint8_t accQuadrant;
123
  uint8_t accQuadrant;
122
  uint8_t imuReversedFlags;
124
  uint8_t imuReversedFlags;
123
 
125
 
124
  uint8_t gyroPIDFilterConstant;
126
  uint8_t gyroPIDFilterConstant;
125
  uint8_t gyroDWindowLength;
127
  uint8_t gyroDWindowLength;
126
  // uint8_t gyroDFilterConstant;
128
  // uint8_t gyroDFilterConstant;
127
  uint8_t accFilterConstant;
129
  uint8_t accFilterConstant;
128
 
130
 
129
  uint8_t zerothOrderCorrection;
131
  uint8_t zerothOrderCorrection;
130
  uint8_t rateTolerance;
132
  uint8_t rateTolerance;
131
 
133
 
132
  uint8_t gyroActivityDamping;
134
  uint8_t gyroActivityDamping;
133
  uint8_t driftCompDivider; // 1/k  (Koppel_ACC_Wirkung)
135
  uint8_t driftCompDivider; // 1/k  (Koppel_ACC_Wirkung)
134
  uint8_t driftCompLimit;   // limit for gyrodrift compensation
136
  uint8_t driftCompLimit;   // limit for gyrodrift compensation
135
} IMUConfig_t;
137
} IMUConfig_t;
136
 
138
 
137
extern IMUConfig_t IMUConfig;
139
extern IMUConfig_t IMUConfig;
138
 
140
 
139
// values above 250 representing poti1 to poti4
141
// values above 250 representing poti1 to poti4
140
typedef struct {
142
typedef struct {
141
  // Global bitflags
143
  // Global bitflags
142
  uint8_t bitConfig;  // see upper defines for bitcoding
144
  uint8_t bitConfig;  // see upper defines for bitcoding
143
 
145
 
144
  // uint8_t axisCoupling1; // Value: 0-250  Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung)
146
  // uint8_t axisCoupling1; // Value: 0-250  Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung)
145
  // uint8_t axisCoupling2; // Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
147
  // uint8_t axisCoupling2; // 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
148
  // uint8_t axisCouplingYawCorrection;// Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
147
 
149
 
148
  uint8_t levelCorrection[2];
150
  uint8_t levelCorrection[2];
149
 
151
 
150
  // Control
152
  // Control
151
  uint8_t gyroP;
153
  uint8_t gyroP;
152
  uint8_t gyroI;
154
  uint8_t gyroI;
153
  uint8_t gyroD;
155
  uint8_t gyroD;
154
 
156
 
155
  uint8_t attitudeControl;
157
  uint8_t attitudeControl;
156
 
158
 
157
  uint8_t stickP;
159
  uint8_t stickP;
158
  uint8_t stickD;
160
  uint8_t stickD;
159
  uint8_t stickYawP;
161
  uint8_t stickYawP;
160
  uint8_t stickThrottleD;
162
  uint8_t stickThrottleD;
161
 
163
 
162
  uint8_t minThrottle;
164
  uint8_t minThrottle;
163
  uint8_t maxThrottle;
165
  uint8_t maxThrottle;
164
 
166
 
165
  uint8_t externalControl; // for serial Control
167
  uint8_t externalControl; // for serial Control
166
  uint8_t motorSmoothing;
168
  uint8_t motorSmoothing;
167
  uint8_t dynamicStability; // PID limit for Attitude controller
169
  uint8_t dynamicStability; // PID limit for Attitude controller
168
 
170
 
169
  uint8_t IFactor;
171
  uint8_t IFactor;
170
  uint8_t yawIFactor;
172
  uint8_t yawIFactor;
171
 
173
 
172
  uint8_t compassMode;      // bitflag thing.
174
  uint8_t compassMode;      // bitflag thing.
173
  uint8_t compassYawCorrection;
175
  uint8_t compassYawCorrection;
174
  uint8_t compassBendingReturnSpeed;
176
  uint8_t compassBendingReturnSpeed;
175
  uint8_t compassP;
177
  uint8_t compassP;
176
 
178
 
177
  uint8_t batteryVoltageWarning;
179
  uint8_t batteryVoltageWarning;
178
  uint8_t emergencyThrottle;
180
  uint8_t emergencyThrottle;
179
  uint8_t emergencyFlightDuration;
181
  uint8_t emergencyFlightDuration;
180
 
182
 
181
  // Height Control
183
  // Height Control
182
  uint8_t airpressureFilterConstant;
184
  uint8_t airpressureFilterConstant;
183
  uint8_t airpressureWindowLength; // 0 means: Use filter.
185
  uint8_t airpressureWindowLength; // 0 means: Use filter.
184
  uint8_t airpressureDWindowLength; // values 1..5 are legal.
186
  uint8_t airpressureDWindowLength; // values 1..5 are legal.
185
  uint8_t airpressureAccZCorrection;
187
  uint8_t airpressureAccZCorrection;
186
 
188
 
187
  uint8_t heightP;
189
  uint8_t heightP;
188
  uint8_t heightI;
190
  uint8_t heightI;
189
  uint8_t heightD;
191
  uint8_t heightD;
190
 
192
 
191
  uint8_t heightSetting;
193
  uint8_t heightSetting;
192
  uint8_t heightControlMaxIntegralIn;
194
  uint8_t heightControlMaxIntegralIn;
193
  uint8_t heightControlMaxIntegralOut;
195
  uint8_t heightControlMaxIntegralOut;
194
  uint8_t heightControlMaxThrottleChange;
196
  uint8_t heightControlMaxThrottleChange;
195
 
197
 
196
  uint8_t heightControlTestOscPeriod;
198
  uint8_t heightControlTestOscPeriod;
197
  uint8_t heightControlTestOscAmplitude;
199
  uint8_t heightControlTestOscAmplitude;
198
 
200
 
199
  // Servos
201
  // Servos
200
  uint8_t servoCount;
202
  uint8_t servoCount;
201
  uint8_t servoManualMaxSpeed;
203
  uint8_t servoManualMaxSpeed;
202
  Servo_t servoConfigurations[2]; // [PITCH, ROLL]
204
  Servo_t servoConfigurations[2]; // [PITCH, ROLL]
203
 
205
 
204
  // Outputs
206
  // Outputs
205
  output_flash_t outputFlash[2];
207
  output_flash_t outputFlash[2];
206
  uint8_t outputDebugMask;
208
  uint8_t outputDebugMask;
207
  uint8_t outputFlags;
209
  uint8_t outputFlags;
208
 
210
 
209
 // Shared for both modes of navigation
211
 // Shared for both modes of navigation
210
  uint8_t naviMode;
212
  uint8_t naviMode;
211
  uint8_t naviStickThreshold;
213
  uint8_t naviStickThreshold;
212
  uint8_t naviStickLimit;
214
  uint8_t naviStickLimit;
213
  uint8_t GPSMininumSatellites;
215
  uint8_t GPSMininumSatellites;
214
  uint8_t naviP;
216
  uint8_t naviP;
215
  uint8_t naviI;
217
  uint8_t naviI;
216
  uint8_t naviD;
218
  uint8_t naviD;
217
 
219
 
218
  uint8_t naviTestOscPeriod;
220
  uint8_t naviTestOscPeriod;
219
  uint8_t naviTestOscAmplitude;
221
  uint8_t naviTestOscAmplitude;
220
 
222
 
221
  // User params
223
  // User params
222
  uint8_t userParams[8];
224
  uint8_t userParams[8];
223
 
225
 
224
  // Name
226
  // Name
225
  char name[12];
227
  char name[12];
226
} ParamSet_t;
228
} ParamSet_t;
227
 
229
 
228
extern ParamSet_t staticParams;
230
extern ParamSet_t staticParams;
229
 
231
 
230
// MKFlags
232
// MKFlags
231
#define MKFLAG_MOTOR_RUN        (1<<0)
233
#define MKFLAG_MOTOR_RUN        (1<<0)
232
//#define MKFLAG_FLY            (1<<1)
234
//#define MKFLAG_FLY            (1<<1)
233
#define MKFLAG_CALIBRATE        (1<<2)
235
#define MKFLAG_CALIBRATE        (1<<2)
234
#define MKFLAG_START            (1<<3)
236
#define MKFLAG_START            (1<<3)
235
#define MKFLAG_EMERGENCY_FLIGHT (1<<4)
237
#define MKFLAG_EMERGENCY_FLIGHT (1<<4)
236
#define MKFLAG_LOWBAT           (1<<5)
238
#define MKFLAG_LOWBAT           (1<<5)
237
#define MKFLAG_RESERVE2         (1<<6)
239
#define MKFLAG_RESERVE2         (1<<6)
238
#define MKFLAG_RESERVE3         (1<<7)
240
#define MKFLAG_RESERVE3         (1<<7)
239
 
241
 
240
// bit mask for staticParams.bitConfig
242
// bit mask for staticParams.bitConfig
241
#define CFG_SIMPLE_HEIGHT_CONTROL               (1<<0)
243
#define CFG_SIMPLE_HEIGHT_CONTROL               (1<<0)
242
#define CFG_SIMPLE_HC_HOLD_SWITCH       (1<<1)
244
#define CFG_SIMPLE_HC_HOLD_SWITCH       (1<<1)
243
#define CFG_HEADING_HOLD                        (1<<2)
245
#define CFG_HEADING_HOLD                        (1<<2)
244
#define CFG_COMPASS_ENABLED             (1<<3)
246
#define CFG_COMPASS_ENABLED             (1<<3)
245
#define CFG_UNUSED                              (1<<4)
247
#define CFG_UNUSED                              (1<<4)
246
#define CFG_NAVI_ENABLED                        (1<<5)
248
#define CFG_NAVI_ENABLED                        (1<<5)
247
#define CFG_AXIS_COUPLING_ENABLED       (1<<6)
249
#define CFG_AXIS_COUPLING_ENABLED       (1<<6)
248
#define CFG_GYRO_SATURATION_PREVENTION  (1<<7)
250
#define CFG_GYRO_SATURATION_PREVENTION  (1<<7)
249
 
251
 
250
#define IMU_REVERSE_GYRO_PR                             (1<<0)
252
#define IMU_REVERSE_GYRO_PR                             (1<<0)
251
#define IMU_REVERSE_GYRO_YAW                    (1<<1)
253
#define IMU_REVERSE_GYRO_YAW                    (1<<1)
252
#define IMU_REVERSE_ACC_XY                              (1<<2)
254
#define IMU_REVERSE_ACC_XY                              (1<<2)
253
#define IMU_REVERSE_ACC_Z                               (1<<3)
255
#define IMU_REVERSE_ACC_Z                               (1<<3)
254
 
256
 
255
#define ATMEGA644       0
257
#define ATMEGA644       0
256
#define ATMEGA644P      1
258
#define ATMEGA644P      1
257
#define SYSCLK F_CPU
259
#define SYSCLK F_CPU
258
 
260
 
259
// Not really a part of configuration, but LEDs and HW s test are the same.
261
// Not really a part of configuration, but LEDs and HW s test are the same.
260
#define RED_OFF   {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else  PORTB |= (1<<PORTB0);}
262
#define RED_OFF   {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);}
263
#define RED_ON    {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else  PORTB &=~(1<<PORTB0);}
262
#define RED_FLASH PORTB ^= (1<<PORTB0)
264
#define RED_FLASH PORTB ^= (1<<PORTB0)
263
#define GRN_OFF   {if(boardRelease  < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);}
265
#define GRN_OFF   {if(boardRelease  < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);}
264
#define GRN_ON    {if(boardRelease  < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);}
266
#define GRN_ON    {if(boardRelease  < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);}
265
#define GRN_FLASH PORTB ^= (1<<PORTB1)
267
#define GRN_FLASH PORTB ^= (1<<PORTB1)
266
 
268
 
267
// Mixer table
269
// Mixer table
268
#define MIX_PITCH               0
270
#define MIX_PITCH               0
269
#define MIX_ROLL                1
271
#define MIX_ROLL                1
270
#define MIX_THROTTLE        2
272
#define MIX_THROTTLE        2
271
#define MIX_YAW             3
273
#define MIX_YAW             3
272
#define MIX_OPPOSITE_MOTOR  4
274
#define MIX_OPPOSITE_MOTOR  4
273
 
275
 
274
#define VARIABLE_COUNT  8
276
#define VARIABLE_COUNT  8
275
 
277
 
276
extern volatile uint8_t MKFlags;
278
extern volatile uint8_t MKFlags;
277
extern uint8_t requiredMotors;
279
extern uint8_t requiredMotors;
278
extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s.
280
extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s.
279
extern uint8_t boardRelease;
281
extern uint8_t boardRelease;
280
extern uint8_t CPUType;
282
extern uint8_t CPUType;
281
 
283
 
282
extern volatile uint8_t MKFlags;
284
extern volatile uint8_t MKFlags;
283
extern uint16_t isFlying;
285
extern uint16_t isFlying;
284
 
286
 
285
void IMUConfig_default(void);
287
void IMUConfig_default(void);
286
void channelMap_default(void);
288
void channelMap_default(void);
287
void paramSet_default(uint8_t setnumber);
289
void paramSet_default(uint8_t setnumber);
288
void motorMixer_default(void);
290
void motorMixer_default(void);
289
 
291
 
290
void configuration_setNormalFlightParameters(void);
292
void configuration_setNormalFlightParameters(void);
291
void configuration_setFailsafeFlightParameters(void);
293
void configuration_setFailsafeFlightParameters(void);
292
void configuration_applyVariablesToParams(void);
294
void configuration_applyVariablesToParams(void);
293
 
295
 
294
void setCPUType(void);
296
void setCPUType(void);
295
void setBoardRelease(void);
297
void setBoardRelease(void);
296
 
298
 
297
// Called after a change in configuration parameters, as a hook for modules to take over changes.
299
// Called after a change in configuration parameters, as a hook for modules to take over changes.
298
void configuration_paramSetDidChange(void);
300
void configuration_paramSetDidChange(void);
299
#endif // _CONFIGURATION_H
301
#endif // _CONFIGURATION_H
300
 
302