Subversion Repositories FlightCtrl

Rev

Rev 2025 | Rev 2102 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2025 Rev 2099
Line 2... Line 2...
2
#define _CONFIGURATION_H
2
#define _CONFIGURATION_H
Line 3... Line 3...
3
 
3
 
4
#include <inttypes.h>
4
#include <inttypes.h>
Line -... Line 5...
-
 
5
#include <avr/io.h>
-
 
6
 
-
 
7
#define MAX_CHANNELS 10
-
 
8
#define MAX_MOTORS 12
-
 
9
 
-
 
10
// bitmask for VersionInfo_t.HardwareError[0]
-
 
11
#define FC_ERROR0_GYRO_PITCH    0x01
-
 
12
#define FC_ERROR0_GYRO_ROLL     0x02
-
 
13
#define FC_ERROR0_GYRO_YAW      0x04
-
 
14
#define FC_ERROR0_ACC_X         0x08
-
 
15
#define FC_ERROR0_ACC_Y         0x10
-
 
16
#define FC_ERROR0_ACC_Z         0x20
-
 
17
#define FC_ERROR0_PRESSURE      0x40
-
 
18
#define FC_ERROR1_RES0          0x80
-
 
19
// bitmask for VersionInfo_t.HardwareError[1]
-
 
20
#define FC_ERROR1_I2C           0x01
-
 
21
#define FC_ERROR1_BL_MISSING    0x02
-
 
22
#define FC_ERROR1_SPI_RX        0x04
-
 
23
#define FC_ERROR1_PPM           0x08
-
 
24
#define FC_ERROR1_MIXER         0x10
-
 
25
#define FC_ERROR1_RES1          0x20
-
 
26
#define FC_ERROR1_RES2          0x40
-
 
27
#define FC_ERROR1_RES3          0x80
-
 
28
 
-
 
29
typedef struct {
-
 
30
    uint8_t SWMajor;
-
 
31
    uint8_t SWMinor;
-
 
32
    uint8_t protoMajor;
-
 
33
    uint8_t protoMinor;
-
 
34
    uint8_t SWPatch;
-
 
35
    uint8_t hardwareErrors[5];
-
 
36
}__attribute__((packed)) VersionInfo_t;
-
 
37
 
5
#include <avr/io.h>
38
extern VersionInfo_t versionInfo;
6
 
39
 
7
typedef struct {
40
typedef struct {
8
  /*PMM*/uint8_t HeightD;
41
  /*PMM*/uint8_t gyroPitchD;
-
 
42
  /* P */uint8_t gyroRollD;
9
  /* P */uint8_t MaxHeight;
43
  /* P */uint8_t gyroYawD;
10
  /*PMM*/uint8_t HeightP;
44
 
11
  /* P */uint8_t Height_ACC_Effect;
45
  // Control
12
  /* P */uint8_t CompassYawEffect;
46
  /* P */uint8_t externalControl;
13
 
47
 
14
  /* P */uint8_t GyroPitchP;
48
  // Height control
15
  /* P */uint8_t GyroRollP;
-
 
16
  /* P */uint8_t GyroYawP;
49
  /*PMM*/uint8_t heightP;
17
 
50
  /* P */uint8_t heightI;
18
  /* P */uint8_t UserParams[8];
51
  /*PMM*/uint8_t heightD;
19
  /* P */uint8_t ServoPitchControl;
52
  /* P */uint8_t heightSetting;
20
 
53
 
21
  /* P */uint8_t GyroPitchD;  // LoopGasLimit in tool
54
  // Output and servo
22
  /* P */uint8_t GyroRollD;   // AxisCoupling1 in tool
55
  /*PMM*/uint8_t output0Timing;
23
  /* P */uint8_t GyroYawD;    // AxisCoupling2 in tool
56
  /*PMM*/uint8_t output1Timing;
24
 
-
 
-
 
57
 
25
  /* P */uint8_t ExternalControl;
58
  uint8_t servoManualControl[2];
26
  /*PMM*/uint8_t J16Timing;
59
 
-
 
60
  /* P */uint8_t userParams[8];
27
  /*PMM*/uint8_t J17Timing;
61
} DynamicParams_t;
Line 28... Line 62...
28
} dynamicParam_t;
62
 
