Skip to content

Commit

Permalink
Precompetencia
Browse files Browse the repository at this point in the history
  • Loading branch information
Tito committed Sep 6, 2014
1 parent 3d2d761 commit 309b987
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 124 deletions.
238 changes: 118 additions & 120 deletions SRC/Codigo Tito 3.14/tito.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ int main() {
int16_t reduccion_velocidad = 0;
estados_t estado_actual = ST_EN_PISTA;
bordes_t ultimo_borde_valido = BORDE_IZQUIERDA;
int8_t coeficiente_error_p = 14;
int16_t coeficiente_error_i = 12016;
int8_t coeficiente_error_d = 6;
int8_t tipo_coeficiente = 0; // de 0 a 15
int16_t gusty1 = 0;
int16_t gusty2 = 0;
int16_t gusty3 = 0;
//int8_t coeficiente_error_p = 14;
//int16_t coeficiente_error_i = 12016;
//int8_t coeficiente_error_d = 6;
//int8_t tipo_coeficiente = 0; // de 0 a 15
//int16_t gusty1 = 0;
//int16_t gusty2 = 0;
//int16_t gusty3 = 0;
startup();

while (1) {
Expand All @@ -185,114 +185,114 @@ int main() {
ClearBit(PORT_LED_3, LED_3_NUMBER);
ClearBit(PORT_LED_4, LED_4_NUMBER);

// cambios de coeficientes
if (tipo_coeficiente == 16) {
tipo_coeficiente = 0;
}
//// cambios de coeficientes
//if (tipo_coeficiente == 16) {
//tipo_coeficiente = 0;
//}

switch (tipo_coeficiente) {
case 0:
// valor de referencia
coeficiente_error_p = 14;
coeficiente_error_i = 240;
coeficiente_error_d = 2;
break;
case 1:
coeficiente_error_p = 14;
coeficiente_error_i = 12016;
coeficiente_error_d = 12;
break;
case 2:
coeficiente_error_p = 14;
coeficiente_error_i = 12016;
coeficiente_error_d = 24;
break;
case 3:
coeficiente_error_p = 14;
coeficiente_error_i = 12016;
coeficiente_error_d = 48;
break;
case 4:
coeficiente_error_p = 14;
coeficiente_error_i = 12016;
coeficiente_error_d = 96;
break;
case 5:
coeficiente_error_p = 14;
coeficiente_error_i = 12016;
coeficiente_error_d = 192;
break;
case 6:
coeficiente_error_p = 14;
coeficiente_error_i = 12016;
coeficiente_error_d = 6;
break;
case 7:
coeficiente_error_p = 14;
coeficiente_error_i = 6000;
coeficiente_error_d = 6;
break;
case 8:
coeficiente_error_p = 14;
coeficiente_error_i = 3000;
coeficiente_error_d = 6;
break;
case 9:
coeficiente_error_p = 14;
coeficiente_error_i = 1500;
coeficiente_error_d = 6;
break;
case 10:
coeficiente_error_p = 14;
coeficiente_error_i = 750;
coeficiente_error_d = 6;
break;
case 11:
coeficiente_error_p = 14;
coeficiente_error_i = 375;
coeficiente_error_d = 6;
break;
case 12:
coeficiente_error_p = 14;
coeficiente_error_i = 200;
coeficiente_error_d = 6;
break;
case 13:
coeficiente_error_p = 14;
coeficiente_error_i = 100;
coeficiente_error_d = 6;
break;
case 14:
coeficiente_error_p = 14;
coeficiente_error_i = 50;
coeficiente_error_d = 6;
break;
case 15:
coeficiente_error_p = 14;
coeficiente_error_i = 25;
coeficiente_error_d = 6;
break;
}
if (tipo_coeficiente & (1 << 0)) {
SetBit(PORT_LED_1, LED_1_NUMBER);
}
if (tipo_coeficiente & (1 << 1)) {
SetBit(PORT_LED_2, LED_2_NUMBER);
}
if (tipo_coeficiente & (1 << 2)) {
SetBit(PORT_LED_3, LED_3_NUMBER);
}
if (tipo_coeficiente & (1 << 3)) {
SetBit(PORT_LED_4, LED_4_NUMBER);
}
tipo_coeficiente++;
//switch (tipo_coeficiente) {
//case 0:
//// valor de referencia
//coeficiente_error_p = 14;
//coeficiente_error_i = 240;
//coeficiente_error_d = 2;
//break;
//case 1:
//coeficiente_error_p = 14;
//coeficiente_error_i = 12016;
//coeficiente_error_d = 12;
//break;
//case 2:
//coeficiente_error_p = 14;
//coeficiente_error_i = 12016;
//coeficiente_error_d = 24;
//break;
//case 3:
//coeficiente_error_p = 14;
//coeficiente_error_i = 12016;
//coeficiente_error_d = 48;
//break;
//case 4:
//coeficiente_error_p = 14;
//coeficiente_error_i = 12016;
//coeficiente_error_d = 96;
//break;
//case 5:
//coeficiente_error_p = 14;
//coeficiente_error_i = 12016;
//coeficiente_error_d = 192;
//break;
//case 6:
//coeficiente_error_p = 14;
//coeficiente_error_i = 12016;
//coeficiente_error_d = 6;
//break;
//case 7:
//coeficiente_error_p = 14;
//coeficiente_error_i = 6000;
//coeficiente_error_d = 6;
//break;
//case 8:
//coeficiente_error_p = 14;
//coeficiente_error_i = 3000;
//coeficiente_error_d = 6;
//break;
//case 9:
//coeficiente_error_p = 14;
//coeficiente_error_i = 1500;
//coeficiente_error_d = 6;
//break;
//case 10:
//coeficiente_error_p = 14;
//coeficiente_error_i = 750;
//coeficiente_error_d = 6;
//break;
//case 11:
//coeficiente_error_p = 14;
//coeficiente_error_i = 375;
//coeficiente_error_d = 6;
//break;
//case 12:
//coeficiente_error_p = 14;
//coeficiente_error_i = 200;
//coeficiente_error_d = 6;
//break;
//case 13:
//coeficiente_error_p = 14;
//coeficiente_error_i = 100;
//coeficiente_error_d = 6;
//break;
//case 14:
//coeficiente_error_p = 14;
//coeficiente_error_i = 50;
//coeficiente_error_d = 6;
//break;
//case 15:
//coeficiente_error_p = 14;
//coeficiente_error_i = 25;
//coeficiente_error_d = 6;
//break;
//}
//if (tipo_coeficiente & (1 << 0)) {
//SetBit(PORT_LED_1, LED_1_NUMBER);
//}
//if (tipo_coeficiente & (1 << 1)) {
//SetBit(PORT_LED_2, LED_2_NUMBER);
//}
//if (tipo_coeficiente & (1 << 2)) {
//SetBit(PORT_LED_3, LED_3_NUMBER);
//}
//if (tipo_coeficiente & (1 << 3)) {
//SetBit(PORT_LED_4, LED_4_NUMBER);
//}
//tipo_coeficiente++;

// ciclos para esperar a que arranque cuando
// se suelta el botón
while (BOTON2_NO_APRETADO) {
//mostrar_sensor_en_leds(S2);
//obtener_sensores(sensores);
//mostrar_leds(sensores);
obtener_sensores(sensores);
mostrar_leds(sensores);
}
_delay_ms(50); //rebote botón

Expand Down Expand Up @@ -343,10 +343,10 @@ int main() {
estado_actual = ST_AFUERA;
} else {
estado_actual = ST_EN_PISTA;
//ClearBit(PORT_LED_1, LED_1_NUMBER);
//ClearBit(PORT_LED_2, LED_2_NUMBER);
//ClearBit(PORT_LED_3, LED_3_NUMBER);
//ClearBit(PORT_LED_4, LED_4_NUMBER);
ClearBit(PORT_LED_1, LED_1_NUMBER);
ClearBit(PORT_LED_2, LED_2_NUMBER);
ClearBit(PORT_LED_3, LED_3_NUMBER);
ClearBit(PORT_LED_4, LED_4_NUMBER);
}

switch (estado_actual) {
Expand All @@ -363,7 +363,7 @@ int main() {
}
err_p_anterior = err_p;

reduccion_velocidad = 0;
//reduccion_velocidad = 0;
//if (coeficiente_error_p > 0) {
//reduccion_velocidad += err_p / coeficiente_error_p;
//}
Expand All @@ -374,9 +374,9 @@ int main() {
//reduccion_velocidad += err_d / coeficiente_error_d;
//}

gusty1=err_p/coeficiente_error_p;
gusty2=err_i/coeficiente_error_i;
gusty3=err_d/coeficiente_error_d;
//gusty1=err_p/coeficiente_error_p;
//gusty2=err_i/coeficiente_error_i;
//gusty3=err_d/coeficiente_error_d;

//if (gusty3 > RANGO_VELOCIDAD){
//SetBit(PORT_LED_1, LED_1_NUMBER);
Expand All @@ -394,9 +394,7 @@ int main() {
//ClearBit(PORT_LED_4, LED_4_NUMBER);
//}

reduccion_velocidad = gusty1 + gusty2 + gusty3;

//reduccion_velocidad = err_p / coeficiente_error_p + err_i / coeficiente_error_i + err_d / coeficiente_error_d;
reduccion_velocidad = err_p * COEFICIENTE_ERROR_P + err_i * COEFICIENTE_ERROR_I + err_d * COEFICIENTE_ERROR_D;

// printf de valores PID
//printf("p:%5i i:%5i d:%5i rv:%5i\n", err_p, err_i, err_d, reduccion_velocidad);
Expand Down
8 changes: 4 additions & 4 deletions SRC/Codigo Tito 3.14/velocidades.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
// las velocidades van de -100 a 100, determinado en tito.h

// (MIN_VELOCIDAD + RANGO_VELOCIDAD) va de 0 a 255
#define RANGO_VELOCIDAD 100
#define RANGO_VELOCIDAD 127
#define MIN_VELOCIDAD 127 // si es <127, los motores van en reversa
#define BASE 50 // define cual es la velocidad que se le suma a MIN_VELOCIDAD en el caso que se este en linea
#define ESCALA_BAJA 2 // define que tan rapido satura la velocidad a MIN_VELOCIDAD para el motor que deseamos que vaya mas lento, valores mas grandes hacen que no se alcance la velocidad minima seguido
#define ESCALA_ALTA 2 // define que tan rapido satura la velocidad a MIN_VELOCIDAD para el motor que deseamos que vaya mas lento, valores mas pequeños hacen que la velocidad maxima se alcance mas seguido

#define COEFICIENTE_ERROR_P 1 / 14
#define COEFICIENTE_ERROR_I 1 / 240
#define COEFICIENTE_ERROR_D 1 / 6
#define COEFICIENTE_ERROR_P 1 / 12
#define COEFICIENTE_ERROR_I 1 / 6000
#define COEFICIENTE_ERROR_D 1 / 3

#define COEFICIENTE_DERECHA FACTOR * 0.9
#define COEFICIENTE_IZQUIERDA FACTOR * 0.9
Expand Down

0 comments on commit 309b987

Please sign in to comment.