Subversion Repositories FlightCtrl

Rev

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

Rev 2125 Rev 2129
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 8
7
#define MAX_CHANNELS 8
8
 
8
 
9
// bitmask for VersionInfo_t.HardwareError[0]
9
// bitmask for VersionInfo_t.HardwareError[0]
10
#define FC_ERROR0_GYRO_PITCH    0x01
10
#define FC_ERROR0_GYRO_PITCH    0x01
11
#define FC_ERROR0_GYRO_ROLL     0x02
11
#define FC_ERROR0_GYRO_ROLL     0x02
12
#define FC_ERROR0_GYRO_YAW      0x04
12
#define FC_ERROR0_GYRO_YAW      0x04
13
#define FC_ERROR0_ACC_X         0x08
13
#define FC_ERROR0_ACC_X         0x08
14
#define FC_ERROR0_ACC_Y         0x10
14
#define FC_ERROR0_ACC_Y         0x10
15
#define FC_ERROR0_ACC_Z         0x20
15
#define FC_ERROR0_ACC_Z         0x20
16
#define FC_ERROR0_PRESSURE      0x40
16
#define FC_ERROR0_PRESSURE      0x40
17
#define FC_ERROR1_RES0          0x80
17
#define FC_ERROR1_RES0          0x80
18
// bitmask for VersionInfo_t.HardwareError[1]
18
// bitmask for VersionInfo_t.HardwareError[1]
19
#define FC_ERROR1_I2C           0x01
19
#define FC_ERROR1_I2C           0x01
20
#define FC_ERROR1_BL_MISSING    0x02
20
#define FC_ERROR1_BL_MISSING    0x02
21
#define FC_ERROR1_SPI_RX        0x04
21
#define FC_ERROR1_SPI_RX        0x04
22
#define FC_ERROR1_PPM           0x08
22
#define FC_ERROR1_PPM           0x08
23
#define FC_ERROR1_MIXER         0x10
23
#define FC_ERROR1_MIXER         0x10
24
#define FC_ERROR1_RES1          0x20
24
#define FC_ERROR1_RES1          0x20
25
#define FC_ERROR1_RES2          0x40
25
#define FC_ERROR1_RES2          0x40
26
#define FC_ERROR1_RES3          0x80
26
#define FC_ERROR1_RES3          0x80
27
 
27
 
28
typedef struct {
28
typedef struct {
29
  uint8_t gyroQuadrant;
29
  uint8_t gyroQuadrant;
30
  uint8_t accQuadrant;
30
  uint8_t accQuadrant;
31
  uint8_t imuReversedFlags;
31
  uint8_t imuReversedFlags;
32
 
32
 
33
  uint8_t gyroPIDFilterConstant;
33
  uint8_t gyroPIDFilterConstant;
34
  uint8_t gyroDWindowLength;
34
  uint8_t gyroDWindowLength;
35
  uint8_t gyroDFilterConstant;
35
  uint8_t gyroDFilterConstant;
36
  uint8_t accFilterConstant;
36
  uint8_t accFilterConstant;
37
 
37
 
38
  uint8_t zerothOrderCorrection;
38
  uint8_t zerothOrderCorrection;
39
  uint8_t rateTolerance;
39
  uint8_t rateTolerance;
40
 
40
 
41
  uint8_t gyroActivityDamping;
41
  uint8_t gyroActivityDamping;
42
  uint8_t driftCompDivider; // 1/k  (Koppel_ACC_Wirkung)
42
  uint8_t driftCompDivider; // 1/k  (Koppel_ACC_Wirkung)
43
  uint8_t driftCompLimit;   // limit for gyrodrift compensation
43
  uint8_t driftCompLimit;   // limit for gyrodrift compensation
44
 
44
 
45
  int8_t gyroCalibrationTweak[3];
45
  int8_t gyroCalibrationTweak[3];
46
} IMUConfig_t;
46
} IMUConfig_t;
47
 
47
 
48
extern IMUConfig_t IMUConfig;
48
extern IMUConfig_t IMUConfig;
49
 
49
 
50
typedef struct {
50
typedef struct {
51
        uint8_t P;
51
        uint8_t P;
52
        uint8_t I;
52
        uint8_t I;
53
        uint8_t D;
53
        uint8_t D;
54
} PID_t;
54
} PID_t;
55
 
55
 