29
extern dynamicParam_t dynamicParams;
63
extern volatile DynamicParams_t dynamicParams;
30
 
64
 
31
typedef struct {
65
typedef struct {
Line -... Line 66...
-
 
66
  uint8_t sourceIdx, targetIdx;
32
  uint8_t sourceIdx, targetIdx;
67
  uint8_t min, max;
33
  uint8_t min, max;
68
} MMXLATION;
34
} MMXLATION;
69
 
-
 
70
/*
-
 
71
typedef struct {
-
 
72
  uint8_t sourceIdx, targetIdx;
-
 
73
} XLATION;
-
 
74
*/
-
 
75
 
-
 
76
typedef struct {
-
 
77
  uint8_t channels[MAX_CHANNELS];
-
 
78
} channelMap_t;
-
 
79
extern channelMap_t channelMap;
-
 
80
 
-
 
81
typedef struct {
Line 35... Line -...
35
 
-
 
36
typedef struct {
82
  char name[12];
37
  uint8_t sourceIdx, targetIdx;
-
 
38
} XLATION;
-
 
39
 
-
 
40
// values above 250 representing poti1 to poti4
-
 
41
typedef struct {
-
 
42
  uint8_t ChannelAssignment[8]; // see upper defines for details
-
 
43
  uint8_t GlobalConfig; // see upper defines for bitcoding
-
 
44
  uint8_t HeightMinGas; // Value : 0-100
-
 
45
  uint8_t HeightD; // Value : 0-250
-
 
46
  uint8_t MaxHeight; // Value : 0-32
83
  int8_t motor[MAX_MOTORS][4];
47
  uint8_t HeightP; // Value : 0-32
-
 
48
  uint8_t Height_Gain; // Value : 0-50
84
}__attribute__((packed)) mixerMatrix_t;
Line -... Line 85...
-
 
85
extern mixerMatrix_t mixerMatrix;
-
 
86
 
49
  uint8_t Height_ACC_Effect; // Value : 0-250
87
typedef struct {
-
 
88
  int16_t offsets[3];
-
 
89
} sensorOffset_t;
-
 
90
 
-
 
91
typedef struct {
-
 
92
  uint8_t manualControl;
-
 
93
  uint8_t stabilizationFactor;
-
 
94
  uint8_t minValue;
-
 
95
  uint8_t maxValue;
-
 
96
  uint8_t flags;
-
 
97
} servo_t;
-
 
98
 
-
 
99
#define SERVO_STABILIZATION_REVERSE 1
-
 
100
 
-
 
101
typedef struct {
-
 
102
  uint8_t bitmask;
-
 
103
  uint8_t timing;
Line 50... Line 104...
50
 
104
} output_flash_t;
-
 
105
 
51
  uint8_t StickElevatorP;
106
typedef struct {
-
 
107
  uint8_t gyroQuadrant;
-
 
108
  uint8_t accQuadrant;
-
 
109
  uint8_t imuReversedFlags;
-
 
110
 
-
 
111
  uint8_t gyroPIDFilterConstant;
-
 
112
  uint8_t gyroDWindowLength;
-
 
113
  uint8_t gyroDFilterConstant;
-
 
114
  uint8_t accFilterConstant;
-
 
115
 
Line 52... Line 116...
52
  uint8_t StickAileronsP;
116
  uint8_t zerothOrderCorrection;
Line -... Line 117...
-
 
117
  uint8_t rateTolerance;
53
  uint8_t StickRudderP;
118
 
54
 
119
  uint8_t gyroActivityDamping;
55
  uint8_t PIDGyroFilter;// Value: 1-8
120
  uint8_t driftCompDivider; // 1/k  (Koppel_ACC_Wirkung)
Line -... Line 121...
-
 
121
  uint8_t driftCompLimit;   // limit for gyrodrift compensation
56
 
122
} IMUConfig_t;
-
 
123
 
Line 57... Line 124...
57
  uint8_t DGyroFilter; // Value: 1-8
124
extern IMUConfig_t IMUConfig;
Line -... Line 125...
-
 
125
 
-
 
126
// values above 250 representing poti1 to poti4
58
  uint8_t attitudeGyroFilter; // Value: 1-8
127
typedef struct {
59
 
128
  // Global bitflags
Line 60... Line 129...
60
  uint8_t accFilter;
129
  uint8_t bitConfig;  // see upper defines for bitcoding
61
 
130
 
62
  uint8_t GyroPitchP;
131
  // uint8_t axisCoupling1; // Value: 0-250  Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung)
Line -... Line 132...
-
 
132
  // uint8_t axisCoupling2; // Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
63
  uint8_t GyroRollP;
133
  // uint8_t axisCouplingYawCorrection;// Value: 0-250  Faktor, mit dem Nick und Roll verkoppelt werden
64
  uint8_t GyroYawP;
134
 
Line 65... Line 135...
65
 
135
  uint8_t levelCorrection[2];
66
  uint8_t UserParams[8]; // Value : 0-250
136
 
67
 
137
  // Control
Line 68... Line -...
68
  uint8_t LowVoltageWarning; // Value : 0-250
-
 
69
 
-
 
70
  uint8_t servoDirections;
-
 
71
  uint8_t ServoRefresh; // Value: 0-250      // Refreshrate of servo pwm output
138
  uint8_t gyroPitchP;
Line 72... Line -...
72
 
-
 
73
  uint8_t GyroPitchD;
139
  uint8_t gyroPitchI;
Line -... Line 140...
-
 
140
  uint8_t gyroPitchD;
-
 
141
 
74
  uint8_t GyroRollD;
142
  uint8_t gyroRollP;
Line -... Line 143...
-
 
143
  uint8_t gyroRollI;
-
 
144
  uint8_t gyroRollD;
75
  uint8_t GyroYawD;
145
 
-
 
146
  uint8_t gyroYawP;
Line 76... Line 147...
76
 
147
  uint8_t gyroYawI;
77
  uint8_t zerothOrderGyroCorrectionZAccLimit;
148
  uint8_t gyroYawD;
78
  uint8_t zerothOrderGyroCorrectionFactorx1000;
149
 
79
 
150
  uint8_t stickIElevator;
-
 
151
  uint8_t stickIAilerons;
-
 
152
  uint8_t stickIRudder;
80
  uint8_t secondOrderGyroCorrectionDivisor;
153
 
Line -... Line 154...
-
 
154
  uint8_t externalControl; // for serial Control
-
 
155
 
-
 
156
  uint8_t IFactor;
-
 
157
 
81
  uint8_t secondOrderGyroCorrectionLimit;
158
  uint8_t batteryVoltageWarning;
Line 82... Line 159...
82
  uint8_t CompassYawEffect; // Value : 0-32
159
  uint8_t emergencyThrottle;
83
 
160
  uint8_t emergencyFlightDuration;
84
  uint8_t J16Bitmask; // for the J16 Output
161
 
85
  uint8_t J16Timing; // for the J16 Output
162
  // Servos
86
  uint8_t J17Bitmask; // for the J17 Output
163
  uint8_t servoCount;
87
  uint8_t J17Timing; // for the J17 Output
164
  uint8_t servoManualMaxSpeed;
88
 
165
  servo_t servoConfigurations[2]; // [PITCH, ROLL]
89
  uint8_t ExternalControl; // for serial Control
166
 
90
} paramset_t;
167
  // Outputs
91
 
168
  output_flash_t outputFlash[2];
92
#define  PARAMSET_STRUCT_LEN  sizeof(paramset_t)
169
  uint8_t outputDebugMask;
93
 
170
  uint8_t outputFlags;
94
extern paramset_t staticParams;
171
 
95
 
172
  // User params
96
typedef struct {
173
  uint8_t userParams[8];
97
  uint8_t Revision;
174
 
98
  int8_t Name[12];
175
  // Name
99
  int8_t Motor[16][4];
176
  char name[12];
100
}__attribute__((packed)) MixerTable_t;
177
} ParamSet_t;
101
 
