Go to Post When you score a Supercell on your own alliance it has a tendency to sway a match... - EricLeifermann [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 09-02-2008, 09:47
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
2008 Gyro Code

Hi. I'm using Kevin's new 2008 code, but I can't figure out how to get the Gyro working in either autonomous mode or user mode. I believe that I set up the code right:

Code:
void Teleop_Init(void)
{
	Initialize_Gyro();
	
	if (Get_Gyro_Bias_Status() == GYRO_BIAS_NOT_DONE)
	{
		Start_Gyro_Bias_Calc();
		
		
		while (t2 < 76)
		{
			printf("Calculating gyro bias. State: %d.\n\r", Get_Gyro_Bias_Status());
			//Start_Gyro_Bias_Calc();
			t2++;
		}
		

		Stop_Gyro_Bias_Calc();
		
		printf("Gyro bias calculated: %ld.\n\r", Get_Gyro_Bias());
		
	}

}
Code:
void Teleop(void)
{
    ...

    	Process_Gyro_Data();
	tmpangle = Get_Gyro_Angle();
	printf("Gyro Angle %d\n\r", tmpangle);

    ...
}

But unfortunately, the only output I get is "Gyro Angle 0". I'm sure I've got the gyro connected right, as I get values from Get_Analog_Value (and they change), but I don't get anything from Kevin's code. Can anyone help?
  #2   Spotlight this post!  
Unread 09-02-2008, 10:36
billbo911's Avatar
billbo911 billbo911 is offline
I prefer you give a perfect effort.
AKA: That's "Mr. Bill"
FRC #2073 (EagleForce)
Team Role: Mentor
 
Join Date: Mar 2005
Rookie Year: 2005
Location: Elk Grove, Ca.
Posts: 2,381
billbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond repute
Re: 2008 Gyro Code

FireJet,
The first thing you need to do is move the Process_Gyro_Data() into the Autonomous_Spin, Disabled_Spin and Teleop_Spin functions. This will allow a Gyro data to be processed all the time, not just during that 26.2 milliseconds loop.
Remember, Get_Gyro_Angle returns a long value. You need to typecast it to an int for your printf statement. Something like this.

Code:
tmpangle = int Get_Gyro_Angle();
printf("Gyro Angle %d\n\r", tmpangle);
__________________
CalGames 2009 Autonomous Champion Award winner
Sacramento 2010 Creativity in Design winner, Sacramento 2010 Quarter finalist
2011 Sacramento Finalist, 2011 Madtown Engineering Inspiration Award.
2012 Sacramento Semi-Finals, 2012 Sacramento Innovation in Control Award, 2012 SVR Judges Award.
2012 CalGames Autonomous Challenge Award winner ($$$).
2014 2X Rockwell Automation: Innovation in Control Award (CVR and SAC). Curie Division Gracious Professionalism Award.
2014 Capital City Classic Winner AND Runner Up. Madtown Throwdown: Runner up.
2015 Innovation in Control Award, Sacramento.
2016 Chezy Champs Finalist, 2016 MTTD Finalist
  #3   Spotlight this post!  
Unread 09-02-2008, 10:53
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,586
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: 2008 Gyro Code

Process_Gyro_Data() should be called in a spin function, as it needs to process the data after each interrupt and the telop function isn't fast enough.

Code:
		Start_Gyro_Bias_Calc();
		
		
		while (t2 < 76)
		{
			printf("Calculating gyro bias. State: %d.\n\r", Get_Gyro_Bias_Status());
			//Start_Gyro_Bias_Calc();
			t2++;
		}
		

		Stop_Gyro_Bias_Calc();
The bias calc should last for several seconds. This starts the gyro bias calc, runs the while loop very quickly, and then stops the gyro bias calc too soon.

You should start the bias calc when t2=0, change your while loop to an if statement (so it gets called once each time through telop()) and stop it when t2=76 (or higher, since longer is better). You might also want to consider a delay so that the bias calc doesn't start right away, for everything to stabilize.

Kevin has an example of all this in the ifi_frc_sensor project.
  #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).
  #5   Spotlight this post!  
Unread 09-02-2008, 11:32
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,586
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: 2008 Gyro Code

Quote:
Originally Posted by FireJet View Post
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.
Did you enable the ADC and timer? Read adc_readme.txt (and gyro_readme.txt).


Quote:
Originally Posted by FireJet View Post
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).
The user processor has to communicate with master processor regularly. You can't have a loop that runs for a long time (ideally, it should never run longer then 26.2ms)*. If it's hung up for too long, it will cause a code error. Because of this, you should not use while loops that are waiting for any type of outside input. You want to make sure the telop function runs very quickly. In almost all cases, replacing your while with an if works, because telop will be called many times.


