Subversion Repositories FlightCtrl

Rev

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

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