56
typedef struct {
56
typedef struct {
57
        uint8_t P;
57
        uint8_t P;
58
        uint8_t I;
58
        uint8_t I;
59
        uint8_t D;
59
        uint8_t D;
60
        uint8_t iMax;
60
        uint8_t iMax;
61
} PIDIM_t;
61
} PIDIM_t;
62
 
62
 
63
typedef enum {
63
typedef enum {
64
  FLIGHT_MODE_NONE,
64
  FLIGHT_MODE_NONE,
65
  FLIGHT_MODE_MANUAL,
65
  FLIGHT_MODE_MANUAL,
66
  FLIGHT_MODE_RATE,
66
  FLIGHT_MODE_RATE,
67
  FLIGHT_MODE_ANGLES
67
  FLIGHT_MODE_ANGLES
68
} FlightMode_t;
68
} FlightMode_t;
69
 
69
 
70
#define CONTROL_SERVO_REVERSE_ELEVATOR 1
70
#define CONTROL_SERVO_REVERSE_ELEVATOR 1
71
#define CONTROL_SERVO_REVERSE_AILERONS 2
71
#define CONTROL_SERVO_REVERSE_AILERONS 2
72
#define CONTROL_SERVO_REVERSE_RUDDER 4
72
#define CONTROL_SERVO_REVERSE_RUDDER 4
73
 
73
 
74
typedef struct {
74
typedef struct {
75
    uint8_t SWMajor;
75
    uint8_t SWMajor;
76
    uint8_t SWMinor;
76
    uint8_t SWMinor;
77
    uint8_t protoMajor;
77
    uint8_t protoMajor;
78
    uint8_t protoMinor;
78
    uint8_t protoMinor;
79
    uint8_t SWPatch;
79
    uint8_t SWPatch;
80
    uint8_t hardwareErrors[5];
80
    uint8_t hardwareErrors[5];
81
}__attribute__((packed)) VersionInfo_t;
81
}__attribute__((packed)) VersionInfo_t;
82
 
82
 
83
extern VersionInfo_t versionInfo;
83
extern VersionInfo_t versionInfo;
84
 
84
 
85
typedef struct {
85
typedef struct {
86
  // IMU stuff:
86
  // IMU stuff:
87
  PID_t gyroPID[3];
87
  PID_t gyroPID[3];
88
 
88
 
89
  // Control
89
  // Control
90
  /* P */uint8_t externalControl;
90
  /* P */uint8_t externalControl;
91
 
91
 
92
  // Output and servo
92
  // Output and servo
93
  /*PMM*/uint8_t output0Timing;
93
  /*PMM*/uint8_t output0Timing;
94
  /*PMM*/uint8_t output1Timing;
94
  /*PMM*/uint8_t output1Timing;
95
 
95
 
96
  uint8_t gimbalServoManualControl[2];
96
  uint8_t gimbalServoManualControl[2];
97
 
97
 
98
  /* P */uint8_t userParams[8];
98
  /* P */uint8_t userParams[8];
99
} DynamicParams_t;
99
} DynamicParams_t;
100
 
100
 
101
extern volatile DynamicParams_t dynamicParams;
101
extern volatile DynamicParams_t dynamicParams;
102
 
102
 
103
typedef struct {
103
typedef struct {
104
  uint8_t sourceIdx, targetIdx;
104
  uint8_t sourceIdx, targetIdx;
105
  uint8_t min, max;
105
  uint8_t min, max;
106
} MMXLATION;
106
} MMXLATION;
107
 
107
 
108
/*
108
/*
109
typedef struct {
109
typedef struct {
110
  uint8_t sourceIdx, targetIdx;
110
  uint8_t sourceIdx, targetIdx;
111
} XLATION;
111
} XLATION;
112
*/
112
*/
113
 
113
 
114
typedef struct {
114
typedef struct {
115
  uint8_t RCPolarity; // 1=positive, 0=negative. Use positive with Futaba receiver, negative with FrSky.
115
  uint8_t RCPolarity; // 1=positive, 0=negative. Use positive with Futaba receiver, negative with FrSky.
116
  uint8_t HWTrim;
116
  uint8_t HWTrim;
117
  uint8_t variableOffset;
117
  uint8_t variableOffset;
118
  uint8_t channels[MAX_CHANNELS];
118
  uint8_t channels[MAX_CHANNELS];
119
} ChannelMap_t;
119
} ChannelMap_t;
120
extern ChannelMap_t channelMap;
120
extern ChannelMap_t channelMap;
121
 
121
 
