3/19
Dependencies: mbed move4wheel2 EC CruizCore_R1370P
Revision 11:9db93bce4eef, committed 2019-03-19
- Comitter:
- yuki0701
- Date:
- Tue Mar 19 02:30:34 2019 +0000
- Parent:
- 10:c741191360de
- Commit message:
- a
Changed in this revision
--- a/can/can.cpp Wed Mar 13 04:23:18 2019 +0000 +++ b/can/can.cpp Tue Mar 19 02:30:34 2019 +0000 @@ -12,12 +12,15 @@ DigitalOut canread_led(LED2); //canread -> on int t1_r=0, T1=0; //動作番号(受け取った値、送信する値(int型)) +int usw_flag; void can_readsend() { CANMessage msg; + // printf("readsend\n\r"); if(can1.read(msg)) { + //printf("read\n\r"); canread_led = 1; @@ -32,12 +35,14 @@ id1_value[6] = (msg.data[0]>>1)%2; //decide right/left(0 or 1) t1_r = msg.data[3]; //value of t(0~7) - /*debug_printf("[0]=%d [1]=%d [2]=%d [3]=%d [4]=%d [5]=%d [6]=%d\n\r" - ,id1_value[0],id1_value[1],id1_value[2],id1_value[3],id1_value[4],id1_value[5],id1_value[6]);*/ - debug_printf("t1_r=%d T1=%d can_ashileddata[1]=%d\n\r",t1_r,T1,can_ashileddata[1]); + // debug_printf("[0]=%d [1]=%d [2]=%d [3]=%d [4]=%d [5]=%d [6]=%d\n\r" + // ,id1_value[0],id1_value[1],id1_value[2],id1_value[3],id1_value[4],id1_value[5],id1_value[6]); + // debug_printf("t1_r=%d T1=%d can_ashileddata[1]=%d\n\r",t1_r,T1,can_ashileddata[1]); } if(msg.id == 3) { + usw_flag = 0; + usw_data1 = 0.1 * (short)((msg.data[0]<<8) | msg.data[1]); //debug_printf("usw_data1 = %f\n\r",usw_data1); @@ -50,6 +55,8 @@ usw_data4 = 0.1 * (short)((msg.data[6]<<8) | msg.data[7]); //debug_printf("usw_data4 = %f\n\r",usw_data4); //debug_printf("usw1=%f usw2=%f usw3=%f usw4=%f\n\r",usw_data1,usw_data2,usw_data3,usw_data4); + }else{ + usw_flag = 1; } } else { @@ -60,8 +67,10 @@ can_ashileddata[1] = T1; //動作番号(id節約のため、can_ashileddata[]と一緒に送る) if(can1.write(CANMessage(4,can_ashileddata,2))) { //IDを4にして送信 + // printf("send\n\r"); cansend_led = 1; } else { + //printf("not_send\n\r"); cansend_led = 0; }
--- a/can/can.h Wed Mar 13 04:23:18 2019 +0000 +++ b/can/can.h Tue Mar 19 02:30:34 2019 +0000 @@ -2,6 +2,7 @@ #define HARUROBO2019_CAN extern int T1; +extern int usw_flag; void can_readsend();
--- a/main.cpp Wed Mar 13 04:23:18 2019 +0000 +++ b/main.cpp Tue Mar 19 02:30:34 2019 +0000 @@ -15,6 +15,15 @@ int go_waitmode = 0; +/*------------運動時の各速度の設定----------*/ +double st_speed = 500; // 移動開始時の速度 +double max_speed = 2500; // 直線移動時の最大速度 +double mid_speed = 2000; // 直線移動時の中間速度 +double turn_speed = 1000; // 旋回時の速度 +double end_speed = 200; // 停止直前の速度 +double fruit_speed = 200; // 果物を取る時の速度 +/*--------------------------------------*/ + //-----mbed led------------------//点灯条件-----------------------//参照場所------------------------------// //DigitalOut cansend_led(LED1); //cansend -> on //can.cpp //DigitalOut canread_led(LED2); //canread -> on //can.cpp @@ -37,62 +46,74 @@ #endif while(1) { - + //id1_value[0] = 1; switch(id1_value[0]) { //-----auto mode----------------------------------------------------------------------------------------------------------------------// case 1: - + //id1_value[6] = 0; switch(id1_value[6]) { case 0: //-----right mode-------------------------------------------------------------------------------------------------------------// + //未修正 + flag = 0; UserLoopSetting_enc_right(); if(T1 == 0) { //スタート位置からみかんの木まで移動 + /* gogo_straight(1,1,2962,3500,2962,2900,200,1000,5,0.1,10,0.1,600,0); purecurve(6,1,1,2962,2900,2317,2500,9,1000,5,0.1,10,0.1,600,0); purecurve(5,1,1,2317,2500,1672,2000,9,1000,5,0.1,10,0.1,600,0); set_cond(2,1,1050,1,1076); - gogo_straight(0,0,1672,2000,1672,1400,1000,200,5,0.1,10,0.1,600,0); + gogo_straight(0,0,1672,2000,1672,1600,1000,200,5,0.1,10,0.1,600,0); MaxonControl(0,0,0,0); - pos_correction(1672,1400,0,0,0); + pos_correction(1672,1600,0,0,0,25); enc_correction(1,1); - wait(0.5); + gogo_straight(0,0,1672,1600,1672,1400,200,200,5,0.1,10,0.1,600,0); + */ + printf("t1 = 0\n\r"); + wait(1); T1++; } if(T1 == 1) { while(1) { wait(0.1); + //calc_xy(0,0,0); if(T1 == 2) { + // enc_correction(1,1); break; } } } if(T1 == 2) { //みかんの木から三宝置き場まで移動 - gogo_straight(1,1,1672,1400,1672,2000,200,1000,5,0.1,10,0.1,600,0); + /*gogo_straight(1,1,1672,1400,1672,2000,200,1000,5,0.1,10,0.1,600,0); purecurve(2,1,1,1672,2000,2317,2500,9,1000,5,0.1,10,0.1,600,0); purecurve(1,1,1,2317,2500,2962,3000,9,1000,5,0.1,10,0.1,600,90); //purecurve(4,1,1,-2317,2500,-2962,3000,9,1000,5,0.1,10,0.1,600,-90); gogo_straight(1,1,2962,3000,2962,4000,1000,1000,5,0.1,10,0.1,600,90); gogo_straight(1,1,2962,4000,2962,4500,1000,200,5,0.1,10,0.1,600,90); MaxonControl(0,0,0,0); - pos_correction(2962,4500,90,1,1); + // pos_correction(2962,4500,90,1,1); set_cond(2,1,2462,0,6000); gogo_straight(0,0,2962,4500,2850,4500,200,200,5,0.1,10,0.1,800,90); MaxonControl(0,0,0,0); - pos_correction(2850,4500,90,0,0); + pos_correction(2850,4500,90,0,0,10); enc_correction(1,1); - wait(0.5); + wait(0.5);*/ + printf("t1 = 2\n\r"); + wait(1); T1++; } if(T1 == 3) { while(1) { wait(0.1); + //calc_xy(90,0,0); if(T1 == 4) { + // enc_correction(1,1); break; } } } if(T1 == 4) { //三宝置き場からりんごの木まで移動 - gogo_straight(1,1,2850,4500,2850,5150,200,1000,5,0.1,10,0.1,800,90); + /*gogo_straight(1,1,2850,4500,2850,5150,200,1000,5,0.1,10,0.1,800,90); purecurve(3,1,1,2850,5150,2257,5500,9,1000,5,0.1,10,0.1,800,90); purecurve(4,1,1,2257,5500,1700,6000,9,1000,5,0.1,10,0.1,800,90); purecurve(2,1,1,1700,6000,2257,6550,9,1000,5,0.1,10,0.1,800,90); @@ -100,31 +121,38 @@ set_cond(2,0,3500,1,6050); gogo_straight(0,0,2500,6550,2700,6600,1000,200,5,0.1,10,0.1,800,90); MaxonControl(0,0,0,0); - pos_correction(2700,6600,90,0,0); + pos_correction(2700,6600,90,0,0,15); enc_correction(1,1); - wait(0.5); + wait(0.5);*/ + printf("t1 = 4\n\r"); + wait(1); T1++; } if(T1 == 5) { while(1) { wait(0.1); + //calc_xy(90,0,0); if(T1 == 6) { + // enc_correction(1,1); break; } } } if(T1 == 6) { //りんごの木からお供え台まで移動 - gogo_straight(1,1,2700,6600,2500,6550,200,1000,5,0.1,10,0.1,800,90); - gogo_straight(1,1,2500,6550,1300,6550,1000,1000,5,0.1,10,0.1,800,90); - gogo_straight(1,1,1300,6550,1000,6500,1000,1000,5,0.1,10,0.1,800,90); - purecurve(5,1,1,1000,6550,519,6000,9,1000,5,0.1,10,0.1,600,180); - gogo_straight(1,1,519,6000,519,4700,1000,1000,5,0.1,10,0.1,600,180); - set_cond(2,0,1000,1,4000); - gogo_straight(0,0,519,4700,519,4500,1000,200,5,0.1,10,0.1,800,180); + /*gogo_straight(1,1,-3112,3500,-2962,3100,st_speed,mid_speed,5,0.1,10,0.1,600,0); + gogo_straight(1,1,-2962,3100,-2962,2900,mid_speed,turn_speed,5,0.1,10,0.1,600,0); + purecurve(7,1,1,-2962,2900,-2317,2500,9,turn_speed,5,0.1,10,0.1,600,0); + purecurve(8,1,1,-2317,2500,-1672,2000,9,turn_speed,5,0.1,10,0.1,600,0); + set_cond(2,0,-1050,1,1076); + gogo_straight(0,0,-1672,2000,-1672,1600,turn_speed,end_speed,5,0.1,10,0.1,600,0); MaxonControl(0,0,0,0); - pos_correction(519,4500,180,0,0); + pos_correction(-1672,1600,0,0,0,25); enc_correction(1,1); + gogo_straight(0,0,-1672,1600,-1672,1375,fruit_speed,fruit_speed,5,0.1,10,0.1,600,0); MaxonControl(0,0,0,0); + */ + printf("t1 = 6\n\r"); + wait(1); T1++; } if(T1 == 7) { @@ -136,105 +164,154 @@ } } break; - + case 1: //-----left mode--------------------------------------------------------------------------------------------------------------// flag = 1; + printf("start\n\r"); UserLoopSetting_enc_left(); if(T1 == 0) { //スタート位置からみかんの木まで移動 - gogo_straight(1,1,-2962,3500,-2962,2900,200,1000,5,0.1,10,0.1,600,0); - purecurve(7,1,1,-2962,2900,-2317,2500,9,1000,5,0.1,10,0.1,600,0); - purecurve(8,1,1,-2317,2500,-1672,2000,9,1000,5,0.1,10,0.1,600,0); + + gogo_straight(1,1,-3112,3500,-2962,3100,st_speed,mid_speed,5,0.1,10,0.1,600,0); + gogo_straight(1,1,-2962,3100,-2962,2900,mid_speed,turn_speed,5,0.1,10,0.1,600,0); + purecurve(7,1,1,-2962,2900,-2317,2500,9,turn_speed,5,0.1,10,0.1,600,0); + purecurve(8,1,1,-2317,2500,-1672,2000,9,turn_speed,5,0.1,10,0.1,600,0); set_cond(2,0,-1050,1,1076); - gogo_straight(0,0,-1672,2000,-1672,1400,1000,200,5,0.1,10,0.1,600,0); + gogo_straight(0,0,-1672,2000,-1672,1600,turn_speed,end_speed,5,0.1,10,0.1,600,0); MaxonControl(0,0,0,0); - pos_correction(-1672,1400,0,0,0); + pos_correction(-1672,1600,0,0,0,25); enc_correction(1,1); - wait(0.5); + gogo_straight(0,0,-1672,1600,-1672,1375,fruit_speed,fruit_speed,5,0.1,10,0.1,600,0); + MaxonControl(0,0,0,0); + T1++; } if(T1 == 1) { while(1) { wait(0.1); + calc_xy(0,0,0); if(T1 == 2) { + enc_correction(1,1); break; } } } if(T1 == 2) { //みかんの木から三宝置き場まで移動 - gogo_straight(1,1,-1672,1400,-1672,2000,200,1000,5,0.1,10,0.1,600,0); - purecurve(3,1,1,-1672,2000,-2317,2500,9,1000,5,0.1,10,0.1,600,0); - purecurve(4,1,1,-2317,2500,-2962,3000,9,1000,5,0.1,10,0.1,600,-90); //purecurve(4,1,1,-2317,2500,-2962,3000,9,1000,5,0.1,10,0.1,600,-90); - gogo_straight(1,1,-2962,3000,-2962,4000,1000,1000,5,0.1,10,0.1,600,-90); - gogo_straight(1,1,-2962,4000,-2962,4500,1000,200,5,0.1,10,0.1,600,-90); + gogo_straight(1,1,-1672,1375,-1672,2000,st_speed,turn_speed,5,0.1,10,0.1,600,0); + purecurve(3,1,1,-1672,2000,-2317,2500,9,turn_speed,5,0.1,10,0.1,600,0); + purecurve(4,1,1,-2317,2500,-2962,3000,9,turn_speed,5,0.1,10,0.1,600,-90); //purecurve(4,1,1,-2317,2500,-2962,3000,9,1000,5,0.1,10,0.1,600,-90); + gogo_straight(1,1,-2962,3000,-2962,4000,turn_speed,max_speed,5,0.1,10,0.1,600,-90); + gogo_straight(1,1,-2962,4000,-2962,4820,max_speed,end_speed,5,0.1,10,0.1,600,-90); MaxonControl(0,0,0,0); - pos_correction(-2962,4500,-90,1,1); set_cond(2,0,-2462,0,6000); - gogo_straight(0,0,-2962,4500,-2850,4500,200,200,5,0.1,10,0.1,800,-90); + pos_correction(-2962,4837.5,-90,0,0,7); + gogo_straight(0,0,-2962,4837.5,-2800,4837.5,300,200,5,0.1,10,0.1,800,-90); MaxonControl(0,0,0,0); - pos_correction(-2850,4500,-90,0,0); enc_correction(1,1); - wait(0.5); + T1++; } if(T1 == 3) { while(1) { wait(0.1); + calc_xy(-90,0,0); if(T1 == 4) { + enc_correction(1,1); break; } } } if(T1 == 4) { //三宝置き場からりんごの木まで移動 - gogo_straight(1,1,-2850,4500,-2850,5150,200,1000,5,0.1,10,0.1,800,-90); - purecurve(2,1,1,-2850,5150,-2257,5500,9,1000,5,0.1,10,0.1,800,-90); - purecurve(1,1,1,-2257,5500,-1700,6000,9,1000,5,0.1,10,0.1,800,-90); - purecurve(3,1,1,-1700,6000,-2257,6550,9,1000,5,0.1,10,0.1,800,-90); - gogo_straight(1,1,-2257,6550,-2500,6550,1000,1000,5,0.1,10,0.1,800,-90); - set_cond(2,1,-3500,1,6050); - gogo_straight(0,0,-2500,6550,-2700,6600,1000,200,5,0.1,10,0.1,800,-90); + gogo_straight(1,1,-2782,4837.5,-2782,5150,st_speed,turn_speed,5,0.1,10,0.1,800,-90); + purecurve(2,1,1,-2850,5150,-2257,5500,9,turn_speed,5,0.1,10,0.1,800,-90); + purecurve(1,1,1,-2257,5500,-1700,6000,9,turn_speed,5,0.1,10,0.1,800,-90); + purecurve(3,1,1,-1700,6000,-2257,6550,9,turn_speed,5,0.1,10,0.1,800,-90); + gogo_straight(1,1,-2257,6550,-2500,6593,turn_speed,end_speed,5,0.1,10,0.1,800,-90); MaxonControl(0,0,0,0); - pos_correction(-2700,6600,-90,0,0); + set_cond(1,0,0,1,6050); + pos_correction(-2500,6600,-90,1,0,8); + set_cond(2,1,-3162,1,6038); + gogo_straight(0,0,-2500,6600,-2700,6600,fruit_speed,fruit_speed,5,0.1,10,0.1,800,-90); + MaxonControl(0,0,0,0); enc_correction(1,1); - wait(0.5); + T1++; } if(T1 == 5) { while(1) { wait(0.1); + calc_xy(-90,0,0); if(T1 == 6) { + enc_correction(1,1); break; } } } if(T1 == 6) { //りんごの木からお供え台まで移動 - gogo_straight(1,1,-2700,6600,-2500,6550,200,1000,5,0.1,10,0.1,800,-90); - gogo_straight(1,1,-2500,6550,-1300,6550,1000,1000,5,0.1,10,0.1,800,-90); - gogo_straight(1,1,-1300,6550,-1000,6500,1000,1000,5,0.1,10,0.1,800,-90); - purecurve(8,1,1,-1000,6550,-519,6000,9,1000,5,0.1,10,0.1,600,-180); - gogo_straight(1,1,-519,6000,-519,4700,1000,1000,5,0.1,10,0.1,600,-180); + set_cond(1,0,0,0,6962); + gogo_straight(1,0,-2700,6600,-2500,6550,st_speed,max_speed,5,0.1,10,0.1,800,-90); + gogo_straight(1,0,-2500,6550,-1300,6550,max_speed,max_speed,5,0.1,10,0.1,800,-90); + gogo_straight(1,0,-1300,6550,-850,6550,max_speed,turn_speed,5,0.1,10,0.1,800,-90); + enc_correction(0,1); + set_cond(2,0,-19,0,6962); + purecurve(8,0,0,-850,6550,-519,6000,9,turn_speed,10,0.1,10,0.1,600,-180); + enc_correction(1,0); + set_cond(0,0,-19,0,0); + gogo_straight(0,1,-519,6000,-519,5500,turn_speed,max_speed,5,0.1,10,0.1,600,-180); + gogo_straight(0,1,-519,5500,-519,5000,max_speed,max_speed,5,0.1,10,0.1,600,-180); set_cond(2,1,-1000,1,4000); - gogo_straight(0,0,-519,4700,-519,4500,1000,200,5,0.1,10,0.1,800,-180); + gogo_straight(0,0,-519,5000,-519,4600,max_speed,end_speed,5,0.1,10,0.1,800,-180); MaxonControl(0,0,0,0); - pos_correction(-519,4500,-180,0,0); + pos_correction(-519,4370,-180,0,0,30); enc_correction(1,1); MaxonControl(0,0,0,0); + T1++; } if(T1 == 7) { while(1) { printf("ashi finished\n\r"); MaxonControl(0,0,0,0); + + /*gogo_straight(1,1,-519,4500,-519,5000,200,1000,5,0.1,10,0.1,600,-180); + gogo_straight(1,1,-519,5000,-519,6000,1000,1000,5,0.1,10,0.1,600,-180); + gogo_straight(1,1,-519,6000,-519,6600,1000,200,5,0.1,10,0.1,600,-180); + MaxonControl(0,0,0,0); + set_cond(2,0,0,0,7000); + //pos_correction(-519,6600,-180,0,0,30); + calc_xy(-180,0,0); + enc_correction(1,1); + gogo_straight(1,1,-519,6600,-1000,6600,200,1000,5,0.1,10,0.1,600,-180); + purecurve(5,1,1,-1000,6600,-1672,6000,9,1000,5,0.1,10,0.1,600,-180); + purecurve(6,1,1,-1672,6000,-2462,5500,9,1000,5,0.1,10,0.1,600,-180); + gogo_straight(1,1,-2462,5500,-2962,5500,1000,200,5,0.1,10,0.1,600,-180); + MaxonControl(0,0,0,0); + set_cond(2,1,-3500,0,6000); + //pos_correction(-2962,5500,-180,0,0,30); + enc_correction(1,1); + calc_xy(-180,0,0); + gogo_straight(1,1,-2962,5500,-2962,4700,200,1000,5,0.1,10,0.1,600,-90); + gogo_straight(1,1,-2962,4700,-2962,4000,1000,1000,5,0.1,10,0.1,600,0); + gogo_straight(1,1,-2962,4000,-2962,3500,1000,200,5,0.1,10,0.1,600,0); + MaxonControl(0,0,0,0); + set_cond(2,1,-3500,1,2000); + pos_correction(-3112,3500,0,0,0,15); + enc_correction(1,1); + MaxonControl(0,0,0,0);*/ + if(id1_value[0] != 1)break; //これらは他のwhileにも入れる必要あり if(id1_value[6] != flag)break; } } + + break; } //-----wait mode----------------------------------------------------------------------------------------------------------------------// case 0: + // printf("wait\n\r"); calc_xy(0,1,1); ashi_led(); MaxonControl(0,0,0,0);
--- a/movement/movement.cpp Wed Mar 13 04:23:18 2019 +0000 +++ b/movement/movement.cpp Tue Mar 19 02:30:34 2019 +0000 @@ -71,12 +71,12 @@ } void UserLoopSetting_enc_right() { - info.nowX.enc = 2962; //エンコーダの初期位置の設定(右側フィールド) + info.nowX.enc = 3112; //エンコーダの初期位置の設定(右側フィールド) info.nowY.enc = 3500; } void UserLoopSetting_enc_left() { - info.nowX.enc = -2962; //エンコーダの初期位置の設定(左側フィールド) + info.nowX.enc = -3112; //エンコーダの初期位置の設定(左側フィールド) info.nowY.enc = 3500; } @@ -272,6 +272,11 @@ //エンコーダにより求めた機体の座標と超音波センサーにより求めた機体の座標を(エンコーダ : 超音波 = u : 1-u / v : 1-v)の割合で混ぜて now_x,now_y に代入する calc_xy_enc(); + + if(usw_flag == 1){ + u = 1; + v = 1; + } if(u != 1 || v != 1) { calc_xy_usw(target_angle); //エンコーダの値しか使用しない場合は超音波センサーによる座標計算は行わずに計算量を減らす。 @@ -533,14 +538,13 @@ } MaxonControl(0,0,0,0); }*/ - -void pos_correction(double tgt_x, double tgt_y, double tgt_angle, double u, double v) //改良版 位置補正(使用前にMaxonControl(0,0,0,0)を入れる) +void pos_correction(double tgt_x, double tgt_y, double tgt_angle, double u, double v, double R) //改良版 位置補正(使用前にMaxonControl(0,0,0,0)を入れる) { //距離に比例的に補正初速度を増加させる。(最大速度を設定しそれ以上は出ないようにする/初期速度が目標速度を下回らないようにする) - double first_speed, first_speed50 = 100,last_speed = 50, Max_speed = 300; + double first_speed, first_speed50 = 150,last_speed = 50, Max_speed = 300; //first_speed50:5センチのズレを補正するときの補正初速度 / last_speed:目標速度 / first_speed:first_speed50とlast_speedを元に計算した実際の補正初速度 / Max_speed:補正速度の上限 - double r, R=10; // r:一回補正が入るごとの機体の位置と目標位置の距離(ズレ) R:補正終了とみなす目標位置からの機体の位置のズレ + double r; // r:一回補正が入るごとの機体の位置と目標位置の距離(ズレ) R:補正終了とみなす目標位置からの機体の位置のズレ double out; double tgt_xx, tgt_yy; @@ -581,7 +585,7 @@ //calc_gyro(); now_angle=gyro.getAngle(); - printf("angle = %f\n\r",now_angle); + //printf("angle = %f\n\r",now_angle); out = 10 * (tgt_angle - now_angle); @@ -599,6 +603,7 @@ MaxonControl(0,0,0,0); } + /*----------------------コメント------------------------*/ /* 3/10(日):pos_correctionの中身を一部修正しました。(引数に変更はありません。)
--- a/movement/movement.h Wed Mar 13 04:23:18 2019 +0000 +++ b/movement/movement.h Tue Mar 19 02:30:34 2019 +0000 @@ -51,6 +51,6 @@ double r_out_max, double target_angle); -void pos_correction(double tgt_x, double tgt_y, double tgt_angle, double u, double v); +void pos_correction(double tgt_x, double tgt_y, double tgt_angle, double u, double v, double R); #endif \ No newline at end of file