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: QEI TextLCD mbed
Fork of grafica_PID_android by
Revision 5:82ac4b34c3d9, committed 2017-06-03
- Comitter:
- NicolasV
- Date:
- Sat Jun 03 01:07:49 2017 +0000
- Parent:
- 3:2e823b16a4a1
- Commit message:
- Gr?fica PID (Android)
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat May 13 20:36:07 2017 +0000
+++ b/main.cpp Sat Jun 03 01:07:49 2017 +0000
@@ -23,11 +23,10 @@
DigitalIn button3(PTC16); // Botón del encoder
DigitalIn button4(PTC17); // Pulsador
-// Códigos movimiento del cursor:
int C1=0x0F;
-int C2=0x18; // desplaza izquierda
-int C3=0x1A; // desplaza derecha
-int C4=0x0C; // quito cursor bajo
+int C2=0x18;
+int C3=0x1A;
+int C4=0x0C;
int cambio = 0, diferencia = 0;
float pid, o, ai, ad, ap, med, err, setpoint;
@@ -44,7 +43,10 @@
GSM.format(8,Serial::None,1);
t.start();
- for (int i = 3; i < 24; ++i) {
+
+ // Animación de bienvenida:
+
+ for (int i = 3; i < 15; ++i) {
lcd.cls();
lcd.locate(0,0);
lcd.printf("**Control PID**");
@@ -86,7 +88,7 @@
lcd.locate(0,0);
lcd.printf("Kp=%d", kpnum);
- bool state = 1;
+ bool state = 1; // Esta variable determina si se están modificando las constantes del controlador o el Set-Point.
while(true) {
@@ -152,7 +154,7 @@
if (!button3) { // Cambia la posición de ingreso de parámetros
- led3 = !led3;
+ led2 = !led2;
switch(pos++) {
case 3:
pos = 1;
@@ -203,9 +205,9 @@
if (t.read_ms() - t_pid > 10) {
med = y.read()*999;
- err = spnum - med; // Se calcula el error
- ap = kpnum*err*0.01f; // Se calcula la acción proporcional
- ai += kinum*err*0.01f; // Cálculo de la integral del error
+ err = spnum - med; // Se calcula el error
+ ap = kpnum*err*0.01f; // Se calcula la acción proporcional
+ ai += kinum*err*0.01f; // Cálculo de la integral del error
ad = kdnum*(err - err_v)*0.01f; // Cálculo de la acción derivativa
pid = ap + ai + ad;
@@ -213,8 +215,8 @@
if (pid > 999) pid = 999;
setpoint = spnum;
- GSM.printf("#%3.0f%3.0f&", med, setpoint);
-
+ GSM.printf("#%3.0f%3.0f&", med, setpoint); // Se envía una cadena de caracteres por el puerto serial. Se agregan identificadores #...& que denotan el comienzo y la terminación de la misma.
+ // Esto se hace con el fin de evitar errores en la transmisión. Estos identificadores se usan en la aplicación de AppInventor.
lcd.locate(3,0); lcd.printf("%3.0f ", med);
lcd.locate(3,1); lcd.printf("%3d ", spnum);
lcd.locate(11,0); lcd.printf("%3.0f ", err);
@@ -228,7 +230,7 @@
}
else {
- diferencia=(encoder.getPulses() - cambio)*6;
+ diferencia=(encoder.getPulses() - cambio)*6; // Es posible cambiar el Set-Point cuando el controlador ya está funcionando.
cambio=encoder.getPulses();
if (diferencia != 0) {
@@ -239,7 +241,7 @@
}
- if (!button4) {
+ if (!button4) { // Si se presiona el pulsador se vuelve al menú inicial para configurar de nuevo el controlador.
u.write(0);
med = 0;
err = 0;
