Subversion Repositories FlightCtrl

Rev

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

Rev 2116 Rev 2119
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 gyroQuadrant;
30
  uint8_t gyroQuadrant;
31
  uint8_t accQuadrant;
31
  uint8_t accQuadrant;
32
  uint8_t imuReversedFlags;
32
  uint8_t imuReversedFlags;
33
 
33
 
34
  uint8_t gyroPIDFilterConstant;
34
  uint8_t gyroPIDFilterConstant;
35
  uint8_t gyroDWindowLength;
35
  uint8_t gyroDWindowLength;
36
  uint8_t gyroDFilterConstant;
36
  uint8_t gyroDFilterConstant;
37
  uint8_t accFilterConstant;
37
  uint8_t accFilterConstant;
38
 
38
 
39
  uint8_t zerothOrderCorrection;
39
  uint8_t zerothOrderCorrection;
40
  uint8_t rateTolerance;
40
  uint8_t rateTolerance;
41
 
41
 
42
  uint8_t gyroActivityDamping;
42
  uint8_t gyroActivityDamping;
43
  uint8_t driftCompDivider; // 1/k  (Koppel_ACC_Wirkung)
43
  uint8_t driftCompDivider; // 1/k  (Koppel_ACC_Wirkung)
44
  uint8_t driftCompLimit;   // limit for gyrodrift compensation
44
  uint8_t driftCompLimit;   // limit for gyrodrift compensation
45
} IMUConfig_t;
45
} IMUConfig_t;
46
 
46
 
47
extern IMUConfig_t IMUConfig;
47
extern IMUConfig_t IMUConfig;
48
 
48
 
49
typedef struct {
49
typedef struct {
50
        uint8_t P;
50
        uint8_t P;
51
        uint8_t I;
51
        uint8_t I;
52
        uint8_t D;
52
        uint8_t D;
53
} PID_t;
53
} PID_t;
54
 
54
 
55
typedef struct {
55
typedef struct {
56
        uint8_t P;
56
        uint8_t P;
57
        uint8_t I;
57
        uint8_t I;
58
        uint8_t D;
58
        uint8_t D;
59
        uint8_t iMax;
59
        uint8_t iMax;
60
} PIDIM_t;
60
} PIDIM_t;
61
 
61
 
62
typedef enum {
62
typedef enum {
63
  FLIGHT_MODE_NONE,
63
  FLIGHT_MODE_NONE,
64
  FLIGHT_MODE_MANUAL,
64
  FLIGHT_MODE_MANUAL,
65
  FLIGHT_MODE_RATE,
65
  FLIGHT_MODE_RATE,
66
  FLIGHT_MODE_ANGLES
66
  FLIGHT_MODE_ANGLES
67
} FlightMode_t;
67
} FlightMode_t;
68
 
68
 
69
#define CONTROL_SERVO_REVERSE_ELEVATOR 1
69
#define CONTROL_SERVO_REVERSE_ELEVATOR 1
70
#define CONTROL_SERVO_REVERSE_AILERONS 2
70
#define CONTROL_SERVO_REVERSE_AILERONS 2
71
#define CONTROL_SERVO_REVERSE_RUDDER 4
71
#define CONTROL_SERVO_REVERSE_RUDDER 4
72
 
72
 
73
typedef struct {
73
typedef struct {
74
    uint8_t SWMajor;
74
    uint8_t SWMajor;
75
    uint8_t SWMinor;
75
    uint8_t SWMinor;
76
    uint8_t protoMajor;
76
    uint8_t protoMajor;
77
    uint8_t protoMinor;
77
    uint8_t protoMinor;
78
    uint8_t SWPatch;
78
    uint8_t SWPatch;
79
    uint8_t hardwareErrors[5];
79
    uint8_t hardwareErrors[5];
80
}__attribute__((packed)) VersionInfo_t;
80
}__attribute__((packed)) VersionInfo_t;
81
 
81
 
82
extern VersionInfo_t versionInfo;
82
extern VersionInfo_t versionInfo;
83
 
83
 
84
typedef struct {
84
typedef struct {
85
  // IMU stuff:
85
  // IMU stuff:
86
  PID_t gyroPID[3];
86
  PID_t gyroPID[3];
87
 
87
 
88
  // Control
88
  // Control
89
  /* P */uint8_t externalControl;
89
  /* P */uint8_t externalControl;
90
 
90
 
91
  // Output and servo
91
  // Output and servo
92
  /*PMM*/uint8_t output0Timing;
92
  /*PMM*/uint8_t output0Timing;
93
  /*PMM*/uint8_t output1Timing;
93
  /*PMM*/uint8_t output1Timing;
94
 
94
 
95
  uint8_t servoManualControl[2];
95
  uint8_t servoManualControl[2];
96
 
96
 
97
  /* P */uint8_t userParams[8];
97
  /* P */uint8_t userParams[8];
98
} DynamicParams_t;
98
} DynamicParams_t;
99
 
