2021sample

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
MCR_Xavier
Date:
Sat May 29 04:58:51 2021 +0000
Parent:
1:c5854b9559f9
Commit message:
Minitrace2021sample

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Jun 09 07:46:22 2019 +0000
+++ b/main.cpp	Sat May 29 04:58:51 2021 +0000
@@ -45,7 +45,7 @@
 int SensR[9],SensL[9];
 double PGainCLB=0;          //Pゲイン調整変数
 double IGainCLB=0;          //Iゲイン調整変数
-double DGainCLB=1.7;          //Dゲイン調整変数
+double DGainCLB=0;//1.7;          //Dゲイン調整変数
 double SensVal_I,SensVal_IBuf=0;
 char turnFlg=0;
 char Stime;
@@ -115,13 +115,13 @@
         //ledval = int(RMotorVal*0.016);
             }
         
-        L_Dir = MotorL_Rev;             //右モータ回転方向(H:CW)
+        L_Dir = !MotorL_Rev;             //右モータ回転方向(H:CW)
         R_Dir = !MotorR_Rev;            //左モータ回転方向(L:FW)
                     }    
 //------------ライントレース--------------------
 void LineTrace(void){
     int SensVal,SensVal_D;
-    double PGain=0.026,IGain=0.0002,DGain=0.7;
+    double PGain=0.026,IGain=0.0002,DGain=1.6;
     if(SensorR <= 5000 && SensorL <= 5000) CommSpeed=0;
     SensVal = SensorR - SensorL;
     if(SensVal <= 0 && !turnFlg){//turnL
@@ -138,8 +138,8 @@
     if(SensVal_I <= (-100000000)) SensVal_I = (-100000000);
     SensVal_D = SensValBuf - SensVal;
     SensValBuf = SensVal;
-    MotorR = int((CommSpeed - ((SensVal * PGain)+(SensVal_I*IGain)-(SensVal_D*DGainCLB))))/10;
-    MotorL = int(CommSpeed + ((SensVal * PGain)+(SensVal_I*IGain)-(SensVal_D*DGainCLB)))/10;
+    MotorR = int(((CommSpeed - ((SensVal * PGain)+(SensVal_I*IGain)-(SensVal_D*DGain))))/10);
+    MotorL = int((CommSpeed + ((SensVal * PGain)+(SensVal_I*IGain)-(SensVal_D*DGain)))/10);
     ledval = int(SensVal_IBuf / (-100000));
     //MotorR = int(CommSpeed - (SensVal * PGainCLB));
     //MotorL = int(CommSpeed + (SensVal * PGainCLB));
@@ -201,13 +201,14 @@
     while(1) {
         if(!SW_IN)
          {
-             DGainCLB = DGainCLB + 0.1;
+             //DGainCLB = DGainCLB + 0.1;
              pc.printf("%5d  %5d  %5d %5d %f %d \r\n",SensorL,SensorR,MotorL,MotorR,DGainCLB,turnFlg);
              //ledval++;
+             wait(0.1);
              }   
              if(timer1 <= 1000)SensVal_IBuf = 0;
              if(SensVal_I <= (-10000) || SensVal_I >= 10000 )CommSpeed = 200;
-              else CommSpeed=490;
+              else CommSpeed=450;
         wait(0.01);
 
     }