Subversion Repositories FlightCtrl

Rev

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

Rev 2020 Rev 2026
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
  // IMU
41
  // IMU
42
  /*PMM*/uint8_t gyroP;
42
  /*PMM*/uint8_t gyroP;
43
  /* P */uint8_t gyroD;
43
  /* P */uint8_t gyroD;
44
  /* P */uint8_t gyroI;
44
  /* P */uint8_t gyroI;
45
  /* P */uint8_t IFactor;
45
  /* P */uint8_t IFactor;
46
  uint8_t yawIFactor;
46
  uint8_t yawIFactor;
47
  /* P */uint8_t compassYawEffect;
47
  /* P */uint8_t compassYawEffect;
48
 
48
 
49
  // Control
49
  // Control
50
  /* P */uint8_t externalControl;
50
  /* P */uint8_t externalControl;
51
 
51
 
52
  /* P */uint8_t axisCoupling1;
52
  /* P */uint8_t axisCoupling1;
53
  /* P */uint8_t axisCoupling2;
53
  /* P */uint8_t axisCoupling2;
54
  /* P */uint8_t axisCouplingYawCorrection;
54
  /* P */uint8_t axisCouplingYawCorrection;
55
  /* P */uint8_t dynamicStability;
55
  /* P */uint8_t dynamicStability;
56
  uint8_t maxAccVector;
56
  uint8_t maxAccVector;
57
 
57
 
58
  // Height control
58
  // Height control
59
  /*PMM*/uint8_t heightP;
59
  /*PMM*/uint8_t heightP;
60
  /*PMM*/uint8_t heightD;
60
  /*PMM*/uint8_t heightD;
61
  /* P */uint8_t heightSetting;
61
  /* P */uint8_t heightSetting;
62
  /* P */uint8_t heightACCEffect;
62
  /* P */uint8_t heightACCEffect;
63
 
63
 
64
  uint8_t attitudeControl;
64
  uint8_t attitudeControl;
65
 
65
 
66
  // The rest...
66
  // The rest...
67
  /* P */uint8_t userParams[8];
67
  /* P */uint8_t userParams[8];
68
  /*PMM*/uint8_t output0Timing;
68
  /*PMM*/uint8_t output0Timing;
69
  /*PMM*/uint8_t output1Timing;
69
  /*PMM*/uint8_t output1Timing;
70
 
70
 
71
  uint8_t servoManualControl[2];
71
  uint8_t servoManualControl[2];
72
 
72
 
73
  uint8_t motorSmoothing;
73
  uint8_t motorSmoothing;
74
  uint8_t levelCorrection[2];
74
  uint8_t levelCorrection[2];
75
} dynamicParam_t;
75
} dynamicParam_t;
76
 
76
 
77
extern volatile dynamicParam_t dynamicParams;
77
extern volatile dynamicParam_t dynamicParams;
78
 
78
 
79
typedef struct {
79
typedef struct {
80
  uint8_t sourceIdx, targetIdx;
80
  uint8_t sourceIdx, targetIdx;
81
  uint8_t min, max;
81
  uint8_t min, max;
82
} MMXLATION;
82
} MMXLATION;
83
 
83
 
84
typedef struct {
84
typedef struct {
85
  uint8_t sourceIdx, targetIdx;
85
  uint8_t sourceIdx, targetIdx;
86
} XLATION;
86
} XLATION;
87
 
87
 
88
typedef struct {
88
typedef struct {
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 motor[MAX_MOTORS][4];
96
}__attribute__((packed)) mixerMatrix_t;
96
}__attribute__((packed)) mixerMatrix_t;
97
extern mixerMatrix_t mixerMatrix;
97
extern mixerMatrix_t mixerMatrix;
98
 
98
 
99
typedef struct {
99
typedef struct {
100
  int16_t offsets[3];
100
  int16_t offsets[3];
101
} sensorOffset_t;
101
} sensorOffset_t;
102
 
102
 
103
typedef struct {
103
typedef struct {
104
  uint8_t manualControl;
104
  uint8_t manualControl;
105
  uint8_t stabilizationFactor;
105
  uint8_t stabilizationFactor;
106
  uint8_t minValue;
106
  uint8_t minValue;
107
  uint8_t maxValue;
107
  uint8_t maxValue;
108
  uint8_t flags;
108
  uint8_t flags;
109
} servo_t;
109
} servo_t;
110
 
