Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | /*####################################################################################### |
2 | Flight Control |
||
3 | #######################################################################################*/ |
||
4 | |||
5 | #ifndef _FC_H |
||
6 | #define _FC_H |
||
886 | killagreg | 7 | |
8 | #include <inttypes.h> |
||
9 | |||
1180 | killagreg | 10 | // scaling from AdAccNick, AdAccRoll -> AccNick, AccRoll |
11 | // i.e. AccNick = ACC_AMPLIFY * AdAccNick |
||
12 | #define ACC_AMPLIFY 6 |
||
886 | killagreg | 13 | |
1180 | killagreg | 14 | // scaling from AccNick, AccRoll -> Attitude in deg (approx sin(x) = x), |
15 | // i.e. Nick Angle in deg = AccNick / ACC_DEG_FACTOR |
||
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 |
||
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) |
||
27 | |||
28 | |||
886 | killagreg | 29 | typedef struct |
30 | { |
||
1180 | killagreg | 31 | uint8_t HeightD; |
886 | killagreg | 32 | uint8_t MaxHeight; |
1180 | killagreg | 33 | uint8_t HeightP; |
886 | killagreg | 34 | uint8_t Height_ACC_Effect; |
35 | uint8_t CompassYawEffect; |
||
1180 | killagreg | 36 | uint8_t GyroD; |
37 | uint8_t GyroP; |
||
38 | uint8_t GyroI; |
||
39 | uint8_t StickYawP; |
||
40 | uint8_t IFactor; |
||
886 | killagreg | 41 | uint8_t UserParam1; |
42 | uint8_t UserParam2; |
||
43 | uint8_t UserParam3; |
||
44 | uint8_t UserParam4; |
||
45 | uint8_t UserParam5; |
||
46 | uint8_t UserParam6; |
||
47 | uint8_t UserParam7; |
||
48 | uint8_t UserParam8; |
||
911 | killagreg | 49 | uint8_t ServoNickControl; |
50 | uint8_t LoopGasLimit; |
||
1180 | killagreg | 51 | uint8_t AxisCoupling1; |
52 | uint8_t AxisCoupling2; |
||
53 | uint8_t AxisCouplingYawCorrection; |
||
886 | killagreg | 54 | uint8_t DynamicStability; |
936 | killagreg | 55 | uint8_t ExternalControl; |
56 | uint8_t J16Timing; |
||
57 | uint8_t J17Timing; |
||
1078 | killagreg | 58 | #if (defined (USE_KILLAGREG) || defined (USE_MK3MAG)) |
936 | killagreg | 59 | uint8_t NaviGpsModeControl; |
60 | uint8_t NaviGpsGain; |
||
61 | uint8_t NaviGpsP; |
||
62 | uint8_t NaviGpsI; |
||
63 | uint8_t NaviGpsD; |
||
64 | uint8_t NaviGpsACC; |
||
1080 | killagreg | 65 | uint8_t NaviOperatingRadius; |
1078 | killagreg | 66 | uint8_t NaviWindCorrection; |
67 | uint8_t NaviSpeedCompensation; |
||
68 | #endif |
||
1180 | killagreg | 69 | int8_t KalmanK; |
70 | int8_t KalmanMaxDrift; |
||
71 | int8_t KalmanMaxFusion; |
||
886 | killagreg | 72 | } fc_param_t; |
73 | |||
74 | extern fc_param_t FCParam; |
||
75 | |||
76 | |||
1180 | killagreg | 77 | // rotation rates |
78 | extern int16_t GyroNick, GyroRoll, GyroYaw; |
||
886 | killagreg | 79 | |
1180 | killagreg | 80 | // attitude calcualted by temporal integral of gyro rates |
81 | extern int32_t IntegralGyroNick, IntegralGyroRoll, IntegralGyroYaw; |
||
886 | killagreg | 82 | |
83 | |||
1180 | killagreg | 84 | // bias values |
85 | extern int16_t BiasHiResGyroNick, BiasHiResGyroRoll, AdBiasGyroYaw; |
||
86 | extern int16_t AdBiasAccNick, AdBiasAccRoll; |
||
87 | extern volatile float AdBiasAccTop; |
||
88 | |||
89 | extern volatile int32_t ReadingIntegralTop; // calculated in analog.c |
||
90 | |||
886 | killagreg | 91 | // compass navigation |
1180 | killagreg | 92 | extern int16_t CompassHeading; |
93 | extern int16_t CompassCourse; |
||
94 | extern int16_t CompassOffCourse; |
||
95 | extern uint8_t CompassCalState; |
||
886 | killagreg | 96 | extern int32_t YawGyroHeading; |
97 | extern int16_t YawGyroHeadingInDeg; |
||
98 | |||
99 | // hight control |
||
100 | extern int ReadingHeight; |
||
101 | extern int SetPointHeight; |
||
102 | |||
1180 | killagreg | 103 | // accelerations |
104 | extern int16_t AccNick, AccRoll, AccTop; |
||
886 | killagreg | 105 | |
106 | // acceleration send to navi board |
||
911 | killagreg | 107 | extern int16_t NaviAccNick, NaviAccRoll, NaviCntAcc; |
886 | killagreg | 108 | |
109 | |||
110 | // looping params |
||
911 | killagreg | 111 | extern long TurnOver180Nick, TurnOver180Roll; |
886 | killagreg | 112 | |
113 | // external control |
||
911 | killagreg | 114 | extern int16_t ExternStickNick, ExternStickRoll, ExternStickYaw; |
886 | killagreg | 115 | |
1180 | killagreg | 116 | #define ACC_CALIB 1 |
117 | #define NO_ACC_CALIB 0 |
||
886 | killagreg | 118 | |
119 | void MotorControl(void); |
||
1 | ingob | 120 | void SendMotorData(void); |
1180 | killagreg | 121 | void SetNeutral(uint8_t AccAdjustment); |
886 | killagreg | 122 | void Beep(uint8_t numbeeps); |
1 | ingob | 123 | |
124 | |||
886 | killagreg | 125 | extern int16_t Poti1, Poti2, Poti3, Poti4, Poti5, Poti6, Poti7, Poti8; |
499 | hbuss | 126 | |
886 | killagreg | 127 | // setpoints for motors |
1180 | killagreg | 128 | extern volatile uint8_t Motor1, Motor2, Motor3, Motor4, Motor5, Motor6, Motor7, Motor8; |
1 | ingob | 129 | |
886 | killagreg | 130 | // current stick values |
911 | killagreg | 131 | extern int16_t StickNick; |
886 | killagreg | 132 | extern int16_t StickRoll; |
133 | extern int16_t StickYaw; |
||
1180 | killagreg | 134 | // current GPS-stick values |
135 | extern int16_t GPSStickNick; |
||
136 | extern int16_t GPSStickRoll; |
||
396 | hbuss | 137 | |
886 | killagreg | 138 | // current stick elongations |
911 | killagreg | 139 | extern int16_t MaxStickNick, MaxStickRoll, MaxStickYaw; |
936 | killagreg | 140 | |
141 | |||
1180 | killagreg | 142 | extern uint16_t ModelIsFlying; |
1 | ingob | 143 | |
144 | |||
936 | killagreg | 145 | // MKFlags |
146 | #define MKFLAG_MOTOR_RUN 0x01 |
||
147 | #define MKFLAG_FLY 0x02 |
||
148 | #define MKFLAG_CALIBRATE 0x04 |
||
149 | #define MKFLAG_START 0x08 |
||
150 | #define MKFLAG_EMERGENCY_LANDING 0x10 |
||
151 | #define MKFLAG_RESERVE1 0x20 |
||
152 | #define MKFLAG_RESERVE2 0x40 |
||
153 | #define MKFLAG_RESERVE3 0x80 |
||
154 | |||
1180 | killagreg | 155 | extern uint8_t MKFlags; |
936 | killagreg | 156 | |
1 | ingob | 157 | #endif //_FC_H |
158 |