配列を使用し記憶走行を行う

Dependencies:   mbed AQM0802 CRotaryEncoder TB6612FNG

Revision:
1:19e2241a7aa7
Parent:
0:df99e50ed3fd
Child:
2:a28ca7c25ed1
--- a/main.cpp	Mon Jul 22 04:03:37 2019 +0000
+++ b/main.cpp	Mon Aug 26 04:55:44 2019 +0000
@@ -3,6 +3,10 @@
  #include "mbed.h"
  #include "CRotaryEncoder.h"
  
+ #define    PULSE_TO_UM     10  //エンコーダ1パルス当たりのタイヤ移動距離[um]
+                                //実測で値を調整する。
+ 
+  
  Serial PC(USBTX,USBRX);
  CRotaryEncoder encoder_a(D1,D0);       //モータAのエンコーダ
  CRotaryEncoder encoder_b(D11,D12);     //モータBのエンコーダ
@@ -10,14 +14,14 @@
  
  int main(){
     int enc_count_a=0,enc_count_b=0;    //エンコーダパルス数を格納
-    int rotation_a=0,rotation_b=0;      //回転数を格納
+    int distance_a=0,distance_b=0;      //タイヤ移動距離を格納[mm]
      while(1)
     {
          enc_count_a=encoder_a.Get();   //エンコーダパルス数を取得
          enc_count_b=encoder_b.Get();
-         rotation_a=enc_count_a/400;    //400パルスで一回転
-         rotation_b=enc_count_b/400;    
-         PC.printf("enc_a:%d   enc_b:%d\r\n",rotation_a,rotation_b);//表示
+         distance_a=(enc_count_a*PULSE_TO_UM)/1000;    //移動距離をmm単位で格納
+         distance_b=(enc_count_b*PULSE_TO_UM)/1000;    
+         PC.printf("dis_a:%d   dis_b:%d\r\n",distance_a,distance_b);//表示
          wait(0.5);
     }
  }