Gyro Autonomous Problems

The problem is that when you switch to autnomous code the gyro gains numbers very rapidly into the 10000’s then once we go back to Process_Data_From_Master_uP the gyro gains numbers normally. What is the problem with this.

Sounds like you’re adding the current gyro value in rapidly in autonomous, but slowly in Operator mode without taking the rate into account.
Are you using Kevin Watson’s code as a base?
How and where in the code are you updating the gyro?

The Code looks like this in autonomous
while (autonomous_mode)
{
if(Get_ADC_Result_Count())
{
Process_Gyro_Data();
}
etc etc etc.
The only gyro things in here are gyro = Get_Gyro_Angle();
and gyro is a variable declared as long gyro;
We are using kevins camera code as a base and combined the encoder and gyro code into it using his instructions.

in Process_Data_From_Master_uP the Gyro is initialized in User_Initialization and is calibrated in Process_Data_From_Master_uP using the stop and start bias offset. Then it is using kevins temp_gyro_angle = Get_Gyro_Angle(); to get the angle of the gyro. If you have anymore question feel free to ask.


  if(Get_ADC_Result_Count())
  {
    Process_Gyro_Data();
 
    Reset_ADC_Result_Count();
  } 

should be called all the time, in autonomous mode or not.

If you follow the default style then the code above would be in Process_Data_From_Local_IO() and you’d need to add a call to Process_Data_From_Local_IO() within the User_Autonomous_Code() autonomous_mode loop (but outside the 26.2ms slow loop).

Have you caclulated the Bias for the gyro?

This is the value for the null (Not Rotating) output of the gyro. Until you calculate and save this value, the Gyro code will “Think” it’s rotating very fast conter clockwise.

The bias is caclulated by taking the average of many gyro values while the robot is stationary. Kevin has provided an easy way to do this…

First you call Start_Gyro_Bias_Calc() and then a few seconds later you call Stop_Gyro_Bias_Calc(). You must be calling Process_Gyro_Data() thoughout this time interval.

You probably don’t want to do this at the start of tele-operated mode, or autonomous mode, unless you are willing to keep the robot still for a few seconds.

In our code we do this ONCE when the robot enters “Disabled” mode. We figure that it will be in that state for at least two seconds. Just in case we save the gyro bais in EEPROM. If we don’t get a full two seconds in disable mode we use the last saved vale from EEPROM.

To debug this, print out the “Rate” value every second. That way you’ll know if the gyro thinks it’s turning or not. Use Get_Gyro_Rate();

:smiley: Thanks, The Reset_ADC_Result_Count(); did the trick thank you so much Mark Mcleod.