Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed QEI TextLCD DebouncedIn
Revision 2:921bc4072c83, committed 2019-06-07
- Comitter:
- demo71
- Date:
- Fri Jun 07 18:23:59 2019 +0000
- Parent:
- 1:f0fa90a6fb6e
- Commit message:
- PID DISCRETO;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Oct 27 01:10:35 2015 +0000
+++ b/main.cpp Fri Jun 07 18:23:59 2019 +0000
@@ -19,12 +19,7 @@
//Configuracion pantalla LCD
TextLCD lcd(PTB8,PTB9,PTB10,PTB11,PTE2,PTE3); // rs, e, d4-d7
-//codigos movimiento del cursor LCD
-//int C2=0x18; // desplaza izquierda
-//int C3=0x1A; // desplaza derecha
-//int C4=0x0C; // quito cursor bajo
-//int C1=0x0F; // solo muestra el cursor
-
+//Variables y parametros del control PID
int Kp=0,Ki=0,Kd=0;
float Sp=0;
float K1,K2,K3,ek=0,ekm1=0,ekm2=0,Ts=0.1; //Ts Tiempo Muestreo
@@ -44,7 +39,7 @@
lcd.locate(9,1);
lcd.printf("Sp=%.1f",Sp);
-
+ //Configuracion de constante Kp
set_Kp:
lcd.cls();
lcd.locate(0,0);
@@ -84,6 +79,7 @@
}
+ //Configuracion de Ki
set_Ki:
lcd.cls();
@@ -97,7 +93,6 @@
lcd.locate(9,1);
lcd.printf("Sp=%.1f",Sp);
- //Ki=0;
while(1){
Ki=Ki+wheel.getPulses();
@@ -123,6 +118,7 @@
}
+ //Configuracion de Kd
set_Kd:
lcd.cls();
@@ -137,7 +133,7 @@
lcd.printf("Sp=%.1f",Sp);
- //Kd=0;
+
while(1){
Kd=Kd+wheel.getPulses();
@@ -163,6 +159,7 @@
}
+ //Configuracion de Sp
set_Sp:
lcd.cls();
@@ -176,7 +173,7 @@
lcd.locate(1,1);
lcd.printf("Kd=%d",Kd);
- //Sp=0;
+
while(1){
Sp=Sp+0.1*wheel.getPulses();
@@ -202,6 +199,7 @@
}
+ //Inicia algoritmo del PID
PID:
lcd.cls();
@@ -212,6 +210,7 @@
//Conversion de parametros PID Continuo a parametros de PID Digital
//ESTO ES UN PID DIGITAL Y LOS PARAMETROS AGREGADOS SON PARA UN PID CONTINUO!!
+
K1=Kp+(Ki/2)*Ts+(Kd/Ts);
K2=-Kp+(Ki/2)*Ts-(2*Kd/Ts);
K3=Kd/Ts;
@@ -226,14 +225,17 @@
control=(float)uk/3.3; //Accion de control mapeada a PWM; salida de la tarjeta.
- ekm2=ekm1;
+ //Actualizacion de datos para el siguiente paso
+ ekm2=ekm1;
ekm1=ek;
ukm1=uk;
+
+ //Mostrando error y salida actual
lcd.locate(0,0);
lcd.printf("Error=%.2f ",ek);
lcd.locate(0,1);
lcd.printf("Y_act=%.2f",yT);
- wait(Ts); // Muestreos
+ wait(Ts); //Tiempo de muestreo
}
}