f3rc 3班のエンコーダのプログラムです。

Dependencies:   EC2 Math mbed

Revision:
2:a682612dd8b7
Parent:
1:0ff59878537a
Child:
3:f3ef2e7a9407
--- a/main.cpp	Mon Sep 03 05:21:06 2018 +0000
+++ b/main.cpp	Mon Sep 03 13:38:27 2018 +0000
@@ -1,6 +1,6 @@
 #include "mbed.h"
 #include "Math.h"
-#include "Ec.h"
+#include "EC.h"
 #include "SpeedController.h"
 DigitalIn cylinder(p9,PullUp);
 DigitalIn cylindert(p10,PullUp);
@@ -21,19 +21,18 @@
 
 EC wheel_1 (p11,p12,/*z相*/,/*分解能*/,0.05)
 EC wheel_2 (p13,p14,/*z相*/,/*分解能*/,0.05)
-//SpeedControl (p11,p12,/*z相*/,/*分解能*/,0.05,,) pwmでないのでscは使えないかも
-//SpeedControl (p13,p14,/*z相*/,/*分解能*/,0.05,,) pwmでないのでscは使えないかも
 
 /*直進用*/
-void straight(double t,int l)  //t=時間 l=移動距離
+void straight(int l)  //l=移動距離(mm)
 {
     mortor1.period_us(50);
     mortor2.period_us(50);
-    double EC1_omega = wheel_1.getOmega(); //ec1の角速度
-    double EC2_omega = wheel_2.getOmega(); //ec2の角速度
-    double L_1 = EC1_omega*"ecの半径"*t;
-    double L_2 = EC2_omega*"ecの半径"*t;
-    while(L_1 <= l && L_2 <= l) {
+    wheel_1.setDiameter_mm(/*測定輪半径(mm)*/);
+    wheel_2.setDiameter_mm(/*測定輪半径(mm)*/);
+    double EC1_distance = wheel_1.getDistance_mm (); //ec1の移動距離(mm)
+    double EC2_distance = wheel_2.getDistance_mm (); //ec2の移動距離(mm)
+    
+    while(EC1_distance <= l && EC2_distance <= l) {
         motor1 = ;
         motor2 = ;
         motor1cw = ;
@@ -42,15 +41,16 @@
 }
 
 /*後退用*/
-void back(double t,int l)  //t=時間 l=移動距離
+void straight(int l)  //l=移動距離(mm)
 {
     mortor1.period_us(50);
     mortor2.period_us(50);
-    double EC1_omega = wheel_1.getOmega();
-    double EC2_omega = wheel_2.getOmega();
-    double L_1 = EC1_omega*"ecの半径"*t;
-    double L_2 = EC2_omega*"ecの半径"*t;
-    while(L_1 <= l && L_2 <= l) {
+    wheel_1.setDiameter_mm(/*測定輪半径(mm)*/);
+    wheel_2.setDiameter_mm(/*測定輪半径(mm)*/);
+    double EC1_distance = wheel_1.getDistance_mm (); //ec1の移動距離(mm)
+    double EC2_distance = wheel_2.getDistance_mm (); //ec2の移動距離(mm)
+    
+    while(EC1_distance <= l && EC2_distance <= l) {
         motor1 = ;
         motor2 = ;
         motor1cw = ;
@@ -59,15 +59,16 @@
 }
 
 /*右回転*/
-void right(double t,int l)  //t=時間 l=機体の中心を回転中心としたときのエンコーダの移動距離
+void straight(int l)  //l=ecの移動距離(mm)
 {
     mortor1.period_us(50);
     mortor2.period_us(50);
-    double EC1_omega = wheel_1.getOmega();
-    double EC2_omega = wheel_2.getOmega();
-    double L_1 = EC1_omega*"ecの半径"*t;
-    double L_2 = EC2_omega*"ecの半径"*t;
-    while(L_1 <= l && L_2 <= -1*l) {
+    wheel_1.setDiameter_mm(/*測定輪半径(mm)*/);
+    wheel_2.setDiameter_mm(/*測定輪半径(mm)*/);
+    double EC1_distance = wheel_1.getDistance_mm (); //ec1の移動距離(mm)
+    double EC2_distance = wheel_2.getDistance_mm (); //ec2の移動距離(mm)
+    
+    while(EC1_distance <= l && EC2_distance <= -1*l) {
         motor1 = ;
         motor2 = ;
         motor1cw = ;
@@ -76,15 +77,16 @@
 }
 
 /*左回転*/
-void left(double t,int l)  //t=時間 l=l=機体の中心を回転中心としたときのエンコーダの移動距離
+void straight(int l)  //l=ecの移動距離(mm)
 {
     mortor1.period_us(50);
     mortor2.period_us(50);
-    double EC1_omega = wheel_1.getOmega();
-    double EC2_omega = wheel_2.getOmega();
-    double L_1 = EC1_omega*"ecの半径"*t;
-    double L_2 = EC2_omega*"ecの半径"*t;
-    while(L_1 <= -1*l && L_2 <= l) {
+    wheel_1.setDiameter_mm(/*測定輪半径(mm)*/);
+    wheel_2.setDiameter_mm(/*測定輪半径(mm)*/);
+    double EC1_distance = wheel_1.getDistance_mm (); //ec1の移動距離(mm)
+    double EC2_distance = wheel_2.getDistance_mm (); //ec2の移動距離(mm)
+    
+    while(EC1_distance <= -1*l && EC2_distance <= l) {
         motor1 = ;
         motor2 = ;
         motor1cw = ;