99
 
100
extern volatile DynamicParams_t dynamicParams;
100
extern volatile DynamicParams_t dynamicParams;
101
 
101
 
102
typedef struct {
102
typedef struct {
103
  uint8_t sourceIdx, targetIdx;
103
  uint8_t sourceIdx, targetIdx;
104
  uint8_t min, max;
104
  uint8_t min, max;
105
} MMXLATION;
105
} MMXLATION;
106
 
106
 
107
/*
107
/*
108
typedef struct {
108
typedef struct {
109
  uint8_t sourceIdx, targetIdx;
109
  uint8_t sourceIdx, targetIdx;
110
} XLATION;
110
} XLATION;
111
*/
111
*/
112
 
112
 
113
typedef struct {
113
typedef struct {
114
        uint8_t trim;
114
        uint8_t trim;
115
        uint8_t variableOffset;
115
        uint8_t variableOffset;
116
  uint8_t channels[MAX_CHANNELS];
116
  uint8_t channels[MAX_CHANNELS];
117
} ChannelMap_t;
117
} ChannelMap_t;
118
extern ChannelMap_t channelMap;
118
extern ChannelMap_t channelMap;
119
 
119
 
120
typedef struct {
120
typedef struct {
121
  int16_t offsets[3];
121
  int16_t offsets[3];
122
} sensorOffset_t;
122
} sensorOffset_t;
123
 
123
 
124
typedef struct {
124
typedef struct {
125
  uint8_t manualControl;
125
  uint8_t manualControl;
126
  uint8_t stabilizationFactor;
126
  uint8_t stabilizationFactor;
127
  uint8_t minValue;
127
  uint8_t minValue;
128
  uint8_t maxValue;
128
  uint8_t maxValue;
129
  uint8_t flags;
129
  uint8_t flags;
130
} Servo_t;
130
} Servo_t;
131
 
131
 
132
#define SERVO_STABILIZATION_REVERSE 1
132
#define SERVO_STABILIZATION_REVERSE 1
133
 
133
 
134
typedef struct {
134
typedef struct {
135
  uint8_t bitmask;
135
  uint8_t bitmask;
136
  uint8_t timing;
136
  uint8_t timing;
137
} output_flash_t;
137
} output_flash_t;
138
 
138
 
139
// values above 250 representing poti1 to poti4
139
// values above 250 representing poti1 to poti4
140
typedef struct {
140
typedef struct {
141
  // Global bitflags
141
  // Global bitflags
142
  uint8_t bitConfig;  // see upper defines for bitcoding
142
  uint8_t bitConfig;  // see upper defines for bitcoding
143
 
143
 
144
  // Control
144
  // Control
145
  PIDIM_t gyroPID[3];
145
  PIDIM_t gyroPID[3];
146
 
146
 
147
  uint8_t stickIElevator;
147
  uint8_t stickIElevator;
148
  uint8_t stickIAilerons;
148
  uint8_t stickIAilerons;
149
  uint8_t stickIRudder;
149
  uint8_t stickIRudder;
150
 
150
 
151
  uint8_t externalControl; // for serial Control
151
  uint8_t externalControl; // for serial Control
152
 
152
 
153
  uint8_t IFactor;
153
  uint8_t IFactor;
154
 
154
 
155
  uint8_t batteryVoltageWarning;
155
  uint8_t batteryWarningVoltage;
156
  uint8_t emergencyThrottle;
156
  uint8_t emergencyThrottle;
157
  uint8_t emergencyFlightDuration;
157
  uint8_t emergencyFlightDuration;
158
 
158
 
159
  // Airspeed
159
  // Airspeed
160
  uint8_t airspeedCorrection;
160
  uint8_t airspeedCorrection;
161
  uint8_t isFlyingThreshold;
161
  uint8_t isFlyingThreshold;
162
 
162
 
163
  // Servos
163
  // Servos
164
  uint8_t controlServosReverse;
164
  uint8_t controlServosReverse;
165
 
165
 
166
  uint8_t servoCount;
166
  uint8_t servoCount;
167
  uint8_t controlServoMinValue;
167
  uint8_t controlServoMinValue;
168
  uint8_t controlServoMaxValue;
168
  uint8_t controlServoMaxValue;
169
 
169
 
170
  uint8_t servoManualMaxSpeed;
170
  uint8_t servoManualMaxSpeed;
171
  Servo_t servoConfigurations[2]; // [PITCH, ROLL]
171
  Servo_t servoConfigurations[2]; // [PITCH, ROLL]
172
 
172
 
173
  // Outputs
173
  // Outputs
174
  output_flash_t outputFlash[2];
174
  output_flash_t outputFlash[2];
175
  uint8_t outputDebugMask;
175
  uint8_t outputDebugMask;
176
  uint8_t outputFlags;
176
  uint8_t outputFlags;
177
 
177
 
178
  // User params
178
  // User params
179
  uint8_t userParams[8];
179
  uint8_t userParams[8];
180
 
180
 
181
  // Name
181
  // Name
182
  char name[12];
182
  char name[12];
183
} ParamSet_t;
183
} ParamSet_t;
184
 
