ROBOSTEP_5期 / Mbed 2 deprecated George_Master_Param

Dependencies:   mbed robot

Committer:
shimizuta
Date:
Mon May 20 03:37:02 2019 +0000
Revision:
51:8b66c953d73a
Parent:
50:3e73f68c3b37
Child:
52:dc3d83eb31eb
a

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