Asignación de valores controlador PID sencillo.
Fork of controlPID by
main.cpp@2:434bb36fa59f, 2013-10-18 (annotated)
- Committer:
- jmcallef
- Date:
- Fri Oct 18 05:12:02 2013 +0000
- Revision:
- 2:434bb36fa59f
- Parent:
- 1:83ffe66ee756
Asignar valores control PID sencillo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris | 0:672241227e0d | 1 | #include "mbed.h" |
chris | 0:672241227e0d | 2 | #include "DebouncedIn.h" |
tony63 | 1:83ffe66ee756 | 3 | #include "TextLCD.h" |
tony63 | 1:83ffe66ee756 | 4 | AnalogIn Vin(PTC2); |
tony63 | 1:83ffe66ee756 | 5 | TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 |
tony63 | 1:83ffe66ee756 | 6 | |
tony63 | 1:83ffe66ee756 | 7 | DigitalOut led1(LED1); |
tony63 | 1:83ffe66ee756 | 8 | DigitalOut led2(LED2); |
tony63 | 1:83ffe66ee756 | 9 | DebouncedIn button1(PTC12); |
tony63 | 1:83ffe66ee756 | 10 | DebouncedIn button2(PTC13); |
tony63 | 1:83ffe66ee756 | 11 | DebouncedIn button3(PTC16); |
tony63 | 1:83ffe66ee756 | 12 | DebouncedIn button4(PTC17); |
tony63 | 1:83ffe66ee756 | 13 | |
tony63 | 1:83ffe66ee756 | 14 | /* codigos movimiento del curzor |
tony63 | 1:83ffe66ee756 | 15 | 18 para izquierda |
tony63 | 1:83ffe66ee756 | 16 | 1A para derecha |
tony63 | 1:83ffe66ee756 | 17 | */ |
chris | 0:672241227e0d | 18 | |
tony63 | 1:83ffe66ee756 | 19 | int C1=0x0E; // solo muestra el curzor |
tony63 | 1:83ffe66ee756 | 20 | int C2=0x18; // desplaza izquierda |
tony63 | 1:83ffe66ee756 | 21 | int C3=0x1A; // desplaza derecha |
tony63 | 1:83ffe66ee756 | 22 | int C4=0x0C; // quito cursor bajo |
tony63 | 1:83ffe66ee756 | 23 | int i; // indice de la variable |
tony63 | 1:83ffe66ee756 | 24 | int j; |
tony63 | 1:83ffe66ee756 | 25 | int kp, ki, kd, sp, err, med, yr, pid, ap, ai, ad, err_v, cycle; |
chris | 0:672241227e0d | 26 | |
chris | 0:672241227e0d | 27 | int main() { |
jmcallef | 2:434bb36fa59f | 28 | |
jmcallef | 2:434bb36fa59f | 29 | lcd.writeCommand(C1); // Ubico el cursor en el Display. |
jmcallef | 2:434bb36fa59f | 30 | |
tony63 | 1:83ffe66ee756 | 31 | lcd.cls(); |
jmcallef | 2:434bb36fa59f | 32 | lcd.locate(0,0); |
tony63 | 1:83ffe66ee756 | 33 | lcd.printf("Sp%d",sp); |
tony63 | 1:83ffe66ee756 | 34 | lcd.locate(8,0); |
tony63 | 1:83ffe66ee756 | 35 | lcd.printf("Kp%d",kp); |
tony63 | 1:83ffe66ee756 | 36 | lcd.locate(0,1); |
tony63 | 1:83ffe66ee756 | 37 | lcd.printf("Ki%d",ki); |
tony63 | 1:83ffe66ee756 | 38 | lcd.locate(8,1); |
tony63 | 1:83ffe66ee756 | 39 | lcd.printf("Kd%d",kd); |
jmcallef | 2:434bb36fa59f | 40 | |
tony63 | 1:83ffe66ee756 | 41 | lcd.locate(0,0); |
tony63 | 1:83ffe66ee756 | 42 | lcd.printf("Sp%d",sp); |
tony63 | 1:83ffe66ee756 | 43 | |
tony63 | 1:83ffe66ee756 | 44 | |
chris | 0:672241227e0d | 45 | while(1) { |
tony63 | 1:83ffe66ee756 | 46 | if (button3.falling()) { |
tony63 | 1:83ffe66ee756 | 47 | ++j; |
jmcallef | 2:434bb36fa59f | 48 | } //INCREMENTA POSICION DEL MENU CON BOTON 3 |
tony63 | 1:83ffe66ee756 | 49 | if (j==0){ |
jmcallef | 2:434bb36fa59f | 50 | lcd.locate(3,0); |
tony63 | 1:83ffe66ee756 | 51 | lcd.printf("%d",sp); |
tony63 | 1:83ffe66ee756 | 52 | if (button1.falling()) { |
jmcallef | 2:434bb36fa59f | 53 | ++sp; // ademas revisa boton 1 para incrementar |
tony63 | 1:83ffe66ee756 | 54 | } |
tony63 | 1:83ffe66ee756 | 55 | if (button2.falling()) { |
jmcallef | 2:434bb36fa59f | 56 | --sp; // ademas revisa boton 2 para decrementar |
tony63 | 1:83ffe66ee756 | 57 | } |
tony63 | 1:83ffe66ee756 | 58 | } |
tony63 | 1:83ffe66ee756 | 59 | if (j==1) { |
jmcallef | 2:434bb36fa59f | 60 | lcd.locate(11,0); |
tony63 | 1:83ffe66ee756 | 61 | lcd.printf("%d",kp); |
tony63 | 1:83ffe66ee756 | 62 | if (button1.falling()) { |
tony63 | 1:83ffe66ee756 | 63 | ++kp; |
tony63 | 1:83ffe66ee756 | 64 | } |
tony63 | 1:83ffe66ee756 | 65 | if (button2.falling()) { |
tony63 | 1:83ffe66ee756 | 66 | --kp; |
tony63 | 1:83ffe66ee756 | 67 | } |
tony63 | 1:83ffe66ee756 | 68 | } |
tony63 | 1:83ffe66ee756 | 69 | if (j==2) { |
jmcallef | 2:434bb36fa59f | 70 | lcd.locate(3,1); |
tony63 | 1:83ffe66ee756 | 71 | lcd.printf("%d",ki); |
tony63 | 1:83ffe66ee756 | 72 | if (button1.falling()){ |
jmcallef | 2:434bb36fa59f | 73 | ++ki;9 |
tony63 | 1:83ffe66ee756 | 74 | } |
tony63 | 1:83ffe66ee756 | 75 | if (button2.falling()){ |
tony63 | 1:83ffe66ee756 | 76 | --ki; |
tony63 | 1:83ffe66ee756 | 77 | } |
tony63 | 1:83ffe66ee756 | 78 | } |
tony63 | 1:83ffe66ee756 | 79 | if (j==3) { |
jmcallef | 2:434bb36fa59f | 80 | lcd.locate(11,1); |
tony63 | 1:83ffe66ee756 | 81 | lcd.printf("%d",kd); |
tony63 | 1:83ffe66ee756 | 82 | if (button1.falling()){ |
tony63 | 1:83ffe66ee756 | 83 | ++kd; |
tony63 | 1:83ffe66ee756 | 84 | } |
tony63 | 1:83ffe66ee756 | 85 | if (button2.falling()){ |
tony63 | 1:83ffe66ee756 | 86 | --kd; |
tony63 | 1:83ffe66ee756 | 87 | } |
tony63 | 1:83ffe66ee756 | 88 | } |
tony63 | 1:83ffe66ee756 | 89 | if (j==4) { |
tony63 | 1:83ffe66ee756 | 90 | j=0; |
tony63 | 1:83ffe66ee756 | 91 | } |
tony63 | 1:83ffe66ee756 | 92 | |
tony63 | 1:83ffe66ee756 | 93 | if (button4.falling()){ |
tony63 | 1:83ffe66ee756 | 94 | break; //sale del bucle si pisan suiche4 |
tony63 | 1:83ffe66ee756 | 95 | } |
tony63 | 1:83ffe66ee756 | 96 | |
jmcallef | 2:434bb36fa59f | 97 | |
jmcallef | 2:434bb36fa59f | 98 | } |
tony63 | 1:83ffe66ee756 | 99 | } |