Determine motor constants

Dependencies:   HIDScope QEI mbed

Fork of frdm_motorConstantesBepalen by Gerhard Berman

Files at this revision

API Documentation at this revision

Comitter:
Marieke
Date:
Tue Nov 01 16:24:38 2016 +0000
Parent:
1:b7a1138131bb
Commit message:
Script to determine motor constants

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r b7a1138131bb -r 78a4dccff486 main.cpp
--- a/main.cpp	Fri Oct 28 11:32:42 2016 +0000
+++ b/main.cpp	Tue Nov 01 16:24:38 2016 +0000
@@ -13,12 +13,14 @@
 DigitalOut motor2 (D4);
 PwmOut pwm_motor2 (D5);
 HIDScope    scope( 4 );
-Ticker      sample_timer;
+Ticker      sample_timer, snelheid_ticker;
 
 double t;
-float pi=3.14159;
-float Aout;
-float PWMAout;
+double pi=3.14159;
+double Aout;
+double PWMAout;
+//float v_1;
+int counts1_old;
 int counts1;
 int counts2;
 const int cw=0;
@@ -26,48 +28,72 @@
 
 void sample()
 {
+    //v_1 = (float) ((counts1 - counts1_old)/0.02);
+    //counts1_old=counts1;
     scope.set(0, counts1);
     scope.set(1, counts2);
     scope.set(2, Aout);
     scope.set(3, PWMAout);
+    //scope.set(3, PWMAout);
     scope.send();
 }
 
 
+/*void snelheid()
+{
+        //counts1 = Encoder1.getPulses();
+        v_1 = (float) ((counts1 - counts1_old)/0.01);
+        counts1_old=counts1;
+        //counts2 = Encoder2.getPulses();
+        
+        scope.set(2, v_1);
+        scope.send();
+}*/
+
+
 int main() {
-    const double frequency_pwm = 100.0;
+    const double frequency_pwm = 0.5;
     pwm_motor1.period(1.0/frequency_pwm);
     pwm_motor2.period(1.0/frequency_pwm);
     QEI Encoder1(D12, D13, NC, 32); //maakt de encoder aan, NC niet aanwezig, 32 bits
     QEI Encoder2(D10, D11, NC, 32); //maakt de encoder aan, NC niet aanwezig, 32 bits
     sample_timer.attach(&sample, 0.001);
+    //snelheid_ticker.attach(&snelheid, 0.01f);
+    
  
     while(true){
-      for (t=0; t<10; t=t+0.05) {
-                Aout=1*sin(2*pi*t);
-                PWMAout=(Aout+1)/2;
+      for (t=0; t<2000; t=t+0.1) {
+                Aout= (double) 1*sin(0.001*pi*t);
+                PWMAout=fabs((Aout+1)/2);
             if (Aout >=0) //clockwise rotation
-                {motor1=cw;        
+                {motor1.write(cw);        //?
             }
-        else    //counterclockwise rotation 
-            {motor1=ccw;         
+            else    //counterclockwise rotation 
+            {motor1.write(ccw);         
             }
-        pwm_motor1.write(PWMAout);
+            pwm_motor1.write(PWMAout);
     
-        if (Aout >=0) //clockwise rotation
-            {motor2=cw;        
+            if (Aout >=0) //clockwise rotation
+            {motor2.write(ccw);        
             }
-        else    //counterclockwise rotation 
-            {motor2=ccw;         
+            else    //counterclockwise rotation 
+            {motor2.write(cw);         
             }
-        pwm_motor2.write(PWMAout);
+            pwm_motor2.write(PWMAout);
     
-        counts1 = Encoder1.getPulses();
-        counts2 = Encoder2.getPulses(); 
-     }
-            
-    
+        
+        
+        //while(true){
+      
+            /*motor1 = cw;  //clockwise
+            pwm_motor1.write(0.5);
+            motor2 = ccw;        
+            pwm_motor2.write(0.5);*/
+            counts1 = Encoder1.getPulses();
+            counts2 = Encoder2.getPulses();
+            }
     }
  }
 
-   
\ No newline at end of file
+
+