Subversion Repositories FlightCtrl

Rev

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

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