184
 
185
extern ParamSet_t staticParams;
185
extern ParamSet_t staticParams;
186
 
186
 
187
// bit mask for staticParams.bitConfig
187
// bit mask for staticParams.bitConfig
188
#define CFG_GYRO_SATURATION_PREVENTION  (1<<0)
188
#define CFG_GYRO_SATURATION_PREVENTION  (1<<0)
189
#define CFG_USE_AIRSPEED_PID            (1<<1)
189
#define CFG_USE_AIRSPEED_PID            (1<<1)
190
 
190
 
191
#define IMU_REVERSE_GYRO_PR             (1<<0)
191
#define IMU_REVERSE_GYRO_PR             (1<<0)
192
#define IMU_REVERSE_GYRO_YAW            (1<<1)
192
#define IMU_REVERSE_GYRO_YAW            (1<<1)
193
#define IMU_REVERSE_ACC_XY              (1<<2)
193
#define IMU_REVERSE_ACC_XY              (1<<2)
194
#define IMU_REVERSE_ACC_Z               (1<<3)
194
#define IMU_REVERSE_ACC_Z               (1<<3)
195
 
195
 
196
#define ATMEGA644   0
196
#define ATMEGA644   0
197
#define ATMEGA644P  1
197
#define ATMEGA644P  1
198
#define SYSCLK F_CPU
198
#define SYSCLK F_CPU
199
 
199
 
200
// Not really a part of configuration, but LEDs and HW s test are the same.
200
// Not really a part of configuration, but LEDs and HW s test are the same.
201
#define RED_OFF   {PORTD &=~(1<<PORTD6);}
201
#define RED_OFF   {PORTD &=~(1<<PORTD6);}
202
#define RED_ON    {PORTD |= (1<<PORTD6);}
202
#define RED_ON    {PORTD |= (1<<PORTD6);}
203
#define RED_FLASH PORTD ^= (1<<PORTD6)
203
#define RED_FLASH PORTD ^= (1<<PORTD6)
204
#define GRN_OFF   {PORTD &=~(1<<PORTD7);}
204
#define GRN_OFF   {PORTD &=~(1<<PORTD7);}
205
#define GRN_ON    {PORTD |= (1<<PORTD7);}
205
#define GRN_ON    {PORTD |= (1<<PORTD7);}
206
#define GRN_FLASH PORTD ^= (1<<PORTD7)
206
#define GRN_FLASH PORTD ^= (1<<PORTD7)
207
 
207
 
208
// Mixer table
208
// Mixer table
209
#define MIX_THROTTLE    0
209
#define MIX_THROTTLE    0
210
#define MIX_PITCH   1
210
#define MIX_PITCH   1
211
#define MIX_ROLL    2
211
#define MIX_ROLL    2
212
#define MIX_YAW     3
212
#define MIX_YAW     3
213
 
213
 
214
#define VARIABLE_COUNT 8
214
#define VARIABLE_COUNT 8
215
 
215
 
216
extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s.
216
extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s.
217
extern uint8_t CPUType;
217
extern uint8_t CPUType;
218
 
218
 
219
extern volatile uint16_t isFlying;
219
extern volatile uint16_t isFlying;
220
extern FlightMode_t currentFlightMode;
220
extern FlightMode_t currentFlightMode;
221
 
221
 
222
void IMUConfig_default(void);
222
void IMUConfig_default(void);
223
void channelMap_default(void);
223
void channelMap_default(void);
224
void paramSet_default(uint8_t setnumber);
224
void paramSet_default(uint8_t setnumber);
225
 
225
 
226
void configuration_setFlightParameters(uint8_t newFlightMode);
226
void configuration_setFlightParameters(uint8_t newFlightMode);
227
void configuration_applyVariablesToParams(void);
227
void configuration_applyVariablesToParams(void);
228
 
228
 
229
void setCPUType(void);
229
void setCPUType(void);
230
 
230
 
231
// Called after a change in configuration parameters, as a hook for modules to take over changes.
231
// Called after a change in configuration parameters, as a hook for modules to take over changes.
232
void configuration_paramSetDidChange(void);
232
void configuration_paramSetDidChange(void);
233
#endif // _CONFIGURATION_H
233
#endif // _CONFIGURATION_H
234
 
234