Con la variacion del encoder, nos moveremos a traves de los parametros del PID,luego al pulsarlo nos enviara una señal a un speaker.

Dependencies:   Debounced QEI TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
Jesse
Date:
Thu Apr 03 20:19:31 2014 +0000
Commit message:
Tarea4_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 cdf4bcffb35a Debounced.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Debounced.lib	Thu Apr 03 20:19:31 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/WarwickRacing/code/Debounced/#8992c13bbb9b
diff -r 000000000000 -r cdf4bcffb35a QEI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QEI.lib	Thu Apr 03 20:19:31 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/aberk/code/QEI/#5c2ad81551aa
diff -r 000000000000 -r cdf4bcffb35a TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Thu Apr 03 20:19:31 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/amarincan/code/TextLCD/#d692719a4c59
diff -r 000000000000 -r cdf4bcffb35a main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Apr 03 20:19:31 2014 +0000
@@ -0,0 +1,159 @@
+//Jesse Mauricio Beltran
+//Michelle Maceas Henao
+
+
+#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 Enco(PTC5);
+DebouncedIn button1(PTC10);
+DebouncedIn button2(PTC6);
+DebouncedIn button3(PTC11);
+PwmOut Pwm(PTA5);
+
+ 
+float pp=0.001;
+float Dd=0.1;
+int SP1=0,Sp=0,Kp1=0,Kp=0,Ki=0,Ki1=0,Kd=0,Kd1=0,v,m;
+int C1=0x0E; // solo muestra el curzor
+int i; // indice de la variable
+
+int PWMmodule(float pp,float Dd)
+{
+        Pwm.period(pp);
+        Pwm.write(Dd);
+        wait(0.2);
+        Pwm.write(0); 
+        return 0;
+} 
+
+int main() 
+
+{
+    lcd.writeCommand(0x0E);
+    lcd.printf("Sp=0    Kp=0");
+    lcd.locate(0,1);
+    lcd.printf("Ki=0    Kd=0");
+    lcd.locate(2,0);
+    lcd.printf("=");
+
+    while(1) 
+    {  
+     m=wheel.getPulses();
+     
+            if(m!=v) {  
+                                                
+            switch(i) {
+            
+                case 0:
+                    Kd1=Kd;
+                    
+                    lcd.locate(2,0);
+                    lcd.printf("=     ");
+                    lcd.locate(3,0);
+                    lcd.printf("%d",Sp);
+                    //Sp=m;
+                    Sp=SP1+m;  
+                    if(Sp<0)
+                    {
+                        Sp=0; 
+                        wheel.reset();  
+                        m=0; 
+                    }                
+                    break;
+                case 1:
+                    SP1=Sp;
+                    lcd.locate(10,0);
+                    lcd.printf("=     ");
+                    lcd.locate(11,0);
+                    lcd.printf("%d",Kp);
+                    //Kp=m;
+                    Kp=Kp1+m;  
+                    if(Kp<0)
+                    {
+                        Kp=0; 
+                        wheel.reset();  
+                        m=0; 
+                    }  
+                    break;
+                case 2:
+                    Kp1=Kp;
+                    lcd.locate(2,1);
+                    lcd.printf("=     ");
+                    lcd.locate(3,1);
+                    lcd.printf("%d",Ki);
+                    //Ki=m;
+                    Ki=Ki1+m;  
+                    if(Ki<0)
+                    {
+                        Ki=0; 
+                        wheel.reset();  
+                        m=0; 
+                    } 
+                    
+                    break;
+                case 3:
+                    Ki1=Ki;
+                    lcd.locate(10,1);
+                    lcd.printf("=     ");
+                    lcd.locate(11,1);
+                    lcd.printf("%d",Kd);
+                    Kd=Kd1+m;
+                    if(Kd<0)
+                    {
+                        Kd=0; 
+                        wheel.reset();  
+                        m=0; 
+                    } 
+                    
+                    break;
+            }
+            v=m;
+        }
+                  
+        
+        if(button3.falling() || Enco.falling()) 
+        {
+            PWMmodule(pp,Dd);
+            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;
+                    
+                    
+            }
+        } 
+        /*if(button3.falling())
+        {
+                PWMmodule(pp,Dd);
+        } */
+    }
+}       
\ No newline at end of file
diff -r 000000000000 -r cdf4bcffb35a mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Apr 03 20:19:31 2014 +0000
@@ -0,0 +1,1 @@
+http://world3.dev.mbed.org/users/mbed_official/code/mbed/builds/824293ae5e43
\ No newline at end of file