Rev 1179 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1179 | Rev 1180 | ||
---|---|---|---|
1 | /*####################################################################################### |
1 | /*####################################################################################### |
2 | Flight Control |
2 | Flight Control |
3 | #######################################################################################*/ |
3 | #######################################################################################*/ |
4 | 4 | ||
5 | #ifndef _FC_H |
5 | #ifndef _FC_H |
6 | #define _FC_H |
6 | #define _FC_H |
7 | 7 | ||
8 | #include <inttypes.h> |
8 | #include <inttypes.h> |
- | 9 | ||
- | 10 | // scaling from AdAccNick, AdAccRoll -> AccNick, AccRoll |
|
- | 11 | // i.e. AccNick = ACC_AMPLIFY * AdAccNick |
|
- | 12 | #define ACC_AMPLIFY 6 |
|
- | 13 | ||
- | 14 | // scaling from AccNick, AccRoll -> Attitude in deg (approx sin(x) = x), |
|
- | 15 | // i.e. Nick Angle in deg = AccNick / ACC_DEG_FACTOR |
|
9 | 16 | ||
- | 17 | // the value is derived from the datasheet of the ACC sensor where 5g are scaled to vref |
|
- | 18 | // therefore 1g is 1024/5 = 205 counts. the adc isr combines 2 acc samples to AdValueAcc |
|
- | 19 | // and 1g yields to AdValueAcc = 2* 205 * 410 wich is again scaled by ACC_DEG_FACTOR |
|
- | 20 | // that results in 1g --> Acc = 205 * 12 = 2460. the linear approx of the arcsin and the scaling |
|
10 | #define YAW_GYRO_DEG_FACTOR 1291L // Factor between Yaw Gyro Integral and HeadingAngle in deg |
21 | // of Acc gives the factor below. sin(20deg) * 2460 = 841 --> 841 / 20 = 42 |
- | 22 | #define ACC_DEG_FACTOR 42 |
|
- | 23 | ||
- | 24 | // scaling from IntegralGyroNick, IntegralGyroRoll, IntegralGyroYaw -> Attitude in deg |
|
- | 25 | // i.e. Nick Angle in deg = IntegralGyroNick / GYRO_DEG_FACTOR |
|
- | 26 | #define GYRO_DEG_FACTOR ((int16_t)(ParamSet.GyroAccFactor) * ACC_DEG_FACTOR) |
|
11 | #define STICK_GAIN 4 |
27 | |
12 | 28 | ||
13 | typedef struct |
29 | typedef struct |
14 | { |
30 | { |
15 | uint8_t Height_D; |
31 | uint8_t HeightD; |
16 | uint8_t MaxHeight; |
32 | uint8_t MaxHeight; |
17 | uint8_t Height_P; |
33 | uint8_t HeightP; |
18 | uint8_t Height_ACC_Effect; |
34 | uint8_t Height_ACC_Effect; |
19 | uint8_t CompassYawEffect; |
35 | uint8_t CompassYawEffect; |
- | 36 | uint8_t GyroD; |
|
20 | uint8_t Gyro_P; |
37 | uint8_t GyroP; |
21 | uint8_t Gyro_I; |
38 | uint8_t GyroI; |
22 | uint8_t Yaw_P; |
39 | uint8_t StickYawP; |
23 | uint8_t I_Factor; |
40 | uint8_t IFactor; |
24 | uint8_t UserParam1; |
41 | uint8_t UserParam1; |
25 | uint8_t UserParam2; |
42 | uint8_t UserParam2; |
26 | uint8_t UserParam3; |
43 | uint8_t UserParam3; |
27 | uint8_t UserParam4; |
44 | uint8_t UserParam4; |
28 | uint8_t UserParam5; |
45 | uint8_t UserParam5; |
29 | uint8_t UserParam6; |
46 | uint8_t UserParam6; |
30 | uint8_t UserParam7; |
47 | uint8_t UserParam7; |
31 | uint8_t UserParam8; |
48 | uint8_t UserParam8; |
32 | uint8_t ServoNickControl; |
49 | uint8_t ServoNickControl; |
33 | uint8_t LoopGasLimit; |
50 | uint8_t LoopGasLimit; |
34 | uint8_t Yaw_PosFeedback; |
51 | uint8_t AxisCoupling1; |
35 | uint8_t Yaw_NegFeedback; |
52 | uint8_t AxisCoupling2; |
- | 53 | uint8_t AxisCouplingYawCorrection; |
|
36 | uint8_t DynamicStability; |
54 | uint8_t DynamicStability; |
37 | uint8_t ExternalControl; |
55 | uint8_t ExternalControl; |
38 | uint8_t J16Timing; |
56 | uint8_t J16Timing; |
39 | uint8_t J17Timing; |
57 | uint8_t J17Timing; |
40 | #if (defined (USE_KILLAGREG) || defined (USE_MK3MAG)) |
58 | #if (defined (USE_KILLAGREG) || defined (USE_MK3MAG)) |
41 | uint8_t NaviGpsModeControl; |
59 | uint8_t NaviGpsModeControl; |
42 | uint8_t NaviGpsGain; |
60 | uint8_t NaviGpsGain; |
43 | uint8_t NaviGpsP; |
61 | uint8_t NaviGpsP; |
44 | uint8_t NaviGpsI; |
62 | uint8_t NaviGpsI; |
45 | uint8_t NaviGpsD; |
63 | uint8_t NaviGpsD; |
46 | uint8_t NaviGpsACC; |
64 | uint8_t NaviGpsACC; |
47 | uint8_t NaviOperatingRadius; |
65 | uint8_t NaviOperatingRadius; |
48 | uint8_t NaviWindCorrection; |
66 | uint8_t NaviWindCorrection; |
49 | uint8_t NaviSpeedCompensation; |
67 | uint8_t NaviSpeedCompensation; |
50 | #endif |
68 | #endif |
51 | int8_t Kalman_K; |
69 | int8_t KalmanK; |
52 | int8_t Kalman_MaxDrift; |
70 | int8_t KalmanMaxDrift; |
53 | int8_t Kalman_MaxFusion; |
71 | int8_t KalmanMaxFusion; |
54 | } fc_param_t; |
72 | } fc_param_t; |
55 | 73 | ||
56 | extern fc_param_t FCParam; |
74 | extern fc_param_t FCParam; |
57 | - | ||
58 | // attitude |
- | |
59 | extern int32_t IntegralNick, IntegralRoll, IntegralYaw; |
- | |
60 | extern int16_t Reading_GyroNick, Reading_GyroRoll, Reading_GyroYaw; |
75 | |
61 | 76 | ||
- | 77 | // rotation rates |
|
62 | // offsets |
78 | extern int16_t GyroNick, GyroRoll, GyroYaw; |
63 | extern int16_t AdNeutralNick, AdNeutralRoll, AdNeutralYaw; |
79 | |
- | 80 | // attitude calcualted by temporal integral of gyro rates |
|
- | 81 | extern int32_t IntegralGyroNick, IntegralGyroRoll, IntegralGyroYaw; |
|
- | 82 | ||
- | 83 | ||
- | 84 | // bias values |
|
64 | extern volatile int16_t NeutralAccX, NeutralAccY; |
85 | extern int16_t BiasHiResGyroNick, BiasHiResGyroRoll, AdBiasGyroYaw; |
65 | extern volatile float NeutralAccZ; |
86 | extern int16_t AdBiasAccNick, AdBiasAccRoll; |
66 | 87 | extern volatile float AdBiasAccTop; |
|
67 | 88 | ||
68 | extern volatile int32_t Reading_Integral_Top; // calculated in analog.c |
89 | extern volatile int32_t ReadingIntegralTop; // calculated in analog.c |
69 | 90 | ||
70 | // compass navigation |
91 | // compass navigation |
71 | extern volatile int16_t CompassHeading; |
92 | extern int16_t CompassHeading; |
72 | extern volatile int16_t CompassCourse; |
93 | extern int16_t CompassCourse; |
73 | extern volatile int16_t CompassOffCourse; |
94 | extern int16_t CompassOffCourse; |
74 | extern volatile uint8_t CompassCalState; |
95 | extern uint8_t CompassCalState; |
75 | extern int32_t YawGyroHeading; |
96 | extern int32_t YawGyroHeading; |
76 | extern int16_t YawGyroHeadingInDeg; |
97 | extern int16_t YawGyroHeadingInDeg; |
77 | 98 | ||
78 | // hight control |
99 | // hight control |
79 | extern int ReadingHeight; |
100 | extern int ReadingHeight; |
80 | extern int SetPointHeight; |
101 | extern int SetPointHeight; |
81 | 102 | ||
82 | // mean accelerations |
103 | // accelerations |
83 | extern int16_t Mean_AccNick, Mean_AccRoll, Mean_AccTop; |
104 | extern int16_t AccNick, AccRoll, AccTop; |
84 | 105 | ||
85 | // acceleration send to navi board |
106 | // acceleration send to navi board |
86 | extern int16_t NaviAccNick, NaviAccRoll, NaviCntAcc; |
107 | extern int16_t NaviAccNick, NaviAccRoll, NaviCntAcc; |
87 | 108 | ||
88 | 109 | ||
89 | // looping params |
110 | // looping params |
90 | extern long TurnOver180Nick, TurnOver180Roll; |
111 | extern long TurnOver180Nick, TurnOver180Roll; |
91 | 112 | ||
92 | // external control |
113 | // external control |
93 | extern int16_t ExternStickNick, ExternStickRoll, ExternStickYaw; |
114 | extern int16_t ExternStickNick, ExternStickRoll, ExternStickYaw; |
- | 115 | ||
- | 116 | #define ACC_CALIB 1 |
|
94 | 117 | #define NO_ACC_CALIB 0 |
|
95 | 118 | ||
96 | void MotorControl(void); |
119 | void MotorControl(void); |
97 | void SendMotorData(void); |
120 | void SendMotorData(void); |
98 | void CalibMean(void); |
- | |
99 | void Mean(void); |
- | |
100 | void SetNeutral(void); |
121 | void SetNeutral(uint8_t AccAdjustment); |
101 | void Beep(uint8_t numbeeps); |
122 | void Beep(uint8_t numbeeps); |
102 | 123 | ||
103 | 124 | ||
104 | extern int16_t Poti1, Poti2, Poti3, Poti4, Poti5, Poti6, Poti7, Poti8; |
125 | extern int16_t Poti1, Poti2, Poti3, Poti4, Poti5, Poti6, Poti7, Poti8; |
105 | 126 | ||
106 | // setpoints for motors |
127 | // setpoints for motors |
107 | extern volatile uint8_t Motor_Front, Motor_Rear, Motor_Right, Motor_Left; //used by twimaster isr |
128 | extern volatile uint8_t Motor1, Motor2, Motor3, Motor4, Motor5, Motor6, Motor7, Motor8; |
108 | 129 | ||
109 | // current stick values |
130 | // current stick values |
110 | extern int16_t StickNick; |
131 | extern int16_t StickNick; |
111 | extern int16_t StickRoll; |
132 | extern int16_t StickRoll; |
112 | extern int16_t StickYaw; |
133 | extern int16_t StickYaw; |
- | 134 | // current GPS-stick values |
|
113 | extern int16_t GPS_Nick; |
135 | extern int16_t GPSStickNick; |
114 | extern int16_t GPS_Roll; |
136 | extern int16_t GPSStickRoll; |
115 | 137 | ||
116 | // current stick elongations |
138 | // current stick elongations |
117 | extern int16_t MaxStickNick, MaxStickRoll, MaxStickYaw; |
139 | extern int16_t MaxStickNick, MaxStickRoll, MaxStickYaw; |
118 | 140 | ||
119 | 141 | ||
120 | extern uint16_t Model_Is_Flying; |
142 | extern uint16_t ModelIsFlying; |
121 | 143 | ||
122 | 144 | ||
123 | // MKFlags |
145 | // MKFlags |
124 | #define MKFLAG_MOTOR_RUN 0x01 |
146 | #define MKFLAG_MOTOR_RUN 0x01 |
125 | #define MKFLAG_FLY 0x02 |
147 | #define MKFLAG_FLY 0x02 |
126 | #define MKFLAG_CALIBRATE 0x04 |
148 | #define MKFLAG_CALIBRATE 0x04 |
127 | #define MKFLAG_START 0x08 |
149 | #define MKFLAG_START 0x08 |
128 | #define MKFLAG_EMERGENCY_LANDING 0x10 |
150 | #define MKFLAG_EMERGENCY_LANDING 0x10 |
129 | #define MKFLAG_RESERVE1 0x20 |
151 | #define MKFLAG_RESERVE1 0x20 |
130 | #define MKFLAG_RESERVE2 0x40 |
152 | #define MKFLAG_RESERVE2 0x40 |
131 | #define MKFLAG_RESERVE3 0x80 |
153 | #define MKFLAG_RESERVE3 0x80 |
132 | 154 | ||
133 | volatile extern uint8_t MKFlags; |
155 | extern uint8_t MKFlags; |
134 | 156 | ||
135 | #endif //_FC_H |
157 | #endif //_FC_H |
136 | 158 | ||
137 | 159 |