110
 
111
#define SERVO_STABILIZATION_REVERSE 1
111
#define SERVO_STABILIZATION_REVERSE 1
112
 
112
 
113
typedef struct {
113
typedef struct {
114
  uint8_t bitmask;
114
  uint8_t bitmask;
115
  uint8_t timing;
115
  uint8_t timing;
116
} output_flash_t;
116
} output_flash_t;
117
 
117
 
118
// values above 250 representing poti1 to poti4
118
// values above 250 representing poti1 to poti4
119
typedef struct {
119
typedef struct {
120
  // Global bitflags
120
  // Global bitflags
121
  uint8_t bitConfig;  // see upper defines for bitcoding
121
  uint8_t bitConfig;  // see upper defines for bitcoding
122
 
122
 
123
  // Height Control
123
  // Height Control
124
  uint8_t airpressureFilter;
124
  uint8_t airpressureFilter;
-
 
125
  uint8_t airpressureAccZCorrection;
125
  uint8_t heightP;
126
  uint8_t heightP;
126
  uint8_t heightD;
127
  uint8_t heightD;
127
  uint8_t heightSetting;
128
  uint8_t heightSetting;
128
  uint8_t heightControlMaxThrottleChange;
129
  uint8_t heightControlMaxThrottleChange;
129
  uint8_t heightSlewRate;
130
  uint8_t heightSlewRate;
130
 
131
 
131
  // Attitude Control
132
  // Attitude Control
132
  uint8_t attitudeControl;
133
  uint8_t attitudeControl;
133
 
134
 
134
  // Control
135
  // Control
135
  uint8_t stickP;
136
  uint8_t stickP;
136
  uint8_t stickD;
137
  uint8_t stickD;
137
  uint8_t stickYawP;
138
  uint8_t stickYawP;
138
  uint8_t stickThrottleD;
139
  uint8_t stickThrottleD;
139
  uint8_t minThrottle;
140
  uint8_t minThrottle;
140
  uint8_t maxThrottle;
141
  uint8_t maxThrottle;
141
  uint8_t externalControl; // for serial Control
142
  uint8_t externalControl; // for serial Control
142
  uint8_t maxAccVector;
143
  uint8_t maxAccVector;
143
  uint8_t maxControlActivity;
144
  uint8_t maxControlActivity;
144
  uint8_t motorSmoothing;
145
  uint8_t motorSmoothing;
145
 
146
 
146
  // IMU
147
  // IMU
147
  uint8_t gyroQuadrant;
148
  uint8_t gyroQuadrant;
148
  uint8_t accQuadrant;
149
  uint8_t accQuadrant;
149
  uint8_t imuReversedFlags;
150
  uint8_t imuReversedFlags;
150
 
151
 
151
  uint8_t gyroPIDFilterConstant;
152
  uint8_t gyroPIDFilterConstant;
152
  uint8_t gyroATTFilterConstant;
153
  uint8_t gyroATTFilterConstant;
153
  uint8_t gyroDFilterConstant;
154
  uint8_t gyroDFilterConstant;
154
  uint8_t accFilterConstant;
155
  uint8_t accFilterConstant;
155
 
156
 
156
  uint8_t gyroP;
157
  uint8_t gyroP;
157
  uint8_t gyroI;
158
  uint8_t gyroI;
158
  uint8_t gyroD;
159
  uint8_t gyroD;
159
 
160
 
160
  uint8_t zerothOrderCorrection;
161
  uint8_t zerothOrderCorrection;
161
  uint8_t driftCompDivider; // 1/k  (Koppel_ACC_Wirkung)
162
  uint8_t driftCompDivider; // 1/k  (Koppel_ACC_Wirkung)
162
  uint8_t driftCompLimit;   // limit for gyrodrift compensation
163
  uint8_t driftCompLimit;   // limit for gyrodrift compensation
163
 
164
 
164
  uint8_t axisCoupling1; // Value: 0-250  Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung)
165
  uint8_t axisCoupling1; // Value: 0-250  Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung)
165
  uint8_t axisCoupling2; // Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
166
  uint8_t axisCoupling2; // Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
166
  uint8_t axisCouplingYawCorrection;// Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
167
  uint8_t axisCouplingYawCorrection;// Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
167
 
168
 
168
  uint8_t dynamicStability; // PID limit for Attitude controller
169
  uint8_t dynamicStability; // PID limit for Attitude controller
169
  uint8_t IFactor;
170
  uint8_t IFactor;
170
  uint8_t yawIFactor;
171
  uint8_t yawIFactor;
171
  uint8_t compassYawEffect;
172
  uint8_t compassYawEffect;
172
  uint8_t levelCorrection[2];
173
  uint8_t levelCorrection[2];
173
 
174
 
174
  // Servos
175
  // Servos
175
  uint8_t servoCount;
176
  uint8_t servoCount;
176
  uint8_t servoManualMaxSpeed;
177
  uint8_t servoManualMaxSpeed;
177
  servo_t servoConfigurations[2]; // [PITCH, ROLL]
178
  servo_t servoConfigurations[2]; // [PITCH, ROLL]
178
 
179
 
179
  // Battery warning and emergency flight
180
  // Battery warning and emergency flight
180
  uint8_t batteryVoltageWarning;
181
  uint8_t batteryVoltageWarning;
181
  uint8_t emergencyThrottle;
182
  uint8_t emergencyThrottle;
182
  uint8_t emergencyFlightDuration;
183
  uint8_t emergencyFlightDuration;
183
 
184
 
184
  // Outputs
185
  // Outputs
185
  output_flash_t outputFlash[2];
186
  output_flash_t outputFlash[2];
186
  uint8_t outputDebugMask;
187
  uint8_t outputDebugMask;
187
  uint8_t outputFlags;
188
  uint8_t outputFlags;
188
 
189
 
189
  // User params
190
  // User params
190
  uint8_t userParams[8];
191
  uint8_t userParams[8];
191
 
192
 
192
  // Name
193
  // Name
193
  char name[12];
194
  char name[12];
194
} paramset_t;
195
} paramset_t;
195
extern paramset_t staticParams;
196
extern paramset_t staticParams;
196
 
