Пример #1
0
int main(void){

	initPIC32();
	closedLoopControl( false );
	setVel2(0, 0); //Stop Engines

	while(1){
		printf("Press start to continue\n");
					
		while(!startButton());
		
		do{

			waitTick40ms();

			int ground = readLineSensors(0);
			
			 if(NEAR_LEFT_BLACK(ground))
			
				setVel2(0, 50);
				
			else if(NEAR_RIGHT_BLACK(ground))
			
				setVel2(50, 0);
				
			else if(FAR_LEFT_BLACK(ground))
			
				setVel2(-50, 50);
				
			else if (FAR_RIGHT_BLACK(ground))	
			
				setVel2(50, -50);
			
			else if(GROUND_CENTER_BLACK(ground))
				setVel2(55, 60);
			else
				setVel2(50, -50);
			

		}while(!stopButton());
	}

return 0;

}
Пример #2
0
	int main(void){
	
	initPIC32();
	closedLoopControl( false );
		setVel2(0, 0); //Stop Engines


	int start, oldStart = 2;
	resetCoreTimer();
		while(1){
			start = startButton();
				if(start != oldStart)
					printf("%10d %d\n",readCoreTimer()/1000, start);

			oldStart = start;
		}
	return 0;

}
Пример #3
0
int main (void)
{
	//iniciçao da pic
  	initPIC32 ();
  	closedLoopControl( true );
  	setVel2(0, 0);

  	T4CONbits.TCKPS=5;
PR4=(PBCLK/32/3)-1;//fout 20MHz/(32*(62499+1))*10Hz,freq a 1 hz
TMR4=0;//Reset timer T2
T4CONbits.TON=1;
//Interrupts
IFS0bits.T4IF=0;//reset do timer
IPC4bits.T4IP=2;//priority
IEC0bits.T4IE=1;//enable timer3
EnableInterrupts();

	printStr(__FILE__); // para saber o nome do ficheiro que esta a correr no robot
	printf("\r    battery: %d ", batteryVoltage());
	printStr("\n");
	

//desligar os leds para o inicio
	leds(0b1111);	//leds off


  #if 0

	while(1)
	{
		while(!tick40ms);
		tick40ms=0;
		readAnalogSensors();
		


	}


  #endif



  while (TRUE)
    {
	
	
	TimeOut();		// timeOut => tb devia ir para uma inturrupcao

	//Sensor(); 	 //leitura os sensores tem de se por numa interropecao

	


	//botao de estado 

	if(startButton() == 1) // Botao start(preto) primido
	{
		estado = 1;
		resetCoreTimer();
		leds(0x1);
	
	}
	else if(stopButton() == 1) //Botao stop(vermelho) primido
	{
		estado = 0;
		leds(0x0);
	}

 	//funcoa de funcionameneto
	if(estado == 1) // robot fica em presesamento
	{
		Ver_Farol();
		printf("D: %d   F: %d   E: %d     LINHA: %d    Farol: %d \r",	sensor_dir,sensor_frente,sensor_esq,linha ,farolsen );
		ANDAR2();
	}
	//quando e primido o botao stop
	else if(stopButton() == 1)		// deslica o funcionamento, nenhum led activo
	{
		
		Stop_robot();
	
	}

    }
  return (0);
}
Пример #4
0
int main (void)
{
	int countCiclos = 100;
	//iniciçao da pic
  	initPIC32 ();
  	closedLoopControl( true );
  	setVel2(0, 0);


	printStr(__FILE__); // para saber o nome do ficheiro que esta a correr no robot
	printf("\r    battery: %d ", batteryVoltage());
	if(batteryVoltage() <94){
		printf("_Bateria fraca, MUDAR Bateria\n");

	}
	printStr("\n");
	while(1)
	{	
		while(!tick40ms);
		tick40ms=0;
		readAnalogSensors();

		//state buttons

		if(startButton() == 1) 				// Botao start(preto) primido
		{
			estado = 1;
			enableObstSens();
			leds(0x0);						//leds off
			countCiclos = 100;
		}

		else if(stopButton() == 1) 			//Botao stop(vermelho) primido
		{
			printf("Red button pressed!!! \n");
			estado = 0;
			disableObstSens();
		}

		if(estado == 1) 
		{
			TimeOut();						// timeOut => tb devia ir para uma inturrupcao
			Chegada_Farol();
			if(countCiclos++ >= 100)
			{

				Ver_Farol();
				countCiclos = 0;
			}
			Run_Beacon();
		}

		if(estado == 2)
		{
			leds(0x1);
			Stop_robot();
		}

		if(estado == 3)
			Fim();

		else if(stopButton() == 1 || estado == 0)		// deslica o funcionamento, nenhum led activo
		{
			Stop_robot();
		}
 	}
  return (0);
}