122
// With fixed wing, we need some way to trim the plane. This is done during a trim flight without gyros activated,
122
// With fixed wing, we need some way to trim the plane. This is done during a trim flight without gyros activated,
123
// and then save in a succeeding gyro calibration command.
123
// and then save in a succeeding gyro calibration command.
124
typedef struct {
124
typedef struct {
125
  int16_t trim[MAX_CHANNELS];
125
  int16_t trim[MAX_CHANNELS];
126
} RCTrim_t;
126
} RCTrim_t;
127
extern RCTrim_t rcTrim;
127
extern RCTrim_t rcTrim;
128
 
128
 
129
typedef struct {
129
typedef struct {
130
  int16_t offsets[3];
130
  int16_t offsets[3];
131
} sensorOffset_t;
131
} sensorOffset_t;
132
 
132
 
133
typedef struct {
133
typedef struct {
134
  uint8_t manualControl;
134
  uint8_t manualControl;
135
  uint8_t stabilizationFactor;
135
  uint8_t stabilizationFactor;
136
  uint8_t minValue;
136
  uint8_t minValue;
137
  uint8_t maxValue;
137
  uint8_t maxValue;
138
  uint8_t flags;
138
  uint8_t flags;
139
} Servo_t;
139
} Servo_t;
140
 
140
 
141
#define SERVO_STABILIZATION_REVERSE 1
141
#define SERVO_STABILIZATION_REVERSE 1
142
 
142
 
143
typedef struct {
143
typedef struct {
144
  uint8_t bitmask;
144
  uint8_t bitmask;
145
  uint8_t timing;
145
  uint8_t timing;
146
} output_flash_t;
146
} output_flash_t;
147
 
147
 
148
// values above 250 representing poti1 to poti4
148
// values above 250 representing poti1 to poti4
149
typedef struct {
149
typedef struct {
150
  // Global bitflags
150
  // Global bitflags
151
  uint8_t bitConfig;  // see upper defines for bitcoding
151
  uint8_t bitConfig;  // see upper defines for bitcoding
152
 
152
 
153
  // Control
153
  // Control
154
  PIDIM_t gyroPID[3];
154
  PIDIM_t gyroPID[3];
155
 
155
 
156
  uint8_t stickIElevator;
156
  uint8_t stickIElevator;
157
  uint8_t stickIAilerons;
157
  uint8_t stickIAilerons;
158
  uint8_t stickIRudder;
158
  uint8_t stickIRudder;
159
 
-
 
160
  uint8_t IFactor;
-
 
161
 
159
 
-
 
160
  uint8_t externalControl; // for serial Control
-
 
161
 
-
 
162
  uint8_t IFactor;
162
  uint8_t externalControl; // for serial Control
163
 
163
  uint8_t batteryWarningVoltage;
164
  uint8_t batteryWarningVoltage;
164
 
165
 
165
  // Airspeed
166
  // Airspeed
166
  uint8_t airspeedCorrection;
167
  uint8_t airspeedCorrection;
167
  uint8_t isFlyingThreshold;
168
  uint8_t isFlyingThreshold;
168
 
169
 
169
  // Servos
170
  // Servos
170
 
171
 
171
  uint8_t servoCount;
172
  uint8_t servoCount;
172
  uint8_t servosReverse;
173
  uint8_t servosReverse;
173
 
174
 
174
  uint8_t controlServoMinValue;
175
  uint8_t controlServoMinValue;
175
  uint8_t controlServoMaxValue;
176
  uint8_t controlServoMaxValue;
176
 
177
 
177
  uint8_t gimbalServoMaxManualSpeed;
178
  uint8_t gimbalServoMaxManualSpeed;
178
  Servo_t gimbalServoConfigurations[2]; // [PITCH, ROLL]
179
  Servo_t gimbalServoConfigurations[2]; // [PITCH, ROLL]
179
 
180
 
180
  // Outputs
181
  // Outputs
181
  output_flash_t outputFlash[2];
182
  output_flash_t outputFlash[2];
182
  uint8_t outputDebugMask;
183
  uint8_t outputDebugMask;
183
  uint8_t outputFlags;
184
  uint8_t outputFlags;
184
 
185
 
185
  // User params
186
  // User params
186
  uint8_t userParams[8];
187
  uint8_t userParams[8];
187
 
188
 
188
  // Name
189
  // Name
189
  char name[12];
190
  char name[12];
190
} ParamSet_t;
191
} ParamSet_t;
191
 
192
 
