Ryota Kotani / Mbed 2 deprecated ROS_R2_YONRIN

Dependencies:   mbed URF MD_MDDS30_oit_ ros_lib_melodic

Committer:
akihiron
Date:
Tue May 03 08:02:58 2022 +0000
Revision:
0:450a7208c682
05/03

Who changed what in which revision?

UserRevisionLine numberNew contents of line
akihiron 0:450a7208c682 1 #include "mbed.h"
akihiron 0:450a7208c682 2 #include "URF.h"
akihiron 0:450a7208c682 3
akihiron 0:450a7208c682 4 Serial pc(USBTX, USBRX, 115200);
akihiron 0:450a7208c682 5
akihiron 0:450a7208c682 6 URF usdRight(D6);
akihiron 0:450a7208c682 7 URF usdLeft(D8);
akihiron 0:450a7208c682 8
akihiron 0:450a7208c682 9 Ticker update;
akihiron 0:450a7208c682 10
akihiron 0:450a7208c682 11 DigitalOut led(LED1);
akihiron 0:450a7208c682 12 DigitalOut led2(PC_4);
akihiron 0:450a7208c682 13
akihiron 0:450a7208c682 14 DigitalIn btn(USER_BUTTON);
akihiron 0:450a7208c682 15
akihiron 0:450a7208c682 16 void inter(void)
akihiron 0:450a7208c682 17 {
akihiron 0:450a7208c682 18 usdRight.send();
akihiron 0:450a7208c682 19 usdLeft.send();
akihiron 0:450a7208c682 20 }
akihiron 0:450a7208c682 21
akihiron 0:450a7208c682 22 void URF(int dataRight, int dataLeft){
akihiron 0:450a7208c682 23 if(dataRight>100 && dataRight<=230){
akihiron 0:450a7208c682 24 pc.printf("right slow\n");
akihiron 0:450a7208c682 25 //Yonrin(-0.3f, 0);
akihiron 0:450a7208c682 26 if(dataLeft>100 && dataLeft<=230){
akihiron 0:450a7208c682 27 pc.printf("left slow\n");
akihiron 0:450a7208c682 28 //Yonrin(0.3f, 0);
akihiron 0:450a7208c682 29 }
akihiron 0:450a7208c682 30 else if(dataLeft<=100){
akihiron 0:450a7208c682 31 pc.printf("left stop\n");
akihiron 0:450a7208c682 32 //Yonrin(0);
akihiron 0:450a7208c682 33 }
akihiron 0:450a7208c682 34 }
akihiron 0:450a7208c682 35 else if(dataRight<=100){
akihiron 0:450a7208c682 36 pc.printf("right stop\n");
akihiron 0:450a7208c682 37 //Yonrin(0);
akihiron 0:450a7208c682 38 if(dataLeft>100 && dataLeft<=230){
akihiron 0:450a7208c682 39 pc.printf("left slow\n");
akihiron 0:450a7208c682 40 //Yonrin(0.3f, 0);
akihiron 0:450a7208c682 41 }
akihiron 0:450a7208c682 42 else if(dataLeft<=100){
akihiron 0:450a7208c682 43 pc.printf("left stop\n");
akihiron 0:450a7208c682 44 //Yonrin(0);
akihiron 0:450a7208c682 45 }
akihiron 0:450a7208c682 46 }
akihiron 0:450a7208c682 47 else if(dataLeft>100 && dataLeft<=230){
akihiron 0:450a7208c682 48 pc.printf("left slow\n");
akihiron 0:450a7208c682 49 //Yonrin(0.3f, 0);
akihiron 0:450a7208c682 50 if(dataRight>100 && dataRight<=230){
akihiron 0:450a7208c682 51 pc.printf("right slow\n");
akihiron 0:450a7208c682 52 //Yonrin(-0.3f, 0);
akihiron 0:450a7208c682 53 }
akihiron 0:450a7208c682 54 else if(dataRight<=100){
akihiron 0:450a7208c682 55 pc.printf("right stop\n");
akihiron 0:450a7208c682 56 //Yonrin(0);
akihiron 0:450a7208c682 57 }
akihiron 0:450a7208c682 58 }
akihiron 0:450a7208c682 59 else if(dataLeft<=100){
akihiron 0:450a7208c682 60 pc.printf("left stop\n");
akihiron 0:450a7208c682 61 //Yonrin(0);
akihiron 0:450a7208c682 62 if(dataRight>100 && dataRight<=230){
akihiron 0:450a7208c682 63 pc.printf("right slow\n");
akihiron 0:450a7208c682 64 //Yonrin(-0.3f, 0);
akihiron 0:450a7208c682 65 }
akihiron 0:450a7208c682 66 else if(dataRight<=100){
akihiron 0:450a7208c682 67 pc.printf("right stop\n");
akihiron 0:450a7208c682 68 //Yonrin(0);
akihiron 0:450a7208c682 69 }
akihiron 0:450a7208c682 70 }
akihiron 0:450a7208c682 71 }
akihiron 0:450a7208c682 72
akihiron 0:450a7208c682 73 int main(){
akihiron 0:450a7208c682 74 pc.printf("check1\n");
akihiron 0:450a7208c682 75
akihiron 0:450a7208c682 76 update.attach(&inter, 0.06);
akihiron 0:450a7208c682 77
akihiron 0:450a7208c682 78 while(1){
akihiron 0:450a7208c682 79 int dataRight = usdRight.read(mm);
akihiron 0:450a7208c682 80 int dataLeft = usdLeft.read(mm);
akihiron 0:450a7208c682 81 //pc.printf("right: %d, left: %d\n", dataRight, dataLeft);
akihiron 0:450a7208c682 82
akihiron 0:450a7208c682 83 if(dataRight<=230 || dataLeft<=230){
akihiron 0:450a7208c682 84 URF(dataRight,dataLeft);
akihiron 0:450a7208c682 85 }
akihiron 0:450a7208c682 86 }
akihiron 0:450a7208c682 87 }