Ejemplo n.º 1
0
int bump_init(){
	
//Bumper init and interupt
	BumpSensorsInit();
	BumpSensorsInterupEnable(bump_interuptFunction);
	BumperEnableSide(BUMP_LEFT);
	BumperEnableSide(BUMP_RIGHT);


	return 1;
}
Ejemplo n.º 2
0
/**
 * Performs one-time setup of peripherals
 */
static void vInit(void)
{
    /* Sets Clock Speed to 50MHz */
    ROM_SysCtlClockSet(
            SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN
            | SYSCTL_XTAL_16MHZ);

    /* Initializes Bumpers with Interrupt */
    BumpSensorsInit();
    GPIOPinIntEnable(GPIO_PORTE_BASE, (1 << 0) | (1 << 1));
    GPIOIntTypeSet(GPIO_PORTE_BASE, (1 << 0) | (1 << 1), GPIO_FALLING_EDGE);
    IntEnable(20);

    /* Initializes timer, required for scheduler */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER_UP);
    TimerEnable(TIMER0_BASE, TIMER_A);

    SoundInit();
    SoundVolumeSet(95);

    IntMasterEnable();

    /* Hardware initialization for Bouncy related peripherals */
    vBouncyInit();

    /* Hardware initialization for Gamepad related peripherals */
    vGamepadInit();

    initDriveControl();

    // Init the rangefinder
    initRangeFinder();

    return;
}
Ejemplo n.º 3
0
int
main(void)
{
    unsigned long ulPHYMR0;
    tBoolean bButtonWasPressed = false;
    tMotorState sMotorState=STATE_STOPPED;
    tWaveHeader sWaveHeader;
    unsigned long ulWaveIndex = 1;
    int losL,losH;
    
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ETH);
    ulPHYMR0 = ROM_EthernetPHYRead(ETH_BASE, PHY_MR0);
    ROM_EthernetPHYWrite(ETH_BASE, PHY_MR0, ulPHYMR0 | PHY_MR0_PWRDN);

	         	 // Display96x16x1Init(true);
	        	//  Display96x16x1StringDraw("MOTOR", 29, 0);
	         	 //  Display96x16x1StringDraw("DEMO", 31, 1);

    LEDsInit();
    LED_On(LED_1);
    PushButtonsInit();
    BumpSensorsInit();
    MotorsInit();
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();
    SoundInit();
    // WaveOpen((unsigned long *) sWaveClips[ulWaveIndex].pucWav, &sWaveHeader);
    //mozliwe ze trzeba przed kazdym odtworzeniem ;/
   // while(WaveOpen((unsigned long *)
     //                            sWaveClips[ulWaveIndex].pucWav,
       //                          &sWaveHeader) != WAVE_OK);//do zablokowania w razie bledu
    for(;;)
    {

       
            tBoolean bButtonIsPressed;
            tBoolean bBumperIsPressed[2];

            bButtonIsPressed = !PushButtonGetDebounced((tButton)1);
            bBumperIsPressed[0] = !BumpSensorGetDebounced((tBumper)0);
            bBumperIsPressed[1] = !BumpSensorGetDebounced((tBumper)1);

            switch(sMotorState)
            {
                case STATE_STOPPED:
                {
                    if(bButtonIsPressed && !bButtonWasPressed)
                    {
                    	sterowanie(0,50,50);
                        sMotorState = STATE_RUNNING;
                    }
                    break;
                }

                 case STATE_RUNNING:
                {
                	 
                    if(bButtonIsPressed && !bButtonWasPressed)
                    {
                        MotorStop((tSide)0);
                        MotorStop((tSide)1);
                        sMotorState = STATE_STOPPED;
                    }

                    else if(bBumperIsPressed[0])
                    {
                         MotorStop((tSide)0);
                         MotorStop((tSide)1);
                //       WavePlayStart(&sWaveHeader); mozliwe ze tu
                	losL =10+ g_ulTickCount % 20;//i dać los zamiast 15,mamy losowe skrecanie(10-30)
                     	losH =40+ g_ulTickCount % 30;//i dać los zamiast 60,mamy losowe skrecanie(40-70)
                         sterowanie(1,losL,losH);
                	 sMotorState = STATE_TYL;
                    }

                    else if(bBumperIsPressed[1]){
                          MotorStop((tSide)0);
                          MotorStop((tSide)1);
                      	  losL =10+ g_ulTickCount % 20;//i dać los zamiast 15,mamy losowe skrecanie(10-30)
                     	  losH =40+ g_ulTickCount % 30;//i dać los zamiast 60,mamy losowe skrecanie(40-70)
                          sterowanie(1,losH,losL);
                //       WavePlayStart(&sWaveHeader); mozliwe ze tu
                          sMotorState = STATE_TYL;
                          }
                    break;
                }

               case STATE_TYL:
                {//cofanie tez moze byc losowe np losH+losL(50-100)+160=(210-260)
                	 while(cofanie<250);
                        MotorStop((tSide)0);
                        MotorStop((tSide)1);
                        sterowanie(0,50,50);
                        sMotorState = STATE_RUNNING;

                    break;
                }
                
               default:
                {
                    MotorStop((tSide)1);
                    MotorStop((tSide)0);
                    sMotorState = STATE_STOPPED;
                  break;
                }
            } 

           bButtonWasPressed = bButtonIsPressed;

         
    } 
}