Tarea para manejo de Encoder, el cual incrementa y decrementa los parámetros del PID y presionando el boton suena

Dependencies:   Debounced QEI TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
diego_carvajal
Date:
Fri Apr 04 16:57:20 2014 +0000
Commit message:
Tarea_Encoder

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
diff -r 000000000000 -r a7b349b8861d Debounced.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Debounced.lib	Fri Apr 04 16:57:20 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/WarwickRacing/code/Debounced/#8992c13bbb9b
diff -r 000000000000 -r a7b349b8861d QEI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QEI.lib	Fri Apr 04 16:57:20 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/aberk/code/QEI/#5c2ad81551aa
diff -r 000000000000 -r a7b349b8861d TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Fri Apr 04 16:57:20 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/diego_carvajal/code/TextLCD/#6f50014a1b62
diff -r 000000000000 -r a7b349b8861d main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Apr 04 16:57:20 2014 +0000
@@ -0,0 +1,156 @@
+/* Tarea No. 4
+                Diego Fernando Carvajal Castrillón
+                    Santiago Lopez Restrepo
+                    Ingeniería de Control
+
+
+Practica realizada para aprendizaje de manejo de Encoder. El desarrollo
+de esta esta dado por el aumento y disminución de los datos del 
+controlador PID, además que al presionar el boton del Encoder suene
+mediante un PWM.
+*/
+
+
+#include "mbed.h"
+#include "DebouncedIn.h"
+#include "TextLCD.h"
+#include "QEI.h"
+
+
+QEI wheel (PTA16, PTA17, NC, 48);
+TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7
+
+
+DebouncedIn botonEncoder(PTC5);
+PwmOut Pwm(PTA5);
+
+ 
+float periodo=0.001;
+float dureza=0.1;
+int Spbias=0,Sp=0,Kpbias=0,Kp=0,Ki=0,Kibias=0,Kd=0,Kdbias=0,Enc;
+int C1=0x0E; // solo muestra el curzor
+int i; // indice de la variable
+
+int PWMmodule(float pp,float Dd)
+{
+        Pwm.period(periodo);
+        Pwm.write(dureza);
+        wait(0.3);
+        Pwm.write(0); 
+        return 0;
+} 
+
+int main() 
+
+{
+    lcd.writeCommand(C1);
+    lcd.locate(0,0);
+    lcd.printf("Sp=0");
+    lcd.locate(8,0);
+    lcd.printf("Kp=0");
+    lcd.locate(0,1);
+    lcd.printf("Ki=0");
+    lcd.locate(8,1);
+    lcd.printf("Kd=0");
+
+    while(1) 
+    {  
+     Enc=wheel.getPulses();
+       
+                                                
+            switch(i) {
+            
+                case 0:
+                    Kdbias=Kd;
+                    
+                    lcd.locate(3,0);
+                    lcd.printf("%d",Sp);
+                    
+                    Sp=Spbias+Enc;  
+                    if(Sp<0)
+                    {
+                        Sp=0; 
+                        wheel.reset();  
+                        Enc=0; 
+                    }                
+                    break;
+                case 1:
+                    Spbias=Sp;
+                    lcd.locate(11,0);
+                    lcd.printf("%d",Kp);
+                    
+                    Kp=Kpbias+Enc;  
+                    if(Kp<0)
+                    {
+                        Kp=0; 
+                        wheel.reset();  
+                        Enc=0; 
+                    }  
+                    break;
+                case 2:
+                    Kpbias=Kp;
+                    lcd.locate(3,1);
+                    lcd.printf("%d",Ki);
+                    
+                    Ki=Kibias+Enc;  
+                    if(Ki<0)
+                    {
+                        Ki=0; 
+                        wheel.reset();  
+                        Enc=0; 
+                    } 
+                    
+                    break;
+                case 3:
+                    Kibias=Ki;
+                    
+                    lcd.locate(11,1);
+                    lcd.printf("%d",Kd);
+                    Kd=Kdbias+Enc;
+                    if(Kd<0)
+                    {
+                        Kd=0; 
+                        wheel.reset();  
+                        Enc=0; 
+                    } 
+                    
+                    break;
+            }
+        
+        
+                  
+        
+        if(botonEncoder.falling()) 
+        {
+            PWMmodule(periodo,dureza);
+            wait(0.2);
+            wheel.reset();
+            i++;
+            if(i>3) 
+            {
+                i=0;
+            }
+            switch (i) 
+            {
+                case 0:
+                    lcd.locate(2,0);
+                    lcd.printf("=");
+                    break;
+                case 1:
+                    lcd.locate(10,0);
+                    lcd.printf("=");
+                    break;
+                case 2:
+                    lcd.locate(2,1);
+                    lcd.printf("=");
+                    break;
+                case 3:
+                    lcd.locate(10,1);
+                    lcd.printf("=");
+                    break;
+                    
+                    
+            }
+        } 
+    }
+}       
\ No newline at end of file
diff -r 000000000000 -r a7b349b8861d mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Apr 04 16:57:20 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7d30d6019079
\ No newline at end of file