a controller for a furuta pendulum

Dependencies:   QEI mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
jaoramos
Date:
Wed Dec 04 04:36:27 2013 +0000
Parent:
11:7e19e51b325d
Child:
13:6b3533b4f664
Commit message:
combined swing up and stabilization works!

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Dec 04 04:19:30 2013 +0000
+++ b/main.cpp	Wed Dec 04 04:36:27 2013 +0000
@@ -134,7 +134,7 @@
 void computing(void const *args) {
     float z1=0.0, z2=0.0, dz1 = 0.0, dz2 = 0.0, z3 = 0.0, dz3 = 0.0; 
     bool firstTime = true;
-    
+    bool controller = 0;
     while (true ) {
         t = T.read();
         
@@ -173,12 +173,18 @@
         z3 = z3 + dz3 * dt;
         mCurrent = z3;
         
+        if (sin(theta2) < 0.0)
+        controller = 1;
+        if (cos(theta2) < 0.96)
+        controller = 0;
+        
         //set pwm 
-        if (cos(theta2) < 0.96) { 
+        if ( controller == 0) {
+            
             flag = 1;
             currentEnergy = calcEnergy();
             inputVoltage = -2.3*dtheta2*(0.0372 - currentEnergy); 
-            inputVoltage = 0.0;                  
+            //inputVoltage = 0.0;                  
             
         } else {
             flag = 1;