197
 
197
// MKFlags
198
// MKFlags
198
#define MKFLAG_MOTOR_RUN        (1<<0)
199
#define MKFLAG_MOTOR_RUN        (1<<0)
199
#define MKFLAG_FLY              (1<<1)
200
#define MKFLAG_FLY              (1<<1)
200
#define MKFLAG_CALIBRATE        (1<<2)
201
#define MKFLAG_CALIBRATE        (1<<2)
201
#define MKFLAG_START            (1<<3)
202
#define MKFLAG_START            (1<<3)
202
#define MKFLAG_EMERGENCY_FLIGHT (1<<4)
203
#define MKFLAG_EMERGENCY_FLIGHT (1<<4)
203
#define MKFLAG_RESERVE1         (1<<5)
204
#define MKFLAG_RESERVE1         (1<<5)
204
#define MKFLAG_RESERVE2         (1<<6)
205
#define MKFLAG_RESERVE2         (1<<6)
205
#define MKFLAG_RESERVE3         (1<<7)
206
#define MKFLAG_RESERVE3         (1<<7)
206
 
207
 
207
// bit mask for staticParams.bitConfig
208
// bit mask for staticParams.bitConfig
208
#define CFG_SIMPLE_HEIGHT_CONTROL               (1<<0)
209
#define CFG_SIMPLE_HEIGHT_CONTROL               (1<<0)
209
#define CFG_SIMPLE_HC_HOLD_SWITCH       (1<<1)
210
#define CFG_SIMPLE_HC_HOLD_SWITCH       (1<<1)
210
#define CFG_HEADING_HOLD                        (1<<2)
211
#define CFG_HEADING_HOLD                        (1<<2)
211
#define CFG_COMPASS_ACTIVE                          (1<<3)
212
#define CFG_COMPASS_ACTIVE                          (1<<3)
212
#define CFG_COMPASS_FIX                                 (1<<4)
213
#define CFG_COMPASS_FIX                                 (1<<4)
213
#define CFG_GPS_ACTIVE                          (1<<5)
214
#define CFG_GPS_ACTIVE                          (1<<5)
214
#define CFG_AXIS_COUPLING_ACTIVE        (1<<6)
215
#define CFG_AXIS_COUPLING_ACTIVE        (1<<6)
215
#define CFG_GYRO_SATURATION_PREVENTION  (1<<7)
216
#define CFG_GYRO_SATURATION_PREVENTION  (1<<7)
216
 
