can出来ない~
Dependencies: mbed move4wheel2 EC CruizCore_R1370P
movement/movement.cpp@10:6d60c0927770, 2019-03-06 (annotated)
- Committer:
- yuki0701
- Date:
- Wed Mar 06 06:19:53 2019 +0000
- Revision:
- 10:6d60c0927770
- Parent:
- 9:337fe0747940
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
la00noix | 0:c61c6e4775ca | 1 | #include "EC.h" |
la00noix | 0:c61c6e4775ca | 2 | #include "R1370P.h" |
la00noix | 0:c61c6e4775ca | 3 | #include "move4wheel.h" |
la00noix | 0:c61c6e4775ca | 4 | #include "mbed.h" |
la00noix | 0:c61c6e4775ca | 5 | #include "math.h" |
la00noix | 0:c61c6e4775ca | 6 | #include "PathFollowing.h" |
la00noix | 0:c61c6e4775ca | 7 | #include "movement.h" |
la00noix | 0:c61c6e4775ca | 8 | #include "maxonsetting.h" |
la00noix | 0:c61c6e4775ca | 9 | #include "manual.h" |
la00noix | 0:c61c6e4775ca | 10 | #include "can.h" |
la00noix | 0:c61c6e4775ca | 11 | |
la00noix | 0:c61c6e4775ca | 12 | #define PI 3.141592 |
la00noix | 0:c61c6e4775ca | 13 | |
yuki0701 | 9:337fe0747940 | 14 | char can_ashileddata[2]= {0}; |
la00noix | 6:26724c287387 | 15 | int can_ashileddata0_0,can_ashileddata0_1,can_ashileddata0_2,can_ashileddata0_3; |
la00noix | 0:c61c6e4775ca | 16 | |
la00noix | 6:26724c287387 | 17 | Ec EC1(p22,p21,NC,500,0.05); |
yuki0701 | 3:8a0faa3b08c3 | 18 | Ec EC2(p26,p8,NC,500,0.05); |
la00noix | 6:26724c287387 | 19 | |
la00noix | 0:c61c6e4775ca | 20 | Ticker ec_ticker; //ec角速度計算用ticker |
la00noix | 0:c61c6e4775ca | 21 | |
la00noix | 0:c61c6e4775ca | 22 | R1370P gyro(p28,p27); |
la00noix | 0:c61c6e4775ca | 23 | |
la00noix | 0:c61c6e4775ca | 24 | double new_dist1=0,new_dist2=0; |
la00noix | 0:c61c6e4775ca | 25 | double old_dist1=0,old_dist2=0; |
la00noix | 0:c61c6e4775ca | 26 | double d_dist1=0,d_dist2=0; //座標計算用関数 |
la00noix | 0:c61c6e4775ca | 27 | double d_x,d_y; |
la00noix | 0:c61c6e4775ca | 28 | //現在地X,y座標、現在角度については、PathFollowingでnow_x,now_y,now_angleを定義済 |
la00noix | 0:c61c6e4775ca | 29 | double start_x=0,start_y=0; //スタート位置 |
la00noix | 0:c61c6e4775ca | 30 | double x_out,y_out,r_out; //出力値 |
la00noix | 0:c61c6e4775ca | 31 | |
la00noix | 0:c61c6e4775ca | 32 | int16_t m1=0, m2=0, m3=0, m4=0; //int16bit = int2byte |
la00noix | 0:c61c6e4775ca | 33 | |
la00noix | 0:c61c6e4775ca | 34 | double xy_type,pm_typeX,pm_typeY,x_base,y_base; |
la00noix | 0:c61c6e4775ca | 35 | |
la00noix | 0:c61c6e4775ca | 36 | ///////////////////機体情報をメンバとする構造体"robo_data"と構造体型変数info(←この変数に各センサーにより求めた機体情報(機体位置/機体角度)を格納する)の宣言///////////////// |
la00noix | 0:c61c6e4775ca | 37 | |
la00noix | 0:c61c6e4775ca | 38 | /*「info.(機体情報の種類).(使用センサーの種類)」に各情報を格納する |
la00noix | 0:c61c6e4775ca | 39 | *状況に応じて、どのセンサーにより算出した情報を信用するかを選択し、その都度now_angle,now_x,now_yに代入する。(何種類かのセンサーの情報を混ぜて使用することも可能) |
la00noix | 0:c61c6e4775ca | 40 | *(ex) |
la00noix | 0:c61c6e4775ca | 41 | *info.nowX.enc → エンコーダにより算出した機体位置のx座標 |
la00noix | 0:c61c6e4775ca | 42 | *info.nowY.usw → 超音波センサーにより求めた機体位置のy座標 |
la00noix | 0:c61c6e4775ca | 43 | */ |
la00noix | 0:c61c6e4775ca | 44 | |
la00noix | 6:26724c287387 | 45 | typedef struct { //使用センサーの種類 |
la00noix | 0:c61c6e4775ca | 46 | double usw; //超音波センサー |
la00noix | 0:c61c6e4775ca | 47 | double enc; //エンコーダ |
la00noix | 0:c61c6e4775ca | 48 | double gyro; //ジャイロ |
la00noix | 0:c61c6e4775ca | 49 | //double line;//ラインセンサー |
la00noix | 6:26724c287387 | 50 | } robo_sensor; |
la00noix | 0:c61c6e4775ca | 51 | |
la00noix | 6:26724c287387 | 52 | typedef struct { //機体情報の種類 |
la00noix | 0:c61c6e4775ca | 53 | robo_sensor angle; //←機体角度は超音波センサーやラインセンサーからも算出可能なので一応格納先を用意したが、ジャイロの値を完全に信用してもいいかも |
la00noix | 0:c61c6e4775ca | 54 | robo_sensor nowX; |
la00noix | 0:c61c6e4775ca | 55 | robo_sensor nowY; |
la00noix | 6:26724c287387 | 56 | } robo_data; |
la00noix | 0:c61c6e4775ca | 57 | |
la00noix | 6:26724c287387 | 58 | robo_data info= {{0,0,0},{0,0,0},{0,0,0}}; //全てのデータを0に初期化 |
la00noix | 0:c61c6e4775ca | 59 | |
la00noix | 0:c61c6e4775ca | 60 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
la00noix | 0:c61c6e4775ca | 61 | |
la00noix | 6:26724c287387 | 62 | void UserLoopSetting_sensor() |
la00noix | 6:26724c287387 | 63 | { |
la00noix | 6:26724c287387 | 64 | |
la00noix | 0:c61c6e4775ca | 65 | gyro.initialize(); |
la00noix | 0:c61c6e4775ca | 66 | ec_ticker.attach(&calOmega,0.05); //0.05秒間隔で角速度を計算 |
la00noix | 4:317c53a674fa | 67 | EC1.setDiameter_mm(25.5); |
la00noix | 4:317c53a674fa | 68 | EC2.setDiameter_mm(25.5); //測定輪半径//後で測定 |
yuki0701 | 1:3c11e07da92a | 69 | info.nowX.enc = -2962; //初期位置の設定 |
yuki0701 | 1:3c11e07da92a | 70 | info.nowY.enc = 3500; |
la00noix | 0:c61c6e4775ca | 71 | } |
la00noix | 0:c61c6e4775ca | 72 | |
la00noix | 0:c61c6e4775ca | 73 | void calOmega() //角速度計算関数 |
la00noix | 0:c61c6e4775ca | 74 | { |
la00noix | 0:c61c6e4775ca | 75 | EC1.CalOmega(); |
la00noix | 0:c61c6e4775ca | 76 | EC2.CalOmega(); |
la00noix | 0:c61c6e4775ca | 77 | } |
la00noix | 0:c61c6e4775ca | 78 | |
la00noix | 0:c61c6e4775ca | 79 | void output(double FL,double BL,double BR,double FR) |
la00noix | 0:c61c6e4775ca | 80 | { |
la00noix | 0:c61c6e4775ca | 81 | m1=FL; |
la00noix | 0:c61c6e4775ca | 82 | m2=BL; |
la00noix | 0:c61c6e4775ca | 83 | m3=BR; |
la00noix | 0:c61c6e4775ca | 84 | m4=FR; |
la00noix | 0:c61c6e4775ca | 85 | } |
la00noix | 0:c61c6e4775ca | 86 | |
la00noix | 0:c61c6e4775ca | 87 | void base(double FL,double BL,double BR,double FR,double Max) |
la00noix | 0:c61c6e4775ca | 88 | //いろんな加算をしても最大OR最小がMaxになるような補正//絶対値が一番でかいやつで除算 |
la00noix | 0:c61c6e4775ca | 89 | //DCモーターならMax=1、マクソンは-4095~4095だからMax=4095にする |
la00noix | 0:c61c6e4775ca | 90 | { |
la00noix | 0:c61c6e4775ca | 91 | if(fabs(FL)>=Max||fabs(BL)>=Max||fabs(BR)>=Max||fabs(FR)>=Max) { |
la00noix | 0:c61c6e4775ca | 92 | |
la00noix | 0:c61c6e4775ca | 93 | if (fabs(FL)>=fabs(BL)&&fabs(FL)>=fabs(BR)&&fabs(FL)>=fabs(FR))output(Max*FL/fabs(FL),Max*BL/fabs(FL),Max*BR/fabs(FL),Max*FR/fabs(FL)); |
la00noix | 0:c61c6e4775ca | 94 | else if(fabs(BL)>=fabs(FL)&&fabs(BL)>=fabs(BR)&&fabs(BL)>=fabs(FR))output(Max*FL/fabs(BL),Max*BL/fabs(BL),Max*BR/fabs(BL),Max*FR/fabs(BL)); |
la00noix | 0:c61c6e4775ca | 95 | else if(fabs(BR)>=fabs(FL)&&fabs(BR)>=fabs(BL)&&fabs(BR)>=fabs(FR))output(Max*FL/fabs(BR),Max*BL/fabs(BR),Max*BR/fabs(BR),Max*FR/fabs(BR)); |
la00noix | 0:c61c6e4775ca | 96 | else output(Max*FL/fabs(FR),Max*BL/fabs(FR),Max*BR/fabs(FR),Max*FR/fabs(FR)); |
la00noix | 6:26724c287387 | 97 | } else { |
la00noix | 0:c61c6e4775ca | 98 | output(FL,BL,BR,FR); |
la00noix | 0:c61c6e4775ca | 99 | } |
la00noix | 0:c61c6e4775ca | 100 | } |
la00noix | 0:c61c6e4775ca | 101 | |
la00noix | 6:26724c287387 | 102 | void ashi_led() |
la00noix | 6:26724c287387 | 103 | { |
la00noix | 6:26724c287387 | 104 | |
la00noix | 6:26724c287387 | 105 | if(now_angle > -1 && now_angle < 1) { |
la00noix | 6:26724c287387 | 106 | can_ashileddata0_0 = 1; |
la00noix | 6:26724c287387 | 107 | } else { |
la00noix | 6:26724c287387 | 108 | can_ashileddata0_0 = 0; |
la00noix | 0:c61c6e4775ca | 109 | } |
la00noix | 6:26724c287387 | 110 | |
la00noix | 6:26724c287387 | 111 | if(now_angle > 350) { |
la00noix | 6:26724c287387 | 112 | can_ashileddata0_1 = 1; |
la00noix | 6:26724c287387 | 113 | } else { |
la00noix | 6:26724c287387 | 114 | can_ashileddata0_1 = 0; |
la00noix | 0:c61c6e4775ca | 115 | } |
la00noix | 6:26724c287387 | 116 | |
la00noix | 6:26724c287387 | 117 | if(now_x > -1 && now_x < 1) { |
la00noix | 6:26724c287387 | 118 | can_ashileddata0_2 = 1; |
la00noix | 6:26724c287387 | 119 | } else { |
la00noix | 6:26724c287387 | 120 | can_ashileddata0_2 = 0; |
la00noix | 0:c61c6e4775ca | 121 | } |
la00noix | 6:26724c287387 | 122 | |
la00noix | 6:26724c287387 | 123 | if(now_y > -1 && now_y < 1) { |
la00noix | 6:26724c287387 | 124 | can_ashileddata0_3 = 1; |
la00noix | 6:26724c287387 | 125 | } else { |
la00noix | 6:26724c287387 | 126 | can_ashileddata0_3 = 0; |
la00noix | 0:c61c6e4775ca | 127 | } |
la00noix | 6:26724c287387 | 128 | |
la00noix | 6:26724c287387 | 129 | can_ashileddata[0] = (can_ashileddata0_0<<7 | can_ashileddata0_1<<6 | can_ashileddata0_2<<5 | can_ashileddata0_3<<4); |
la00noix | 0:c61c6e4775ca | 130 | } |
la00noix | 0:c61c6e4775ca | 131 | |
la00noix | 6:26724c287387 | 132 | void calc_gyro() |
la00noix | 6:26724c287387 | 133 | { |
la00noix | 0:c61c6e4775ca | 134 | now_angle=gyro.getAngle(); //ジャイロの値読み込み |
la00noix | 0:c61c6e4775ca | 135 | } |
la00noix | 0:c61c6e4775ca | 136 | |
la00noix | 0:c61c6e4775ca | 137 | void calc_xy_enc() //エンコーダ&ジャイロによる座標計算 |
la00noix | 0:c61c6e4775ca | 138 | { |
la00noix | 0:c61c6e4775ca | 139 | now_angle=gyro.getAngle(); //ジャイロの値読み込み |
la00noix | 0:c61c6e4775ca | 140 | |
la00noix | 0:c61c6e4775ca | 141 | new_dist1=EC1.getDistance_mm(); |
la00noix | 0:c61c6e4775ca | 142 | new_dist2=EC2.getDistance_mm(); |
la00noix | 0:c61c6e4775ca | 143 | d_dist1=new_dist1-old_dist1; |
la00noix | 0:c61c6e4775ca | 144 | d_dist2=new_dist2-old_dist2; |
la00noix | 0:c61c6e4775ca | 145 | old_dist1=new_dist1; |
la00noix | 0:c61c6e4775ca | 146 | old_dist2=new_dist2; //微小時間当たりのエンコーダ読み込み |
la00noix | 0:c61c6e4775ca | 147 | |
la00noix | 0:c61c6e4775ca | 148 | d_x=d_dist2*sin(now_angle*PI/180)-d_dist1*cos(now_angle*PI/180); |
la00noix | 0:c61c6e4775ca | 149 | d_y=d_dist2*cos(now_angle*PI/180)+d_dist1*sin(now_angle*PI/180); //微小時間毎の座標変化 |
la00noix | 0:c61c6e4775ca | 150 | info.nowX.enc = info.nowX.enc + d_x; |
la00noix | 0:c61c6e4775ca | 151 | info.nowY.enc = info.nowY.enc - d_y; //微小時間毎に座標に加算 |
la00noix | 0:c61c6e4775ca | 152 | } |
la00noix | 0:c61c6e4775ca | 153 | |
la00noix | 6:26724c287387 | 154 | void set_cond(int t, int px, double bx, int py, double by) //超音波センサーを使用するときの条件設定関数 |
la00noix | 6:26724c287387 | 155 | { |
la00noix | 0:c61c6e4775ca | 156 | //引数の詳細は関数"calc_xy_usw"参照 |
la00noix | 6:26724c287387 | 157 | |
la00noix | 6:26724c287387 | 158 | xy_type = t; |
la00noix | 6:26724c287387 | 159 | |
la00noix | 6:26724c287387 | 160 | pm_typeX = px; |
la00noix | 6:26724c287387 | 161 | x_base = bx; |
la00noix | 6:26724c287387 | 162 | |
la00noix | 6:26724c287387 | 163 | pm_typeY = py; |
la00noix | 6:26724c287387 | 164 | y_base = by; |
la00noix | 0:c61c6e4775ca | 165 | } |
la00noix | 0:c61c6e4775ca | 166 | |
la00noix | 6:26724c287387 | 167 | void calc_xy_usw(double tgt_angle) //超音波センサーによる座標計算(機体が旋回する場合はこの方法による座標計算は出来ない) |
la00noix | 6:26724c287387 | 168 | { |
la00noix | 0:c61c6e4775ca | 169 | //tgt_angle:機体の目標角度(運動初期角度と同じ/今大会では0,90,180のみ) |
la00noix | 0:c61c6e4775ca | 170 | //xy_type:(0:Y軸平行の壁を読む/1:X軸平行の壁を読む/2:X,Y軸平行の壁を共に読む) |
la00noix | 0:c61c6e4775ca | 171 | //pm_typeX,pm_typeY:(0:各軸正方向側の壁を読む/1:各軸負方向側の壁を読む) |
la00noix | 0:c61c6e4775ca | 172 | //x_base,y_base:超音波センサーで読む壁の座標(y軸並行の壁のx座標/x軸平行の壁のy座標) |
la00noix | 6:26724c287387 | 173 | |
la00noix | 0:c61c6e4775ca | 174 | double R1=240,R2=240,R3=240,R4=240; //機体の中心から各超音波センサーが付いている面までの距離 |
yuki0701 | 9:337fe0747940 | 175 | double D1=42,D2=0,D3=0,D4=0; //各超音波センサーが付いている面の中心から各超音波センサーまでの距離 |
la00noix | 6:26724c287387 | 176 | |
la00noix | 0:c61c6e4775ca | 177 | now_angle=gyro.getAngle(); //ジャイロの値読み込み |
la00noix | 6:26724c287387 | 178 | |
la00noix | 6:26724c287387 | 179 | if(tgt_angle==0) { |
la00noix | 6:26724c287387 | 180 | if((xy_type==0 || xy_type==2) && pm_typeX==0) { |
la00noix | 6:26724c287387 | 181 | |
la00noix | 6:26724c287387 | 182 | info.nowX.usw = x_base - (usw_data4 + R4*cos(now_angle*PI/180) + D4*sin(now_angle*PI/180)); |
la00noix | 6:26724c287387 | 183 | |
la00noix | 6:26724c287387 | 184 | } else if((xy_type==0 || xy_type==2) && pm_typeX==1) { |
la00noix | 6:26724c287387 | 185 | |
la00noix | 6:26724c287387 | 186 | info.nowX.usw = x_base + (usw_data3 + R3*cos(now_angle*PI/180) + D3*sin(now_angle*PI/180)); |
la00noix | 6:26724c287387 | 187 | |
la00noix | 6:26724c287387 | 188 | } |
la00noix | 6:26724c287387 | 189 | if((xy_type==1 || xy_type==2) && pm_typeY==0) { |
la00noix | 6:26724c287387 | 190 | |
la00noix | 6:26724c287387 | 191 | info.nowY.usw = y_base - (usw_data2 + R2*cos(now_angle*PI/180) + D2*sin(now_angle*PI/180)); |
la00noix | 6:26724c287387 | 192 | |
la00noix | 6:26724c287387 | 193 | } else if((xy_type==1 || xy_type==2) && pm_typeY==1) { |
la00noix | 6:26724c287387 | 194 | |
la00noix | 6:26724c287387 | 195 | info.nowY.usw = y_base + (usw_data1 + R1*cos(now_angle*PI/180) + D1*sin(now_angle*PI/180)); |
la00noix | 6:26724c287387 | 196 | |
la00noix | 6:26724c287387 | 197 | } |
la00noix | 6:26724c287387 | 198 | |
la00noix | 6:26724c287387 | 199 | } else if(tgt_angle==90) { |
la00noix | 6:26724c287387 | 200 | if((xy_type==0 || xy_type==2) && pm_typeX==0) { |
la00noix | 6:26724c287387 | 201 | |
la00noix | 6:26724c287387 | 202 | info.nowX.usw = x_base - (usw_data1 + R1*cos(now_angle*PI/180) + D1*sin(now_angle*PI/180)); |
la00noix | 6:26724c287387 | 203 | |
la00noix | 6:26724c287387 | 204 | } else if((xy_type==0 || xy_type==2) && pm_typeX==1) { |
la00noix | 6:26724c287387 | 205 | |
la00noix | 6:26724c287387 | 206 | info.nowX.usw = x_base + (usw_data2 + R2*cos(now_angle*PI/180) + D2*sin(now_angle*PI/180)); |
la00noix | 6:26724c287387 | 207 | |
la00noix | 6:26724c287387 | 208 | } |
la00noix | 6:26724c287387 | 209 | if((xy_type==1 || xy_type==2) && pm_typeY==0) { |
la00noix | 6:26724c287387 | 210 | |
la00noix | 6:26724c287387 | 211 | info.nowY.usw = y_base - (usw_data4 + R4*cos(now_angle*PI/180) + D4*sin(now_angle*PI/180)); |
la00noix | 6:26724c287387 | 212 | |
la00noix | 6:26724c287387 | 213 | } else if((xy_type==1 || xy_type==2) && pm_typeY==1) { |
la00noix | 6:26724c287387 | 214 | |
la00noix | 6:26724c287387 | 215 | info.nowY.usw = y_base + (usw_data3 + R3*cos(now_angle*PI/180) + D3*sin(now_angle*PI/180)); |
la00noix | 6:26724c287387 | 216 | |
la00noix | 6:26724c287387 | 217 | } |
la00noix | 6:26724c287387 | 218 | |
yuki0701 | 8:4bdfac5b52e1 | 219 | } else if(tgt_angle==180 || tgt_angle == -180) { |
la00noix | 6:26724c287387 | 220 | if((xy_type==0 || xy_type==2) && pm_typeX==0) { |
la00noix | 6:26724c287387 | 221 | |
la00noix | 6:26724c287387 | 222 | info.nowX.usw = x_base - (usw_data3 + R3*cos(now_angle*PI/180) + D3*sin(now_angle*PI/180)); |
la00noix | 6:26724c287387 | 223 | |
la00noix | 6:26724c287387 | 224 | } else if((xy_type==0 || xy_type==2) && pm_typeX==1) { |
la00noix | 6:26724c287387 | 225 | |
la00noix | 6:26724c287387 | 226 | info.nowX.usw = x_base + (usw_data4 + R4*cos(now_angle*PI/180) + D4*sin(now_angle*PI/180)); |
la00noix | 6:26724c287387 | 227 | |
la00noix | 6:26724c287387 | 228 | } |
la00noix | 6:26724c287387 | 229 | if((xy_type==1 || xy_type==2) && pm_typeY==0) { |
la00noix | 6:26724c287387 | 230 | |
la00noix | 6:26724c287387 | 231 | info.nowY.usw = y_base - (usw_data1+ R1*cos(now_angle*PI/180) + D1*sin(now_angle*PI/180)); |
la00noix | 6:26724c287387 | 232 | |
la00noix | 6:26724c287387 | 233 | } else if((xy_type==1 || xy_type==2) && pm_typeY==1) { |
la00noix | 6:26724c287387 | 234 | |
la00noix | 6:26724c287387 | 235 | info.nowY.usw = y_base + (usw_data2 + R2*cos(now_angle*PI/180) + D2*sin(now_angle*PI/180)); |
la00noix | 6:26724c287387 | 236 | |
la00noix | 6:26724c287387 | 237 | } |
yuki0701 | 8:4bdfac5b52e1 | 238 | }else if(tgt_angle==-90) { |
yuki0701 | 8:4bdfac5b52e1 | 239 | if((xy_type==0 || xy_type==2) && pm_typeX==0) { |
yuki0701 | 8:4bdfac5b52e1 | 240 | |
yuki0701 | 8:4bdfac5b52e1 | 241 | info.nowX.usw = x_base - (usw_data2 + R2*cos(now_angle*PI/180) + D2*sin(now_angle*PI/180)); |
yuki0701 | 8:4bdfac5b52e1 | 242 | |
yuki0701 | 8:4bdfac5b52e1 | 243 | } else if((xy_type==0 || xy_type==2) && pm_typeX==1) { |
yuki0701 | 8:4bdfac5b52e1 | 244 | |
yuki0701 | 8:4bdfac5b52e1 | 245 | info.nowX.usw = x_base + (usw_data1 + R1*cos(now_angle*PI/180) + D1*sin(now_angle*PI/180)); |
yuki0701 | 8:4bdfac5b52e1 | 246 | |
yuki0701 | 8:4bdfac5b52e1 | 247 | } |
yuki0701 | 8:4bdfac5b52e1 | 248 | if((xy_type==1 || xy_type==2) && pm_typeY==0) { |
yuki0701 | 8:4bdfac5b52e1 | 249 | |
yuki0701 | 8:4bdfac5b52e1 | 250 | info.nowY.usw = y_base - (usw_data3 + R3*cos(now_angle*PI/180) + D3*sin(now_angle*PI/180)); |
yuki0701 | 8:4bdfac5b52e1 | 251 | |
yuki0701 | 8:4bdfac5b52e1 | 252 | } else if((xy_type==1 || xy_type==2) && pm_typeY==1) { |
yuki0701 | 8:4bdfac5b52e1 | 253 | |
yuki0701 | 8:4bdfac5b52e1 | 254 | info.nowY.usw = y_base + (usw_data4 + R4*cos(now_angle*PI/180) + D4*sin(now_angle*PI/180)); |
yuki0701 | 8:4bdfac5b52e1 | 255 | |
yuki0701 | 8:4bdfac5b52e1 | 256 | } |
yuki0701 | 8:4bdfac5b52e1 | 257 | |
la00noix | 0:c61c6e4775ca | 258 | } |
la00noix | 0:c61c6e4775ca | 259 | } |
la00noix | 0:c61c6e4775ca | 260 | |
la00noix | 6:26724c287387 | 261 | void calc_xy(double target_angle, double u,double v) |
la00noix | 6:26724c287387 | 262 | { |
la00noix | 0:c61c6e4775ca | 263 | //エンコーダにより求めた機体の座標と超音波センサーにより求めた機体の座標を(エンコーダ : 超音波 = u : 1-u / v : 1-v)の割合で混ぜて now_x,now_y に代入する |
la00noix | 6:26724c287387 | 264 | |
la00noix | 6:26724c287387 | 265 | calc_xy_enc(); |
la00noix | 6:26724c287387 | 266 | |
la00noix | 6:26724c287387 | 267 | if(u != 1 || v != 1) { |
la00noix | 6:26724c287387 | 268 | calc_xy_usw(target_angle); //エンコーダの値しか使用しない場合は超音波センサーによる座標計算は行わずに計算量を減らす。 |
la00noix | 6:26724c287387 | 269 | } |
la00noix | 6:26724c287387 | 270 | |
la00noix | 0:c61c6e4775ca | 271 | now_x = u * info.nowX.enc + (1-u) * info.nowX.usw; |
la00noix | 0:c61c6e4775ca | 272 | now_y = v * info.nowY.enc + (1-v) * info.nowY.usw; |
la00noix | 6:26724c287387 | 273 | |
la00noix | 0:c61c6e4775ca | 274 | /*if(now_x >-1 && now_x <1 && now_y >-1 && now_y <1){ //スタート時の0合わせ用 |
la00noix | 0:c61c6e4775ca | 275 | ec_led = 1; |
la00noix | 0:c61c6e4775ca | 276 | }else{ |
la00noix | 0:c61c6e4775ca | 277 | ec_led = 0; |
la00noix | 0:c61c6e4775ca | 278 | } |
la00noix | 6:26724c287387 | 279 | |
la00noix | 0:c61c6e4775ca | 280 | if(now_angle >-0.5 && now_angle <0.5){ |
la00noix | 0:c61c6e4775ca | 281 | gyro_led = 1; |
la00noix | 0:c61c6e4775ca | 282 | }else{ |
la00noix | 0:c61c6e4775ca | 283 | gyro_led = 0; |
la00noix | 0:c61c6e4775ca | 284 | }*/ |
la00noix | 0:c61c6e4775ca | 285 | } |
la00noix | 0:c61c6e4775ca | 286 | |
yuki0701 | 9:337fe0747940 | 287 | void enc_correction(int x_select,int y_select){ //エンコーダの座標を超音波センサの座標で上書き |
yuki0701 | 9:337fe0747940 | 288 | //x_select,y_select → (0:上書きしない/1:上書きする) |
yuki0701 | 9:337fe0747940 | 289 | |
yuki0701 | 9:337fe0747940 | 290 | if(x_select == 1){ |
yuki0701 | 9:337fe0747940 | 291 | info.nowX.enc = info.nowX.usw; |
yuki0701 | 9:337fe0747940 | 292 | } |
yuki0701 | 9:337fe0747940 | 293 | if(y_select == 1){ |
yuki0701 | 9:337fe0747940 | 294 | info.nowY.enc = info.nowY.usw; |
yuki0701 | 9:337fe0747940 | 295 | } |
yuki0701 | 9:337fe0747940 | 296 | |
yuki0701 | 9:337fe0747940 | 297 | } |
yuki0701 | 9:337fe0747940 | 298 | |
la00noix | 0:c61c6e4775ca | 299 | //ここからそれぞれのプログラム///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
la00noix | 0:c61c6e4775ca | 300 | //now_x(現在のx座標),now_y(現在のy座標),now_angle(機体角度(ラジアンではない)(0~360や-180~180とは限らない))(反時計回りが正) |
la00noix | 0:c61c6e4775ca | 301 | //ジャイロの出力は角度だが三角関数はラジアンとして計算する |
la00noix | 0:c61c6e4775ca | 302 | //通常の移動+座標のずれ補正+機体の角度補正(+必要に応じさらに別補正) |
la00noix | 0:c61c6e4775ca | 303 | //ジャイロの仕様上、角度補正をするときに計算式内で角度はそのままよりsinをとったほうがいいかもね |
la00noix | 0:c61c6e4775ca | 304 | |
la00noix | 0:c61c6e4775ca | 305 | void purecurve(int type,double u,double v, //正面を変えずに円弧or楕円を描いて曲がる |
la00noix | 0:c61c6e4775ca | 306 | double point_x1,double point_y1, |
la00noix | 0:c61c6e4775ca | 307 | double point_x2,double point_y2, |
la00noix | 0:c61c6e4775ca | 308 | int theta, |
la00noix | 0:c61c6e4775ca | 309 | double speed, |
la00noix | 0:c61c6e4775ca | 310 | double q_p,double q_d, |
la00noix | 0:c61c6e4775ca | 311 | double r_p,double r_d, |
la00noix | 0:c61c6e4775ca | 312 | double r_out_max, |
la00noix | 0:c61c6e4775ca | 313 | double target_angle) |
la00noix | 0:c61c6e4775ca | 314 | //type:動きの種類(8パターン) point_x1,point_y1=出発地点の座標 point_x2,point_x2=目標地点の座標 theta=plotの間隔(0~90°) speed=速度 |
la00noix | 0:c61c6e4775ca | 315 | { |
la00noix | 0:c61c6e4775ca | 316 | //-----PathFollowingのパラメーター設定-----// |
la00noix | 0:c61c6e4775ca | 317 | q_setPDparam(q_p,q_d); //ベクトルABに垂直な方向の誤差を埋めるPD制御のパラメータ設定関数 |
la00noix | 0:c61c6e4775ca | 318 | r_setPDparam(r_p,r_d); //機体角度と目標角度の誤差を埋めるPD制御のパラメータ設定関数 |
la00noix | 0:c61c6e4775ca | 319 | set_r_out(r_out_max); //旋回時の最大出力値設定関数 |
la00noix | 0:c61c6e4775ca | 320 | set_target_angle(target_angle); //機体目標角度設定関数 |
la00noix | 0:c61c6e4775ca | 321 | |
la00noix | 0:c61c6e4775ca | 322 | int s; |
la00noix | 0:c61c6e4775ca | 323 | int t = 0; |
la00noix | 0:c61c6e4775ca | 324 | double X,Y;//X=楕円の中心座標、Y=楕円の中心座標 |
la00noix | 0:c61c6e4775ca | 325 | double a,b; //a=楕円のx軸方向の幅の半分,b=楕円のy軸方向の幅の半分 |
la00noix | 0:c61c6e4775ca | 326 | double plotx[(90/theta)+1]; //楕円にとるplotのx座標 |
la00noix | 0:c61c6e4775ca | 327 | double ploty[(90/theta)+1]; |
la00noix | 0:c61c6e4775ca | 328 | |
la00noix | 0:c61c6e4775ca | 329 | double x_out,y_out,r_out; |
la00noix | 0:c61c6e4775ca | 330 | |
la00noix | 0:c61c6e4775ca | 331 | a=fabs(point_x1-point_x2); |
la00noix | 0:c61c6e4775ca | 332 | b=fabs(point_y1-point_y2); |
la00noix | 0:c61c6e4775ca | 333 | |
la00noix | 0:c61c6e4775ca | 334 | switch(type) { |
la00noix | 0:c61c6e4775ca | 335 | |
la00noix | 0:c61c6e4775ca | 336 | case 1://→↑移動 |
la00noix | 0:c61c6e4775ca | 337 | X=point_x1; |
la00noix | 0:c61c6e4775ca | 338 | Y=point_y2; |
la00noix | 0:c61c6e4775ca | 339 | |
la00noix | 0:c61c6e4775ca | 340 | for(s=0; s<((90/theta)+1); s++) { |
la00noix | 0:c61c6e4775ca | 341 | plotx[s] = X + a * cos(-PI/2 + s * (PI*theta/180)); |
la00noix | 0:c61c6e4775ca | 342 | ploty[s] = Y + b * sin(-PI/2 + s * (PI*theta/180)); |
la00noix | 0:c61c6e4775ca | 343 | //debug_printf("plotx[%d]=%f ploty[%d]=%f\n\r",s,plotx[s],s,ploty[s]); |
la00noix | 0:c61c6e4775ca | 344 | } |
la00noix | 0:c61c6e4775ca | 345 | break; |
la00noix | 0:c61c6e4775ca | 346 | |
la00noix | 0:c61c6e4775ca | 347 | case 2://↑→移動 |
la00noix | 0:c61c6e4775ca | 348 | X=point_x2; |
la00noix | 0:c61c6e4775ca | 349 | Y=point_y1; |
la00noix | 0:c61c6e4775ca | 350 | |
la00noix | 0:c61c6e4775ca | 351 | for(s=0; s<((90/theta)+1); s++) { |
la00noix | 0:c61c6e4775ca | 352 | plotx[s] = X + a * cos(PI - s * (PI*theta/180)); |
la00noix | 0:c61c6e4775ca | 353 | ploty[s] = Y + b * sin(PI - s * (PI*theta/180)); |
la00noix | 0:c61c6e4775ca | 354 | //debug_printf("plotx[%d]=%f ploty[%d]=%f\n\r",s,plotx[s],s,ploty[s]); |
la00noix | 0:c61c6e4775ca | 355 | } |
la00noix | 0:c61c6e4775ca | 356 | break; |
la00noix | 0:c61c6e4775ca | 357 | |
la00noix | 0:c61c6e4775ca | 358 | case 3://↑←移動 |
la00noix | 0:c61c6e4775ca | 359 | X=point_x2; |
la00noix | 0:c61c6e4775ca | 360 | Y=point_y1; |
la00noix | 0:c61c6e4775ca | 361 | |
la00noix | 0:c61c6e4775ca | 362 | for(s=0; s<((90/theta)+1); s++) { |
la00noix | 0:c61c6e4775ca | 363 | plotx[s] = X + a * cos(s * (PI*theta/180)); |
la00noix | 0:c61c6e4775ca | 364 | ploty[s] = Y + b * sin(s * (PI*theta/180)); |
la00noix | 0:c61c6e4775ca | 365 | //debug_printf("plotx[%d]=%f ploty[%d]=%f\n\r",s,plotx[s],s,ploty[s]); |
la00noix | 0:c61c6e4775ca | 366 | } |
la00noix | 0:c61c6e4775ca | 367 | break; |
la00noix | 0:c61c6e4775ca | 368 | |
la00noix | 0:c61c6e4775ca | 369 | case 4://←↑移動 |
la00noix | 0:c61c6e4775ca | 370 | X=point_x1; |
la00noix | 0:c61c6e4775ca | 371 | Y=point_y2; |
la00noix | 0:c61c6e4775ca | 372 | |
la00noix | 0:c61c6e4775ca | 373 | for(s=0; s<((90/theta)+1); s++) { |
la00noix | 0:c61c6e4775ca | 374 | plotx[s] = X + a * cos(-PI/2 - s * (PI*theta/180)); |
la00noix | 0:c61c6e4775ca | 375 | ploty[s] = Y + b * sin(-PI/2 - s * (PI*theta/180)); |
la00noix | 0:c61c6e4775ca | 376 | //debug_printf("plotx[%d]=%f ploty[%d]=%f\n\r",s,plotx[s],s,ploty[s]); |
la00noix | 0:c61c6e4775ca | 377 | } |
la00noix | 0:c61c6e4775ca | 378 | break; |
la00noix | 0:c61c6e4775ca | 379 | |
la00noix | 0:c61c6e4775ca | 380 | case 5://←↓移動 |
la00noix | 0:c61c6e4775ca | 381 | X=point_x1; |
la00noix | 0:c61c6e4775ca | 382 | Y=point_y2; |
la00noix | 0:c61c6e4775ca | 383 | |
la00noix | 0:c61c6e4775ca | 384 | for(s=0; s<((90/theta)+1); s++) { |
la00noix | 0:c61c6e4775ca | 385 | plotx[s] = X + a * cos(PI/2 + s * (PI*theta/180)); |
la00noix | 0:c61c6e4775ca | 386 | ploty[s] = Y + b * sin(PI/2 + s * (PI*theta/180)); |
la00noix | 0:c61c6e4775ca | 387 | //debug_printf("plotx[%d]=%f ploty[%d]=%f\n\r",s,plotx[s],s,ploty[s]); |
la00noix | 0:c61c6e4775ca | 388 | } |
la00noix | 0:c61c6e4775ca | 389 | break; |
la00noix | 0:c61c6e4775ca | 390 | |
la00noix | 0:c61c6e4775ca | 391 | case 6://↓←移動 |
la00noix | 0:c61c6e4775ca | 392 | X=point_x2; |
la00noix | 0:c61c6e4775ca | 393 | Y=point_y1; |
la00noix | 0:c61c6e4775ca | 394 | |
la00noix | 0:c61c6e4775ca | 395 | for(s=0; s<((90/theta)+1); s++) { |
la00noix | 0:c61c6e4775ca | 396 | plotx[s] = X + a * cos(-s * (PI*theta/180)); |
la00noix | 0:c61c6e4775ca | 397 | ploty[s] = Y + b * sin(-s * (PI*theta/180)); |
la00noix | 0:c61c6e4775ca | 398 | //debug_printf("plotx[%d]=%f ploty[%d]=%f\n\r",s,plotx[s],s,ploty[s]); |
la00noix | 0:c61c6e4775ca | 399 | } |
la00noix | 0:c61c6e4775ca | 400 | break; |
la00noix | 0:c61c6e4775ca | 401 | |
la00noix | 0:c61c6e4775ca | 402 | case 7://↓→移動 |
la00noix | 0:c61c6e4775ca | 403 | X=point_x2; |
la00noix | 0:c61c6e4775ca | 404 | Y=point_y1; |
la00noix | 0:c61c6e4775ca | 405 | |
la00noix | 0:c61c6e4775ca | 406 | for(s=0; s<((90/theta)+1); s++) { |
la00noix | 0:c61c6e4775ca | 407 | plotx[s] = X + a * cos(PI + s * (PI*theta/180)); |
la00noix | 0:c61c6e4775ca | 408 | ploty[s] = Y + b * sin(PI + s * (PI*theta/180)); |
la00noix | 0:c61c6e4775ca | 409 | //debug_printf("plotx[%d]=%f ploty[%d]=%f\n\r",s,plotx[s],s,ploty[s]); |
la00noix | 0:c61c6e4775ca | 410 | } |
la00noix | 0:c61c6e4775ca | 411 | break; |
la00noix | 0:c61c6e4775ca | 412 | |
la00noix | 0:c61c6e4775ca | 413 | case 8://→↓移動 |
la00noix | 0:c61c6e4775ca | 414 | X=point_x1; |
la00noix | 0:c61c6e4775ca | 415 | Y=point_y2; |
la00noix | 0:c61c6e4775ca | 416 | |
la00noix | 0:c61c6e4775ca | 417 | for(s=0; s<((90/theta)+1); s++) { |
la00noix | 0:c61c6e4775ca | 418 | plotx[s] = X + a * cos(PI/2 - s * (PI*theta/180)); |
la00noix | 0:c61c6e4775ca | 419 | ploty[s] = Y + b * sin(PI/2 - s * (PI*theta/180)); |
la00noix | 0:c61c6e4775ca | 420 | //debug_printf("plotx[%d]=%f ploty[%d]=%f\n\r",s,plotx[s],s,ploty[s]); |
la00noix | 0:c61c6e4775ca | 421 | } |
la00noix | 0:c61c6e4775ca | 422 | break; |
la00noix | 0:c61c6e4775ca | 423 | } |
la00noix | 0:c61c6e4775ca | 424 | |
la00noix | 0:c61c6e4775ca | 425 | while(1) { |
la00noix | 0:c61c6e4775ca | 426 | |
la00noix | 0:c61c6e4775ca | 427 | calc_xy(target_angle,u,v); |
la00noix | 0:c61c6e4775ca | 428 | |
la00noix | 0:c61c6e4775ca | 429 | XYRmotorout(plotx[t],ploty[t],plotx[t+1],ploty[t+1],&x_out,&y_out,&r_out,speed,speed); |
la00noix | 0:c61c6e4775ca | 430 | CalMotorOut(x_out,y_out,r_out); |
la00noix | 0:c61c6e4775ca | 431 | //debug_printf("t=%d now_x=%f now_y=%f x_out=%f y_out=%f\n\r",t,now_x,now_y,x_out,y_out); |
la00noix | 0:c61c6e4775ca | 432 | |
la00noix | 0:c61c6e4775ca | 433 | base(GetMotorOut(0),GetMotorOut(1),GetMotorOut(2),GetMotorOut(3),4095); //m1~m4に代入 |
la00noix | 0:c61c6e4775ca | 434 | //debug_printf("t=%d (0)=%f (1)=%f (2)=%f (3)=%f\n\r",t,GetMotorOut(0),GetMotorOut(1),GetMotorOut(2),GetMotorOut(3)); |
la00noix | 6:26724c287387 | 435 | |
la00noix | 0:c61c6e4775ca | 436 | if(((plotx[t+1] - now_x)*(plotx[t+1] - plotx[t]) + (ploty[t+1] - now_y)*(ploty[t+1] - ploty[t])) < 0)t++; |
la00noix | 0:c61c6e4775ca | 437 | |
la00noix | 0:c61c6e4775ca | 438 | MaxonControl(m1,m2,m3,m4); //出力 |
la00noix | 0:c61c6e4775ca | 439 | debug_printf("t=%d m1=%d m2=%d m3=%d m4=%d x=%f y=%f angle=%f\n\r",t,m1,m2,m3,m4,now_x,now_y,now_angle); |
la00noix | 6:26724c287387 | 440 | |
la00noix | 0:c61c6e4775ca | 441 | if(t == (90/theta))break; |
la00noix | 0:c61c6e4775ca | 442 | if(id1_value[0] != 1)break; |
la00noix | 0:c61c6e4775ca | 443 | } |
la00noix | 0:c61c6e4775ca | 444 | } |
la00noix | 0:c61c6e4775ca | 445 | |
la00noix | 0:c61c6e4775ca | 446 | void gogo_straight(double u,double v, //直線運動プログラム |
la00noix | 0:c61c6e4775ca | 447 | double x1_point,double y1_point, |
la00noix | 0:c61c6e4775ca | 448 | double x2_point,double y2_point, |
la00noix | 0:c61c6e4775ca | 449 | double speed1,double speed2, |
la00noix | 0:c61c6e4775ca | 450 | double q_p,double q_d, |
la00noix | 0:c61c6e4775ca | 451 | double r_p,double r_d, |
la00noix | 0:c61c6e4775ca | 452 | double r_out_max, |
la00noix | 0:c61c6e4775ca | 453 | double target_angle) |
la00noix | 0:c61c6e4775ca | 454 | //引数:出発地点の座標(x,y)、目標地点の座標(x,y)、初速度(speed1)、目標速度(speed2)//speed1=speed2 のとき等速運動 |
la00noix | 0:c61c6e4775ca | 455 | { |
la00noix | 0:c61c6e4775ca | 456 | //-----PathFollowingのパラメーター設定-----// |
la00noix | 0:c61c6e4775ca | 457 | q_setPDparam(q_p,q_d); //ベクトルABに垂直な方向の誤差を埋めるPD制御のパラメータ設定関数 |
la00noix | 0:c61c6e4775ca | 458 | r_setPDparam(r_p,r_d); //機体角度と目標角度の誤差を埋めるPD制御のパラメータ設定関数 |
la00noix | 0:c61c6e4775ca | 459 | set_r_out(r_out_max); //旋回時の最大出力値設定関数 |
la00noix | 0:c61c6e4775ca | 460 | set_target_angle(target_angle); //機体目標角度設定関数 |
la00noix | 6:26724c287387 | 461 | |
la00noix | 0:c61c6e4775ca | 462 | while (1) { |
la00noix | 0:c61c6e4775ca | 463 | |
la00noix | 0:c61c6e4775ca | 464 | calc_xy(target_angle,u,v); |
la00noix | 0:c61c6e4775ca | 465 | |
la00noix | 0:c61c6e4775ca | 466 | XYRmotorout(x1_point,y1_point,x2_point,y2_point,&x_out,&y_out,&r_out,speed1,speed2); |
la00noix | 0:c61c6e4775ca | 467 | //printf("x = %f, y = %f,angle = %f,x_out=%lf, y_out=%lf, r_out=%lf\n\r",now_x,now_y,now_angle,x_out, y_out,r_out); |
la00noix | 0:c61c6e4775ca | 468 | |
la00noix | 0:c61c6e4775ca | 469 | CalMotorOut(x_out,y_out,r_out); |
la00noix | 0:c61c6e4775ca | 470 | //printf("out1=%lf, out2=%lf, out3=%lf, out4=%lf\n",GetMotorOut(0),GetMotorOut(1),GetMotorOut(2),GetMotorOut(3)); |
la00noix | 0:c61c6e4775ca | 471 | |
la00noix | 0:c61c6e4775ca | 472 | base(GetMotorOut(0),GetMotorOut(1),GetMotorOut(2),GetMotorOut(3),4095); |
la00noix | 0:c61c6e4775ca | 473 | //printf("m1=%d, m2=%d, m3=%d, m4=%d\r\n",m_1,m_2,m_3,m_4); |
la00noix | 6:26724c287387 | 474 | |
la00noix | 0:c61c6e4775ca | 475 | MaxonControl(m1,m2,m3,m4); |
la00noix | 0:c61c6e4775ca | 476 | debug_printf("m1=%d m2=%d m3=%d m4=%d x=%f y=%f angle=%f\n\r",m1,m2,m3,m4,now_x,now_y,now_angle); |
la00noix | 0:c61c6e4775ca | 477 | |
la00noix | 0:c61c6e4775ca | 478 | if(((x2_point - now_x)*(x2_point - x1_point) + (y2_point - now_y)*(y2_point - y1_point)) < 0)break; |
la00noix | 6:26724c287387 | 479 | if(id1_value[0] != 1)break; |
la00noix | 0:c61c6e4775ca | 480 | } |
la00noix | 0:c61c6e4775ca | 481 | } |
la00noix | 0:c61c6e4775ca | 482 | |
la00noix | 6:26724c287387 | 483 | void pos_correction(double tgt_x, double tgt_y, double tgt_angle, double u, double v) //位置補正(使用前にMaxonControl(0,0,0,0)を入れる) |
la00noix | 6:26724c287387 | 484 | { |
la00noix | 6:26724c287387 | 485 | |
la00noix | 0:c61c6e4775ca | 486 | double r, R=10; // r:一回補正が入るごとの機体の位置と目標位置の距離(ズレ) R:補正終了とみなす目標位置からの機体の位置のズレ |
la00noix | 0:c61c6e4775ca | 487 | double out; |
la00noix | 6:26724c287387 | 488 | |
la00noix | 0:c61c6e4775ca | 489 | calc_xy(tgt_angle, u, v); |
la00noix | 6:26724c287387 | 490 | |
la00noix | 6:26724c287387 | 491 | while(1) { //機体の位置を目標領域(目標座標+許容誤差)に収める |
la00noix | 4:317c53a674fa | 492 | gogo_straight(u,v,now_x,now_y,tgt_x,tgt_y,200,50,5,0.1,10,0.1,500,tgt_angle); |
la00noix | 0:c61c6e4775ca | 493 | MaxonControl(0,0,0,0); |
la00noix | 6:26724c287387 | 494 | |
la00noix | 0:c61c6e4775ca | 495 | calc_xy(tgt_angle, u, v); |
la00noix | 6:26724c287387 | 496 | |
la00noix | 0:c61c6e4775ca | 497 | r=hypot(now_x - tgt_x, now_y - tgt_y); |
la00noix | 6:26724c287387 | 498 | |
la00noix | 0:c61c6e4775ca | 499 | if(r < R) break; |
la00noix | 7:44ce34007499 | 500 | if(id1_value[0] != 1)break; |
la00noix | 0:c61c6e4775ca | 501 | } |
la00noix | 6:26724c287387 | 502 | |
la00noix | 6:26724c287387 | 503 | while(1) { |
la00noix | 6:26724c287387 | 504 | |
la00noix | 0:c61c6e4775ca | 505 | calc_gyro(); |
la00noix | 6:26724c287387 | 506 | |
la00noix | 0:c61c6e4775ca | 507 | out = 10 * (tgt_angle - now_angle); |
la00noix | 6:26724c287387 | 508 | |
la00noix | 0:c61c6e4775ca | 509 | if(out > 300) { //0~179°のときは時計回りに回転 |
la00noix | 0:c61c6e4775ca | 510 | MaxonControl(300,300,300,300); |
la00noix | 6:26724c287387 | 511 | } else if(out < -300) { |
la00noix | 6:26724c287387 | 512 | MaxonControl(-300,-300,-300,-300); |
la00noix | 6:26724c287387 | 513 | } else if(out <= 300 && out > -300) { |
la00noix | 0:c61c6e4775ca | 514 | MaxonControl(out,out,out,out); |
la00noix | 0:c61c6e4775ca | 515 | } |
la00noix | 6:26724c287387 | 516 | |
yuki0701 | 3:8a0faa3b08c3 | 517 | if(tgt_angle - 0.5 < now_angle && now_angle < tgt_angle + 0.5) break; //目標角度からの許容誤差内に機体の角度が収まった時、補正終了 |
la00noix | 7:44ce34007499 | 518 | if(id1_value[0] != 1)break; |
la00noix | 0:c61c6e4775ca | 519 | } |
la00noix | 0:c61c6e4775ca | 520 | MaxonControl(0,0,0,0); |
la00noix | 0:c61c6e4775ca | 521 | } |