Subversion Repositories FlightCtrl

Rev

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

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