DECS @UNIST / Mbed 2 deprecated Anybaro_ver_7

Dependencies:   mbed

Committer:
whutsup
Date:
Fri Dec 21 20:39:24 2018 +0000
Revision:
4:bf4ad2079096
Child:
6:549177f76f8e
updated 181222

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
whutsup 4:bf4ad2079096 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]);
whutsup 4:bf4ad2079096 72
whutsup 4:bf4ad2079096 73 readCount=0;
whutsup 4:bf4ad2079096 74
whutsup 4:bf4ad2079096 75 for(int i =0; i<4 ; i++)
whutsup 4:bf4ad2079096 76 {
whutsup 4:bf4ad2079096 77 sum_L[i] = 0;
whutsup 4:bf4ad2079096 78 sum_R[i] = 0;
whutsup 4:bf4ad2079096 79 avg_L[i] = 0;
whutsup 4:bf4ad2079096 80 avg_R[i] = 0;
whutsup 4:bf4ad2079096 81 }
whutsup 4:bf4ad2079096 82
whutsup 4:bf4ad2079096 83
whutsup 4:bf4ad2079096 84 }
whutsup 4:bf4ad2079096 85
whutsup 4:bf4ad2079096 86
whutsup 4:bf4ad2079096 87 }
whutsup 4:bf4ad2079096 88
whutsup 4:bf4ad2079096 89 void ReadForce()
whutsup 4:bf4ad2079096 90 {
whutsup 4:bf4ad2079096 91 float force_L[4];
whutsup 4:bf4ad2079096 92 float force_R[4];
whutsup 4:bf4ad2079096 93
whutsup 4:bf4ad2079096 94 force_L[0] = force_L1.read();
whutsup 4:bf4ad2079096 95 force_L[1] = force_L2.read();
whutsup 4:bf4ad2079096 96 force_L[2] = force_L3.read();
whutsup 4:bf4ad2079096 97 force_L[3] = force_L4.read();
whutsup 4:bf4ad2079096 98 force_R[0] = force_R1.read();
whutsup 4:bf4ad2079096 99 force_R[1] = force_R2.read();
whutsup 4:bf4ad2079096 100 force_R[2] = force_R3.read();
whutsup 4:bf4ad2079096 101 force_R[3] = force_R4.read();
whutsup 4:bf4ad2079096 102
whutsup 4:bf4ad2079096 103 bt.printf("%1.3f,%1.3f,%1.3f,%1.3f,%1.3f,%1.3f,%1.3f,%1.3f\n", force_L[0],force_L[1],force_L[2],force_L[3],force_R[0],force_R[1],force_R[2],force_R[3]);
whutsup 4:bf4ad2079096 104
whutsup 4:bf4ad2079096 105
whutsup 4:bf4ad2079096 106
whutsup 4:bf4ad2079096 107 }