192
extern ParamSet_t staticParams;
193
extern ParamSet_t staticParams;
193
 
194
 
194
// bit mask for staticParams.bitConfig
195
// bit mask for staticParams.bitConfig
195
#define CFG_GYRO_SATURATION_PREVENTION  (1<<0)
196
#define CFG_GYRO_SATURATION_PREVENTION  (1<<0)
196
#define CFG_USE_AIRSPEED_PID            (1<<1)
197
#define CFG_USE_AIRSPEED_PID            (1<<1)
197
 
198
 
198
#define IMU_REVERSE_GYRO_PR             (1<<0)
199
#define IMU_REVERSE_GYRO_PR             (1<<0)
199
#define IMU_REVERSE_GYRO_YAW            (1<<1)
200
#define IMU_REVERSE_GYRO_YAW            (1<<1)
200
#define IMU_REVERSE_ACC_XY              (1<<2)
201
#define IMU_REVERSE_ACC_XY              (1<<2)
201
#define IMU_REVERSE_ACC_Z               (1<<3)
202
#define IMU_REVERSE_ACC_Z               (1<<3)
202
 
203
 
203
#define ATMEGA644   0
204
#define ATMEGA644   0
204
#define ATMEGA644P  1
205
#define ATMEGA644P  1
205
#define SYSCLK F_CPU
206
#define SYSCLK F_CPU
206
 
207
 
207
// Not really a part of configuration, but LEDs and HW s test are the same.
208
// Not really a part of configuration, but LEDs and HW s test are the same.
208
#define RED_OFF   {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else  PORTB |= (1<<PORTB0);}
209
#define RED_OFF   {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else  PORTB |= (1<<PORTB0);}
209
#define RED_ON    {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else  PORTB &=~(1<<PORTB0);}
210
#define RED_ON    {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else  PORTB &=~(1<<PORTB0);}
210
#define RED_FLASH PORTB ^= (1<<PORTB0)
211
#define RED_FLASH PORTB ^= (1<<PORTB0)
211
#define GRN_OFF   {if(boardRelease  < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);}
212
#define GRN_OFF   {if(boardRelease  < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);}
212
#define GRN_ON    {if(boardRelease  < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);}
213
#define GRN_ON    {if(boardRelease  < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);}
213
#define GRN_FLASH PORTB ^= (1<<PORTB1)
214
#define GRN_FLASH PORTB ^= (1<<PORTB1)
214
 
215
 
215
// Mixer table
216
// Mixer table
216
#define MIX_THROTTLE    0
217
#define MIX_THROTTLE    0
217
#define MIX_PITCH   1
218
#define MIX_PITCH   1
218
#define MIX_ROLL    2
219
#define MIX_ROLL    2
219
#define MIX_YAW     3
220
#define MIX_YAW     3
220
 
221
 
221
#define VARIABLE_COUNT 8
222
#define VARIABLE_COUNT 8
222
 
223
 
223
extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s.
224
extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s.
224
extern uint8_t boardRelease;
225
extern uint8_t boardRelease;
225
extern uint8_t CPUType;
226
extern uint8_t CPUType;
226
 
227
 
227
extern volatile uint16_t isFlying;
228
extern volatile uint16_t isFlying;
228
extern FlightMode_t currentFlightMode;
229
extern FlightMode_t currentFlightMode;
229
 
230
 
230
void IMUConfig_default(void);
231
void IMUConfig_default(void);
231
void channelMap_default(void);
232
void channelMap_default(void);
232
void rcTrim_setZero(void);
233
void rcTrim_setZero(void);
233
void paramSet_default(uint8_t setnumber);
234
void paramSet_default(uint8_t setnumber);
234
 
235
 
235
void configuration_setFlightParameters(uint8_t newFlightMode);
236
void configuration_setFlightParameters(uint8_t newFlightMode);
236
void configuration_applyVariablesToParams(void);
237
void configuration_applyVariablesToParams(void);
237
 
238
 
238
void setCPUType(void);
239
void setCPUType(void);
239
void setBoardRelease(void);
240
void setBoardRelease(void);
240
 
241
 
241
// Called after a change in configuration parameters, as a hook for modules to take over changes.
242
// Called after a change in configuration parameters, as a hook for modules to take over changes.
242
void configuration_paramSetDidChange(void);
243
void configuration_paramSetDidChange(void);
243
#endif // _CONFIGURATION_H
244
#endif // _CONFIGURATION_H
244
 
245