Inverted Pendulum / Mbed 2 deprecated IP-Interface

Dependencies:   mbed QEI

Revision:
21:eac29cf3f061
Parent:
20:8063c82bbb35
Child:
22:c18f04d1dc49
diff -r 8063c82bbb35 -r eac29cf3f061 main.cpp
--- a/main.cpp	Wed Nov 16 08:28:46 2016 +0000
+++ b/main.cpp	Wed Nov 16 23:48:46 2016 +0000
@@ -82,45 +82,38 @@
     int start = encoder.getPulses();
     if(pulses >= 0){
         while(encoder.getPulses() < start + pulses){
-            printf("here");
-          // motor.clockwise(wait);    
+            motor.clockwise(wait);    
         } 
     }else{
         while(encoder.getPulses() > start + pulses){
-          // motor.anticlockwise(wait);
+            motor.anticlockwise(wait);
         }
     } 
 }
 
-void test_pulsetodist(){ // have user input x amount of pulses to move motor a certain distance
-
-    while(1)
-    {
-        char str[4];
-        int steps = 0;
-        int wait = 1000;
-        time_t start = time(0);
-        double elapsed;      
-        printf("Enter the amount of steps: ");
-        fgets(str,4,stdin);
-        printf("\r\nSteps: %s", str);
-        steps = atoi(str);
-        
-        if(steps > 0)
-            motor.step_clockwise(steps, wait);
-        else
-            motor.step_anticlockwise(steps, wait);
-        elapsed = difftime( time(0), start);
-        printf("\r\nTook %i steps in time: %f \r\n",steps, elapsed);
-    }
-}
 void update_handler(){
     pend.update();
 }
-int main() {
-  update.attach(&update_handler, pend.UPDATE_TIME);
+int main(){
+    int neg = -1;
+    encoder.reset();
+    update.attach(&update_handler, pend.UPDATE_TIME);
+    pend.set_zeros();
+    int waits = 700;
+    while(1){
+        move_pulses(1000*neg, waits);
+        neg*= -1;
+        if(neg == -1)
+            waits -= 10;
+        printf("Wait time: %i\r\n", waits);
+        pend.print_test();
+        wait(3);
+    }
+}
+/*  update.attach(&update_handler, pend.UPDATE_TIME);
   wait(1);
   pend.set_zeros(); 
     while(1)pend.print_test();
     
 }
+*/