Jon Freeman / Mbed 2 deprecated Brute_TS_Controller_2018_11

Dependencies:   TS_DISCO_F746NG mbed Servo LCD_DISCO_F746NG BSP_DISCO_F746NG QSPI_DISCO_F746NG AsyncSerial FastPWM

Committer:
JonFreeman
Date:
Wed May 09 15:42:43 2018 +0000
Revision:
7:3b1f44cd4735
Parent:
4:67478861c670
Panic recovery from updating mbed lib causing total wipeout

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JonFreeman 4:67478861c670 1 #include "mbed.h"
JonFreeman 4:67478861c670 2 /*
JonFreeman 4:67478861c670 3 Purpose of this file is to provide sin and cos functions. Yes, C++ has these already, but using inbuilt sin and cos on
JonFreeman 4:67478861c670 4 DISCO-F746NG causes display to flicker! Interrupt getting missed or whatever, these look-up functions solve the flicker !
JonFreeman 4:67478861c670 5 */
JonFreeman 4:67478861c670 6 static const double HALF_PI = 2.0 * atan(1.0);
JonFreeman 4:67478861c670 7 static const double TWO_PI = 8.0 * atan(1.0);
JonFreeman 4:67478861c670 8
JonFreeman 4:67478861c670 9 double jcos (double angle) {
JonFreeman 4:67478861c670 10 //At costabgen with 180 points
JonFreeman 4:67478861c670 11 static const double costab[] = {
JonFreeman 4:67478861c670 12 +1.000000, +0.999962, +0.999848, +0.999657, +0.999391, +0.999048, +0.998630, +0.998135,
JonFreeman 4:67478861c670 13 +0.997564, +0.996917, +0.996195, +0.995396, +0.994522, +0.993572, +0.992546, +0.991445,
JonFreeman 4:67478861c670 14 +0.990268, +0.989016, +0.987688, +0.986286, +0.984808, +0.983255, +0.981627, +0.979925,
JonFreeman 4:67478861c670 15 +0.978148, +0.976296, +0.974370, +0.972370, +0.970296, +0.968148, +0.965926, +0.963630,
JonFreeman 4:67478861c670 16 +0.961262, +0.958820, +0.956305, +0.953717, +0.951057, +0.948324, +0.945519, +0.942641,
JonFreeman 4:67478861c670 17 +0.939693, +0.936672, +0.933580, +0.930418, +0.927184, +0.923880, +0.920505, +0.917060,
JonFreeman 4:67478861c670 18 +0.913545, +0.909961, +0.906308, +0.902585, +0.898794, +0.894934, +0.891007, +0.887011,
JonFreeman 4:67478861c670 19 +0.882948, +0.878817, +0.874620, +0.870356, +0.866025, +0.861629, +0.857167, +0.852640,
JonFreeman 4:67478861c670 20 +0.848048, +0.843391, +0.838671, +0.833886, +0.829038, +0.824126, +0.819152, +0.814116,
JonFreeman 4:67478861c670 21 +0.809017, +0.803857, +0.798636, +0.793353, +0.788011, +0.782608, +0.777146, +0.771625,
JonFreeman 4:67478861c670 22 +0.766044, +0.760406, +0.754710, +0.748956, +0.743145, +0.737277, +0.731354, +0.725374,
JonFreeman 4:67478861c670 23 +0.719340, +0.713250, +0.707107, +0.700909, +0.694658, +0.688355, +0.681998, +0.675590,
JonFreeman 4:67478861c670 24 +0.669131, +0.662620, +0.656059, +0.649448, +0.642788, +0.636078, +0.629320, +0.622515,
JonFreeman 4:67478861c670 25 +0.615661, +0.608761, +0.601815, +0.594823, +0.587785, +0.580703, +0.573576, +0.566406,
JonFreeman 4:67478861c670 26 +0.559193, +0.551937, +0.544639, +0.537300, +0.529919, +0.522499, +0.515038, +0.507538,
JonFreeman 4:67478861c670 27 +0.500000, +0.492424, +0.484810, +0.477159, +0.469472, +0.461749, +0.453990, +0.446198,
JonFreeman 4:67478861c670 28 +0.438371, +0.430511, +0.422618, +0.414693, +0.406737, +0.398749, +0.390731, +0.382683,
JonFreeman 4:67478861c670 29 +0.374607, +0.366501, +0.358368, +0.350207, +0.342020, +0.333807, +0.325568, +0.317305,
JonFreeman 4:67478861c670 30 +0.309017, +0.300706, +0.292372, +0.284015, +0.275637, +0.267238, +0.258819, +0.250380,
JonFreeman 4:67478861c670 31 +0.241922, +0.233445, +0.224951, +0.216440, +0.207912, +0.199368, +0.190809, +0.182236,
JonFreeman 4:67478861c670 32 +0.173648, +0.165048, +0.156434, +0.147809, +0.139173, +0.130526, +0.121869, +0.113203,
JonFreeman 4:67478861c670 33 +0.104528, +0.095846, +0.087156, +0.078459, +0.069756, +0.061049, +0.052336, +0.043619,
JonFreeman 4:67478861c670 34 +0.034899, +0.026177, +0.017452, +0.008727, +0.000000, 0.0 } ;
JonFreeman 4:67478861c670 35 //End of costab
JonFreeman 4:67478861c670 36 const int costab_points_i = (sizeof(costab) / sizeof(double)) - 1;
JonFreeman 4:67478861c670 37 const double costab_points_d = (double) costab_points_i;
JonFreeman 4:67478861c670 38 bool isneg = false;
JonFreeman 4:67478861c670 39 int offset;
JonFreeman 4:67478861c670 40 while (angle > TWO_PI) angle -= TWO_PI;
JonFreeman 4:67478861c670 41 while (angle < 0.0) angle += TWO_PI;
JonFreeman 4:67478861c670 42 // now got 0.0 <= angle <= 2PI
JonFreeman 4:67478861c670 43 offset = (int)(angle * costab_points_d / HALF_PI); // ang2 is 0.0 <= ang2 <= 2.0 * PI
JonFreeman 4:67478861c670 44 if (offset > 3 * costab_points_i) { // quadrant = 3;
JonFreeman 4:67478861c670 45 offset = (4 * costab_points_i) - offset - 1;
JonFreeman 4:67478861c670 46 }
JonFreeman 4:67478861c670 47 else if (offset > 2 * costab_points_i) { // quadrant = 2;
JonFreeman 4:67478861c670 48 offset -= 2 * costab_points_i;
JonFreeman 4:67478861c670 49 isneg = true;
JonFreeman 4:67478861c670 50 }
JonFreeman 4:67478861c670 51 else if (offset > 1 * costab_points_i) { // quadrant = 1;
JonFreeman 4:67478861c670 52 offset = (2 * costab_points_i) - offset - 1;
JonFreeman 4:67478861c670 53 isneg = true;
JonFreeman 4:67478861c670 54 } // else quadrant = 0;
JonFreeman 4:67478861c670 55 if (offset < 0) offset = 0;
JonFreeman 4:67478861c670 56 if (offset > costab_points_i) offset = costab_points_i;
JonFreeman 4:67478861c670 57 if (isneg) return - costab[offset];
JonFreeman 4:67478861c670 58 else return costab[offset];
JonFreeman 4:67478861c670 59 }
JonFreeman 4:67478861c670 60
JonFreeman 4:67478861c670 61 double jsin (double angle) {
JonFreeman 4:67478861c670 62 return -jcos (angle + HALF_PI);
JonFreeman 4:67478861c670 63 }
JonFreeman 4:67478861c670 64
JonFreeman 4:67478861c670 65