Exemple #1
0
int main()
{
	// Set the clocking to run directly from the crystal.
	SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);

	//Initialize peripherals
	InitializeDisplay();
	InitializeTimers();
	InitializeADC();
	InitializeInterrupts();

	//Main program loop
	unsigned long avgADCValue = 0;
	while(1)
	{
		if(BufOneReadyToRead)
		{
			avgADCValue = GetAvgOfBuf(1);
			usnprintf(str, 25, "Buf1: %5u", avgADCValue);
			RIT128x96x4StringDraw(str, 0, 0, 15);
			BufOneReadyToRead = 0;
		}
		else if(BufTwoReadyToRead)
		{
			avgADCValue = GetAvgOfBuf(2);
			usnprintf(str, 25, "Buf2: %5u", avgADCValue);
			RIT128x96x4StringDraw(str, 0, 10, 15);
			BufTwoReadyToRead = 0;
		}
	}
}
Exemple #2
0
U8 InitializeMicroAPI(void)
{
	InitializePorts();
	InitializeClock();
	InitializeSPI();

	InitializeUART1(k115200);
	InitializeInterrupts();
	GpioSet(NSSpin);

	InitializeTimers();
	RealTimeClockOn();
	StartIntervalTimer();

	return 0;
}
Exemple #3
0
void main( void )
{  
   InitializeCelebratory();
   InitializeTimers();
   InitializePositioningSystem();
   InitializeObstacleAvoidanceSystem();
   InitializeNavigationSystem( &targetNodes );
   InitializeMotorControlSystem();
   InitializeCompass();
   //CalibrateCompass();
   //Delay( 10000 );
   
   nextState = PursueTarget;
   
   SetRoversBearing( 0 );
   SetRoversPosition( 36, 36 );
   
   for ( ; ; )
   {
      switch ( nextState )
      {
         case FindClosestTarget:
            nextState = FindNextTarget( &nextTargetIndex );
            break;
         case PursueTarget:
            nextState = NavigateToTarget( nextTargetIndex );
            break;
         case SenseAndPlaceObstacle:
            DetermineRoversPosition( GetRoversPosition() );
            nextState = DetectAndPlaceObstacle();
            break;
         case TimeToCelebrate:
            Celebrate();
            for(;;);
            break;
         default:
            nextState = FindClosestTarget;
            break;
      }
   }
}
Exemple #4
0
///////////////////
// Initialize the standard Auxiliary Library
int InitializeAuxLib(const std::string& config, int bpp, int vidflags)
{
	// We have already loaded all options from the config file at this time.

#ifdef linux
	//XInitThreads();	// We should call this before any SDL video stuff and window creation
#endif


	ConfigFile=config;

	if(getenv("SDL_VIDEODRIVER"))
		notes << "SDL_VIDEODRIVER=" << getenv("SDL_VIDEODRIVER") << endl;

	// Solves problem with FPS in fullscreen
#ifdef WIN32
	if(!getenv("SDL_VIDEODRIVER")) {
		notes << "SDL_VIDEODRIVER not set, setting to directx" << endl;
		putenv((char*)"SDL_VIDEODRIVER=directx");
	}
#endif

	// Initialize SDL
	int SDLflags = SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE;
	if(!bDedicated) {
		SDLflags |= SDL_INIT_VIDEO;
	} else {
		hints << "DEDICATED MODE" << endl;
		bDisableSound = true;
		bJoystickSupport = false;
	}

	if(SDL_Init(SDLflags) == -1) {
		errors << "Failed to initialize the SDL system!\nErrorMsg: " << std::string(SDL_GetError()) << endl;
#ifdef WIN32
		// retry it with any available video driver
		unsetenv("SDL_VIDEODRIVER");
		if(SDL_Init(SDLflags) != -1)
			hints << "... but we have success with the any driver" << endl;
		// retry with windib
		else if(putenv((char*)"SDL_VIDEODRIVER=windib") == 0 && SDL_Init(SDLflags) != -1)
			hints << "... but we have success with the windib driver" << endl;
		else
#endif
		return false;
	}

#ifndef DISABLE_JOYSTICK
	if(bJoystickSupport) {
		if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) != 0) {
			warnings << "WARNING: couldn't init joystick subystem: " << SDL_GetError() << endl;
			bJoystickSupport = false;
		}
	}
