Exemplo n.º 1
0
void dispatchFixedMessage(int operation, unsigned long param)
{
  if (VERBOSE) {
    fprintf(stderr,"Calling base operation %d\n",operation);
  }

  confirmCommandToClient(operation, param); /* sends a message back to all
					     * baseClients, confirming the
					     * command, sebastian 7-97 */

  switch(operation) {
    
    /**** GENERAL ****/ 
  case BASE_baseKill:		baseKill(); break;	
  case BASE_loadHeading:	loadHeading(param); break;	
  case BASE_loadPosition:	loadPosition(param); break;	
  case BASE_statusReportData:	statusReportData(param);break;
  case BASE_statusReportPeriod:	statusReportPeriod(param);break;
  case BASE_batteryVoltage:	batteryVoltage();break;
  case BASE_batteryCurrent:	batteryCurrent();break;

  case BASE_watchdogTimer:	watchdogTimer(param);break;
  case BASE_assumeWatchdog:	assumeWatchdog();break;


    /**** ROTATION ****/ 
  case BASE_rotateLimp:		rotateLimp(); break;
  case BASE_rotateHalt:		rotateHalt(); break;
  case BASE_rotateVelocityPos:	rotateVelocityPos(); break;	
  case BASE_rotateVelocityNeg:  rotateVelocityNeg(); break;	
  case BASE_rotateRelativePos:  rotateRelativePos(param); break;	
  case BASE_rotateRelativeNeg: 	rotateRelativeNeg(param); break;	
  case BASE_rotateTorquePos:	rotateTorquePos(param); break;	
  case BASE_rotateTorqueNeg: 	rotateTorqueNeg(param); break;	
  case BASE_rotatePowerPos:	rotatePowerPos(param); break;	
  case BASE_rotatePowerNeg: 	rotatePowerNeg(param); break;	
  case BASE_rotateToPosition: 	rotateToPosition(param); break;	
  case BASE_findRotIndex:
    if (bRobot.base_hasIndex) {
      findRotIndex();
    }
    else {
      sendClientFixed(BASE_indexReport, 0xFFFFFF);
    }
    break;

  case BASE_setRotateVelocity:	setRotateVelocity(param); break;	
  case BASE_setRotateAcceleration: setRotateAcceleration(param); break;	
  case BASE_setRotateFriction: 	setRotateFriction(param); break;	
  case BASE_setRotateSlope: 	setRotateSlope(param); break;	
  case BASE_setRotateTorque: 	setRotateTorque(param); break;	
  case BASE_setRotateZero: 	setRotateZero(param); break;	

  case BASE_rotateCurrent:	rotateCurrent(); break;	
  case BASE_rotateWhere:	rotateWhere(); break;	


    /**** TRANSLATION ****/ 
  case BASE_translateLimp:		translateLimp(); break;
  case BASE_translateHalt:		translateHalt(); break;
  case BASE_translateVelocityPos:  	translateVelocityPos(); break;	
  case BASE_translateVelocityNeg:  	translateVelocityNeg(); break;	
  case BASE_translateRelativePos:  	translateRelativePos(param); break;
  case BASE_translateRelativeNeg:  	translateRelativeNeg(param); break;
  case BASE_translateTorquePos:		translateTorquePos(param); break;
  case BASE_translateTorqueNeg: 	translateTorqueNeg(param); break;
  case BASE_translatePowerPos:		translatePowerPos(param); break;
  case BASE_translatePowerNeg: 		translatePowerNeg(param); break;
  case BASE_translateToPosition: 	translateToPosition(param); break;
  case BASE_setTranslateVelocity:	setTranslateVelocity(param); break;
  case BASE_setTranslateAcceleration: 	setTranslateAcceleration(param); break;
  case BASE_setTranslateSlope: 		setTranslateSlope(param); break;
  case BASE_setTranslateTorque: 	setTranslateTorque(param); break;
  case BASE_setTranslateZero: 		setTranslateZero(param); break;

  case BASE_translateCurrent:		translateCurrent(); break;	
  case BASE_translateWhere:		translateWhere(); break;	

  /**** SONARS ****/
  case BASE_sonarStart:                 SIM_sonarStart(); break;
  case BASE_sonarStop:                  SIM_sonarStop(); break;

  /**** Odometry stuff ****/
  case BASE_odometryChangeX:
    ntohf(param, bOriginX);
    sendClientFixed(BASE_odometryChangeX, param);
    break;
  case BASE_odometryChangeY:
    ntohf(param, bOriginY);
    sendClientFixed(BASE_odometryChangeY, param);
    break;
  case BASE_odometryChangeH:
    ntohf(param, bOriginHeading);
    sendClientFixed(BASE_odometryChangeH, param);
    break;

  /**** Odometry lock requests ****/
  case BASE_requestOdometryLock:
    requestOdometryLock((unsigned short)param);
    break;
  case BASE_releaseOdometryLock:
    releaseOdometryLock();
    break;

  default: 
    fprintf(stderr, "BaseServer: Operation %d not yet implemented.\n",
            operation); 	
  }
  
  if (VERBOSE) {
    fprintf(stderr,"Operation %d complete\n",operation);
  }
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
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);
}