Inverted Pendulum / Mbed 2 deprecated IP-Interface

Dependencies:   mbed QEI

Revision:
20:8063c82bbb35
Parent:
19:0e9bf6d61d0d
Child:
21:eac29cf3f061
--- a/main.cpp	Wed Nov 16 03:44:19 2016 +0000
+++ b/main.cpp	Wed Nov 16 08:28:46 2016 +0000
@@ -10,7 +10,9 @@
 //Use X2 encoding by default.
 QEI encoder (PTC16, PTC17, PTB9, 512);
 Motor motor(PTC4, PTD0, PTC3, PTC12, PTB23, 2000);
-Pot pend(PTC10,0); 
+Pot pend(PTC10, &encoder,0);
+Ticker update;
+
 void test_distance(){
     int wait = 1000;
     int steps = 100;
@@ -73,31 +75,25 @@
 void calibrate_pendulum(){
     encoder.reset();
     while(1){
-        printf("voltage %%: %f  pulse: %i", pend.get_voltage(), encoder.getPulses());
+        printf("voltage %%: %f  pulse: %i", pend.angle_as_voltage(), encoder.getPulses());
     }
 }
 void move_pulses(int pulses, int wait){ // find number of pulses from the encoder going from one end to the other.
     int start = encoder.getPulses();
-    if(pulses >=0){
+    if(pulses >= 0){
         while(encoder.getPulses() < start + pulses){
-            motor.clockwise(wait);    
+            printf("here");
+          // motor.clockwise(wait);    
         } 
     }else{
-        while(encoder.getPulses() > start + pulses)
-            motor.anticlockwise(wait);
-        } 
-}
-void disttopulse(int distance) //find amount of pulses to distance
-{
-    
-}
-void set_speed(int speed) // wait time correspondence to speed
-{
-        
+        while(encoder.getPulses() > start + pulses){
+          // motor.anticlockwise(wait);
+        }
+    } 
 }
 
-void test_pulsetodist() // have user input x amount of pulses to move motor a certain distance
-{
+void test_pulsetodist(){ // have user input x amount of pulses to move motor a certain distance
+
     while(1)
     {
         char str[4];
@@ -118,22 +114,13 @@
         printf("\r\nTook %i steps in time: %f \r\n",steps, elapsed);
     }
 }
+void update_handler(){
+    pend.update();
+}
 int main() {
-    int wait = 600;
-    printf("Hi");
-    while(wait > 10)
-    {
-        printf("Current wait tme is %d",wait);
-        move_pulses(-5000,wait);
- //     printf("Took: %lf \r\n",elapsed);
-        move_pulses(5000,wait);\
- //     printf("Took: %lf \r\n",elapsed);
-        wait-=25;
-    }
-    //motor.step_clockwise(100,1500);
-    //motor.step_clockwise(100,1000);
-    //motor.step_clockwise(100,700);
+  update.attach(&update_handler, pend.UPDATE_TIME);
+  wait(1);
+  pend.set_zeros(); 
+    while(1)pend.print_test();
     
-    
- 
 }