#endif

	if(!bDedicated && !SetVideoMode())
		return false;

    // Enable the system events
    SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
	SDL_EventState(SDL_VIDEOEXPOSE, SDL_ENABLE);

	// Enable unicode and key repeat
	SDL_EnableUNICODE(1);
	SDL_EnableKeyRepeat(200,20);

	
	/*
	Note about the different sound vars:
	  bDisableSound - if the sound system+driver is disabled permanentely
	  tLXOptions->bSoundOn - if the sound is enabled temporarely (false -> volume=0, nothing else)

	I.e., even with tLXOptions->bSoundOn=false (Audio.Enabled=false in config), the sound system
	will be loaded. To start OLX without the sound system, use the -nosound parameter.

	The console variable Audio.Enabled links to tLXOptions->bSoundOn.
	The console command 'sound' also wraps around tLXOptions->bSoundOn.

	tLXOptions->iSoundVolume will never be touched by OLX itself, only the user can modify it.
	tLXOptions->bSoundOn will also not be touched by OLX itself, only user actions can modify it.
	(Both points were somewhat broken earlier and kind of annoying.)
	*/
	
    if( !bDisableSound ) {
	    // Initialize sound
		//if(!InitSoundSystem(22050, 1, 512)) {
		if(!InitSoundSystem(44100, 1, 512)) {
		    warnings << "Failed the initialize the sound system" << endl;
			bDisableSound = true;
		}
    }
	if(bDisableSound) {
		notes << "soundsystem completly disabled" << endl;
		// NOTE: Don't change tLXOptions->bSoundOn here!
	}

	if( tLXOptions->bSoundOn ) {
		StartSoundSystem();
	}
	else
		StopSoundSystem();


	// Give a seed to the random number generator
	srand((unsigned int)time(NULL));

	if(!bDedicated) {
		SmartPointer<SDL_Surface> bmpIcon = LoadGameImage("data/icon.png", true);
		if(bmpIcon.get())
			SDL_WM_SetIcon(bmpIcon.get(), NULL);
	}

	InitEventQueue();
	
	// Initialize the keyboard & mouse
	InitEventSystem();

	// Initialize timers
	InitializeTimers();

#ifdef DEBUG
	// Cache
	InitCacheDebug();
#endif


	return true;
}
//Here, the distinctions between the autonomous personality and driver personality is defined.
task main()
{
	InitializeLCDScreen();
	InitializePIDControllers();
	InitializeDebugStream();
	InitializeTimers();
	InitializeEncoders();
	SenAutoPot = SensorValue(AutoSelector);
	UpdateAutonomousRoutine();
	while(true)
	{
		Input();
		if(!IsRobotDisabled) //Simulation Allowed but Competiton still works if defined
		{
			if (IsRobotInAutonomousMode || IsRobotInVirtualAutonomousMode ||
				(DriverMode != DriverJoystickControl && DriverMode != DriverMotorTest))
			{
				AutonomousControl();
				UpdateScreen(DispAutonomousMode);
				#ifdef LOGENCODERS
					LogEncoders();
				#endif
				if (!IsRobotInAutonomousMode)
					if (!JoystickCheck(true))
						IsRobotInVirtualAutonomousMode = false;
			}
			else
			{
				AutonomousStep=0;
				UpdateAutonomousRoutine();
				UpdateScreen(DispDriverMode);
				if (DriverMode == DriverJoystickControl)
				{
					AutonomousReset(Finish);
					SubroutineCheck();
					DriveControl();
					IntakeControl();
					LiftControl();
					DescorerControl();
				}
				else if (DriverMode == DriverMotorTest)
				{
					if (!JoystickCheck(false))
						DriverMode = DriverJoystickControl;
				}
			}
		}
		else
		{
			AutonomousStep=0;
			AutonomousReset(Finish);
			UpdateAutonomousRoutine();
			UpdateScreen(DispDisabledMode);
		}
		Output();
		MainNonDelayedLoopTime = time1[T4];
		while (time1[T4] < MinLoopMS) {}
		MainLoopTime = time1[T4];
		ClearTimer(T4);
	}
}