Subversion Repositories FlightCtrl

Rev

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

Rev 2099 Rev 2102
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
 
-
 
29
typedef enum {
-
 
30
  FLIGHT_MODE_NONE,
-
 
31
  FLIGHT_MODE_MANUAL,
-
 
32
  FLIGHT_MODE_RATE,
-
 
33
  FLIGHT_MODE_ANGLES
-
 
34
} FlightMode_t;
-
 
35
 
-
 
36
#define CONTROL_SERVO_REVERSE_ELEVATOR 1
-
 
37
#define CONTROL_SERVO_REVERSE_AILERONS 2
-
 
38
#define CONTROL_SERVO_REVERSE_RUDDER 4
28
 
39
 
29
typedef struct {
40
typedef struct {
30
    uint8_t SWMajor;
41
    uint8_t SWMajor;
31
    uint8_t SWMinor;
42
    uint8_t SWMinor;
32
    uint8_t protoMajor;
43
    uint8_t protoMajor;
33
    uint8_t protoMinor;
44
    uint8_t protoMinor;
34
    uint8_t SWPatch;
45
    uint8_t SWPatch;
35
    uint8_t hardwareErrors[5];
46
    uint8_t hardwareErrors[5];
36
}__attribute__((packed)) VersionInfo_t;
47
}__attribute__((packed)) VersionInfo_t;
37
 
48
 
38
extern VersionInfo_t versionInfo;
49
extern VersionInfo_t versionInfo;
39
 
50
 
40
typedef struct {
51
typedef struct {
41
  /*PMM*/uint8_t gyroPitchD;
52
  /*PMM*/uint8_t gyroPitchD;
42
  /* P */uint8_t gyroRollD;
53
  /* P */uint8_t gyroRollD;\
43
  /* P */uint8_t gyroYawD;
54
  /* P */uint8_t gyroYawD;
44
 
55
 
45
  // Control
56
  // Control
46
  /* P */uint8_t externalControl;
57
  /* P */uint8_t externalControl;
47
 
-
 
48
  // Height control
-
 
49
  /*PMM*/uint8_t heightP;
-
 
50
  /* P */uint8_t heightI;
-
 
51
  /*PMM*/uint8_t heightD;
-
 
52
  /* P */uint8_t heightSetting;
-
 
53
 
58
 
54
  // Output and servo
59
  // Output and servo
55
  /*PMM*/uint8_t output0Timing;
60
  /*PMM*/uint8_t output0Timing;
56
  /*PMM*/uint8_t output1Timing;
61
  /*PMM*/uint8_t output1Timing;
57
 
62
 
58
  uint8_t servoManualControl[2];
63
  uint8_t servoManualControl[2];
59
 
64
 
60
  /* P */uint8_t userParams[8];
65
  /* P */uint8_t userParams[8];
61
} DynamicParams_t;
66
} DynamicParams_t;
62
 
67
 
63
extern volatile DynamicParams_t dynamicParams;
68
extern volatile DynamicParams_t dynamicParams;
64
 
69
 
65
typedef struct {
70
typedef struct {
66
  uint8_t sourceIdx, targetIdx;
71
  uint8_t sourceIdx, targetIdx;
67
  uint8_t min, max;
72
  uint8_t min, max;
68
} MMXLATION;
73
} MMXLATION;
69
 
74
 
70
/*
75
/*
71
typedef struct {
76
typedef struct {
72
  uint8_t sourceIdx, targetIdx;
77
  uint8_t sourceIdx, targetIdx;
73
} XLATION;
78
} XLATION;
74
*/
79
*/
75
 
80
 
76
typedef struct {
81
typedef struct {
77
  uint8_t channels[MAX_CHANNELS];
82
  uint8_t channels[MAX_CHANNELS];
78
} channelMap_t;
83
} channelMap_t;
79
extern channelMap_t channelMap;
84
extern channelMap_t channelMap;
80
 
85
 
81
typedef struct {
86
typedef struct {
82
  char name[12];
87
  char name[12];
83
  int8_t motor[MAX_MOTORS][4];
88
  int8_t motor[MAX_MOTORS][4];
84
}__attribute__((packed)) mixerMatrix_t;
89
}__attribute__((packed)) mixerMatrix_t;
85
extern mixerMatrix_t mixerMatrix;
90
extern mixerMatrix_t mixerMatrix;
86
 
