ライントレーサー制御用のプログラムです.

Dependencies:   mbed

Committer:
Hirotomo777
Date:
Thu Nov 16 06:15:58 2017 +0000
Revision:
0:e9af471e2a2b
?7????????????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Hirotomo777 0:e9af471e2a2b 1 #include "linetracer.h"
Hirotomo777 0:e9af471e2a2b 2 #define K 0.000001 //ハンドルのききの良さを決める定数
Hirotomo777 0:e9af471e2a2b 3 DigitalOut test1(PTB8);
Hirotomo777 0:e9af471e2a2b 4 DigitalOut test2(PTB9);
Hirotomo777 0:e9af471e2a2b 5 DigitalOut test3(PTB10);
Hirotomo777 0:e9af471e2a2b 6 DigitalOut test4(PTB11);
Hirotomo777 0:e9af471e2a2b 7
Hirotomo777 0:e9af471e2a2b 8 void linetracerInit(){
Hirotomo777 0:e9af471e2a2b 9 servoInit();
Hirotomo777 0:e9af471e2a2b 10 sensorInit();
Hirotomo777 0:e9af471e2a2b 11 motorInit();
Hirotomo777 0:e9af471e2a2b 12 start();
Hirotomo777 0:e9af471e2a2b 13 }
Hirotomo777 0:e9af471e2a2b 14
Hirotomo777 0:e9af471e2a2b 15 void linetracerLoop(){
Hirotomo777 0:e9af471e2a2b 16 float pulse;
Hirotomo777 0:e9af471e2a2b 17 pulse = 0.00155;
Hirotomo777 0:e9af471e2a2b 18 int reaction = 0;
Hirotomo777 0:e9af471e2a2b 19 int flag = 0;
Hirotomo777 0:e9af471e2a2b 20 while(1){
Hirotomo777 0:e9af471e2a2b 21 reaction = getReaction();
Hirotomo777 0:e9af471e2a2b 22 /*
Hirotomo777 0:e9af471e2a2b 23 if((reaction & 0b000011) == 0b000000){
Hirotomo777 0:e9af471e2a2b 24 flag++;
Hirotomo777 0:e9af471e2a2b 25 if(flag >= 100){
Hirotomo777 0:e9af471e2a2b 26 wait(0.3);
Hirotomo777 0:e9af471e2a2b 27 stop();
Hirotomo777 0:e9af471e2a2b 28 while(1){
Hirotomo777 0:e9af471e2a2b 29 test1 = 1;
Hirotomo777 0:e9af471e2a2b 30 }
Hirotomo777 0:e9af471e2a2b 31 }
Hirotomo777 0:e9af471e2a2b 32 }
Hirotomo777 0:e9af471e2a2b 33 else{
Hirotomo777 0:e9af471e2a2b 34 flag = 0;
Hirotomo777 0:e9af471e2a2b 35 test1 = 0;
Hirotomo777 0:e9af471e2a2b 36 }
Hirotomo777 0:e9af471e2a2b 37 */
Hirotomo777 0:e9af471e2a2b 38
Hirotomo777 0:e9af471e2a2b 39
Hirotomo777 0:e9af471e2a2b 40 if((reaction & 0b100000) == 0b100000){
Hirotomo777 0:e9af471e2a2b 41 rotate(handle,pulse - K,&pulse);
Hirotomo777 0:e9af471e2a2b 42 test1 = 1;
Hirotomo777 0:e9af471e2a2b 43 }
Hirotomo777 0:e9af471e2a2b 44
Hirotomo777 0:e9af471e2a2b 45
Hirotomo777 0:e9af471e2a2b 46 if((reaction & 0b000100) == 0b000100){
Hirotomo777 0:e9af471e2a2b 47 rotate(handle,pulse + K,&pulse);
Hirotomo777 0:e9af471e2a2b 48 test2 = 1;
Hirotomo777 0:e9af471e2a2b 49 }
Hirotomo777 0:e9af471e2a2b 50
Hirotomo777 0:e9af471e2a2b 51 if((reaction & 0b010000) == 0b010000){
Hirotomo777 0:e9af471e2a2b 52 rotate(handle,pulse - K / 3.0,&pulse);
Hirotomo777 0:e9af471e2a2b 53 test3 = 1;
Hirotomo777 0:e9af471e2a2b 54 }
Hirotomo777 0:e9af471e2a2b 55
Hirotomo777 0:e9af471e2a2b 56 if((reaction & 0b001000) == 0b001000){
Hirotomo777 0:e9af471e2a2b 57 rotate(handle,pulse + K / 3.0,&pulse);
Hirotomo777 0:e9af471e2a2b 58 test4 = 1;
Hirotomo777 0:e9af471e2a2b 59 }
Hirotomo777 0:e9af471e2a2b 60
Hirotomo777 0:e9af471e2a2b 61 test1 = 0;
Hirotomo777 0:e9af471e2a2b 62 test2 = 0;
Hirotomo777 0:e9af471e2a2b 63 test3 = 0;
Hirotomo777 0:e9af471e2a2b 64 test4 = 0;
Hirotomo777 0:e9af471e2a2b 65
Hirotomo777 0:e9af471e2a2b 66 /*
Hirotomo777 0:e9af471e2a2b 67 if((reaction & 0b010100) == 0b000000){
Hirotomo777 0:e9af471e2a2b 68 rotate(handle,pulse + K * 0.5,&pulse);
Hirotomo777 0:e9af471e2a2b 69 }
Hirotomo777 0:e9af471e2a2b 70
Hirotomo777 0:e9af471e2a2b 71 if((reaction & 0b1010000) == 0b000000){
Hirotomo777 0:e9af471e2a2b 72 rotate(handle,pulse - K * 0.5,&pulse);
Hirotomo777 0:e9af471e2a2b 73 }
Hirotomo777 0:e9af471e2a2b 74 */
Hirotomo777 0:e9af471e2a2b 75 }
Hirotomo777 0:e9af471e2a2b 76 }