Subversion Repositories FlightCtrl

Rev

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

Rev Author Line No. Line
1612 dongfang 1
#ifndef _CONFIGURATION_H
2
#define _CONFIGURATION_H
3
 
4
#include <inttypes.h>
5
#include <avr/io.h>
6
 
1960 - 7
 
8
#define MAX_CHANNELS 10
9
#define MAX_MOTORS 12
10
 
1612 dongfang 11
typedef struct {
1960 - 12
  // IMU
13
  /*PMM*/uint8_t gyroP;
14
  /* P */uint8_t gyroD;
15
  /* P */uint8_t gyroI;
1864 - 16
  /* P */uint8_t IFactor;
1960 - 17
  uint8_t yawIFactor;
18
  /* P */uint8_t compassYawEffect;
19
 
20
  // Control
21
  /* P */uint8_t externalControl;
22
 
23
  /* P */uint8_t axisCoupling1;
24
  /* P */uint8_t axisCoupling2;
25
  /* P */uint8_t axisCouplingYawCorrection;
26
  /* P */uint8_t dynamicStability;
27
  uint8_t maxControlActivityForAcc;
28
 
29
  // Height control
30
  /*PMM*/uint8_t heightP;
31
  /*PMM*/uint8_t heightD;
32
  /* P */uint8_t heightSetting;
33
  /* P */uint8_t heightACCEffect;
34
 
35
  uint8_t attitudeControl;
36
 
37
  // The rest...
38
  /* P */uint8_t userParams[8];
39
  /*PMM*/uint8_t output0Timing;
40
  /*PMM*/uint8_t output1Timing;
41
 
42
  uint8_t servoManualControl[2];
43
 
44
  uint8_t motorSmoothing;
1775 - 45
} dynamicParam_t;
1960 - 46
 
1775 - 47
extern dynamicParam_t dynamicParams;
1612 dongfang 48
 
1775 - 49
typedef struct {
1864 - 50
  uint8_t sourceIdx, targetIdx;
51
  uint8_t min, max;
1775 - 52
} MMXLATION;
1612 dongfang 53
 
1775 - 54
typedef struct {
1864 - 55
  uint8_t sourceIdx, targetIdx;
1775 - 56
} XLATION;
57
 
1960 - 58
typedef struct {
59
  uint8_t checksum;
60
  uint8_t revisionNumber;
61
  uint8_t channels[MAX_CHANNELS];
62
} channelMap_t;
63
extern channelMap_t channelMap;
64
 
65
typedef struct {
66
  uint8_t checksum;
67
  uint8_t revision;
68
  int8_t name[12];
69
  int8_t motor[MAX_MOTORS][4];
70
}__attribute__((packed)) mixerMatrix_t;
71
extern mixerMatrix_t mixerMatrix;
72
 
73
typedef struct {
74
  uint8_t manualControl;
75
  uint8_t compensationFactor;
76
  uint8_t minValue;
77
  uint8_t maxValue;
78
  uint8_t flags;
79
} servo_t;
80
 
81
typedef struct {
82
  uint8_t bitmask;
83
  uint8_t timing;
84
} output_flash_t;
85
 
1612 dongfang 86
// values above 250 representing poti1 to poti4
87
typedef struct {
1960 - 88
  // Global bitflags
89
  uint8_t bitConfig;  // see upper defines for bitcoding
90
  uint8_t bitConfig2; // see upper defines for bitcoding
91
 
92
  // Height Control
93
  uint8_t heightP; // Value : 0-32
94
  uint8_t heightD; // Value : 0-250
95
  uint8_t heightSetting; // Value : 0-32
96
  uint8_t heightMaxThrottleChange; // Value : 0-100
97
  uint8_t heightSlewRate; // Value : 0-50
98
  uint8_t heightACCEffect; // Value : 0-250
99
 
100
  // Attitude Control
101
  uint8_t attitudeControl;
102
 
103
  // Control
104
  uint8_t stickP; // Value : 1-6
105
  uint8_t stickD; // Value : 0-64
106
  uint8_t stickYawP; // Value : 1-20
107
  uint8_t stickThrottleD;
108
  uint8_t minThrottle; // Value : 0-32
109
  uint8_t maxThrottle; // Value : 33-250
110
  uint8_t externalControl; // for serial Control
111
  uint8_t maxControlActivityForAcc;
112
 
113
  // IMU
114
  uint8_t gyroPIDFilterConstant;
115
  uint8_t gyroATTFilterConstant;
116
  uint8_t gyroDFilterConstant;
117
  uint8_t accFilterConstant;
118
 
119
  uint8_t gyroP; // Value : 10-250
120
  uint8_t gyroI; // Value : 0-250
121
  uint8_t gyroD; // Value : 0-250
122
 
123
  uint8_t zerothOrderCorrection; // Value : 1-64
124
  uint8_t driftCompDivider; // 1/k  (Koppel_ACC_Wirkung)
125
  uint8_t driftCompLimit;   // limit for gyrodrift compensation
126
 
127
  uint8_t axisCoupling1; // Value: 0-250  Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung)
128
  uint8_t axisCoupling2; // Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
129
  uint8_t axisCouplingYawCorrection;// Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
130
 
131
  uint8_t dynamicStability; // PID limit for Attitude controller
1864 - 132
  uint8_t IFactor; // Value : 0-250
1960 - 133
  uint8_t yawIFactor;
134
  uint8_t compassYawEffect; // Value : 0-32
1612 dongfang 135
 
1960 - 136
  // Servos
137
  servo_t servoConfigurations[2]; // [PITCH, ROLL]
138
  uint8_t servoCount;
1612 dongfang 139
 
1960 - 140
  // Battery warning and emergency flight
141
  uint8_t batteryVoltageWarning; // Value : 0-250
142
  uint8_t emergencyThrottle; // Value : 0-250     //Gaswert bei Empüngsverlust  /*
143
  uint8_t emergencyFlightDuration; // Value : 0-250     // Zeitbis auf EmergencyGas geschaltet wird, wg. Rx-Problemen
1612 dongfang 144
 
1960 - 145
  // Outputs
146
  output_flash_t outputFlash[2];
147
  uint8_t outputDebugMask;
148
  // bit0: Test all OFF
149
  // bit1: Test all ON
150
  // bit2: flash when beeping
151
  uint8_t outputFlags;
1612 dongfang 152
 
1960 - 153
  // User params
154
  uint8_t userParams[8]; // Value : 0-250
1612 dongfang 155
 
1960 - 156
  // Name
157
  uint8_t name[12];
158
} paramset_t;
159
extern paramset_t staticParams;
160
 
