Thread: 2008 Gyro Code
View Single Post
  #4   Spotlight this post!  
Unread 09-02-2008, 11:17
FireJet FireJet is offline
Registered User
AKA: Jero Sutlovic
FRC #2386 (Trojans)
Team Role: Programmer
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Burlington, Ontario
Posts: 8
FireJet is an unknown quantity at this point
Re: 2008 Gyro Code

I tried running Process_Gyro_Data in the _Spin functions, but it still won't help. To make sure that it wasn't my code that was broken, I also added a bit of debug output to Kevin's gyro.c code, in Process_Gyro_Data, so that it now looks like this:

Code:
void Process_Gyro_Data(void)
{
	int temp_gyro_rate;

	// fresh ADC data available?
	if(Get_ADC_Result(GYRO_CHANNEL))
	{	
		// should the completed sample set be used to calculate the gyro bias?
		if(calc_gyro_bias == 1)
		{
			// put the ADC reading on the circular queue
			Gyro_Queue[Gyro_Queue_Index] = Get_ADC_Result(GYRO_CHANNEL);
		
			// increment the write pointer
			Gyro_Queue_Index++;
		
			// is the circular queue now full?
			if(Gyro_Queue_Index == GYRO_QUEUE_SIZE-1)
			{ 
				// update the gyro bias status
				Gyro_Bias_Status = GYRO_BIAS_BUFFER_FULL;
			}

			// If the index pointer overflowed, cut-off the high-order bit. Doing this
			// every time is quicker than checking for overflow every time with an if()
			// statement and only then occasionally setting it back to zero. For this 
			// to work, the queue size must be a power of 2 (e.g., 16,32,64,128).
			Gyro_Queue_Index &= GYRO_QUEUE_INDEX_MASK;
		}
		else
		{
			// get the latest measured gyro rate
			temp_gyro_rate = (int)Get_ADC_Result(GYRO_CHANNEL) - gyro_bias;
	
			// update reported gyro rate and angle only if 
			// measured gyro rate lies outside the deadband
			if(temp_gyro_rate < -GYRO_DEADBAND || temp_gyro_rate > GYRO_DEADBAND)
			{
				// update the gyro rate
				gyro_rate = temp_gyro_rate;
	
				// integrate the gyro rate to derive the heading 
				gyro_angle += (long)temp_gyro_rate;
			}
			else
			{
				gyro_rate = 0;
			}
		}

		Reset_ADC_Result_Count();
	}
	else
	{
		printf("NO NEW ADC DATA.\n\r");
	}
}
Every time Process_Gyro_Data gets called, I get "NO NEW ADC DATA." output. So, I don't believe there's a problem with my code.

As well, I've tried replacing that hard-timed loop with this:

Code:
while (Get_Gyro_Bias_Status() != GYRO_BIAS_BUFFER_FULL)
{
    printf("Calculating gyro bias.\n\r");
}
But that seems to cause the controller to run out of RAM (it locks up and shows a code error).