Dectection take 1. Fixed adaptation step. Detect based on a number of standard deviations away from the mean.
Dependencies: SI1143 m3pi mbed
Fork of Proximity_Sensor_2_detect by
main.cpp@6:f2c616fa9ffe, 2014-06-16 (annotated)
- Committer:
- mfillinois
- Date:
- Mon Jun 16 15:07:07 2014 +0000
- Revision:
- 6:f2c616fa9ffe
- Parent:
- 5:b77b678ed22f
- Child:
- 7:73a722360cdb
fooling with sample rate;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dmcohen24 | 3:0359b918f658 | 1 | |
dmcohen24 | 0:1802ead3667e | 2 | #include "mbed.h" |
dmcohen24 | 0:1802ead3667e | 3 | #include "SI1143.h" |
mfillinois | 5:b77b678ed22f | 4 | #include "m3pi.h" |
dmcohen24 | 0:1802ead3667e | 5 | |
dmcohen24 | 3:0359b918f658 | 6 | //DigitalOut enable(p30); |
dmcohen24 | 3:0359b918f658 | 7 | |
mfillinois | 5:b77b678ed22f | 8 | //Ticker timer; |
dmcohen24 | 3:0359b918f658 | 9 | |
dmcohen24 | 3:0359b918f658 | 10 | I2C* i2c = new I2C(p28, p27); |
mfillinois | 5:b77b678ed22f | 11 | Serial bt(p13, p14); |
mfillinois | 5:b77b678ed22f | 12 | m3pi pi; |
dmcohen24 | 0:1802ead3667e | 13 | |
mfillinois | 6:f2c616fa9ffe | 14 | DigitalOut led1(LED1); |
mfillinois | 6:f2c616fa9ffe | 15 | DigitalOut led2(LED2); |
mfillinois | 6:f2c616fa9ffe | 16 | DigitalOut led3(LED3); |
mfillinois | 6:f2c616fa9ffe | 17 | DigitalOut led4(LED4); |
dmcohen24 | 0:1802ead3667e | 18 | |
mfillinois | 5:b77b678ed22f | 19 | InterruptIn event(p26); |
dmcohen24 | 3:0359b918f658 | 20 | |
dmcohen24 | 3:0359b918f658 | 21 | SI1143 sensor1(i2c, p30, p29, 0x01); |
mfillinois | 5:b77b678ed22f | 22 | //SI1143 sensor2(i2c, p25, p26, 0x02); // p25, p26 |
dmcohen24 | 3:0359b918f658 | 23 | |
dmcohen24 | 3:0359b918f658 | 24 | //InterruptIn prox_meas(p26); //26 |
dmcohen24 | 3:0359b918f658 | 25 | int sense1a, sense1b, sense2a, sense2b; |
mfillinois | 6:f2c616fa9ffe | 26 | //int NN = 500; |
mfillinois | 6:f2c616fa9ffe | 27 | int sensor1alog[500]; |
mfillinois | 6:f2c616fa9ffe | 28 | int sensor1blog[500]; |
mfillinois | 6:f2c616fa9ffe | 29 | int whileflag = 1; |
dmcohen24 | 2:8798491332ed | 30 | |
mfillinois | 5:b77b678ed22f | 31 | //int total = 1000; |
mfillinois | 5:b77b678ed22f | 32 | int countingstuffpoop = 0; |
mfillinois | 5:b77b678ed22f | 33 | |
mfillinois | 5:b77b678ed22f | 34 | void meas_int() |
mfillinois | 5:b77b678ed22f | 35 | { |
dmcohen24 | 2:8798491332ed | 36 | led1 = 1; |
mfillinois | 5:b77b678ed22f | 37 | sense1a = sensor1.read_ps1(); |
mfillinois | 5:b77b678ed22f | 38 | sense1b = sensor1.read_ps2(); |
mfillinois | 5:b77b678ed22f | 39 | //sense2a = sensor2.get_ps1(1); |
mfillinois | 5:b77b678ed22f | 40 | //sense2b = sensor2.get_ps2(1); |
mfillinois | 5:b77b678ed22f | 41 | //bt.printf("%d, %d;\r\n",sense1a, sense1b); |
mfillinois | 5:b77b678ed22f | 42 | //wait(0.001); |
mfillinois | 6:f2c616fa9ffe | 43 | |
mfillinois | 5:b77b678ed22f | 44 | countingstuffpoop++; |
mfillinois | 6:f2c616fa9ffe | 45 | if(countingstuffpoop < 500) |
mfillinois | 5:b77b678ed22f | 46 | { |
mfillinois | 5:b77b678ed22f | 47 | led4 = 0; |
mfillinois | 6:f2c616fa9ffe | 48 | sensor1alog[countingstuffpoop-1] = sense1a; |
mfillinois | 6:f2c616fa9ffe | 49 | sensor1blog[countingstuffpoop-1] = sense1b; |
mfillinois | 5:b77b678ed22f | 50 | } |
mfillinois | 6:f2c616fa9ffe | 51 | else |
mfillinois | 6:f2c616fa9ffe | 52 | { |
mfillinois | 6:f2c616fa9ffe | 53 | __disable_irq(); |
mfillinois | 6:f2c616fa9ffe | 54 | whileflag = 0; |
mfillinois | 6:f2c616fa9ffe | 55 | } |
mfillinois | 6:f2c616fa9ffe | 56 | |
mfillinois | 5:b77b678ed22f | 57 | sensor1.clear_int(); |
dmcohen24 | 3:0359b918f658 | 58 | led1 = 0; |
dmcohen24 | 2:8798491332ed | 59 | } |
dmcohen24 | 2:8798491332ed | 60 | |
dmcohen24 | 0:1802ead3667e | 61 | int main() |
mfillinois | 6:f2c616fa9ffe | 62 | { |
dmcohen24 | 0:1802ead3667e | 63 | // Setup the baseline |
dmcohen24 | 3:0359b918f658 | 64 | //sensor1.restart(i2c, 0x01); |
dmcohen24 | 3:0359b918f658 | 65 | //printf("%d ",sensor1.adrs); |
dmcohen24 | 3:0359b918f658 | 66 | //sensor2.restart(i2c, 0x02); |
mfillinois | 6:f2c616fa9ffe | 67 | //printf("%d\r\n",sensor2.adrs); |
dmcohen24 | 3:0359b918f658 | 68 | led2 = 0; |
mfillinois | 6:f2c616fa9ffe | 69 | wait(10); |
mfillinois | 6:f2c616fa9ffe | 70 | |
mfillinois | 5:b77b678ed22f | 71 | event.fall(&meas_int); |
mfillinois | 5:b77b678ed22f | 72 | //timer.attach(&meas_int, 0.01); |
mfillinois | 5:b77b678ed22f | 73 | sensor1.start_ps_auto(); |
mfillinois | 5:b77b678ed22f | 74 | led4 = 1; |
mfillinois | 6:f2c616fa9ffe | 75 | pi.left(0.1); |
dmcohen24 | 3:0359b918f658 | 76 | |
mfillinois | 6:f2c616fa9ffe | 77 | while(whileflag) |
dmcohen24 | 0:1802ead3667e | 78 | { |
dmcohen24 | 0:1802ead3667e | 79 | // Read each led sensor |
dmcohen24 | 2:8798491332ed | 80 | //sense1 = sensor.get_ps1(1); |
mfillinois | 6:f2c616fa9ffe | 81 | |
dmcohen24 | 0:1802ead3667e | 82 | //Numeriacl output through terminal |
dmcohen24 | 2:8798491332ed | 83 | led1 = 0; |
dmcohen24 | 3:0359b918f658 | 84 | led2 = 0; |
dmcohen24 | 0:1802ead3667e | 85 | } |
mfillinois | 6:f2c616fa9ffe | 86 | |
mfillinois | 6:f2c616fa9ffe | 87 | pi.stop(); |
mfillinois | 6:f2c616fa9ffe | 88 | led1 = 1; |
mfillinois | 6:f2c616fa9ffe | 89 | wait(0.3); |
mfillinois | 6:f2c616fa9ffe | 90 | led1 = 0; |
mfillinois | 6:f2c616fa9ffe | 91 | wait(0.3); |
mfillinois | 6:f2c616fa9ffe | 92 | led1 = 1; |
mfillinois | 6:f2c616fa9ffe | 93 | bt.printf("d = ["); |
mfillinois | 6:f2c616fa9ffe | 94 | for (int i = 0; i < 500; i++) |
mfillinois | 6:f2c616fa9ffe | 95 | { |
mfillinois | 6:f2c616fa9ffe | 96 | bt.printf("%d, %d;\r\n", sensor1alog[i], sensor1blog[i]); |
mfillinois | 6:f2c616fa9ffe | 97 | //bt.printf("%d;\r\n", sensorlog[i]); |
mfillinois | 6:f2c616fa9ffe | 98 | } |
mfillinois | 6:f2c616fa9ffe | 99 | bt.printf("0, 0];"); |
mfillinois | 6:f2c616fa9ffe | 100 | led1 = 1; |
mfillinois | 6:f2c616fa9ffe | 101 | wait(0.3); |
mfillinois | 6:f2c616fa9ffe | 102 | led1 = 0; |
mfillinois | 6:f2c616fa9ffe | 103 | wait(0.3); |
mfillinois | 6:f2c616fa9ffe | 104 | led1 = 1; |
dmcohen24 | 3:0359b918f658 | 105 | } |