DECS @UNIST / Mbed 2 deprecated Anybaro_ver_7

Dependencies:   mbed

Committer:
whutsup
Date:
Tue Jun 25 02:10:31 2019 +0000
Revision:
9:7d6fa62f9022
Parent:
8:a435e7aa7a02
Child:
10:3fcaf50f528f
190625 updated ver

Who changed what in which revision?

UserRevisionLine numberNew contents of line
whutsup 4:bf4ad2079096 1 #include "mbed.h"
whutsup 4:bf4ad2079096 2
whutsup 4:bf4ad2079096 3 AnalogIn force_L1(PB_0); // Force Sensor
whutsup 4:bf4ad2079096 4 AnalogIn force_L2(PB_1);
whutsup 4:bf4ad2079096 5 AnalogIn force_L3(PC_0);
whutsup 4:bf4ad2079096 6 AnalogIn force_L4(PC_1);
whutsup 4:bf4ad2079096 7 AnalogIn force_R1(PC_2);
whutsup 4:bf4ad2079096 8 AnalogIn force_R2(PC_3);
whutsup 4:bf4ad2079096 9 AnalogIn force_R3(PC_4);
whutsup 4:bf4ad2079096 10 AnalogIn force_R4(PC_5);
whutsup 4:bf4ad2079096 11
whutsup 4:bf4ad2079096 12 extern Serial bt;
whutsup 4:bf4ad2079096 13 extern Serial pc;
whutsup 4:bf4ad2079096 14
whutsup 4:bf4ad2079096 15 char readCount=0;
whutsup 4:bf4ad2079096 16
whutsup 4:bf4ad2079096 17 float sum_L[4]={0,};
whutsup 4:bf4ad2079096 18 float sum_R[4]={0,};
whutsup 4:bf4ad2079096 19
whutsup 4:bf4ad2079096 20 float avg_L[4]={0,};
whutsup 4:bf4ad2079096 21 float avg_R[4]={0,};
whutsup 4:bf4ad2079096 22
whutsup 4:bf4ad2079096 23
whutsup 4:bf4ad2079096 24 /*----------------------- Callback Functions ------------------------*/
whutsup 4:bf4ad2079096 25
whutsup 4:bf4ad2079096 26 void CalForce()
whutsup 4:bf4ad2079096 27 {
whutsup 4:bf4ad2079096 28
whutsup 4:bf4ad2079096 29 float force_L[4];
whutsup 4:bf4ad2079096 30 float force_R[4];
whutsup 4:bf4ad2079096 31
whutsup 4:bf4ad2079096 32 force_L[0] = force_L1.read();
whutsup 4:bf4ad2079096 33 force_L[1] = force_L2.read();
whutsup 4:bf4ad2079096 34 force_L[2] = force_L3.read();
whutsup 4:bf4ad2079096 35 force_L[3] = force_L4.read();
whutsup 4:bf4ad2079096 36 force_R[0] = force_R1.read();
whutsup 4:bf4ad2079096 37 force_R[1] = force_R2.read();
whutsup 4:bf4ad2079096 38 force_R[2] = force_R3.read();
whutsup 4:bf4ad2079096 39 force_R[3] = force_R4.read();
whutsup 4:bf4ad2079096 40
whutsup 4:bf4ad2079096 41
whutsup 4:bf4ad2079096 42 if ( readCount < 6)
whutsup 4:bf4ad2079096 43 {
whutsup 4:bf4ad2079096 44 sum_L[0] = sum_L[0] + force_L[0];
whutsup 4:bf4ad2079096 45 sum_L[1] = sum_L[1] + force_L[1];
whutsup 4:bf4ad2079096 46 sum_L[2] = sum_L[2] + force_L[2];
whutsup 4:bf4ad2079096 47 sum_L[3] = sum_L[3] + force_L[3];
whutsup 4:bf4ad2079096 48
whutsup 4:bf4ad2079096 49 sum_R[0] = sum_R[0] + force_R[0];
whutsup 4:bf4ad2079096 50 sum_R[1] = sum_R[1] + force_R[1];
whutsup 4:bf4ad2079096 51 sum_R[2] = sum_R[2] + force_R[2];
whutsup 4:bf4ad2079096 52 sum_R[3] = sum_R[3] + force_R[3];
whutsup 4:bf4ad2079096 53
whutsup 4:bf4ad2079096 54 readCount++;
whutsup 4:bf4ad2079096 55
whutsup 4:bf4ad2079096 56 }
whutsup 4:bf4ad2079096 57
whutsup 4:bf4ad2079096 58 else if (readCount == 6 | readCount>6)
whutsup 4:bf4ad2079096 59 {
whutsup 4:bf4ad2079096 60
whutsup 4:bf4ad2079096 61 avg_L[0] = sum_L[0]/6;
whutsup 4:bf4ad2079096 62 avg_L[1] = sum_L[1]/6;
whutsup 4:bf4ad2079096 63 avg_L[2] = sum_L[2]/6;
whutsup 4:bf4ad2079096 64 avg_L[3] = sum_L[3]/6;
whutsup 4:bf4ad2079096 65
whutsup 4:bf4ad2079096 66 avg_R[0] = sum_R[0]/6;
whutsup 4:bf4ad2079096 67 avg_R[1] = sum_R[1]/6;
whutsup 4:bf4ad2079096 68 avg_R[2] = sum_R[2]/6;
whutsup 4:bf4ad2079096 69 avg_R[3] = sum_R[3]/6;
whutsup 4:bf4ad2079096 70
Bhoney 6:549177f76f8e 71 // bt.printf("%1.3f,%1.3f,%1.3f,%1.3f,%1.3f,%1.3f,%1.3f,%1.3f\n", avg_L[0],avg_L[1],avg_L[2],avg_L[3],avg_R[0],avg_R[1],avg_R[2],avg_R[3]);
Bhoney 6:549177f76f8e 72 bt.putc('<');
Bhoney 6:549177f76f8e 73 bt.putc('F');
Bhoney 6:549177f76f8e 74 bt.putc('O');
Bhoney 6:549177f76f8e 75 bt.putc('T');
Bhoney 6:549177f76f8e 76 bt.putc((unsigned char)((int)avg_L[0]*127));
Bhoney 6:549177f76f8e 77 bt.putc((unsigned char)((int)avg_L[1]*127));
Bhoney 6:549177f76f8e 78 bt.putc((unsigned char)((int)avg_L[2]*127));
Bhoney 6:549177f76f8e 79 bt.putc((unsigned char)((int)avg_L[3]*127));
Bhoney 6:549177f76f8e 80 bt.putc((unsigned char)((int)avg_R[0]*127));
Bhoney 6:549177f76f8e 81 bt.putc((unsigned char)((int)avg_R[1]*127));
Bhoney 6:549177f76f8e 82 bt.putc((unsigned char)((int)avg_R[2]*127));
Bhoney 6:549177f76f8e 83 bt.putc((unsigned char)((int)avg_R[3]*127));
Bhoney 6:549177f76f8e 84 bt.putc('>');
whutsup 8:a435e7aa7a02 85 bt.putc('\r');
whutsup 8:a435e7aa7a02 86 bt.putc('\n');
whutsup 4:bf4ad2079096 87
whutsup 4:bf4ad2079096 88 readCount=0;
whutsup 4:bf4ad2079096 89
whutsup 4:bf4ad2079096 90 for(int i =0; i<4 ; i++)
whutsup 4:bf4ad2079096 91 {
whutsup 4:bf4ad2079096 92 sum_L[i] = 0;
whutsup 4:bf4ad2079096 93 sum_R[i] = 0;
whutsup 4:bf4ad2079096 94 avg_L[i] = 0;
whutsup 4:bf4ad2079096 95 avg_R[i] = 0;
whutsup 4:bf4ad2079096 96 }
whutsup 4:bf4ad2079096 97
whutsup 4:bf4ad2079096 98
whutsup 4:bf4ad2079096 99 }
whutsup 4:bf4ad2079096 100
whutsup 4:bf4ad2079096 101
whutsup 4:bf4ad2079096 102 }
whutsup 4:bf4ad2079096 103
whutsup 4:bf4ad2079096 104 void ReadForce()
whutsup 4:bf4ad2079096 105 {
whutsup 4:bf4ad2079096 106 float force_L[4];
whutsup 4:bf4ad2079096 107 float force_R[4];
whutsup 4:bf4ad2079096 108
whutsup 4:bf4ad2079096 109 force_L[0] = force_L1.read();
whutsup 4:bf4ad2079096 110 force_L[1] = force_L2.read();
whutsup 4:bf4ad2079096 111 force_L[2] = force_L3.read();
whutsup 4:bf4ad2079096 112 force_L[3] = force_L4.read();
whutsup 4:bf4ad2079096 113 force_R[0] = force_R1.read();
whutsup 4:bf4ad2079096 114 force_R[1] = force_R2.read();
whutsup 4:bf4ad2079096 115 force_R[2] = force_R3.read();
whutsup 4:bf4ad2079096 116 force_R[3] = force_R4.read();
whutsup 4:bf4ad2079096 117
whutsup 9:7d6fa62f9022 118 bt.printf("%1.3f,%1.3f,%1.3f,%1.3f\n",force_R[0],force_R[1],force_R[2],force_R[3]);
whutsup 9:7d6fa62f9022 119 // bt.putc('<');
whutsup 9:7d6fa62f9022 120 // bt.putc('F');
whutsup 9:7d6fa62f9022 121 // bt.putc('O');
whutsup 9:7d6fa62f9022 122 // bt.putc('T');
whutsup 9:7d6fa62f9022 123 // bt.putc((char)((unsigned int)(force_L[0]*127)));
whutsup 9:7d6fa62f9022 124 // bt.putc((char)((unsigned int)(force_L[1]*127)));
whutsup 9:7d6fa62f9022 125 // bt.putc((char)((unsigned int)(force_L[2]*127)));
whutsup 9:7d6fa62f9022 126 // bt.putc((char)((unsigned int)(force_L[3]*127)));
whutsup 9:7d6fa62f9022 127 // bt.putc((char)((unsigned int)(force_R[0]*127)));
whutsup 9:7d6fa62f9022 128 // bt.putc((char)((unsigned int)(force_R[1]*127)));
whutsup 9:7d6fa62f9022 129 // bt.putc((char)((unsigned int)(force_R[2]*127)));
whutsup 9:7d6fa62f9022 130 // bt.putc((char)((unsigned int)(force_R[3]*127)));
whutsup 9:7d6fa62f9022 131 // bt.putc('>');
whutsup 9:7d6fa62f9022 132 // bt.putc('\r');
whutsup 9:7d6fa62f9022 133 // bt.putc('\n');
whutsup 8:a435e7aa7a02 134
Bhoney 6:549177f76f8e 135
Bhoney 6:549177f76f8e 136
whutsup 4:bf4ad2079096 137
whutsup 4:bf4ad2079096 138
whutsup 4:bf4ad2079096 139
whutsup 4:bf4ad2079096 140 }