Basic motor code

Dependencies:   Motordriver mbed HALLFX_ENCODER Servo

Committer:
jsterling30
Date:
Wed May 02 14:25:43 2018 +0000
Revision:
13:294c06406d06
Parent:
8:e90d9ce42b33
demo changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jsterling30 13:294c06406d06 1 /*
jsterling30 8:e90d9ce42b33 2 typedef struct {
jsterling30 8:e90d9ce42b33 3 double x;
jsterling30 8:e90d9ce42b33 4 double y;
jsterling30 13:294c06406d06 5 int pen;
jsterling30 8:e90d9ce42b33 6 } Transition;
jsterling30 8:e90d9ce42b33 7
jsterling30 8:e90d9ce42b33 8 typedef struct {
jsterling30 13:294c06406d06 9 Transition points[10];
jsterling30 8:e90d9ce42b33 10 } Letter;
jsterling30 8:e90d9ce42b33 11
jsterling30 13:294c06406d06 12 Letter let_a = { .points = { {0.0, 0.0, 0}, {0.25, 0.25, 1}, {1.0, 1.175, 1}, {1.75, .25, 1}, {.625, 1.0, 0}, {1.375, 1.0, 1}, {2.0, 0.0, 0} } };
jsterling30 13:294c06406d06 13 Letter let_h = { .points = { {0.0, 0.0, 0}, {0.0, 2.0, 1}, {2.0, 2.0, 0}, {2.0, 0.0, 1}, {0.0, 1.0, 0}, {2.0, 1.0, 1}, {2.0, 0.0, 0} } };
jsterling30 13:294c06406d06 14 Letter let_l = { .points = { {0.0, 0.0, 0}, {0.25, 0.25, 1}, {0.25, 1.75, 1}, {0.25, 0.25, 0}, {1.25, 0.25, 1}, {2.0, 0.0, 0}}};
jsterling30 13:294c06406d06 15 Letter let_e = { .points = { {0.0, 0.0, 0}, {0.25, 0.25, 1}, {0.25, 1.75, 1}, {1, 1.75, 1}, {0.25, 1, 0}, {1, 1, 1}, {0.25, 0.25, 0}, {1, 0.25, 1}, {2.0, 0.0, 0}}};
jsterling30 13:294c06406d06 16 Letter let_o = { .points = { {0.0, 0.0, 0}, {0.25, 0.25, 1}, {0.25, 1.75, 1}, {1, 1.75, 1}, {1, 0.25, 1}, {0.25, 0.25, 1}, {2.0, 0.0, 0}}};
jsterling30 13:294c06406d06 17 */
jsterling30 13:294c06406d06 18
jsterling30 13:294c06406d06 19 #include <math.h>
jsterling30 13:294c06406d06 20 #define PI 3.1415926535
jsterling30 13:294c06406d06 21
jsterling30 13:294c06406d06 22 class Transition {
jsterling30 13:294c06406d06 23 public:
jsterling30 13:294c06406d06 24 double x_init;
jsterling30 13:294c06406d06 25 double x_final;
jsterling30 13:294c06406d06 26 double y_init;
jsterling30 13:294c06406d06 27 double y_final;
jsterling30 13:294c06406d06 28 int draw;
jsterling30 13:294c06406d06 29
jsterling30 13:294c06406d06 30 Transition (double x_i, double y_i, double x_f, double y_f, int d) {
jsterling30 13:294c06406d06 31 x_init = x_i;
jsterling30 13:294c06406d06 32 x_final = x_f;
jsterling30 13:294c06406d06 33 y_init = y_i;
jsterling30 13:294c06406d06 34 y_final = y_f;
jsterling30 13:294c06406d06 35 draw = d;
jsterling30 13:294c06406d06 36 }
jsterling30 13:294c06406d06 37
jsterling30 13:294c06406d06 38 Transition () {}
jsterling30 13:294c06406d06 39
jsterling30 13:294c06406d06 40 double desired_angle() {
jsterling30 13:294c06406d06 41 return atan2(y_final - y_init, x_final - x_init) * 180.0 / PI;
jsterling30 13:294c06406d06 42 }
jsterling30 13:294c06406d06 43
jsterling30 13:294c06406d06 44 double distance() {
jsterling30 13:294c06406d06 45 return sqrt(pow(y_final - y_init, 2) + pow(x_final - x_init, 2));
jsterling30 13:294c06406d06 46 }
jsterling30 13:294c06406d06 47 };
jsterling30 13:294c06406d06 48
jsterling30 13:294c06406d06 49 Transition h1(0,0,.25,.25,false);
jsterling30 13:294c06406d06 50 Transition h2(.25,.25,.25,1.75,true);
jsterling30 13:294c06406d06 51 Transition h3(.25,1.75,.25,1,false);
jsterling30 13:294c06406d06 52 Transition h4(.25,1,1,1,true);
jsterling30 13:294c06406d06 53 Transition h5(1,1,1,1.75,false);
jsterling30 13:294c06406d06 54 Transition h6(1,1.75,1,.25,true);
jsterling30 13:294c06406d06 55 Transition h7(1,.25,2,0,false);
jsterling30 13:294c06406d06 56
jsterling30 13:294c06406d06 57 Transition let_h[7] = { h1, h2, h3, h4, h5, h6, h7 };
jsterling30 13:294c06406d06 58
jsterling30 13:294c06406d06 59 Transition e1(0,0,1,1.75,false);
jsterling30 13:294c06406d06 60 Transition e2(1,1.75,0.25,1.75,true);
jsterling30 13:294c06406d06 61 Transition e3(0.25,1.75,.25,.25,true);
jsterling30 13:294c06406d06 62 Transition e4(.25,.25,1,.25,true);
jsterling30 13:294c06406d06 63 Transition e5(1,.25,.25,1,false);
jsterling30 13:294c06406d06 64 Transition e6(.25,1,1,1,true);
jsterling30 13:294c06406d06 65 Transition e7(1,1,2,0,false);
jsterling30 13:294c06406d06 66
jsterling30 13:294c06406d06 67 Transition let_e[7] = { e1, e2, e3, e4, e5, e6, e7 };
jsterling30 13:294c06406d06 68
jsterling30 13:294c06406d06 69 Transition l1(0,0,0.25,1.75,false);
jsterling30 13:294c06406d06 70 Transition l2(0.25,1.75,0.25,0.25,true);
jsterling30 13:294c06406d06 71 Transition l3(0.25,0.25,1.25,0.25,true);
jsterling30 13:294c06406d06 72 Transition l4(1.25,0.25,2,0,false);
jsterling30 13:294c06406d06 73
jsterling30 13:294c06406d06 74 Transition let_l[4] = { l1, l2, l3, l4 };
jsterling30 13:294c06406d06 75
jsterling30 13:294c06406d06 76 Transition o1(0,0,.25,.25,false);
jsterling30 13:294c06406d06 77 Transition o2(.25,.25,.25,1.75,true);
jsterling30 13:294c06406d06 78 Transition o3(.25,1.75,1.75,1.75,true);
jsterling30 13:294c06406d06 79 Transition o4(1.75,1.75,1.75,.25,true);
jsterling30 13:294c06406d06 80 Transition o5(1.75,.25,.25,.25,true);
jsterling30 13:294c06406d06 81 Transition o6(.25,.25,2,0,false);
jsterling30 13:294c06406d06 82
jsterling30 13:294c06406d06 83 Transition let_o[6] = { o1, o2, o3, o4, o5, o6 };