Thread: gyro problem
View Single Post
  #10   Spotlight this post!  
Unread 03-03-2008, 15:48
Ken Streeter's Avatar
Ken Streeter Ken Streeter is offline
Let the MAYHEM begin!
FRC #1519 (Mechanical Mayhem)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 2005
Location: Team: Milford, NH; Me: Bedford, NH
Posts: 471
Ken Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond repute
Re: gyro problem

Quote:
Originally Posted by Guarana View Post
Code:
	signed int speed, turn, slide;
	signed int front_r, front_l, back_r, back_l;
	long int l_y, r_y, l_x, r_x;
	static unsigned int i = 0;
	static unsigned int j = 0;
	int temp_gyro_rate;
	long temp_gyro_angle;
	int temp_gyro_bias;
	long temp_gyro_angle_fast;
	long Encoder_Count;

	i++;
	j++; // this will rollover every ~1000 seconds


	// enable this block of code to test your gyro 
	if(j == 10)
	{
		printf("\r\nCalculating Gyro Bias...\r\n");
	}
	if(j == 38) // let the gyro stablize for a second before starting a calibration
	{
		// start a gyro bias calculation
		Start_Gyro_Bias_Calc();
	}
	if(j == 191) // allow calibration routine to run for four seconds 
	{
		// terminate the gyro bias calculation
		Stop_Gyro_Bias_Calc();

		// reset the gyro heading angle
		Reset_Gyro_Angle();

		temp_gyro_bias = Get_Gyro_Bias();
		printf("Gyro Bias=%d\r\n", temp_gyro_bias);
	}
	if(i == 35 && j >= 191)
	{
		temp_gyro_rate = Get_Gyro_Rate();
		temp_gyro_angle = Get_Gyro_Angle();
		printf("Gyro Rate=%d\r\n", temp_gyro_rate);
		printf("Gyro Angle=%d\r\n\r\n", (int)temp_gyro_angle);
Here is the gyro calibration code. Is there anything wrong with this? Something I noticed, is that i and j both add one for each loop. So how does i = 35 and j be higher than 191 if they are always the same (for the last section). maybe i am missing something. would that be any reason?
Further down in the code, i is reset to 0 every time that it increases to 38, in a small block as follows:
Code:
	// reset the loop counter
	if(i >= 38)
	{
		i = 0;
	}
Essentially, i is the number of loops in the "current second" of looping; while j is the total number of loops executed in teleop since the robot was reset.
__________________
Ken Streeter - Team 1519 - Mechanical Mayhem (Milford Area Youth Homeschoolers Enriching Minds)
2015 NE District Winners with 195 & 2067, 125 & 1786, 230 & 4908, and 95 & 1307
2013 World Finalists & Archimedes Division Winners with 33 & 469
2013 & 2012 North Carolina Regional Winners with teams 435 & 4828 and 1311 & 2642
2011, 2010, 2006 Granite State Regional Winners with teams 175 & 176, 1073 & 1058, and 1276 & 133
Team 1519 Video Gallery - including Chairman's Video, and the infamous "Speed Racer!"