91
 
87
typedef struct {
92
typedef struct {
88
  int16_t offsets[3];
93
  int16_t offsets[3];
89
} sensorOffset_t;
94
} sensorOffset_t;
90
 
95
 
91
typedef struct {
96
typedef struct {
92
  uint8_t manualControl;
97
  uint8_t manualControl;
93
  uint8_t stabilizationFactor;
98
  uint8_t stabilizationFactor;
94
  uint8_t minValue;
99
  uint8_t minValue;
95
  uint8_t maxValue;
100
  uint8_t maxValue;
96
  uint8_t flags;
101
  uint8_t flags;
97
} servo_t;
102
} servo_t;
98
 
103
 
99
#define SERVO_STABILIZATION_REVERSE 1
104
#define SERVO_STABILIZATION_REVERSE 1
100
 
105
 
101
typedef struct {
106
typedef struct {
102
  uint8_t bitmask;
107
  uint8_t bitmask;
103
  uint8_t timing;
108
  uint8_t timing;
104
} output_flash_t;
109
} output_flash_t;
105
 
110
 
106
typedef struct {
111
typedef struct {
107
  uint8_t gyroQuadrant;
112
  uint8_t gyroQuadrant;
108
  uint8_t accQuadrant;
113
  uint8_t accQuadrant;
109
  uint8_t imuReversedFlags;
114
  uint8_t imuReversedFlags;
110
 
115
 
111
  uint8_t gyroPIDFilterConstant;
116
  uint8_t gyroPIDFilterConstant;
112
  uint8_t gyroDWindowLength;
117
  uint8_t gyroDWindowLength;
113
  uint8_t gyroDFilterConstant;
118
  uint8_t gyroDFilterConstant;
114
  uint8_t accFilterConstant;
119
  uint8_t accFilterConstant;
115
 
120
 
116
  uint8_t zerothOrderCorrection;
121
  uint8_t zerothOrderCorrection;
117
  uint8_t rateTolerance;
122
  uint8_t rateTolerance;
118
 
123
 
119
  uint8_t gyroActivityDamping;
124
  uint8_t gyroActivityDamping;
120
  uint8_t driftCompDivider; // 1/k  (Koppel_ACC_Wirkung)
125
  uint8_t driftCompDivider; // 1/k  (Koppel_ACC_Wirkung)
121
  uint8_t driftCompLimit;   // limit for gyrodrift compensation
126
  uint8_t driftCompLimit;   // limit for gyrodrift compensation
122
} IMUConfig_t;
127
} IMUConfig_t;
123
 
128
 
124
extern IMUConfig_t IMUConfig;
129
extern IMUConfig_t IMUConfig;
-
 
130
 
-
 
131
typedef struct {
-
 
132
        uint8_t P;
-
 
133
        uint8_t I;
-
 
134
        uint8_t D;
-
 
135
} PID_t;
125
 
136
 