*WPILIB/EasyC works around this by doing the communication in the background, but you have to deal with it in IFI and Kevin's code.
  #6   Spotlight this post!  
Unread 09-02-2008, 12:39
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've read through the ADC and gyro readmes, and everything that they require should be set. I'm not sure about the timer, though... is there a readme for that?

As for the while loop, I did that because I wanted to run the gyro calculations in the initialization functions instead of the Teleop and Autonomous functions.
  #7   Spotlight this post!  
Unread 09-02-2008, 12:49
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: 2008 Gyro Code

Quote:
Originally Posted by FireJet View Post
I've read through the ADC and gyro readmes, and everything that they require should be set. I'm not sure about the timer, though... is there a readme for that?

As for the while loop, I did that because I wanted to run the gyro calculations in the initialization functions instead of the Teleop and Autonomous functions.
You need to follow the instructions in the "readme.txt" file in the documentation folder.

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #8   Spotlight this post!  
Unread 09-02-2008, 13:06
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

Looks like I need to get the really new 2008 code. I still have the version from January that has the old readme.txt file. I'll post more if it still doesn't work.
  #9   Spotlight this post!  
Unread 09-02-2008, 13:33
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: 2008 Gyro Code

Quote:
Originally Posted by FireJet View Post
Looks like I need to get the really new 2008 code. I still have the version from January that has the old readme.txt file. I'll post more if it still doesn't work.
Yeah, that code is sooo January <grin>.

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org

Last edited by Kevin Watson : 09-02-2008 at 16:00. Reason: Spelling gaff
  #10   Spotlight this post!  
Unread 09-02-2008, 14:34
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

Just another question while I'm at it. I used the new default code to test the gyro, and in gyro.h I set "#define TENTHS_OF_A_DEGREE", but when I get input from the gyro I'm getting numbers that range from the double/triple digits to in the thousands, even when I divide by 10. Should this be happening?
  #11   Spotlight this post!  
Unread 09-02-2008, 14:42
DanDon's Avatar
DanDon DanDon is offline
ohhh MY god
AKA: Dan Hoizner
FRC #0375 (The Robotic Plague)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Staten Island, NY
Posts: 1,432
DanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond repute
Send a message via ICQ to DanDon Send a message via AIM to DanDon Send a message via MSN to DanDon
Re: 2008 Gyro Code

Quote:
Originally Posted by FireJet View Post
Just another question while I'm at it. I used the new default code to test the gyro, and in gyro.h I set "#define TENTHS_OF_A_DEGREE", but when I get input from the gyro I'm getting numbers that range from the double/triple digits to in the thousands, even when I divide by 10. Should this be happening?
If you are looking at the output of Get_Gyro_Angle, then readings such as 900 would be 90*, 300 would be 30*, 3600 would be 360*, etc.
__________________
  #12   Spotlight this post!  
Unread 09-02-2008, 14:44
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

Even after it's been divided by 10? And even after that, I shouldn't be getting values over 6000, should I?
  #13   Spotlight this post!  
Unread 11-02-2008, 16:48
heavymetal's Avatar
heavymetal heavymetal is offline
Registered User
FRC #0843 (Wildcats)
Team Role: Programmer
 
Join Date: Feb 2007
Rookie Year: 2005
Location: Canada
Posts: 1
heavymetal is an unknown quantity at this point
Re: 2008 Gyro Code

We are getting output greater then 6000 even after it have been divided 10. Is that suppose to be like that?

Last edited by heavymetal : 11-02-2008 at 16:52.
  #14   Spotlight this post!  
Unread 14-02-2008, 17:06
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

So, does anyone know how to fix this?
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Gyro code problem AMIRAM Programming 10 23-01-2006 04:26
problems using gyro/adc code with camera default code tanstaafl Programming 7 22-01-2006 23:09
gyro code odin892 Programming 2 08-04-2003 14:50
Gyro Chip Code archiver 2001 4 24-06-2002 00:57


All times are GMT -5. The time now is 19:13.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi