Example #1
0
void InitGPS()
{
	CalculateRotateFact();
	OSTimeDly(500);
        InitEncoders();
	InitGyro(GPS_TIMER_PPR / (double)GPS_TIMER_DIV);
	g_X = START_X ;
	g_Y = START_Y ;
	InitTimerInt(GPS_TIMER, GPS_TIMER_PPR, GPS_TIMER_DIV, GPS_ISR, 0x10);
}
Example #2
0
/* Assume starting well aligned to line (black on left, white on right).
   If we leave the iMid region - we return (and set fLoseTrack) */
void LineFollower()
{
  int pwrLeft;
  int pwrRight;

  InitEncoders();
 
  while (!fStalled && !fBlocked)
    {
    Lookdown();
    pwrLeft = WProportion(wLD, wBlack, wWhite, pwrTrackMax, pwrTrackMin);
    pwrRight = WProportion(wLD, wBlack, wWhite, pwrTrackMin, pwrTrackMax);
    printf("Follow: %d - %d\n", pwrRight, pwrLeft);
    SetMotors(pwrLeft, pwrRight);
    ReadEncoders();
    }
  SetMotors(0,0);
}
Example #3
0
void Move(int cLMax, int cRMax)
{
  int sL;
  int sR;
  float tL;
  float tR;
  float tMax;
  int sLSet;
  int sRSet;
  long ms;
  long msLimit;

  printf("Move: %d, %d\n", cLMax, cRMax);
  if (fAssertEnable)
    StartPress();

  msLimit = mseconds() + 2000L;

  InitEncoders();
  
  if (cLMax < 0)
    {
    cLMax = -cLMax;
    sL = -pwrMax;
    }
  else
    sL = pwrMax;

  if (cRMax < 0)
    {
    cRMax = -cRMax;
    sR = -pwrMax;
    }
  else
    sR = pwrMax;

  while (cL < cLMax || cR < cRMax)
    {
    if (stop_button())
      break;
    ReadEncoders();
    if (FBallCapture())
      break;
    if (fStalled || fBlocked)
      {
      if (!fForce)
        {
        beep();beep();beep();
        printf("Abort Move\n");
        break;
        }
      ms = mseconds();
      if (ms >= msLimit)
        {
        beep();beep();beep();
        printf("Time out\n");
        break;
        }
      }

    if (cL >= cLMax)
      sL = 0;
    if (cR >= cRMax)
      sR = 0;
 /*   printf("L: %d, R: %d\n", cL, cR); */
    tL = Parametric(cL, cLMax);
    tR = Parametric(cR, cRMax);
    sRSet = sR;
    sLSet = sL;
    /* BUG: Can need less than 3/4 speed - also need not retart balanced
       motors when both can track the same! */
    if (tL > tR)
      sLSet = sL*3/4;
    else
      sRSet = sR*3/4;
    SetMotors(sLSet, sRSet);
    }

  SetMotors(0,0);
}
Example #4
0
void main( int argc, char** argv)
{
	//struct Position Pos;
	int Ix;

	strcpy( ConfigFile, "config.dat");

	Parity = NoneParity;
	DataBits = 8;
	StopBits = 1;

	CalledByGuideFlag = No;
	KeepGoingFlag = No;
	ReadSlewFlag = No;
	StartScrollFlag = No;

	/* if '-k' and '-s' (after full init): slew to Ra, Dec in slew.dat and keep going, exiting when
	desired, writing slew_out.dat file;
	if '-k' (before full init): (no slew.dat), keep going until centered on init position, write
	slew_out.dat file and exit;
	if '-s': slew to Ra, Dec in slew.dat and exit, writing slew_out.dat file;
	if no '-k' and no '-s': write slew_out.dat file and exit;

	if -c, then use following string as configuration file name, ie scope.exe -c config.dat will
	result in config.dat being used

	if -x, then use following string as scroll file name, and execute scroll file upon program
	startup, ie scope.exe -x nan.scr	will cause nan.scr to be loaded and started */

	/* argv[0] is name of executing program */
	for( Ix = 1; Ix < argc; Ix++)
		if( argv[Ix][0] == '-')
			if( strcmpi( &argv[Ix][1], "GUIDE") == 0)
				CalledByGuideFlag = Yes;
			else if( argv[Ix][1] == 'k')
				KeepGoingFlag = Yes;
			else if( argv[Ix][1] == 's')
				ReadSlewFlag = Yes;
			else if( (argv[Ix][1] == 'c' || argv[Ix][1] == 'C') && Ix < argc-1)
				strcpy( ConfigFile, argv[Ix+1]);
			else if( (argv[Ix][1] == 'x' || argv[Ix][1] == 'X') && Ix < argc-1)
			{
				strcpy( ScrollFilename, argv[Ix+1]);
				StartScrollFlag = Yes;
			}

	InitCommonVars();
	ReadConfig();

	/*
		Pos.Ra = Pos.Dec = 0;
		applyCorrectionsFromDataFileCoordYearToEpochNow(&Pos);
		printf("\n%f %f %f %f %f %f %f %f", Pos.Precession.A*RadToArcsec, Pos.Precession.Z*RadToArcsec,
		Pos.Nutation.A*RadToArcsec, Pos.Nutation.Z*RadToArcsec, Pos.AnnualAberration.A*RadToArcsec,
		Pos.AnnualAberration.Z*RadToArcsec, Pos.Ra*RadToArcsec, Pos.Dec*RadToArcsec);
		ContMsgRoutine();
	*/
	/*
		HsRecFile = fopen( HsRecFilename, "w");
		if( HsRecFile == NULL)
			BadExit( strcat( "Could not create ", HsRecFilename));
		HsRecIx = 0;
	*/

	/*
		InitTimes( DisplayOpeningMsgs, Tz, DST, LongitudeDeg);
		InitConvert();
		TestConvert();
		getch();
		TestAltAltAzTrack();
	*/


	if( DisplayOpeningMsgs)
	{
		printf( "\nCopyright BBAstroDesigns Inc. 2009\n");
		printf( "\nLIMITED WARRANTY This software is provided ``as is'' and any express or");
		printf( "\nimplied warranties, including, but not limited to, the implied warranties");
		printf( "\nof merchantability and fitness for a particular purpose are disclaimed.");
		printf( "\nIn no event shall BBAstroDesigns be liable for any direct, indirect,");
		printf( "\nincidental, special, exemplary, nor consequential damages (including, but");
		printf( "\nnot limited to, procurement of substitute goods or services, loss of use,");
		printf( "\ndate, or profits, or business interruption) however caused and on any");
		printf( "\ntheory of liability, whether in contract, strict liability, or tort");
		printf( "\n(including negligence or otherwise) arising in any way out of the use of");
		printf( "\nthis software, even if advised of the possibility of such damage.\n");
		printf( "\nThis software licensed under the GNU GENERAL PUBLIC LICENSE. You may");
		printf( "\ndistribute this software per the GNU GPL. See the enclosed gpl.txt.\n\n");
		ContMsgRoutine();
	}

	if( DisplayOpeningMsgs)
		printf( "\ncalled by guide: %d, keep_going: %d, read slew.dat file %d",
		CalledByGuideFlag, KeepGoingFlag, ReadSlewFlag);

	/* if( strcmpi( TestString, "TestSerial") == 0)
	{
		InitSerial( EncoderComPort, EncoderBaudRate, Parity, DataBits, StopBits);
		TestSerial( EncoderComPort);
		CloseSerial( EncoderComPort);
	} */
	/* else if( strcmpi( TestString, "TestVideo") == 0)
	{
		InitVideo( DisplayOpeningMsgs);
		TestVideo();
	} */
	/* else if( strcmpi( TestString, "TestATimes") == 0)
	{
		InitTimes( DisplayOpeningMsgs, Tz, DST, LongitudeDeg);
		TestTimes();
	} */
	/* else if( strcmpi( TestString, "TestParallelPort") == 0)
	{
		InitPPort();
		TestPPort();
		ClosePPort();
	} */
	/* else if( strcmpi( TestString, "TestRefract") == 0)
	{
		InitRefract();
		TestRefract();
	} */
	/* else if( strcmpi( TestString, "TestMouse") == 0)
	{
		TestMouse();
	} */
	/* else if( strcmpi( TestString, "TestEncoders") == 0)
	{
		InitSerial( EncoderComPort, EncoderBaudRate, Parity, DataBits, StopBits);
		InitEncoders();
		TestEncoders();
		CloseSerial( EncoderComPort);
	} */
	/* else if( strcmpi( TestString, "TestHandpad") == 0)
	{
		InitPPort();
		InitializeHandpad();
		TestHandpad();
		ClosePPort();
	} */
	/* else if( strcmpi( TestString, "TestConversion") == 0)
	{
		InitTimes( DisplayOpeningMsgs, Tz, DST, LongitudeDeg);
		InitConvert();
		TestConvert();
	} */
	/* else if( strcmpi( TestString, "TestAltOffset") == 0)
	{
		InitTimes( DisplayOpeningMsgs, Tz, DST, LongitudeDeg);
		InitConvert();
		TestAltOffset();
	} */
	/* else if( strcmpi( TestString, "TestIACA") == 0)
	{
		InitTimes( DisplayOpeningMsgs, Tz, DST, LongitudeDeg);
		TestIACA();
		InitIACA();
	} */
	/* else if( strcmpi( TestString, "WritePWMValues") == 0)
	{
		InitTimes( DisplayOpeningMsgs, Tz, DST, LongitudeDeg);
		InitVideo( DisplayOpeningMsgs);
		InitPPort();
		InitMotors();
		WritePWMValues();
		CloseSteppers();
		ClosePPort();
	}
	else */
	{
		if( strcmpi( TestString, "NoTest") != 0
		&& strcmpi( TestString, "PreloadGuidexx.dat") != 0
		&& strcmpi( TestString, "Track") != 0)
		{
			if( DisplayOpeningMsgs)
				printf( "\nsetting unrecognized TestString to 'NoTest'");
			strcpy( TestString, "NoTest");
		}
		InitSerial( EncoderComPort, EncoderBaudRate, Parity, DataBits, StopBits);
		InitEncoders();
		InitMouseControl();
		InitTimes( DisplayOpeningMsgs, Tz, DST, LongitudeDeg);
		InitVideo( DisplayOpeningMsgs);
		InitPPort();
		InitializeHandpad();
		InitMotors();
		InitConvert();
		InitRefract();
		InitPEC();
		InitGuide();
		if( strcmpi( TestString, "PreloadGuidexx.dat") == 0)
		{
			LoadGuideAlts();
			LoadGuideAzs();
		}
		InitIACA();
		InitLX200Input();
		InitHPEvent();
		if( !CalledByGuideFlag ||
		(CalledByGuideFlag && (KeepGoingFlag || ReadSlewFlag)))
		{
			InitKBEvent();
			if( ReadSlewFlag)
				InputEquatSlewDat();
			if( StartScrollFlag)
				LoadScrollFileFromFile();
			if( strcmpi( TestString, "Track") == 0)
				Start2MotorTrackWithDefaultValues();
			while( !QuitFlag)
			{
				SequentialTaskController();
				/* GrandTourFlag used to flag next object: set in ProcessHPEventsModeSwitch() */
				if( GrandTourLoaded && GrandTourFlag)
					ProcessGrandTour();
				else
					if( ScrollLoaded && ScrollFlag)
						ProcessScroll();
					else
						if( HPPolarAlignLoaded && HPPolarAlignFlag)
							ProcessHPPolarAlign();
						else
						{
							if( UseMouseFlag && ProcessMouseEvent())
								;
							else
								if( KeyStroke)
									ProcessKBEvents();
								else
									ProcessHPEvents();
						}
			}
			CloseKBEvent();
			if( DisplayOpeningMsgs)
			{
				AskAndWriteConfig();
				WriteLogFile();
			}
		}
		CloseSteppers();
		ClosePPort();
		CloseEncoderResetLogFile();
		CloseSerial( EncoderComPort);
		CloseSerial( LX200ComPort);
		if( CalledByGuideFlag)
			WriteAltazSlewOutFile();
		CloseMouseControl();
	}

	/*
		for( Ix = 0; Ix < HsRecSize; Ix++)
			fprintf( HsRecFile, "%8ld   %8ld\n", HsRec[Ix].A, HsRec[Ix].Z);
		// first position is index 0
		fprintf( HsRecFile, " last entry in circular queue at position %d", HsRecIx);
		fclose( HsRecFile);
	*/
}
Example #5
0
void Phaser()
{
	// Initialize hardware
	InitAudio(44100);
	InitDisplay_DOGM128();
	InitEncoders();

	// Calibrate touch screen
	TwoPointCalibration cal;
	TwoPointCalibrate_TSC2046(&cal);

	// Prepare a cleared screen
	static uint8_t screen[1024];
	extern uint8_t background[1204];
	memcpy(screen,background,sizeof(screen));
	UpdateDisplay_DOGM128(screen);
    
	// Set up effect parameters and buffers
	const int midpoint=60; // The midpoint for the delay offset value
	int mix=0x8000; // Mixing factor for the phaser effect - set to 50%
	int feedback=0x8000; // Feedback factor for the phaser effect - set to 50%
	int count=0; // LFO control counter
	int maxcount=64; // The number of iterations to run before updating the LFO
	bool update=true; // Update flag for the screen
	static int32_t inbuf[NumberOfSamples*2],outbuf[NumberOfSamples*2]; // Input and output audio buffers
	static int32_t tmpbuf1[NumberOfSamples],tmpbuf2[NumberOfSamples]; // Temporary audio buffers

	// Initialize the phaser effects for both stereo channels
	static DelayPhaser dp[2];
	InitDelayPhaser(&dp[0],0,mix,feedback);
	InitDelayPhaser(&dp[1],0,mix,feedback);

	// Initialize an LFO to control the phaser effect
	LFO lfo;
	InitLFO(&lfo,80,20); // period of 80, amplitude of +-20

	// This loop processes 16 stereo samples at a time,
	// and thus run in 16/44100 seconds, or 363 microseconds.
	for(;;)
	{
		// Read input from the audio codec
		ReadFullAudioBuffer(inbuf,NumberOfSamples*2);

		// Get input from the touch screen
		int x,y;
		bool press=CalibratedTouchscreenPosition_TSC2046(&cal,&x,&y);

		if(press)
		{
			// Handle clicks on the delay slider
			if(x>=18-9&&x<55-9)
			{
				int oldcount=maxcount;
				maxcount=(63-y)*4;

				if(oldcount!=maxcount) update=true;
			}

			// Handle clicks on the mixing slider
			else if(x>=55-9&&x<92-9)
			{
				int oldmix=mix;

				mix=(63-y)*0x400;
				SetDelayPhaserMix(&dp[0],mix);
				SetDelayPhaserMix(&dp[1],mix);

				if(oldmix!=mix) update=true;
			}

			// Handle clicks on the feedback slider
			else if(x>=92-9&&x<92+2*18)
			{
				int oldfeedback=feedback;

				feedback=(63-y)*0x400;
				SetDelayPhaserFeedback(&dp[0],feedback);
				SetDelayPhaserFeedback(&dp[1],feedback);

				if(oldfeedback!=feedback) update=true;
			}
		}

		// Read input from the encoders
		int rot0=ReadEncoderChange(0);
		int rot1=ReadEncoderChange(1);
		int rot2=ReadEncoderChange(2);

		// Handle delay encoder
		if(rot0)
		{
			maxcount+=4*rot0;
			if(maxcount<0) maxcount=0;

			update=true;
		}

		// Handle mixing encoder
		if(rot1)
		{
			mix+=0x800*rot1;
			if(mix>0x10000) mix=0x10000;
			if(mix<0) mix=0;

			SetDelayPhaserMix(&dp[0],mix);
			SetDelayPhaserMix(&dp[1],mix);

			update=true;
		}

		// Handle feedback encoder
		if(rot2)
		{
			feedback+=0x800*rot2;
			if(feedback>0x10000) feedback=0x10000;
			if(feedback<0) feedback=0;

			SetDelayPhaserFeedback(&dp[0],feedback);
			SetDelayPhaserFeedback(&dp[1],feedback);

			update=true;
		}

		// Update screen if necessary
		// TODO: fix this code snippet since it takes too much time to execute and therefore distorts the audio signal
		if(update)
		{
		
			// Draw delay slider
			int delayheight=maxcount/4;
			EraseFilledRectangle(screen,18,0,18,64-delayheight);
			DrawFilledRectangle(screen,18,64-delayheight,18,delayheight);
            
			// Draw mixing slider
			
			int mixheight=mix/0x400;
			EraseFilledRectangle(screen,55,0,18,64-mixheight);
			DrawFilledRectangle(screen,55,64-mixheight,18,mixheight);
            
			// Draw feedback slider
			
			int feedbackheight=feedback/0x400;
			EraseFilledRectangle(screen,92,0,18,64-feedbackheight);
			DrawFilledRectangle(screen,92,64-feedbackheight,18,feedbackheight);
            
			//UpdateDisplay_DOGM128(screen);
			j=0;
			update=false;
			screenupdated=true;
		}

        if(screenupdated) {

	        if (my_updatedisplay(screen) == 8) {

			    screenupdated=false;
            }
        }
		// Run LFO if needed
		if(++count>=maxcount)
		{
			count=0;
			int lfoval=RunTriangleLFO(&lfo);
			SetDelayPhaserOffset(&dp[0],lfoval+midpoint);
			SetDelayPhaserOffset(&dp[1],lfoval+midpoint);
		}

		// Run phaser effect
		for(int channel=0;channel<2;channel++)
		{
			// Extract one channel from the input to a temporary buffer
			for(int i=0;i<NumberOfSamples;i++) tmpbuf1[i]=inbuf[2*i+channel];

			// Run effect in temporary buffers
			RunDelayPhaser(&dp[channel],tmpbuf1,tmpbuf2,NumberOfSamples);

			// Write processed samples back to the output buffer
			for(int i=0;i<NumberOfSamples;i++) outbuf[2*i+channel]=tmpbuf2[i];
		}

		// Send output buffer to audio codec
		WriteAudioBuffer(outbuf,NumberOfSamples*2);
	}
}