126
// values above 250 representing poti1 to poti4
137
// values above 250 representing poti1 to poti4
127
typedef struct {
138
typedef struct {
128
  // Global bitflags
139
  // Global bitflags
129
  uint8_t bitConfig;  // see upper defines for bitcoding
140
  uint8_t bitConfig;  // see upper defines for bitcoding
130
 
141
 
131
  // uint8_t axisCoupling1; // Value: 0-250  Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung)
142
  // uint8_t axisCoupling1; // Value: 0-250  Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung)
132
  // uint8_t axisCoupling2; // Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
143
  // uint8_t axisCoupling2; // Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
133
  // uint8_t axisCouplingYawCorrection;// Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
144
  // uint8_t axisCouplingYawCorrection;// Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
134
 
145
 
135
  uint8_t levelCorrection[2];
146
  uint8_t levelCorrection[2];
136
 
147
 
137
  // Control
148
  // Control
138
  uint8_t gyroPitchP;
-
 
139
  uint8_t gyroPitchI;
-
 
140
  uint8_t gyroPitchD;
149
  PID_t gyroPID[3];
141
 
-
 
142
  uint8_t gyroRollP;
-
 
143
  uint8_t gyroRollI;
-
 
144
  uint8_t gyroRollD;
-
 
145
 
-
 
146
  uint8_t gyroYawP;
-
 
147
  uint8_t gyroYawI;
-
 
148
  uint8_t gyroYawD;
-
 
149
 
150
 
150
  uint8_t stickIElevator;
151
  uint8_t stickIElevator;
151
  uint8_t stickIAilerons;
152
  uint8_t stickIAilerons;
152
  uint8_t stickIRudder;
153
  uint8_t stickIRudder;
153
 
154
 
154
  uint8_t externalControl; // for serial Control
155
  uint8_t externalControl; // for serial Control
155
 
156
 
156
  uint8_t IFactor;
157
  uint8_t IFactor;
157
 
158
 
158
  uint8_t batteryVoltageWarning;
159
  uint8_t batteryVoltageWarning;
159
  uint8_t emergencyThrottle;
160
  uint8_t emergencyThrottle;
160
  uint8_t emergencyFlightDuration;
161
  uint8_t emergencyFlightDuration;
161
 
162
 
162
  // Servos
163
  // Servos
-
 
164
  uint8_t controlServosReverse;
-
 
165
 
163
  uint8_t servoCount;
166
  uint8_t servoCount;
164
  uint8_t servoManualMaxSpeed;
167
  uint8_t servoManualMaxSpeed;
165
  servo_t servoConfigurations[2]; // [PITCH, ROLL]
168
  servo_t servoConfigurations[2]; // [PITCH, ROLL]
166
 
169
 
167
  // Outputs
170
  // Outputs
168
  output_flash_t outputFlash[2];
171
  output_flash_t outputFlash[2];
169
  uint8_t outputDebugMask;
172
  uint8_t outputDebugMask;
170
  uint8_t outputFlags;
173
  uint8_t outputFlags;
171
 
174
 
172
  // User params
175
  // User params
173
  uint8_t userParams[8];
176
  uint8_t userParams[8];
174
 
177
 
175
  // Name
178
  // Name
176
  char name[12];
179
  char name[12];
177
} ParamSet_t;
180
} ParamSet_t;
178
 
181
 
179
extern ParamSet_t staticParams;
182
extern ParamSet_t staticParams;
180
 
-
 
181
// MKFlags
-
 
182
#define MKFLAG_MOTOR_RUN    (1<<0)
-
 
183
//#define MKFLAG_FLY            (1<<1)
-
 
184
#define MKFLAG_CALIBRATE    (1<<2)
-
 
185
#define MKFLAG_START        (1<<3)
-
 
186
#define MKFLAG_EMERGENCY_FLIGHT (1<<4)
-
 
187
#define MKFLAG_LOWBAT       (1<<5)
-
 
188
#define MKFLAG_RESERVE2     (1<<6)
-
 
189
#define MKFLAG_RESERVE3     (1<<7)
-
 
190
 
183
 
191
// bit mask for staticParams.bitConfig
184
// bit mask for staticParams.bitConfig
192
#define CFG_SIMPLE_HEIGHT_CONTROL       (1<<0)
185
#define CFG_SIMPLE_HEIGHT_CONTROL       (1<<0)
193
#define CFG_SIMPLE_HC_HOLD_SWITCH       (1<<1)
186
#define CFG_SIMPLE_HC_HOLD_SWITCH       (1<<1)
194
#define CFG_HEADING_HOLD                (1<<2)
187
#define CFG_HEADING_HOLD                (1<<2)
195
#define CFG_COMPASS_ENABLED             (1<<3)
188
#define CFG_COMPASS_ENABLED             (1<<3)
196
#define CFG_UNUSED                      (1<<4)
189
#define CFG_UNUSED                      (1<<4)
197
#define CFG_NAVI_ENABLED                (1<<5)
190
#define CFG_NAVI_ENABLED                (1<<5)
198
#define CFG_AXIS_COUPLING_ENABLED       (1<<6)
191
#define CFG_AXIS_COUPLING_ENABLED       (1<<6)
199
#define CFG_GYRO_SATURATION_PREVENTION  (1<<7)
192
#define CFG_GYRO_SATURATION_PREVENTION  (1<<7)
200
 
