Ninguna

Dependencies:   TextLCD mbed Debounced

Files at this revision

API Documentation at this revision

Comitter:
fvelasquezv
Date:
Fri Nov 01 00:12:45 2013 +0000
Parent:
0:da8c12e25806
Commit message:
ninguna

Changed in this revision

Debounced.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r da8c12e25806 -r e3356f2c75c3 Debounced.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Debounced.lib	Fri Nov 01 00:12:45 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/WarwickRacing/code/Debounced/#8992c13bbb9b
diff -r da8c12e25806 -r e3356f2c75c3 main.cpp
--- a/main.cpp	Wed Oct 23 15:42:55 2013 +0000
+++ b/main.cpp	Fri Nov 01 00:12:45 2013 +0000
@@ -1,24 +1,79 @@
 #include "mbed.h"
 #include "TextLCD.h"
+#include "DebouncedIn.h"
 
+Timer timer1;
 TextLCD lcd(PTC10, PTC11, PTC12, PTC13, PTC16, PTC17); // rs, e, d4-d7TextLCD lcd(PTC10, PTC11, PTC12, PTC13, PTC16, PTC17); // rs, e, d4-d7
 DigitalOut myled(LED1);
 AnalogOut Aout(PTE30);
 AnalogIn Ain(PTC2);
-float i=0;
-float j=0;
+DebouncedIn Arriba(PTE2);
+DebouncedIn Abajo(PTE3);
+DebouncedIn Ganancia(PTE4);
+
+float i=0.7; // set point
+float j=0; // salida planta
+float k=0; // entrada planta
+float m=3.4; // ganancia
+float js=0;
+float ji=1; 
+float re=0;
+float jo=0;
+float jd=0;
+float t=0; //tiempo
+
 int main() {
-float Setpoint=0.6;
+//float Setpoint=0.6;
     while(1) {
-        if(i<0.999&&j<=Setpoint){
-        i+=0.001;
-        Aout=i;
+        
+        if(Arriba.falling()){
+        i+=0.01;
+        }
+        
+        if(Abajo.falling()){
+        i-=0.01;
+        }
+        
+        if(Ganancia.falling()){
+        m+=0.01;
+        }
+                
+        if(i<0.999){
+       
         j=Ain;
-        //wait(0);
+        k=m*(i-j);
+        Aout=k;
+        wait(0.1);
+        jo=j-jo;
         lcd.locate(0,0);
-        lcd.printf("Out:%f", i);
+        lcd.printf("y:%.3f jd:%.2f", j, jd);
         lcd.locate(0,1);
-        lcd.printf("In:%f", j);
+        lcd.printf("t:%f",t);
+        lcd.locate(10,1);
+        lcd.printf("K:%.2f",m);
+        }
+        
+        if(j>js){
+        js=j;
+        }
+        
+        if(j<ji){
+        ji=j;
         }
+        //wait(0.2);
+        jo=j;
+        re=js-ji;
+        jd=ji+(re/2);
+        
+        if(abs(jd-j)<=0.001){
+        
+        t=timer1.read();
+        timer1.stop();
+        timer1.reset();
+        timer1.start();
+        
+        } 
+  
     }
+    
 }