AresENSEA-CDF2020
/
AresCDFMainCode_us2
Test
main.cpp@20:7d206773f39e, 2020-10-20 (annotated)
- Committer:
- Nanaud
- Date:
- Tue Oct 20 17:53:32 2020 +0000
- Revision:
- 20:7d206773f39e
- Parent:
- 19:c419033c0967
- Child:
- 21:e5f0f5abb5ae
Fonctionnel, detection a ameliorer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Nanaud | 1:2fe8c402ee79 | 1 | // Nom du fichier : main.cpp |
Nanaud | 0:dc036b67c87c | 2 | #include "pins.h" |
Nanaud | 0:dc036b67c87c | 3 | |
Nanaud | 20:7d206773f39e | 4 | //#define TPS_DRAPEAU 20 // 95 |
Nanaud | 20:7d206773f39e | 5 | //#define TPS_FIN 100 |
Nanaud | 20:7d206773f39e | 6 | |
Nanaud | 20:7d206773f39e | 7 | Ticker TimerGlobal; |
Nanaud | 20:7d206773f39e | 8 | int cptGlobal = 0; |
Nanaud | 20:7d206773f39e | 9 | |
Nanaud | 20:7d206773f39e | 10 | bool Match = 0; |
Nanaud | 20:7d206773f39e | 11 | DigitalOut led(LED1); |
Nanaud | 20:7d206773f39e | 12 | DigitalIn tirette(PC_8); |
Nanaud | 20:7d206773f39e | 13 | |
Nanaud | 14:dd3c756c6d48 | 14 | void btnFct() |
Nanaud | 14:dd3c756c6d48 | 15 | { |
Nanaud | 6:ea6b30c4bb01 | 16 | mot_dis(); |
Nanaud | 6:ea6b30c4bb01 | 17 | aff_cd[0] = 0; |
Nanaud | 6:ea6b30c4bb01 | 18 | aff_cd[1] = 0; |
Nanaud | 14:dd3c756c6d48 | 19 | |
Nanaud | 6:ea6b30c4bb01 | 20 | pc.printf("comptG = %d\r\n",comptG); |
Nanaud | 6:ea6b30c4bb01 | 21 | pc.printf("comptD = %d\r\n",comptD); |
Nanaud | 6:ea6b30c4bb01 | 22 | bt.printf("comptG = %d\r\n",comptG); |
Nanaud | 6:ea6b30c4bb01 | 23 | bt.printf("comptD = %d\r\n",comptD); |
Nanaud | 6:ea6b30c4bb01 | 24 | } |
Nanaud | 6:ea6b30c4bb01 | 25 | |
Nanaud | 20:7d206773f39e | 26 | void fctCptGlobal() |
Nanaud | 20:7d206773f39e | 27 | { |
Nanaud | 20:7d206773f39e | 28 | cptGlobal++; |
Nanaud | 20:7d206773f39e | 29 | |
Nanaud | 20:7d206773f39e | 30 | if(cptGlobal==95) { |
Nanaud | 20:7d206773f39e | 31 | FlagGOTO(0); |
Nanaud | 20:7d206773f39e | 32 | } |
Nanaud | 20:7d206773f39e | 33 | |
Nanaud | 20:7d206773f39e | 34 | if(cptGlobal>=100) { |
Nanaud | 20:7d206773f39e | 35 | fnc=0; |
Nanaud | 20:7d206773f39e | 36 | } |
Nanaud | 20:7d206773f39e | 37 | } |
Nanaud | 20:7d206773f39e | 38 | |
Nanaud | 19:c419033c0967 | 39 | /* |
Nanaud | 19:c419033c0967 | 40 | void cordonDem() |
Nanaud | 19:c419033c0967 | 41 | { |
Nanaud | 19:c419033c0967 | 42 | indice++; |
Nanaud | 19:c419033c0967 | 43 | fnc = objEtape[indice]; |
Nanaud | 19:c419033c0967 | 44 | xC = objX[indice]; |
Nanaud | 19:c419033c0967 | 45 | yC = objY[indice]; |
Nanaud | 19:c419033c0967 | 46 | mot_en(); |
Nanaud | 20:7d206773f39e | 47 | myled = 0; |
Nanaud | 19:c419033c0967 | 48 | } |
Nanaud | 19:c419033c0967 | 49 | */ |
Nanaud | 19:c419033c0967 | 50 | |
Nanaud | 20:7d206773f39e | 51 | |
Nanaud | 4:ad9b7355332e | 52 | int main() |
Nanaud | 4:ad9b7355332e | 53 | { |
Nanaud | 20:7d206773f39e | 54 | captUS_init(); |
Nanaud | 20:7d206773f39e | 55 | FlagGOTO(90); |
Nanaud | 20:7d206773f39e | 56 | TimerGlobal.attach(&fctCptGlobal, 1.0); |
Nanaud | 20:7d206773f39e | 57 | |
Nanaud | 20:7d206773f39e | 58 | tirette.mode(PullDown); |
Nanaud | 20:7d206773f39e | 59 | //myled = 1; |
Nanaud | 20:7d206773f39e | 60 | |
Nanaud | 0:dc036b67c87c | 61 | pc.printf("\r\nAresCDFMainCode\r\n"); |
Nanaud | 4:ad9b7355332e | 62 | bt.printf("\r\nAresCDFMainCode\r\n"); |
Nanaud | 4:ad9b7355332e | 63 | |
Nanaud | 6:ea6b30c4bb01 | 64 | btn.rise(&btnFct); |
Nanaud | 6:ea6b30c4bb01 | 65 | |
Nanaud | 1:2fe8c402ee79 | 66 | // debug |
Nanaud | 1:2fe8c402ee79 | 67 | pc.attach(&serialIT); // Interruption liaison série |
Nanaud | 4:ad9b7355332e | 68 | bt.attach(&bluetoothIT); // Interruption bluetooth |
Nanaud | 6:ea6b30c4bb01 | 69 | pc.baud(9600); |
Nanaud | 6:ea6b30c4bb01 | 70 | pc.format(8,SerialBase::None,1); |
Nanaud | 6:ea6b30c4bb01 | 71 | bt.baud(9600); |
Nanaud | 6:ea6b30c4bb01 | 72 | bt.format(8,SerialBase::None,1); |
Nanaud | 6:ea6b30c4bb01 | 73 | |
Nanaud | 20:7d206773f39e | 74 | ticker_US.attach(&captUS_trig,0.2); // On apelle cette fonction toutes 0.2 secondes |
Nanaud | 10:0714feaaaee1 | 75 | //ticker_affUS.attach(&affUltrasons,1.0); |
Nanaud | 16:ae65ce77b1f9 | 76 | //ticker_affcd.attach(&affCodeurs,1.0); |
Nanaud | 16:ae65ce77b1f9 | 77 | //ticker_odo.attach(&odo2,0.02); |
Nanaud | 19:c419033c0967 | 78 | ticker_asserv.attach(&asserv,0.015); |
Nanaud | 14:dd3c756c6d48 | 79 | //ticker_affodo.attach(&affOdo,1.0); |
Nanaud | 4:ad9b7355332e | 80 | |
Nanaud | 1:2fe8c402ee79 | 81 | // Init capteurs à ultrasons |
Nanaud | 1:2fe8c402ee79 | 82 | captUS_init(); |
Nanaud | 0:dc036b67c87c | 83 | echo1.rise(&echoRise1); |
Nanaud | 0:dc036b67c87c | 84 | echo1.fall(&echoFall1); |
Nanaud | 0:dc036b67c87c | 85 | echo2.rise(&echoRise2); |
Nanaud | 0:dc036b67c87c | 86 | echo2.fall(&echoFall2); |
Nanaud | 0:dc036b67c87c | 87 | echo3.rise(&echoRise3); |
Nanaud | 0:dc036b67c87c | 88 | echo3.fall(&echoFall3); |
Nanaud | 0:dc036b67c87c | 89 | echo4.rise(&echoRise4); |
Nanaud | 0:dc036b67c87c | 90 | echo4.fall(&echoFall4); |
Nanaud | 0:dc036b67c87c | 91 | echo5.rise(&echoRise5); |
Nanaud | 0:dc036b67c87c | 92 | echo5.fall(&echoFall5); |
Nanaud | 0:dc036b67c87c | 93 | echo6.rise(&echoRise6); |
Nanaud | 0:dc036b67c87c | 94 | echo6.fall(&echoFall6); |
Nanaud | 4:ad9b7355332e | 95 | |
Nanaud | 1:2fe8c402ee79 | 96 | // Init DRV8825 |
Nanaud | 0:dc036b67c87c | 97 | drv_init(); |
Nanaud | 4:ad9b7355332e | 98 | |
Nanaud | 4:ad9b7355332e | 99 | // Init codeurs |
Nanaud | 0:dc036b67c87c | 100 | cdgA.rise(&cdgaRise); |
Nanaud | 6:ea6b30c4bb01 | 101 | cddA.rise(&cddaRise); |
Nanaud | 0:dc036b67c87c | 102 | cdgA.mode(PullUp); |
Nanaud | 6:ea6b30c4bb01 | 103 | cddA.mode(PullUp); |
Nanaud | 4:ad9b7355332e | 104 | |
Nanaud | 14:dd3c756c6d48 | 105 | while(1) { |
Nanaud | 20:7d206773f39e | 106 | if (tirette == 1 && Match == 0) { |
Nanaud | 20:7d206773f39e | 107 | Match = 0; |
Nanaud | 20:7d206773f39e | 108 | led = 1; |
Nanaud | 20:7d206773f39e | 109 | } else if (tirette == 0 && Match == 0){ |
Nanaud | 20:7d206773f39e | 110 | Match = 1; |
Nanaud | 20:7d206773f39e | 111 | |
Nanaud | 20:7d206773f39e | 112 | led = 0; |
Nanaud | 20:7d206773f39e | 113 | |
Nanaud | 20:7d206773f39e | 114 | //indice++; |
Nanaud | 20:7d206773f39e | 115 | indice=1; |
Nanaud | 20:7d206773f39e | 116 | fnc = objEtape[indice]; |
Nanaud | 20:7d206773f39e | 117 | xC = objX[indice]; |
Nanaud | 20:7d206773f39e | 118 | yC = objY[indice]; |
Nanaud | 20:7d206773f39e | 119 | cptGlobal = 0; |
Nanaud | 20:7d206773f39e | 120 | //mot_en(); |
Nanaud | 20:7d206773f39e | 121 | } |
Nanaud | 20:7d206773f39e | 122 | |
Nanaud | 20:7d206773f39e | 123 | if (indice>=NbObj) { |
Nanaud | 19:c419033c0967 | 124 | fnc = 0; |
Nanaud | 20:7d206773f39e | 125 | //mot_dis(); |
Nanaud | 19:c419033c0967 | 126 | } |
Nanaud | 19:c419033c0967 | 127 | |
Nanaud | 14:dd3c756c6d48 | 128 | } |
Nanaud | 0:dc036b67c87c | 129 | } |