Subversion Repositories FlightCtrl

Rev

Rev 2135 | Rev 2140 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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