Cuarta Tarea

Dependencies:   Debounced QEI TextLCD11 mbed

Files at this revision

API Documentation at this revision

Comitter:
mandres7
Date:
Sun Nov 10 21:41:22 2013 +0000
Commit message:
Cuarta tarea procesadores

Changed in this revision

Debounced.lib Show annotated file Show diff for this revision Revisions of this file
QEI.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Debounced.lib	Sun Nov 10 21:41:22 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/WarwickRacing/code/Debounced/#8992c13bbb9b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QEI.lib	Sun Nov 10 21:41:22 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/aberk/code/QEI/#5c2ad81551aa
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Sun Nov 10 21:41:22 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mandres7/code/TextLCD11/#a4a7576c3795
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Nov 10 21:41:22 2013 +0000
@@ -0,0 +1,240 @@
+#include "mbed.h"
+#include "TextLCD.h"
+#include "DebouncedIn.h"
+#include "QEI.h"
+
+TextLCD lcd(PTC10, PTC11, PTC12, PTC13, PTC16, PTC17); // rs, e, d4-d7.. Nota: No se quiere función de lectura, luego ese puerto a tierra.
+//lectura=1, escritura=0
+QEI leftQei(PTD6, PTD7, NC, 624);
+//Encoder Sp, Kp, Ki, Kd
+PwmOut rled(LED_GREEN);
+
+DebouncedIn next(PTE5);
+AnalogIn Ain(PTC2);
+AnalogOut Aout(PTE30);
+
+int C1=0x0F; 
+int i,j,k,l;
+float ap,ai,ad;
+
+float p; // set point
+float s=0; // salida planta
+float h=0; // entrada planta
+float m=0; // Error
+float mv=0;
+float g=0;
+float x=0;
+
+int main() {
+
+int c;
+c=0;
+
+lcd.cls();     
+lcd.locate(0,0);
+lcd.printf("sp:%d",i);
+lcd.locate(8,0);
+lcd.printf("kp:%d",j);
+lcd.locate(0,1);
+lcd.printf("ki:%d",k);
+lcd.locate(8,1);
+lcd.printf("kd:%d",l);
+
+//SP
+
+while (1){
+
+if (next.falling()){    
+        c++;
+        }          
+
+    //Salto a SP
+    if (c==0){
+        
+        lcd.locate(3,0);
+        lcd.putc(0xFE);                
+        lcd.writeCommand(C1);
+        lcd.locate(3,0);
+        lcd.printf("%d",i);
+        
+            while(c==0){  
+              
+            //espacio de trabajo
+                        
+                i=leftQei.getPulses();
+                //
+                
+                             
+                lcd.locate(3,0);
+                lcd.printf("%i",leftQei.getPulses());
+                wait(0.2);          
+                                   
+           
+            //fin espacio de trabajo            
+            
+            if(next.falling()){
+                c++;
+                }                                                             
+                }
+                } 
+              
+        
+    //Salto a Kp
+    if (c==1){
+        
+        lcd.locate(11,0);
+        lcd.putc(0xFE);                
+        lcd.writeCommand(C1);
+        lcd.locate(11,0);
+        lcd.printf("%d",j);
+        
+            while(c==1){
+            
+            //Work space
+            
+                 j=leftQei.getPulses();
+                 
+            //
+                                             
+                lcd.locate(11,0);
+                lcd.printf("%i",leftQei.getPulses());
+                wait(0.2); 
+           
+            //End work space            
+              
+             if(next.falling()){
+                c++;
+                }                                                             
+                }
+                }
+              
+    //Salto a Kp
+    if (c==2){
+        
+        lcd.locate(3,1);
+        lcd.putc(0xFE);                
+        lcd.writeCommand(C1);
+        lcd.locate(3,1);
+        lcd.printf("%d",k);
+        
+            while(c==2){ 
+            
+            //Work space
+            
+                k=leftQei.getPulses();
+                 
+            //
+                                             
+                lcd.locate(3,1);
+                lcd.printf("%i",leftQei.getPulses());
+                wait(0.2); 
+                
+            //End work space  
+
+             if(next.falling()){
+                c++;
+                }                                                             
+                }
+                }        
+
+    //Salto a Kp
+    if (c==3){
+        
+        lcd.locate(11,1);
+        lcd.putc(0xFE);                
+        lcd.writeCommand(C1);
+        lcd.locate(11,1);
+        lcd.printf("%d",l);
+        
+            while(c==3){
+            
+            //Work space
+            
+                l=leftQei.getPulses();
+                 
+            //
+                                             
+                lcd.locate(11,1);
+                lcd.printf("%i",leftQei.getPulses());
+                wait(0.2); 
+                
+           
+            //End work space                           
+             
+             if(next.falling()){
+                c++;
+                                }                                                             
+                }
+                }   
+
+    //          
+                 if(c==4 || c>4){
+                c=0;
+                                }                                                                                  
+                         
+}
+
+//Borrar
+
+lcd.cls();
+lcd.printf("Er%d",m);
+lcd.locate(8,0);
+lcd.printf("Me%d",s);
+lcd.locate(0,1);
+lcd.printf("Sp%d",i);
+lcd.locate(8,1);
+lcd.printf("Co%d",x);
+wait(5);
+
+//Ahora empieza el PID
+
+p=i/100;
+
+while(1) {
+        wait(0.3);
+              
+        if(p<0.999){
+       
+        s=Ain;
+        m=(p-s);
+        //n=m*100;
+        ap=j*m;
+        ai=(k*m)+ai;
+        
+        if (ai>999){
+        ai=998;
+                   }
+        
+        ad=l*(m-mv);
+        h=ap+ai+ad;
+        x=h/100;
+        g=(h*3.3/100);
+        
+        if (h<0){
+            h=0;
+                }
+                
+
+                        
+        Aout=g;
+        wait(0.22);
+ 
+        
+        lcd.cls();
+        lcd.printf("Er:%.3f",m);
+        lcd.locate(8,0);
+        lcd.printf("Me:%.3f",s);
+        lcd.locate(0,1);
+        lcd.printf("Sp:%.2f",p);
+        lcd.locate(8,1);
+        lcd.printf("Co:%.3f",x);
+        }
+
+
+        mv=m;
+
+        }
+}  
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Nov 10 21:41:22 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file