1612 dongfang 161
// MKFlags
162
#define MKFLAG_MOTOR_RUN        (1<<0)
163
#define MKFLAG_FLY              (1<<1)
164
#define MKFLAG_CALIBRATE        (1<<2)
165
#define MKFLAG_START            (1<<3)
1960 - 166
#define MKFLAG_EMERGENCY_FLIGHT (1<<4)
1612 dongfang 167
#define MKFLAG_RESERVE1         (1<<5)
168
#define MKFLAG_RESERVE2         (1<<6)
169
#define MKFLAG_RESERVE3         (1<<7)
170
 
1960 - 171
// bit mask for staticParams.bitConfig
1612 dongfang 172
#define CFG_HEIGHT_CONTROL      (1<<0)
173
#define CFG_HEIGHT_SWITCH       (1<<1)
174
#define CFG_HEADING_HOLD        (1<<2)
175
#define CFG_COMPASS_ACTIVE      (1<<3)
176
#define CFG_COMPASS_FIX         (1<<4)
177
#define CFG_GPS_ACTIVE          (1<<5)
178
#define CFG_AXIS_COUPLING_ACTIVE (1<<6)
1960 - 179
#define CFG_GYRO_SATURATION_PREVENTION  (1<<7)
1612 dongfang 180
 
1960 - 181
// bit mask for staticParams.bitConfig2
1864 - 182
#define CFG_LOOP_UP                 (1<<0)
1612 dongfang 183
#define CFG_LOOP_DOWN           (1<<1)
184
#define CFG_LOOP_LEFT           (1<<2)
185
#define CFG_LOOP_RIGHT          (1<<3)
186
#define CFG_HEIGHT_3SWITCH      (1<<4)
187
 
188
#define ATMEGA644       0
189
#define ATMEGA644P      1
190
#define SYSCLK F_CPU
191
 
1887 - 192
// Not really a part of configuration, but LEDs and HW version test are the same.
1960 - 193
#define RED_OFF   {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else  PORTB |= (1<<PORTB0);}
194
#define RED_ON    {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else  PORTB &=~(1<<PORTB0);}
1612 dongfang 195
#define RED_FLASH PORTB ^= (1<<PORTB0)
1960 - 196
#define GRN_OFF   {if(boardRelease  < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);}
197
#define GRN_ON    {if(boardRelease  < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);}
1612 dongfang 198
#define GRN_FLASH PORTB ^= (1<<PORTB1)
199
 
200
// Mixer table
201
#define MIX_THROTTLE    0
202
#define MIX_PITCH       1
203
#define MIX_ROLL        2
204
#define MIX_YAW         3
205
 
206
extern volatile uint8_t MKFlags;
1960 - 207
extern uint8_t requiredMotors;
1864 - 208
extern int16_t variables[8]; // The "Poti"s.
1960 - 209
extern uint8_t boardRelease;
1612 dongfang 210
extern uint8_t CPUType;
211
 
1960 - 212
void channelMap_default(void);
213
void paramSet_default(uint8_t setnumber);
214
void mixerMatrix_default(void);
215
 
1612 dongfang 216
void configuration_applyVariablesToParams(void);
217
uint8_t getCPUType(void);
218
uint8_t getBoardRelease(void);
219
 
220
#endif // _CONFIGURATION_H