Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1775 | - | 1 | #include <inttypes.h> |
2 | #include "attitude.h" |
||
3 | #include "configuration.h" |
||
4 | #include "dongfangMath.h" |
||
2048 | - | 5 | #include "controlMixer.h" |
1775 | - | 6 | |
7 | // For scope debugging only! |
||
1872 | - | 8 | #include "output.h" |
1775 | - | 9 | |
10 | // = cos^2(45 degs). |
||
1887 | - | 11 | // const int32_t FACTORSQUARED = 1L << (MATH_UNIT_FACTOR_LOG * 2); |
2047 | - | 12 | const int32_t MINPROJECTION = 1L << (LOG_MATH_UNIT_FACTOR * 2 - 9); |
1775 | - | 13 | |
14 | // Takes 380 - 400 usec. Way too slow. |
||
15 | // With static MINPROJECTION: 220 usec. |
||
2048 | - | 16 | void AC_getPRTY(int16_t* PRTY) { |
17 | int16_t throttle = PRTY[CONTROL_THROTTLE]; |
||
1877 | - | 18 | int32_t projection; |
1960 | - | 19 | uint8_t effect = dynamicParams.attitudeControl; // Userparam 3 |
1887 | - | 20 | int16_t deltaThrottle, y; |
21 | |||
2048 | - | 22 | int16_t rollAngleInDegrees = attitude[ROLL]/GYRO_DEG_FACTOR_PITCHROLL; |
23 | int16_t pitchAngleInDegrees = attitude[PITCH]/GYRO_DEG_FACTOR_PITCHROLL; |
||
2045 | - | 24 | |
25 | projection = (int32_t) cos_360(pitchAngleInDegrees) * (int32_t) cos_360(rollAngleInDegrees); |
||
1887 | - | 26 | projection >>= 8; |
27 | |||
28 | if (projection < 0) { |
||
29 | // Case not yet considered! |
||
30 | y = 0; |
||
31 | } else { |
||
1877 | - | 32 | if (projection < MINPROJECTION && projection >= 0) { |
1887 | - | 33 | projection = MINPROJECTION; |
1877 | - | 34 | } else if (projection > -MINPROJECTION && projection < 0) { |
1887 | - | 35 | projection = -MINPROJECTION; |
1877 | - | 36 | } else { |
1887 | - | 37 | } |
2047 | - | 38 | y = ((int32_t) throttle << (LOG_MATH_UNIT_FACTOR * 2 - 8)) / projection - throttle; |
1887 | - | 39 | } |
40 | deltaThrottle = ((int32_t)y * effect) >> 6; |
||
1978 | - | 41 | // debugOut.analog[8] = deltaThrottle; |
2048 | - | 42 | PRTY[CONTROL_THROTTLE] = throttle; |
1877 | - | 43 | } |