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?