Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of PID by
Diff: main.cpp
- Revision:
- 3:5d7dca0ca819
- Parent:
- 2:18a1325ac2f2
- Child:
- 4:77e3082c7cf7
--- a/main.cpp	Mon Jul 23 22:57:25 2018 +0000
+++ b/main.cpp	Tue Jul 24 01:04:10 2018 +0000
@@ -2,7 +2,7 @@
 #include "EC.h"
 #define K 0.01
 #define stride 0.01
-#define count 20
+#define count 40
 Serial pc(USBTX,USBRX);
 
 PwmOut motorF(PA_3); //モータードライバの接続ピン
@@ -13,7 +13,7 @@
 
 void out (double duty)
 {
-    double duty_max = 0.3;
+    double duty_max = 0.6;
     if(duty > 0) { //入力duty比が正の場合
         if( abs(duty) < duty_max ) { //制限値を超えていない場合
             motorF = abs(duty);
@@ -48,8 +48,8 @@
         pc.printf("Kp = %f : ",K+j*stride);
         timer.reset();
         i=0;
-        while(i<count) {
-            if(omega_old == 0 && Ec1.getOmega() == 0) break;
+        while(i<count && timer.read()<3) {
+            if(omega_old == 0 && Ec1.getOmega() == 0) {}
             else if(omega_old * Ec1.getOmega() <= 0) i++;
             omega_old = Ec1.getOmega();
             out((10*(j%2) - Ec1.getCount()*(-1)*30*5/6*3.14159265359/2048) * (K + j*stride));
@@ -58,6 +58,7 @@
         pc.printf("TimeOut\r\n");
         j++;
     }
+    out(0);
     double period = timer.read() / count;
     pc.printf("K = %f, T = %fs\r\n",K+j*stride,period);
     pc.printf("Kp = %f, Ki = %f, Kd = %f",0.6*(K+j*stride),0.5*period,0.125*period);
    