機械工学実験1

Dependencies:   PID QEI mbed

Revision:
1:35d14e37db1b
Parent:
0:41033932c9ec
Child:
2:d5f964932fce
--- a/main.cpp	Mon Oct 20 11:30:35 2014 +0000
+++ b/main.cpp	Thu Oct 23 08:33:07 2014 +0000
@@ -6,7 +6,10 @@
 
 //define
 #define PULSE_PER_REVOLUTION 200
-#define PID_RATE 10     //wait **ms
+#define PID_RATE 10     //wait **ms. If you change this value, response will be slightly different.
+
+#define KP_SCALE 10
+#define TI_SCALE 20
 
 //IO pin setting
 DigitalOut led1(LED1);      //mbed LED outputs
@@ -127,8 +130,8 @@
                 encoder.reset();
                 timer.reset();
                 
-                kp = KP;        //substitute from setting.h
-                ti = TI;
+                kp = KP / KP_SCALE;        //substitute from setting.h
+                ti = TI * TI_SCALE;
                 td = TD;
                 max_rpm = MAX_RPM;
                 target_rpm = TARGET_RPM;
@@ -161,7 +164,7 @@
                     Buzzer(-1);
                     break;
                 }
-                fprintf(fp,", kp = %f  ki = %f  kd = %f\n",kp, ti, td);
+                fprintf(fp,", kp = %.6f  ki = %.6f  kd = %.6f\n", (float)KP, (float)TI, (float)TD);
                 fprintf(fp,"Time , RPM\n");
                 for(int i = 0; i <= 15*1000/PID_RATE; i++){     //output results
                     fprintf(fp,"%f , %f\n", exp[i].t, exp[i].rpm);