ROBOSTEP_5期 / Mbed 2 deprecated George_Master_Param

Dependencies:   mbed robot

Committer:
shimizuta
Date:
Fri May 17 02:17:40 2019 +0000
Revision:
42:b00cdc97f492
Parent:
40:23a64e9f46a6
Child:
43:1c180b4516bf
not stop

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 40:23a64e9f46a6 6 using namespace Moves;
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;
shimizuta 39:7f3cc8f47710 51 else printf("state_error\r\n");
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;
shimizuta 39:7f3cc8f47710 57 else printf("state_error\r\n");
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");
shimizuta 42:b00cdc97f492 70 motor_lo.setDutyLimit(0.5);
shimizuta 42:b00cdc97f492 71 motor_li.setDutyLimit(0.5);
yuto17320508 32:aee87dcaf7ca 72 for(int i = 0; i < 30; i++) {
shimizuta 42:b00cdc97f492 73 UnSync::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 //段差前旋回
shimizuta 39:7f3cc8f47710 82 motor_lo.setDutyLimit(0.3);//0.5
shimizuta 39:7f3cc8f47710 83 motor_li.setDutyLimit(0.3);
yuto17320508 32:aee87dcaf7ca 84 if(RightOrLeft == 0) turn(35.0);
yuto17320508 32:aee87dcaf7ca 85 else turn(-35.0);
yuto17320508 25:c740e6fd5dab 86 case 1://段差前
yuto17320508 25:c740e6fd5dab 87 printf("climb!!!!!!!!!!\r\n");
yuto17320508 38:89d2a9e6c96f 88 //段差乗り越え
yuto17320508 25:c740e6fd5dab 89 while(get_dist_forward() < 60) {
yuto17320508 32:aee87dcaf7ca 90 if(RightOrLeft == 0) straightAndInfinity(45, 5);
yuto17320508 32:aee87dcaf7ca 91 else straightAndInfinity(-45, 5);
yuto17320508 25:c740e6fd5dab 92 }
yuto17320508 32:aee87dcaf7ca 93 if(RightOrLeft == 0) phasing(45.0);
yuto17320508 32:aee87dcaf7ca 94 else phasing(-45.0);
yuto17320508 38:89d2a9e6c96f 95
yuto17320508 38:89d2a9e6c96f 96 motor_lo.setDutyLimit(0.2);//0.5
yuto17320508 38:89d2a9e6c96f 97 motor_li.setDutyLimit(0.2);
yuto17320508 38:89d2a9e6c96f 98
yuto17320508 25:c740e6fd5dab 99 for(int i= 0; i<14; ++i) straight();
yuto17320508 25:c740e6fd5dab 100 while(get_dist_back() > 80) straight();
yuto17320508 25:c740e6fd5dab 101 //段差後旋回
yuto17320508 32:aee87dcaf7ca 102 motor_lo.setDutyLimit(0.5);//0.5
yuto17320508 32:aee87dcaf7ca 103 motor_li.setDutyLimit(0.5);
yuto17320508 38:89d2a9e6c96f 104
yuto17320508 32:aee87dcaf7ca 105 if(RightOrLeft == 0) turn(85.0);
yuto17320508 32:aee87dcaf7ca 106 else turn(-85.0);
yuto17320508 38:89d2a9e6c96f 107
yuto17320508 25:c740e6fd5dab 108 case 2://段差直後
yuto17320508 25:c740e6fd5dab 109 printf("go lope!!!!!!!!!!\r\n");
yuto17320508 25:c740e6fd5dab 110 //前進
yuto17320508 38:89d2a9e6c96f 111 motor_lo.setDutyLimit(0.6);
yuto17320508 38:89d2a9e6c96f 112 motor_li.setDutyLimit(0.6);
yuto17320508 38:89d2a9e6c96f 113 for(int i=0; i<13; ++i) {
yuto17320508 38:89d2a9e6c96f 114 if(RightOrLeft == 0) straightAndInfinity(90.0, 7.0);
yuto17320508 38:89d2a9e6c96f 115 else straightAndInfinity(-90.0, 7.0);
yuto17320508 38:89d2a9e6c96f 116 }
yuto17320508 25:c740e6fd5dab 117 for(int i=0; i<3; ++i) {
yuto17320508 25:c740e6fd5dab 118 while(get_dist_forward() > 60) {
yuto17320508 32:aee87dcaf7ca 119 if(RightOrLeft == 0) straightAndInfinity(90.0, 7.0);
yuto17320508 32:aee87dcaf7ca 120 else straightAndInfinity(-90.0, 7.0);
yuto17320508 25:c740e6fd5dab 121 }
yuto17320508 25:c740e6fd5dab 122 }
yuto17320508 25:c740e6fd5dab 123 //ロープ前旋回
yuto17320508 25:c740e6fd5dab 124 printf("before roop deg:%.3f\r\n",degree0);
yuto17320508 25:c740e6fd5dab 125 turn(0);
yuto17320508 25:c740e6fd5dab 126 //ロープ位置ジャストまで前進
yuto17320508 25:c740e6fd5dab 127 for(int i=0; i<3; ++i) {
yuto17320508 32:aee87dcaf7ca 128 straightAndInfinity(0.0, 7.0);
yuto17320508 25:c740e6fd5dab 129 }
yuto17320508 25:c740e6fd5dab 130 for(int i=0; i<2; ++i) {
yuto17320508 25:c740e6fd5dab 131 while(get_dist_back() < 100) {
yuto17320508 32:aee87dcaf7ca 132 straightAndInfinity(0.0, 7.0);
yuto17320508 25:c740e6fd5dab 133 }
yuto17320508 25:c740e6fd5dab 134 }
yuto17320508 31:ed4249a288d7 135 phasing(0.0);
yuto17320508 25:c740e6fd5dab 136 //ロープ
yuto17320508 32:aee87dcaf7ca 137 while(switch_modes[2].read() == 0) {
yuto17320508 32:aee87dcaf7ca 138 straightAndInfinity(0, 7);
yuto17320508 25:c740e6fd5dab 139 //straight();
yuto17320508 25:c740e6fd5dab 140 }
yuto17320508 32:aee87dcaf7ca 141 printf("uhai stand by ok!!!!!!!!!!\r\n");
yuto17320508 32:aee87dcaf7ca 142 NoHandSignal();
yuto17320508 25:c740e6fd5dab 143 case 3://坂
yuto17320508 32:aee87dcaf7ca 144 printf("last spart!!!!!!!!");
yuto17320508 38:89d2a9e6c96f 145
yuto17320508 32:aee87dcaf7ca 146 if(RightOrLeft == 0) theta0 = -degree/100.0+90;
yuto17320508 32:aee87dcaf7ca 147 else theta0 = -degree/100.0-90;
yuto17320508 32:aee87dcaf7ca 148 motor_lo.setDutyLimit(0.2);//0.3
yuto17320508 32:aee87dcaf7ca 149 motor_li.setDutyLimit(0.2);
yuto17320508 38:89d2a9e6c96f 150 for(int i=0; i<20; ++i) {
yuto17320508 32:aee87dcaf7ca 151 if(RightOrLeft == 0) straightAndInfinity(-90, 15);//straight();//climbAndInfinity(-90,5);
yuto17320508 32:aee87dcaf7ca 152 else straightAndInfinity(90, 15);
yuto17320508 25:c740e6fd5dab 153 }
yuto17320508 25:c740e6fd5dab 154 printf("wall standby");
yuto17320508 33:2dbbe198adaf 155 motor_lo.setDutyLimit(0.3);//0.3
yuto17320508 33:2dbbe198adaf 156 motor_li.setDutyLimit(0.3);
yuto17320508 25:c740e6fd5dab 157 while(get_dist_back() < 250) {
shimizuta 27:d392a95f4799 158 // straight();
yuto17320508 32:aee87dcaf7ca 159 if(RightOrLeft == 0) climbAndInfinity(-90,15);
yuto17320508 32:aee87dcaf7ca 160 else climbAndInfinity(90,15);
yuto17320508 25:c740e6fd5dab 161 }
yuto17320508 25:c740e6fd5dab 162 for(int i=0; i<1; ++i) {
yuto17320508 31:ed4249a288d7 163 while(get_dist_forward() > 60) {
yuto17320508 25:c740e6fd5dab 164 //straight();
yuto17320508 32:aee87dcaf7ca 165 if(RightOrLeft == 0) climbAndInfinity(-90,15);
yuto17320508 32:aee87dcaf7ca 166 else climbAndInfinity(90,15);
yuto17320508 25:c740e6fd5dab 167 }
yuto17320508 25:c740e6fd5dab 168 }
yuto17320508 25:c740e6fd5dab 169 hand_mode = GOAL;
shimizuta 30:231e6584afe9 170 stop();
yuto17320508 32:aee87dcaf7ca 171 printf("uhai!!!!!!!!!!!!!!!/r/n");
yuto17320508 32:aee87dcaf7ca 172 }
yuto17320508 32:aee87dcaf7ca 173 }
yuto17320508 32:aee87dcaf7ca 174 void Start()
yuto17320508 32:aee87dcaf7ca 175 {
yuto17320508 38:89d2a9e6c96f 176 if(hand.read()==0) { //開始時すでにスイッチが押されていた場合
yuto17320508 32:aee87dcaf7ca 177 SetMode();
yuto17320508 35:04699b49c463 178 hand_mode = G_CLOSE;
yuto17320508 38:89d2a9e6c96f 179 } else {
yuto17320508 32:aee87dcaf7ca 180 SetMode();
yuto17320508 35:04699b49c463 181 hand_mode = G_OPEN;
shimizuta 39:7f3cc8f47710 182 printf("stop start\r\n");
yuto17320508 35:04699b49c463 183 stop();//ここで開くことをcanでslaveに送る
shimizuta 39:7f3cc8f47710 184 printf("wait gerege\r\n");
shimizuta 39:7f3cc8f47710 185 wait(1);
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 }