178
 
102
extern MixerTable_t Mixer;
179
extern ParamSet_t staticParams;
103
 
180
 
104
// MKFlags
181
// MKFlags
105
#define MKFLAG_MOTOR_RUN        (1<<0)
182
#define MKFLAG_MOTOR_RUN    (1<<0)
Line 106... Line 183...
106
#define MKFLAG_FLY              (1<<1)
183
//#define MKFLAG_FLY            (1<<1)
107
#define MKFLAG_CALIBRATE        (1<<2)
184
#define MKFLAG_CALIBRATE    (1<<2)
108
#define MKFLAG_START            (1<<3)
185
#define MKFLAG_START        (1<<3)
Line 109... Line 186...
109
#define MKFLAG_EMERGENCY_LANDING (1<<4)
186
#define MKFLAG_EMERGENCY_FLIGHT (1<<4)
110
#define MKFLAG_RESERVE1         (1<<5)
187
#define MKFLAG_LOWBAT       (1<<5)
111
#define MKFLAG_RESERVE2         (1<<6)
188
#define MKFLAG_RESERVE2     (1<<6)
112
#define MKFLAG_RESERVE3         (1<<7)
189
#define MKFLAG_RESERVE3     (1<<7)
113
 
190
 
114
// bit mask for staticParams.GlobalConfig
191
// bit mask for staticParams.bitConfig
115
#define CFG_HEIGHT_CONTROL      (1<<0)
192
#define CFG_SIMPLE_HEIGHT_CONTROL       (1<<0)
Line 116... Line 193...
116
#define CFG_HEIGHT_SWITCH       (1<<1)
193
#define CFG_SIMPLE_HC_HOLD_SWITCH       (1<<1)
117
#define CFG_HEADING_HOLD        (1<<2)
194
#define CFG_HEADING_HOLD                (1<<2)
118
#define CFG_COMPASS_ACTIVE      (1<<3)
195
#define CFG_COMPASS_ENABLED             (1<<3)
119
#define CFG_COMPASS_FIX         (1<<4)
196
#define CFG_UNUSED                      (1<<4)
120
#define CFG_GPS_ACTIVE          (1<<5)
197
#define CFG_NAVI_ENABLED                (1<<5)
-
 