217
 
217
#define IMU_REVERSE_GYRO_PR                             (1<<0)
218
#define IMU_REVERSE_GYRO_PR                             (1<<0)
218
#define IMU_REVERSE_GYRO_YAW                    (1<<1)
219
#define IMU_REVERSE_GYRO_YAW                    (1<<1)
219
#define IMU_REVERSE_ACC_XY                              (1<<2)
220
#define IMU_REVERSE_ACC_XY                              (1<<2)
220
#define IMU_REVERSE_ACC_Z                               (1<<3)
221
#define IMU_REVERSE_ACC_Z                               (1<<3)
221
 
222
 
222
#define ATMEGA644       0
223
#define ATMEGA644       0
223
#define ATMEGA644P      1
224
#define ATMEGA644P      1
224
#define SYSCLK F_CPU
225
#define SYSCLK F_CPU
225
 
226
 
226
// Not really a part of configuration, but LEDs and HW version test are the same.
227
// Not really a part of configuration, but LEDs and HW version test are the same.
227
#define RED_OFF   {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else  PORTB |= (1<<PORTB0);}
228
#define RED_OFF   {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else  PORTB |= (1<<PORTB0);}
228
#define RED_ON    {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else  PORTB &=~(1<<PORTB0);}
229
#define RED_ON    {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else  PORTB &=~(1<<PORTB0);}
229
#define RED_FLASH PORTB ^= (1<<PORTB0)
230
#define RED_FLASH PORTB ^= (1<<PORTB0)
230
#define GRN_OFF   {if(boardRelease  < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);}
231
#define GRN_OFF   {if(boardRelease  < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);}
231
#define GRN_ON    {if(boardRelease  < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);}
232
#define GRN_ON    {if(boardRelease  < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);}
232
#define GRN_FLASH PORTB ^= (1<<PORTB1)
233
#define GRN_FLASH PORTB ^= (1<<PORTB1)
233
 
234
 
234
// Mixer table
235
// Mixer table
235
#define MIX_THROTTLE    0
236
#define MIX_THROTTLE    0
236
#define MIX_PITCH       1
237
#define MIX_PITCH       1
237
#define MIX_ROLL        2
238
#define MIX_ROLL        2
238
#define MIX_YAW         3
239
#define MIX_YAW         3
239
 
240
 
240
#define VARIABLE_COUNT 8
241
#define VARIABLE_COUNT 8
241
 
242
 
242
extern volatile uint8_t MKFlags;
243
extern volatile uint8_t MKFlags;
243
extern uint8_t requiredMotors;
244
extern uint8_t requiredMotors;
244
extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s.
245
extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s.
245
extern uint8_t boardRelease;
246
extern uint8_t boardRelease;
246
extern uint8_t CPUType;
247
extern uint8_t CPUType;
247
 
248
 
248
extern volatile uint8_t MKFlags;
249
extern volatile uint8_t MKFlags;
249
extern uint16_t isFlying;
250
extern uint16_t isFlying;
250
 
251
 
251
void channelMap_default(void);
252
void channelMap_default(void);
252
void paramSet_default(uint8_t setnumber);
253
void paramSet_default(uint8_t setnumber);
253
void mixerMatrix_default(void);
254
void mixerMatrix_default(void);
254
 
255
 
255
void configuration_applyVariablesToParams(void);
256
void configuration_applyVariablesToParams(void);
256
uint8_t getCPUType(void);
257
uint8_t getCPUType(void);
257
uint8_t getBoardRelease(void);
258
uint8_t getBoardRelease(void);
258
 
259
 
259
#endif // _CONFIGURATION_H
260
#endif // _CONFIGURATION_H
260
 
261