TODOPIC
Mecatrónica => Robótica => Mensaje iniciado por: Linea en 20 de Enero de 2011, 05:21:14
-
Buena a todos, estoy realizando un robot sigue lineas y necesito ayuda con el programa, tengo 3 sensores en mi carro y cuando uno de ellos esta en la linea negra me funciona bien pero cuando estan 2 sensores en la linea negra me falla. Os dejo mi programa y haber si me podeis ayudar, estaria muy agradecido.
Mi programa que tengo es:
#include <12f683.h>
//#fuses NOWDT // SIN WATCH DOG TIMER
#fuses INTRC_IO // OSCILADOR INTERNO SIN CLKOUT
#fuses NOCPD // NO EE PROTECTION
#fuses NOPROTECT // NO SE PUEDE LEER EL CODIGO DEL PIC
#fuses NOMCLR // PIN_A3 USADA PARA ENTRADA Y NO PARA RESET
#fuses NOPUT // SIN POWER UP TIMER
#fuses NOBROWNOUT // SIN BROWNOUT RESET
#use delay (clock=8000000) //CONFIGURACION DEL RELOJ
//#rom 0x7ff = {0x3400} // SOLUCIONA UN BUG DEL COMPILADOR
#DEFINE LIMITE_CONTADOR2 100 // son las veces para llegar a tantos milisegundos del contador 2
#DEFINE LIMITE_CONTADOR0 100 // son las veces para llegar a tantos milisegundos del contador 0
//***************VARIABLES GLOBALES****************************
//***************INTERRUPCIONES********************************
//****************************************************************
//***************FUNCIONES**************************************
//****************************************************************
void main ()
{
int contador0=0, lectimer0=0, lectimer2=0, contador2=0;
int CENTRO=8;
int DERECHA=10;
int IZQUIERDA=6;
//*******************CONFIGURACION INICIAL**************************
setup_oscillator(OSC_8MHZ); //CONFIGURA EL OSCILADOR A 8 MHZ
setup_adc_ports(NO_ANALOGS); //ADCs DESACTIVADOS
setup_adc(ADC_OFF); //ADCs DESACTIVADOS
setup_comparator(NC_NC_NC_NC); //COMPARADOR DESACTIVADO
setup_vref(FALSE); //SIN TENSION DE REFERENCIA
setup_timer_0(RTCC_DIV_2 | RTCC_INTERNAL ); //CONFIRACION TIMER0 - POR CADA 2CUENTA 1 // 256 microsegundos
setup_timer_1(T1_DISABLED); //TIMER1 DESACTIVADO
setup_timer_2(T2_DIV_BY_4,0XFA,1); //TIMER2 - POR CADA 4 CUENTA 1 // 500 microsegundos
//setup_ccp1(CCP_PWM); //ANCHO DE PULSO
set_tris_a(0b00101110); //CONFIGURACIÓN TRISA
output_low(PIN_A0); //INICIALIZAMOS LA PUERTA A.
output_low(PIN_A1);
output_low(PIN_A2);
//output_low(PIN_A3);
output_low(PIN_A4);
output_low(PIN_A5);
delay_ms(500);
//***************CODIGO PRINCIPAL DEL PROGRAMA********************
while(true)
{
lectimer2=get_timer2(); //lectura del valor del timer 2
lectimer0=get_RTCC(); //lectura del valor del timer 0
if (!input(PIN_A1)&&!input(PIN_A5)&&!input(PIN_A2)) // TODAS EN NEGRO
{
if ((lectimer2>248) && (contador2<LIMITE_CONTADOR2)) // El contador del timer 2
{
contador2++;
set_timer2(0);
}
if ((lectimer0>123) && (contador0<DERECHA+1) && (contador2<LIMITE_CONTADOR2)) // Franja del contador 1 desde 0 hasta 8 en un margen de 123
{
output_high(PIN_A4);
set_timer0(0);
contador0++;
}
if ((lectimer0>123) && (contador0>DERECHA) && (contador2<LIMITE_CONTADOR2))
{
output_low(PIN_A4);
set_timer0(0);
contador0++;
}
if (contador2==LIMITE_CONTADOR2)
{
contador0 = 0;
contador2 = 0;
}
}
if (!input(PIN_A1)&& !input(PIN_A5)&& input(PIN_A2)) //sensor izquierda y centro negro, derecho en blanco
{
if ((lectimer2>248) && (contador2<LIMITE_CONTADOR2)) // El contador del timer 2
{
contador2++;
set_timer2(0);
}
if ((lectimer0>123) && (contador0<IZQUIERDA+1) && (contador2<LIMITE_CONTADOR2)) // Franja del contador 1 desde 0 hasta 8 en un margen de 123
{
output_high(PIN_A4);
set_timer0(0);
contador0++;
}
if ((lectimer0>123) && (contador0>IZQUIERDA) && (contador2<LIMITE_CONTADOR2))
{
output_low(PIN_A4);
set_timer0(0);
contador0++;
}
if (contador2==LIMITE_CONTADOR2)
{
contador0 = 0;
contador2 = 0;
}
}
if (!input(PIN_A1)&& input(PIN_A5)&& !input(PIN_A2)) // derecha y izquierda en negro, centro en blanco
{
if ((lectimer2>248) && (contador2<LIMITE_CONTADOR2)) // El contador del timer 2
{
contador2++;
set_timer2(0);
}
if ((lectimer0>123) && (contador0<DERECHA+1) && (contador2<LIMITE_CONTADOR2)) // Franja del contador 1 desde 0 hasta 8 en un margen de 123
{
output_high(PIN_A4);
set_timer0(0);
contador0++;
}
if ((lectimer0>123) && (contador0>DERECHA) && (contador2<LIMITE_CONTADOR2))
{
output_low(PIN_A4);
set_timer0(0);
contador0++;
}
if (contador2==LIMITE_CONTADOR2)
{
contador0 = 0;
contador2 = 0;
}
}
if (!input(PIN_A1)&& input(PIN_A5)&& input(PIN_A2))// centro y derecha blanco, izquierda en negro
{
if ((lectimer2>248) && (contador2<LIMITE_CONTADOR2)) // El contador del timer 2
{
contador2++;
set_timer2(0);
}
if ((lectimer0>123) && (contador0<IZQUIERDA+1) && (contador2<LIMITE_CONTADOR2)) // Franja del contador 1 desde 0 hasta 8 en un margen de 123
{
output_high(PIN_A4);
set_timer0(0);
contador0++;
}
if ((lectimer0>123) && (contador0>IZQUIERDA) && (contador2<LIMITE_CONTADOR2))
{
output_low(PIN_A4);
set_timer0(0);
contador0++;
}
if (contador2==LIMITE_CONTADOR2)
{
contador0 = 0;
contador2 = 0;
}
}
if (input(PIN_A1)&& !input(PIN_A5)&& !input(PIN_A2)) // derecha y centro en negro, izquierda en blanco
{
if ((lectimer2>248) && (contador2<LIMITE_CONTADOR2)) // El contador del timer 2
{
contador2++;
set_timer2(0);
}
if ((lectimer0>123) && (contador0<DERECHA+1) && (contador2<LIMITE_CONTADOR2)) // Franja del contador 1 desde 0 hasta 8 en un margen de 123
{
output_high(PIN_A4);
set_timer0(0);
contador0++;
}
if ((lectimer0>123) && (contador0>DERECHA) && (contador2<LIMITE_CONTADOR2))
{
output_low(PIN_A4);
set_timer0(0);
contador0++;
}
if (contador2==LIMITE_CONTADOR2)
{
contador0 = 0;
contador2 = 0;
}
}
if (input(PIN_A1)&& !input(PIN_A5)&& input(PIN_A2)) // centro negro, izuierda y derecha en blanco
{
if ((lectimer2>248) && (contador2<LIMITE_CONTADOR2)) // El contador del timer 2
{
contador2++;
set_timer2(0);
}
if ((lectimer0>123) && (contador0<CENTRO+1) && (contador2<LIMITE_CONTADOR2)) // Franja del contador 1 desde 0 hasta 8 en un margen de 123
{
output_high(PIN_A4);
set_timer0(0);
contador0++;
}
if ((lectimer0>123) && (contador0>CENTRO) && (contador2<LIMITE_CONTADOR2))
{
output_low(PIN_A4);
set_timer0(0);
contador0++;
}
if (contador2==LIMITE_CONTADOR2)
{
contador0 = 0;
contador2 = 0;
}
}
if (input(PIN_A1)&& input(PIN_A5)&& !input(PIN_A2)) // derecha negro, izquierda y centro en blanco
{
if ((lectimer2>248) && (contador2<LIMITE_CONTADOR2)) // El contador del timer 2
{
contador2++;
set_timer2(0);
}
if ((lectimer0>123) && (contador0<DERECHA+1) && (contador2<LIMITE_CONTADOR2)) // Franja del contador 1 desde 0 hasta 8 en un margen de 123
{
output_high(PIN_A4);
set_timer0(0);
contador0++;
}
if ((lectimer0>123) && (contador0>DERECHA) && (contador2<LIMITE_CONTADOR2))
{
output_low(PIN_A4);
set_timer0(0);
contador0++;
}
if (contador2==LIMITE_CONTADOR2)
{
contador0 = 0;
contador2 = 0;
}
}
if (input(PIN_A1)&& input(PIN_A5)&& input(PIN_A2)) // centro, izquierda y derecha en blanco
{
if ((lectimer2>248) && (contador2<LIMITE_CONTADOR2)) // El contador del timer 2
{
contador2++;
set_timer2(0);
}
if ((lectimer0>123) && (contador0<CENTRO+1) && (contador2<LIMITE_CONTADOR2)) // Franja del contador 1 desde 0 hasta 8 en un margen de 123
{
output_high(PIN_A4);
set_timer0(0);
contador0++;
}
if ((lectimer0>123) && (contador0>CENTRO) && (contador2<LIMITE_CONTADOR2))
{
output_low(PIN_A4);
set_timer0(0);
contador0++;
}
if (contador2==LIMITE_CONTADOR2)
{
contador0 = 0;
contador2 = 0;
}
}
}
}
Muchas gracias y espero que me ayudeis.