ROBOSTEP_5期 / Mbed 2 deprecated George_Master_Param

Dependencies:   mbed robot

Committer:
yuto17320508
Date:
Wed May 15 09:57:11 2019 +0000
Revision:
38:89d2a9e6c96f
Parent:
35:04699b49c463
Child:
39:7f3cc8f47710
Child:
44:39dfefb929eb
Child:
45:6df20a8f4b21
Child:
48:d9f3ce701aca
param

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eri 0:c1476d342c13 1 #include "mbed.h"
shimizuta 17:2b3fa9b1a05b 2 #include "debug.h"
eri 0:c1476d342c13 3 #include "microinfinity.h"
shimizuta 21:14133581387b 4 #include "sensors.h"
shimizuta 22:0ed9de464f40 5 #include "moves.h"
shimizuta 21:14133581387b 6
yuto17320508 25:c740e6fd5dab 7 void StateFlow(int i);
yuto17320508 32:aee87dcaf7ca 8 void SetMode();
yuto17320508 32:aee87dcaf7ca 9 void Start();
yuto17320508 32:aee87dcaf7ca 10 void NoHandSignal();
yuto17320508 33:2dbbe198adaf 11
yuto17320508 32:aee87dcaf7ca 12 int start_state=0;
shimizuta 26:5fb1aa9cb7f0 13
kageyuta 1:86c4c38abe40 14 int main()
kageyuta 1:86c4c38abe40 15 {
shimizuta 26:5fb1aa9cb7f0 16 //setup関連
shimizuta 22:0ed9de464f40 17 can1.frequency(1000000);
shimizuta 22:0ed9de464f40 18 SetupMoves();
yuto17320508 25:c740e6fd5dab 19 set_gyro();
yuto17320508 38:89d2a9e6c96f 20
yuto17320508 32:aee87dcaf7ca 21 /*while(1)
yuto17320508 32:aee87dcaf7ca 22 {
yuto17320508 32:aee87dcaf7ca 23 printf("switch 1:%d 2:%d 3:%d LR:%d \r\n", switch_modes[0].read(),switch_modes[1].read(),switch_modes[2].read(),switch_LR.read());
yuto17320508 38:89d2a9e6c96f 24 wait(0.1);
yuto17320508 32:aee87dcaf7ca 25 }*/
yuto17320508 32:aee87dcaf7ca 26 printf("hand read:%d\r\n",hand.read());
yuto17320508 38:89d2a9e6c96f 27
shimizuta 22:0ed9de464f40 28 printf("reset standby\r\n");
shimizuta 26:5fb1aa9cb7f0 29 reset();//足をリセット位置に移動
shimizuta 22:0ed9de464f40 30 printf("bus standby\r\n");
yuto17320508 5:63462d696256 31 while(1) {
yuto17320508 5:63462d696256 32 if(bus_in.read() == 1) break;
yuto17320508 3:7a608fbd3bcd 33 }
shimizuta 22:0ed9de464f40 34 printf("bus is %d\r\n", bus_in.read());
yuto17320508 12:9a5de6adae9c 35 wait(0.5);
shimizuta 26:5fb1aa9cb7f0 36 //一歩動かして初期位置へ
yuto17320508 25:c740e6fd5dab 37 motor_lo.setDutyLimit(0.1);
yuto17320508 25:c740e6fd5dab 38 motor_li.setDutyLimit(0.1);
yuto17320508 12:9a5de6adae9c 39 straight();
yuto17320508 38:89d2a9e6c96f 40
yuto17320508 38:89d2a9e6c96f 41
shimizuta 26:5fb1aa9cb7f0 42 // mode選択
yuto17320508 32:aee87dcaf7ca 43 Start();
yuto17320508 32:aee87dcaf7ca 44 //SetMode();
yuto17320508 32:aee87dcaf7ca 45
yuto17320508 38:89d2a9e6c96f 46 if(RightOrLeft == 0) {
yuto17320508 32:aee87dcaf7ca 47 if(start_state == 0) theta0 = -degree/100.0;
yuto17320508 32:aee87dcaf7ca 48 else if(start_state == 1) theta0 = -degree/100.0 - 45;
yuto17320508 32:aee87dcaf7ca 49 else if(start_state == 2) theta0 = -degree/100.0 - 90;
yuto17320508 32:aee87dcaf7ca 50 else if(start_state == 3) theta0 = -degree/100.0 + 90;
yuto17320508 32:aee87dcaf7ca 51 else printf("state_error");
yuto17320508 38:89d2a9e6c96f 52 } else {
yuto17320508 32:aee87dcaf7ca 53 if(start_state == 0) theta0 = -degree/100.0;
yuto17320508 32:aee87dcaf7ca 54 else if(start_state == 1) theta0 = -degree/100.0 + 45;
yuto17320508 32:aee87dcaf7ca 55 else if(start_state == 2) theta0 = -degree/100.0 + 90;
yuto17320508 32:aee87dcaf7ca 56 else if(start_state == 3) theta0 = -degree/100.0 - 90;
yuto17320508 32:aee87dcaf7ca 57 else printf("state_error");
yuto17320508 32:aee87dcaf7ca 58 }
yuto17320508 33:2dbbe198adaf 59 FileOpen();
yuto17320508 32:aee87dcaf7ca 60 printf("LR:%d StateFlow:%d\r\n", RightOrLeft,start_state);
yuto17320508 25:c740e6fd5dab 61 StateFlow(start_state);
yuto17320508 33:2dbbe198adaf 62 FileClose();
yuto17320508 25:c740e6fd5dab 63 }
yuto17320508 25:c740e6fd5dab 64
yuto17320508 25:c740e6fd5dab 65 void StateFlow(int i)
yuto17320508 25:c740e6fd5dab 66 {
yuto17320508 25:c740e6fd5dab 67 switch(i) {
yuto17320508 25:c740e6fd5dab 68 case 0://最初の直線
yuto17320508 25:c740e6fd5dab 69 printf("go straight!!!!!!!!!!\r\n");
yuto17320508 38:89d2a9e6c96f 70 motor_lo.setDutyLimit(0.6);
yuto17320508 38:89d2a9e6c96f 71 motor_li.setDutyLimit(0.6);
yuto17320508 32:aee87dcaf7ca 72 for(int i = 0; i < 30; i++) {
yuto17320508 32:aee87dcaf7ca 73 straightAndInfinity(0, 7);
yuto17320508 25:c740e6fd5dab 74 }
yuto17320508 25:c740e6fd5dab 75 printf("get distance mode");
yuto17320508 25:c740e6fd5dab 76 for(int i=0; i<1; ++i) {
MazeTaka 34:0a8ae7f92262 77 while(Hcsr04BackWithEc() < 320) {//300
yuto17320508 32:aee87dcaf7ca 78 straightAndInfinity(0, 7);
yuto17320508 25:c740e6fd5dab 79 }
yuto17320508 25:c740e6fd5dab 80 }
yuto17320508 25:c740e6fd5dab 81 //段差前旋回
yuto17320508 25:c740e6fd5dab 82 motor_lo.setDutyLimit(0.5);//0.5
yuto17320508 25:c740e6fd5dab 83 motor_li.setDutyLimit(0.5);
yuto17320508 38:89d2a9e6c96f 84
yuto17320508 32:aee87dcaf7ca 85 if(RightOrLeft == 0) turn(35.0);
yuto17320508 32:aee87dcaf7ca 86 else turn(-35.0);
yuto17320508 25:c740e6fd5dab 87 case 1://段差前
yuto17320508 25:c740e6fd5dab 88 printf("climb!!!!!!!!!!\r\n");
yuto17320508 38:89d2a9e6c96f 89 //段差乗り越え
yuto17320508 25:c740e6fd5dab 90 while(get_dist_forward() < 60) {
yuto17320508 32:aee87dcaf7ca 91 if(RightOrLeft == 0) straightAndInfinity(45, 5);
yuto17320508 32:aee87dcaf7ca 92 else straightAndInfinity(-45, 5);
yuto17320508 25:c740e6fd5dab 93 }
yuto17320508 32:aee87dcaf7ca 94 if(RightOrLeft == 0) phasing(45.0);
yuto17320508 32:aee87dcaf7ca 95 else phasing(-45.0);
yuto17320508 38:89d2a9e6c96f 96
yuto17320508 38:89d2a9e6c96f 97 motor_lo.setDutyLimit(0.2);//0.5
yuto17320508 38:89d2a9e6c96f 98 motor_li.setDutyLimit(0.2);
yuto17320508 38:89d2a9e6c96f 99
yuto17320508 25:c740e6fd5dab 100 for(int i= 0; i<14; ++i) straight();
yuto17320508 25:c740e6fd5dab 101 while(get_dist_back() > 80) straight();
yuto17320508 25:c740e6fd5dab 102 //段差後旋回
yuto17320508 32:aee87dcaf7ca 103 motor_lo.setDutyLimit(0.5);//0.5
yuto17320508 32:aee87dcaf7ca 104 motor_li.setDutyLimit(0.5);
yuto17320508 38:89d2a9e6c96f 105
yuto17320508 32:aee87dcaf7ca 106 if(RightOrLeft == 0) turn(85.0);
yuto17320508 32:aee87dcaf7ca 107 else turn(-85.0);
yuto17320508 38:89d2a9e6c96f 108
yuto17320508 25:c740e6fd5dab 109 case 2://段差直後
yuto17320508 25:c740e6fd5dab 110 printf("go lope!!!!!!!!!!\r\n");
yuto17320508 25:c740e6fd5dab 111 //前進
yuto17320508 38:89d2a9e6c96f 112 motor_lo.setDutyLimit(0.6);
yuto17320508 38:89d2a9e6c96f 113 motor_li.setDutyLimit(0.6);
yuto17320508 38:89d2a9e6c96f 114 for(int i=0; i<13; ++i) {
yuto17320508 38:89d2a9e6c96f 115 if(RightOrLeft == 0) straightAndInfinity(90.0, 7.0);
yuto17320508 38:89d2a9e6c96f 116 else straightAndInfinity(-90.0, 7.0);
yuto17320508 38:89d2a9e6c96f 117 }
yuto17320508 25:c740e6fd5dab 118 for(int i=0; i<3; ++i) {
yuto17320508 25:c740e6fd5dab 119 while(get_dist_forward() > 60) {
yuto17320508 32:aee87dcaf7ca 120 if(RightOrLeft == 0) straightAndInfinity(90.0, 7.0);
yuto17320508 32:aee87dcaf7ca 121 else straightAndInfinity(-90.0, 7.0);
yuto17320508 25:c740e6fd5dab 122 }
yuto17320508 25:c740e6fd5dab 123 }
yuto17320508 25:c740e6fd5dab 124 //ロープ前旋回
yuto17320508 25:c740e6fd5dab 125 printf("before roop deg:%.3f\r\n",degree0);
yuto17320508 25:c740e6fd5dab 126 turn(0);
yuto17320508 25:c740e6fd5dab 127 //ロープ位置ジャストまで前進
yuto17320508 25:c740e6fd5dab 128 for(int i=0; i<3; ++i) {
yuto17320508 32:aee87dcaf7ca 129 straightAndInfinity(0.0, 7.0);
yuto17320508 25:c740e6fd5dab 130 }
yuto17320508 25:c740e6fd5dab 131 for(int i=0; i<2; ++i) {
yuto17320508 25:c740e6fd5dab 132 while(get_dist_back() < 100) {
yuto17320508 32:aee87dcaf7ca 133 straightAndInfinity(0.0, 7.0);
yuto17320508 25:c740e6fd5dab 134 }
yuto17320508 25:c740e6fd5dab 135 }
yuto17320508 31:ed4249a288d7 136 phasing(0.0);
yuto17320508 25:c740e6fd5dab 137 //ロープ
yuto17320508 32:aee87dcaf7ca 138 while(switch_modes[2].read() == 0) {
yuto17320508 32:aee87dcaf7ca 139 straightAndInfinity(0, 7);
yuto17320508 25:c740e6fd5dab 140 //straight();
yuto17320508 25:c740e6fd5dab 141 }
yuto17320508 32:aee87dcaf7ca 142 printf("uhai stand by ok!!!!!!!!!!\r\n");
yuto17320508 32:aee87dcaf7ca 143 NoHandSignal();
yuto17320508 25:c740e6fd5dab 144 case 3://坂
yuto17320508 32:aee87dcaf7ca 145 printf("last spart!!!!!!!!");
yuto17320508 38:89d2a9e6c96f 146
yuto17320508 32:aee87dcaf7ca 147 if(RightOrLeft == 0) theta0 = -degree/100.0+90;
yuto17320508 32:aee87dcaf7ca 148 else theta0 = -degree/100.0-90;
yuto17320508 32:aee87dcaf7ca 149 motor_lo.setDutyLimit(0.2);//0.3
yuto17320508 32:aee87dcaf7ca 150 motor_li.setDutyLimit(0.2);
yuto17320508 38:89d2a9e6c96f 151 for(int i=0; i<20; ++i) {
yuto17320508 32:aee87dcaf7ca 152 if(RightOrLeft == 0) straightAndInfinity(-90, 15);//straight();//climbAndInfinity(-90,5);
yuto17320508 32:aee87dcaf7ca 153 else straightAndInfinity(90, 15);
yuto17320508 25:c740e6fd5dab 154 }
yuto17320508 25:c740e6fd5dab 155 printf("wall standby");
yuto17320508 33:2dbbe198adaf 156 motor_lo.setDutyLimit(0.3);//0.3
yuto17320508 33:2dbbe198adaf 157 motor_li.setDutyLimit(0.3);
yuto17320508 25:c740e6fd5dab 158 while(get_dist_back() < 250) {
shimizuta 27:d392a95f4799 159 // straight();
yuto17320508 32:aee87dcaf7ca 160 if(RightOrLeft == 0) climbAndInfinity(-90,15);
yuto17320508 32:aee87dcaf7ca 161 else climbAndInfinity(90,15);
yuto17320508 25:c740e6fd5dab 162 }
yuto17320508 25:c740e6fd5dab 163 for(int i=0; i<1; ++i) {
yuto17320508 31:ed4249a288d7 164 while(get_dist_forward() > 60) {
yuto17320508 25:c740e6fd5dab 165 //straight();
yuto17320508 32:aee87dcaf7ca 166 if(RightOrLeft == 0) climbAndInfinity(-90,15);
yuto17320508 32:aee87dcaf7ca 167 else climbAndInfinity(90,15);
yuto17320508 25:c740e6fd5dab 168 }
yuto17320508 25:c740e6fd5dab 169 }
yuto17320508 25:c740e6fd5dab 170 hand_mode = GOAL;
shimizuta 30:231e6584afe9 171 stop();
yuto17320508 32:aee87dcaf7ca 172 printf("uhai!!!!!!!!!!!!!!!/r/n");
yuto17320508 32:aee87dcaf7ca 173 }
yuto17320508 32:aee87dcaf7ca 174 }
yuto17320508 32:aee87dcaf7ca 175 void Start()
yuto17320508 32:aee87dcaf7ca 176 {
yuto17320508 38:89d2a9e6c96f 177 if(hand.read()==0) { //開始時すでにスイッチが押されていた場合
yuto17320508 38:89d2a9e6c96f 178
yuto17320508 32:aee87dcaf7ca 179 SetMode();
yuto17320508 35:04699b49c463 180 hand_mode = G_CLOSE;
yuto17320508 32:aee87dcaf7ca 181 NoHandSignal();
yuto17320508 38:89d2a9e6c96f 182 } else {
yuto17320508 32:aee87dcaf7ca 183 SetMode();
yuto17320508 35:04699b49c463 184 hand_mode = G_OPEN;
yuto17320508 35:04699b49c463 185 stop();//ここで開くことをcanでslaveに送る
yuto17320508 32:aee87dcaf7ca 186 wait_gerege();
yuto17320508 35:04699b49c463 187 hand_mode = G_CLOSE;
yuto17320508 32:aee87dcaf7ca 188 HandMove();
yuto17320508 32:aee87dcaf7ca 189 wait(0.5);
yuto17320508 38:89d2a9e6c96f 190 }
yuto17320508 32:aee87dcaf7ca 191 }
yuto17320508 32:aee87dcaf7ca 192 void SetMode()
yuto17320508 32:aee87dcaf7ca 193 {
yuto17320508 38:89d2a9e6c96f 194 while(get_dist_back() > 50.0) {
yuto17320508 32:aee87dcaf7ca 195 led1 = led2 = led3 = led4 = 0;
yuto17320508 32:aee87dcaf7ca 196 if(switch_modes[2].read()) start_state=3;
yuto17320508 32:aee87dcaf7ca 197 else if(switch_modes[1].read()) start_state=2;
yuto17320508 32:aee87dcaf7ca 198 else if(switch_modes[0].read()) start_state=1;
yuto17320508 32:aee87dcaf7ca 199 else start_state=0;
yuto17320508 38:89d2a9e6c96f 200
yuto17320508 38:89d2a9e6c96f 201 if(switch_LR.read()) RightOrLeft = 1;
yuto17320508 38:89d2a9e6c96f 202 else RightOrLeft = 0;
yuto17320508 38:89d2a9e6c96f 203
yuto17320508 32:aee87dcaf7ca 204 if(start_state==0)led4 = 1;
yuto17320508 32:aee87dcaf7ca 205 else if(start_state==1)led3 = 1;
yuto17320508 32:aee87dcaf7ca 206 else if(start_state==2)led2 = 1;
yuto17320508 32:aee87dcaf7ca 207 else if(start_state==3)led1 = 1;
yuto17320508 38:89d2a9e6c96f 208
yuto17320508 32:aee87dcaf7ca 209 }
yuto17320508 32:aee87dcaf7ca 210 printf("mode is %d RightOrLeft is %d \r\n", start_state, RightOrLeft);
yuto17320508 32:aee87dcaf7ca 211 led1 = led2 = led3 = led4 = 1;
yuto17320508 32:aee87dcaf7ca 212 }
yuto17320508 32:aee87dcaf7ca 213 void NoHandSignal()
yuto17320508 32:aee87dcaf7ca 214 {
yuto17320508 38:89d2a9e6c96f 215 while(get_dist_back() > 40.0) {
yuto17320508 32:aee87dcaf7ca 216 wait(0.01);
yuto17320508 32:aee87dcaf7ca 217 }
yuto17320508 38:89d2a9e6c96f 218 while(get_dist_back() < 40.0) {
yuto17320508 32:aee87dcaf7ca 219 wait(0.01);
shimizuta 22:0ed9de464f40 220 }
shimizuta 22:0ed9de464f40 221 }