193
 
201
#define IMU_REVERSE_GYRO_PR             (1<<0)
194
#define IMU_REVERSE_GYRO_PR             (1<<0)
202
#define IMU_REVERSE_GYRO_YAW            (1<<1)
195
#define IMU_REVERSE_GYRO_YAW            (1<<1)
203
#define IMU_REVERSE_ACC_XY              (1<<2)
196
#define IMU_REVERSE_ACC_XY              (1<<2)
204
#define IMU_REVERSE_ACC_Z               (1<<3)
197
#define IMU_REVERSE_ACC_Z               (1<<3)
205
 
198
 
206
#define ATMEGA644   0
199
#define ATMEGA644   0
207
#define ATMEGA644P  1
200
#define ATMEGA644P  1
208
#define SYSCLK F_CPU
201
#define SYSCLK F_CPU
209
 
202
 
210
// Not really a part of configuration, but LEDs and HW s test are the same.
203
// Not really a part of configuration, but LEDs and HW s test are the same.
211
#define RED_OFF   {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else  PORTB |= (1<<PORTB0);}
204
#define RED_OFF   {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else  PORTB |= (1<<PORTB0);}
212
#define RED_ON    {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else  PORTB &=~(1<<PORTB0);}
205
#define RED_ON    {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else  PORTB &=~(1<<PORTB0);}
213
#define RED_FLASH PORTB ^= (1<<PORTB0)
206
#define RED_FLASH PORTB ^= (1<<PORTB0)
214
#define GRN_OFF   {if(boardRelease  < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);}
207
#define GRN_OFF   {if(boardRelease  < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);}
215
#define GRN_ON    {if(boardRelease  < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);}
208
#define GRN_ON    {if(boardRelease  < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);}
216
#define GRN_FLASH PORTB ^= (1<<PORTB1)
209
#define GRN_FLASH PORTB ^= (1<<PORTB1)
217
 
210
 
218
// Mixer table
211
// Mixer table
219
#define MIX_THROTTLE    0
212
#define MIX_THROTTLE    0
220
#define MIX_PITCH   1
213
#define MIX_PITCH   1
221
#define MIX_ROLL    2
214
#define MIX_ROLL    2
222
#define MIX_YAW     3
215
#define MIX_YAW     3
223
 
216
 
224
#define VARIABLE_COUNT 8
217
#define VARIABLE_COUNT 8
225
 
-
 
226
extern volatile uint8_t MKFlags;
-
 
227
extern uint8_t requiredMotors;
218
 
228
extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s.
219
extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s.
229
extern uint8_t boardRelease;
220
extern uint8_t boardRelease;
230
extern uint8_t CPUType;
221
extern uint8_t CPUType;
231
 
222
 
232
extern volatile uint8_t MKFlags;
223
extern volatile uint8_t isMotorRunning;
233
extern uint16_t isFlying;
224
extern FlightMode_t currentFlightMode;
234
 
225
 
235
void IMUConfig_default(void);
226
void IMUConfig_default(void);
236
void channelMap_default(void);
227
void channelMap_default(void);
237
void paramSet_default(uint8_t setnumber);
228
void paramSet_default(uint8_t setnumber);
238
void mixerMatrix_default(void);
-
 
239
 
229
 
240
void configuration_setNormalFlightParameters(void);
-
 
241
void configuration_setFailsafeFlightParameters(void);
230
void configuration_setFlightParameters(uint8_t newFlightMode);
242
void configuration_applyVariablesToParams(void);
231
void configuration_applyVariablesToParams(void);
243
 
232
 
244
void setCPUType(void);
233
void setCPUType(void);
245
void setBoardRelease(void);
234
void setBoardRelease(void);
246
 
235
 
247
// Called after a change in configuration parameters, as a hook for modules to take over changes.
236
// Called after a change in configuration parameters, as a hook for modules to take over changes.
248
void configuration_paramSetDidChange(void);
237
void configuration_paramSetDidChange(void);
249
#endif // _CONFIGURATION_H
238
#endif // _CONFIGURATION_H
250
 
239