モータードライバーver4.1 角度フィードバック(クーロン摩擦補償) 角速度フィードバック

Dependencies:   mbed QEI PID DBG

Revision:
6:cc51f9e7ef18
Parent:
3:141dc1666df2
--- a/MotorDriver_ver4-1.cpp	Mon Jul 08 16:44:35 2019 +0000
+++ b/MotorDriver_ver4-1.cpp	Mon Aug 26 14:04:08 2019 +0000
@@ -47,7 +47,7 @@
 
 #define CW 1
 #define CCW 0
-#define MOTOR_FREUENCY 8000 //[Hz]
+#define MOTOR_FREUENCY 20000 //[Hz]
 
 #define MOTOR_TARGET_OMEGA_THRESHOLD    0.5f   //[deg/s]
 #define MOTOR_TARGET_THETA_THRESHOLD    0.5f   //[rad]
@@ -141,6 +141,7 @@
 void SerialFunction();
 void CANread();
 
+float buf = 0.0f;
 
 
 int main()
@@ -181,7 +182,7 @@
     
     PWM1 = 0.0f;
     PWM2 = 0.0f;
-    PHASE = 0.0f;
+    PHASE = 1.0f;
     SR = 0;
     
     // PID omega setup
@@ -223,13 +224,33 @@
     
     while(1)
     { 
+        /*
+        pc.printf("buf: %f \r\n", buf);
+        
+        if(buf > 0.0f)
+        {
+            SR = ABLE;
+            PHASE = (float)CW;
+            PWM1 = buf;
+            PWM2 = 1.0f;  
+        }
+        
+        else if(buf <= 0.0f)
+        {
+            SR = ABLE;
+            PHASE = (float)CCW;
+            PWM1 = -1*buf;
+            PWM2 = 1.0f;  
+        }
+        */
+        
         //Motor.current = ((Current.read()-current_bias)*((float)CURRENT_SENSOR_VCC/2.0f))/(CURRENT_SENSOR_RANGE*0.001f);
         
         //pc.printf("motor2.compute : %6.3f motor.compute : %6.3f theta : %6.3f omega[rps] :%6.3f \r\n", motor2.compute(), motor.compute(), Motor.theta, Motor.omega);
-        pc.printf("theta:%6.3f omega:%6.3f\r\n", Motor.theta, Motor.omega);
+        //pc.printf("theta:%6.3f omega:%6.3f\r\n", Motor.theta, Motor.omega);
         
-        MotorDrive(THETA_FEEDBACK, Motor.target);
-        //MotorDrive(OMEGA_FEEDBACK, Motor.target);
+        //MotorDrive(THETA_FEEDBACK, Motor.target);
+        MotorDrive(OMEGA_FEEDBACK, Motor.target);
         
         //pc.printf("current:%f omega:%f pwm:%f \r\n",current.read(), omega ,motor.compute());  
         //CurrentFunction();
@@ -267,7 +288,7 @@
             case 'p': 
                 
                 //motor.setSetPoint(1.5f);  //PID target value
-                
+                buf += 0.15f;
                 Motor.target += 30.0f;
                 pc.printf("get 'p' \r\n");    
                 
@@ -276,7 +297,7 @@
             case 'l':
         
                 //motor.setSetPoint(0.5f);  //PID target value
-                
+                buf -= 0.15f;
                 Motor.target -= 30.0f;
                 pc.printf("get 'l' \r\n");