예제 #1
0
task main()
{
	waitForStart();

	initializeRobot();



	// The amount of time the robot...

	// ...moves forward at an angle.
	const int forwardTimeA	= 150;
	// ...turns to line up perpendicular to the center rack.
	const int turnTimeB		= 40;
	// ...drives up to the peg before lifting the lift up.
	const int forwardTimeC	= 155;
	// ...lifts the claw to put a ring on (row 2).
	const int liftTimeF		= 79;
	// ...moves forward, putting the ring onto the peg.
	const int forwardTimeG	= 65;
	// ...lowers its lift to get rid of the ring.
	const int liftTimeH		= 55;
	// ...backs up and gets ready to go to a dispenser.
	const int backwardTimeI	= 300;

	// ...turns to face parallel to the walls.
	const int turnTimeJ		= 40;
	// ...moves forward to align itself with a dispenser.
	const int forwardTimeK	= 100;
	// ...turns to face the dispenser.
	const int turnTimeL		= 80;
	// ...moves forward to be under the dispenser.
	const int forwardTimeM	= 50;


	Move_Forward	(forwardTimeA, g_AccurateMotorPower);
	Turn_Left		(turnTimeB, g_AccurateMotorPower, g_AccurateMotorPower);
	Move_Forward	(forwardTimeC, g_AccurateMotorPower);
	Lift_Lift		(liftTimeF, g_AccurateMotorPower);
	Move_Forward	(forwardTimeG, g_AccurateMotorPower);

	// Lift power is negative so that the lift goes DOWN, not UP.
	Lift_Lift		(liftTimeH, (-1) * g_AccurateMotorPower);
	Move_Backward	(backwardTimeI, g_AccurateMotorPower);

	// Turn power doesn't need to be negative (turns in-place).
	Turn_Left		(turnTimeJ, g_AccurateMotorPower, g_AccurateMotorPower);
	Move_Forward	(forwardTimeK, g_AccurateMotorPower);
	Turn_Left		(turnTimeL, g_AccurateMotorPower, g_AccurateMotorPower);
	Move_Forward	(forwardTimeM, g_AccurateMotorPower);


	while (true)
	{
		PlaySoundFile("moo.rso");
		while(bSoundActive == true)
		{
			Time_Wait(1);
		}
	}



}
예제 #2
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  char buffer[] = "AT";
  uint8_t delay_type = 0;

  /* Chip errata */
  CHIP_Init();

  /* initalize clocks */
  CMU->CTRL |= (1 << 14);                         // Set HF clock divider to /2 to keep core frequency <32MHz
  CMU->OSCENCMD |= 0x4;                           // Enable XTAL Oscillator
  while(! (CMU->STATUS & 0x8) );                  // Wait for XTAL osc to stabilize
  CMU->CMD = 0x2;                                 // Select HF XTAL osc as system clock source. 48MHz XTAL, but we divided the system clock by 2, therefore our HF clock should be 24MHz

  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ;

  usart_init();
  motor_init();

  usart_enable_rx_isr();

  BSP_LedsInit();
  BSP_LedSet(0);
  BSP_LedSet(1);

  usart_send_string(buffer);

  /* Infinite loop */
  while (1) {
	  BSP_LedToggle(1);

	  switch(rx_data){
	    case 'f':
		  Move_Forward();
		  delay_type = 1;
		  break;
	    case 'b':
		  Move_Backward();
		  delay_type = 1;
		  break;
	    case 'r':
		  Move_Left();
		  delay_type = 2;
		  break;
	    case 'l':
		  Move_Right();
		  delay_type = 2;
		  break;
	    default:
	      delay_type = 1;
		  Stop_Robot();
		  break;
	  }

	  rx_data = 0;

	  //Chooses the delay depending on the movement
	  if (delay_type == 1){
		  Delay(1000);
	  }else if(delay_type == 2){
		  Delay(200);
	  }

  }
}
예제 #3
0
task main()
{
    // The IR signal strengh in all 5 directions.
    int IRdirA = 0;
    int IRdirB = 0;
    int IRdirC = 0;
    int IRdirD = 0;
    int IRdirE = 0;



    waitForStart();

    initializeRobot();



    // The amount of time the robot...
    const int forwardTimeAA	= 25;
    const int turnTimeA 	= 50;

    const int forwardTimeA 	= 170;
    const int turnTimeB 	= 110;
    const int forwardTimeB 	= 100;
    const int liftTimeB 	= 45;

    const int forwardTimeCA	= 110;	//TODO
    const int forwardTimeCB = 40;	//TODO
    const int turnTimeD 	= 152;
    const int forwardTimeD 	= 110;
    const int liftTimeD 	= 135;

    const int forwardTimeE 	= 95;	//TODO
    const int turnTimeF 	= 112;
    const int forwardTimeF 	= 80;
    const int liftTimeF 	= 47;

    const int liftTimeG		= 30;	//TODO
    const int backwardTimeG	= 100;	//TODO
    const int turnTimeG		= 70;	//TODO
    const int forwardTimeG	= 20;	//TODO

    const int liftTimeH		= 50;	//TODO
    const int backwardTimeH	= 90;	//TODO
    const int turnTimeH		= 100;	//TODO
    const int forwardTimeH	= 70;	//TODO

    const int liftTimeI		= 30;	//TODO
    const int backwardTimeI	= 130;	//TODO
    const int turnTimeI		= 70;	//TODO
    const int forwardTimeI	= 170;	//TODO

    const int forwardTimeJ	= 50;	//TODO
    const int turnTimeK		= 90;	//TODO
    const int liftTimeK		= 30;	//TODO
    const int forwardTimeK	= 50;	//TODO



    Move_Forward	(forwardTimeAA, g_AccurateMotorPower);
    Turn_Left		(turnTimeA, g_AccurateMotorPower, g_AccurateMotorPower);
    Move_Forward	(forwardTimeA, g_AccurateMotorPower);

    Time_Wait(50);
    HTIRS2readAllDCStrength(infrared, IRdirA, IRdirB, IRdirC, IRdirD, IRdirE);

    if ( (IRdirA+IRdirB+IRdirC+IRdirD+IRdirE) > g_IRthreshold )
    {
        Turn_Right		(turnTimeB, g_AccurateMotorPower, g_AccurateMotorPower);
        Lift_Up			(liftTimeB, g_AccurateMotorPower);
        Move_Forward	(forwardTimeB, g_AccurateMotorPower);

        Lift_Down		(liftTimeG, g_AccurateMotorPower);
        Move_Backward	(backwardTimeG, g_AccurateMotorPower);
        Turn_Right		(turnTimeG, g_AccurateMotorPower, g_AccurateMotorPower);

        Move_Forward	(forwardTimeG, g_AccurateMotorPower);
    }
    else
    {
        Move_Forward	(forwardTimeCA, g_AccurateMotorPower);
        Time_Wait(50);
        HTIRS2readAllACStrength(infrared, IRdirA, IRdirB, IRdirC, IRdirD, IRdirE);
        Move_Forward	(forwardTimeCB, g_AccurateMotorPower);

        if ( (IRdirA+IRdirB+IRdirC+IRdirD+IRdirE) > g_IRthreshold )
        {
            Turn_Right		(turnTimeD, g_AccurateMotorPower, g_AccurateMotorPower);
            Lift_Up			(liftTimeD, g_AccurateMotorPower);
            Move_Forward	(forwardTimeD, g_AccurateMotorPower);

            Lift_Down		(liftTimeH, g_AccurateMotorPower);
            Move_Backward	(backwardTimeH, g_AccurateMotorPower);
            Turn_Right		(turnTimeH, g_AccurateMotorPower, g_AccurateMotorPower);

            Move_Forward	(forwardTimeH, g_AccurateMotorPower);
        }
        else
        {
            Move_Forward	(forwardTimeE, g_AccurateMotorPower);

            Turn_Right		(turnTimeF, g_AccurateMotorPower, g_AccurateMotorPower);
            Lift_Up			(liftTimeF, g_AccurateMotorPower);
            Move_Forward	(forwardTimeF, g_AccurateMotorPower);

            Lift_Down		(liftTimeI, g_AccurateMotorPower);
            Move_Backward	(backwardTimeI, g_AccurateMotorPower);
            Turn_Right		(turnTimeI, g_AccurateMotorPower, g_AccurateMotorPower);

            Move_Forward	(forwardTimeI, g_AccurateMotorPower);
        }
    }
    Move_Forward	(forwardTimeJ, g_AccurateMotorPower);
    Turn_Right		(turnTimeK, g_AccurateMotorPower, g_AccurateMotorPower);
    Lift_Up			(liftTimeK, g_AccurateMotorPower);
    Move_Forward	(forwardTimeK, g_AccurateMotorPower);



    while (true)
    {
        PlaySoundFile("moo.rso");
        while(bSoundActive == true)
        {
            Time_Wait(1);
        }
    }
}