2023春ロボ2班 足回りコード

Dependencies:   CalPID_2022 Encoder_2022 MPU6050 Madgwickfilter MotorController_2022 mbed

Files at this revision

API Documentation at this revision

Comitter:
yn_4009
Date:
Thu Dec 29 14:42:47 2022 +0000
Parent:
3:7c29db78fa24
Commit message:
test;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 7c29db78fa24 -r fc9688f7614a main.cpp
--- a/main.cpp	Thu Oct 27 08:16:01 2022 +0000
+++ b/main.cpp	Thu Dec 29 14:42:47 2022 +0000
@@ -18,61 +18,28 @@
 Serial pc(USBTX,USBRX);
 
 //速度制御のPID 前3つが係数なのでこれを調整 P→D→Iの順に調整
-CalPID speed_pidA(0.01,0.0,0.000,DELTA_T,DUTY_MAX);
-CalPID speed_pidB(0.01,0.0,0.000,DELTA_T,DUTY_MAX);
-CalPID speed_pidC(0.01,0.0,0.000,DELTA_T,DUTY_MAX);
-CalPID speed_pidD(0.01,0.0,0.000,DELTA_T,DUTY_MAX);
+CalPID speed_pidA(0.002,0.0,0.000,DELTA_T,DUTY_MAX);
+CalPID speed_pidB(0.002,0.0,0.000,DELTA_T,DUTY_MAX);
+CalPID speed_pidC(0.002,0.0,0.000,DELTA_T,DUTY_MAX);
+CalPID speed_pidD(0.002,0.0,0.000,DELTA_T,DUTY_MAX);
 //角度制御のPID 今回は不要だけどMotorContorollerの引数なので消さずに放置してください
 CalPID angle_omega_pid(0.0,0.0,0.0,DELTA_T,OMEGA_MAX);
 //エンコーダ(A層,B層,分解能)
 //モーター(正転,逆転,PWM周期,エンコーダ,CALPIDの角速度PID,角度PID)
-/////////////R1(f446re)////////////////
-
-/*
-//タイヤA
-Ec2multi ecA(PC_6,PC_8,RESOLUTION);
-MotorController motorA(PA_8,PA_9,50,ecA,speed_pidA,angle_omega_pid);
-//タイヤB
-Ec2multi ecB(PB_14,PB_15,RESOLUTION); 
-MotorController motorB(PB_1,PA_11,50,ecB,speed_pidB,angle_omega_pid);
-//タイヤC
-Ec2multi ecC(PC_12,PC_10,RESOLUTION);  
-MotorController motorC(PA_0,PA_1,50,ecC,speed_pidC,angle_omega_pid);
-//タイヤD
-Ec2multi ecD(PC_2,PC_3,RESOLUTION);  
-MotorController motorD(PB_4,PB_5,50,ecD,speed_pidC,angle_omega_pid);
-*/
-
 
 //タイヤA
-Ec2multi ecA(PC_3,PC_2,RESOLUTION);
-MotorController motorA(PA_8,PA_9,50,ecA,speed_pidA,angle_omega_pid);
+Ec2multi ecA(PC_12,PC_10,RESOLUTION); 
+MotorController motorA(PA_11,PB_1,50,ecA,speed_pidA,angle_omega_pid);
 //タイヤB
-Ec2multi ecB(PC_12,PC_10,RESOLUTION); 
-MotorController motorB(PB_1,PA_11,50,ecB,speed_pidB,angle_omega_pid);
+Ec2multi ecB(PC_3,PC_2,RESOLUTION);
+MotorController motorB(PB_5,PB_4,50,ecB,speed_pidB,angle_omega_pid);
 //タイヤC
-Ec2multi ecC(PC_6,PC_8,RESOLUTION);  
+Ec2multi ecC(PB_14,PB_15,RESOLUTION);  
 MotorController motorC(PA_0,PA_1,50,ecC,speed_pidC,angle_omega_pid);
 //タイヤD
-Ec2multi ecD(PB_14,PB_15,RESOLUTION);  
-MotorController motorD(PB_4,PB_5,50,ecD,speed_pidC,angle_omega_pid);
-
+Ec2multi ecD(PC_6,PC_8,RESOLUTION);  
+MotorController motorD(PA_8,PA_9,50,ecD,speed_pidC,angle_omega_pid);
 
-////////////////R2(f303k8)///////////////////////
-/*
-//タイヤA
-Ec2multi ecA(PB_4,PB_5,RESOLUTION);
-MotorController motorA(PA_10,PA_9,50,ecA,speed_pidA,angle_omega_pid);
-//タイヤB
-Ec2multi ecB(PB_7,PB_6,RESOLUTION); 
-MotorController motorB(PA_6,PA_7,50,ecB,speed_pidB,angle_omega_pid);
-//タイヤC
-Ec2multi ecC(PB_3,PF_1,RESOLUTION);  
-MotorController motorC(PA_1,PA_3,50,ecC,speed_pidC,angle_omega_pid);
-//タイヤD
-Ec2multi ecD(PA_8,PF_0,RESOLUTION);  
-MotorController motorD(PB_1,PB_0,50,ecD,speed_pidC,angle_omega_pid);
-*/
 
 Ticker ticker;  //割り込みタイマー
 
@@ -98,6 +65,7 @@
 float target_speed=0;
 int save_count;
 #define SAVE_COUNT_THRESHOLD 5 //0.05秒ごとに角速度を配列に格納
+
 void motorOut()//モーターを目標角速度で動かそうとし、一定の間隔で角速度を配列に保存
 {
     motorA.Sc(target_speed);
@@ -182,7 +150,7 @@
     //STARTが書かれた時点で開始する
     printf("START\r\n");
 
-    target_speed=-18.0;//ここで目標角速度を設定 最初はduty2の角速度で上手くいきそうならduty4.5の角速度
+    target_speed=18.0;//ここで目標角速度を設定 最初はduty2の角速度で上手くいきそうならduty4.5の角速度
     ticker.attach(&motorOut,DELTA_T);//割り込みタイマーをオンにする
 
     wait(5.0);//モーターが割り込みでまわり5秒分のデータを取る