Inverted Pendulum / Mbed 2 deprecated IP-Interface

Dependencies:   mbed QEI

Revision:
8:2abfdbf5a3b8
Parent:
6:8d2171811f14
Child:
11:ed9539245ea0
--- a/main.cpp	Fri Nov 11 06:37:24 2016 +0000
+++ b/main.cpp	Fri Nov 11 21:19:06 2016 +0000
@@ -1,19 +1,60 @@
 #include "QEI.h"
 #include "Motor.h"
+#include "pot.h"
  
 Serial pc(USBTX, USBRX);
 //Use X4 encoding.
 //QEI wheel(p29, p30, NC, 624, QEI::X4_ENCODING);
 //Use X2 encoding by default.
-QEI wheel (PTC16, PTC17, PTB9, 512);
-Motor motor(PTC4, PTD0, PTC3, PTC12, PTB23); 
+QEI encoder (PTC16, PTC17, PTB9, 512);
+Motor motor(PTC4, PTD0, PTC3, PTC12, PTB23, 1000);
+Pot pend(PTC10); 
+void test_distance(){
+    int wait = 1000;
+    int steps = 100;
+    while (wait > 500){
+        while (steps > 10){
+            printf("steps: %i wait: %i \r\n", steps, wait);
+            for( int i = 0; i < 3; i++){
+                encoder.reset();
+                motor.step_clockwise(steps, wait);
+                int pulses_cw = encoder.getPulses();
+                wait_ms(200);
+                int coast_pulses_cw = encoder.getPulses();
+                
+                
+                encoder.reset();
+                motor.step_anticlockwise(steps, wait);
+                int pulses_ccw = encoder.getPulses();
+                wait_ms(200);
+                int coast_pulses_ccw = encoder.getPulses();
+                printf("trial: %i \tclockwise pluses: \t%i  \tanticlockwise pluses: \t%i \r\n", i + 1, pulses_cw, pulses_ccw);
+                printf("\t\tpulses after coast: \t%i \tpulses after coast: \t%i\r\n", coast_pulses_cw, coast_pulses_ccw);
+            }
+            steps -=10;
+            printf("\r\n");
+        }
+        
+        wait-=100;
+        steps=100;
+    }       
+}
 
-int main() {
+void test_speed(){
+
+}
+void test_pendulum(){
     while(1){
-        motor.clockwise();
-       
-        motor.anticlockwise();
-        pc.printf("Pulses is: %i\n", wheel.getPulses());
+        printf("angle: %f \r\n", pend.get_angle());   
     }
+}
+int main() {
+    
+    test_pendulum();
+    //motor.step_clockwise(100,1500);
+    //motor.step_clockwise(100,1000);
+    //motor.step_clockwise(100,700);
+    
+    
  
-}
\ No newline at end of file
+}