198
#define CFG_AXIS_COUPLING_ENABLED       (1<<6)
-
 
199
#define CFG_GYRO_SATURATION_PREVENTION  (1<<7)
Line 121... Line 200...
121
#define CFG_AXIS_COUPLING_ACTIVE (1<<6)
200
 
-
 
201
#define IMU_REVERSE_GYRO_PR             (1<<0)
122
#define CFG_ROTARY_RATE_LIMITER (1<<7)
202
#define IMU_REVERSE_GYRO_YAW            (1<<1)
123
 
203
#define IMU_REVERSE_ACC_XY              (1<<2)
124
// bit mask for staticParams.ServoDirections
204
#define IMU_REVERSE_ACC_Z               (1<<3)
Line -... Line 205...
-
 
205
 
-
 
206
#define ATMEGA644   0
-
 
207
#define ATMEGA644P  1
-
 
208
#define SYSCLK F_CPU
-
 
209
 
-
 
210
// Not really a part of configuration, but LEDs and HW s test are the same.
-
 
211
#define RED_OFF   {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else  PORTB |= (1<<PORTB0);}
-
 
212
#define RED_ON    {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else  PORTB &=~(1<<PORTB0);}
-
 
213
#define RED_FLASH PORTB ^= (1<<PORTB0)
-
 
214
#define GRN_OFF   {if(boardRelease  < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);}
125
#define SERVO_DIRECTION_ELEVATOR        (1<<0)
215
#define GRN_ON    {if(boardRelease  < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);}
-
 
216
#define GRN_FLASH PORTB ^= (1<<PORTB1)
126
#define SERVO_DIRECTION_AILERONS        (1<<1)
217
 
127
#define SERVO_DIRECTION_RUDDER          (1<<2)
218
// Mixer table
Line -... Line 219...
-
 
219
#define MIX_THROTTLE    0
-
 
220
#define MIX_PITCH   1
128
 
221
#define MIX_ROLL    2