Gyro Implementation

Okay, so I am still trying to get this ‘installed’ into my code right now. I did a little searching but it seems everyone is already past the part where I seem to get stuck. I have read the gyro_readme and I get confused on a few steps.

  1. The gyro’s rate output is wired to one of the analog inputs
    of your robot controller and gyro.h/#define GYRO_CHANNEL is
    updated with the analog channel your gyro is attached to.

  2. Process_Gyro_Data() must be called when the ADC software
    generates an update. An example of how to do this can be found
    in user_routines_fast.c/Process_Data_From_Local_IO(). If you
    use the gyro during autonomous period, Process_Gyro_Data()
    must also be called from User_Autonomous_Code().

  3. A gyro bias calculation must take place using the functions
    Start_Gyro_Bias_Calc() & Stop_Gyro_Bias_Calc() described below.
    This must be done several hundred milliseconds after the gyro
    powers-up and is allowed to stabilize.

  4. For optimal performance, you’ll need to calibrate the gyro
    scaling factor using the instructions above or those included
    in gyro.h.

I’m not very experienced when it comes to this, so any help is appreciated.

Also, do I need to ‘install’ the adc code also to get this to work?

Thanks

I guess I’ll just clarify the steps you listed…? Although I’m not quite too sure about this, but I’ll see if I can help.

  1. The gyro is based off the analog-to-digital converter. So you’ll want to hook up the T on the gyro to an analog input. (Make sure it’s T and not R. It’s not Rotation and Temperature, but Turning and Relative Temperature. Who came up with that?)

  2. You need to call Process_Gyro_Data in your code to use the gyro. The referenced files contain examples of how to do this.

  3. Calculating the gyro bias… You need to calibrate the gyroscope before you can use it. If you’re not using Kevin Watson’s new code, I believe this is the default calibration routine:

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

    if (j == 10) {
        printf("
Calculating Gyro Bias...
");
    }

    if (j == 60) {
        // start a gyro bias calculation
        Start_Gyro_Bias_Calc();
    }

    if (j == 300) {
        // 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
", temp_gyro_bias);
    }

    if (i == 35 && j >= 300) {
        temp_gyro_rate = Get_Gyro_Rate();
        temp_gyro_angle = Get_Gyro_Angle();
        printf(" Gyro Rate=%d
", temp_gyro_rate);
        printf("Gyro Angle=%d

", (int)temp_gyro_angle);
    }

Although I thought that was included somewhere… Make sure i and j are declared somewhere. (This should be in teleop.c or the Process Data function of user_routines.c.

  1. I’d leave this alone for now. You’re better off trying to get the gyro working than working optimaly, really. Save this for later.

Not entirely sure all that information is correct. If it isn’t if someone could let me know? So I don’t go about spreading misinformation? Thanks.

okay, and is the adc code required to be implemented? or can the gyro run without it.

Since the gyro is based off of the ADC, I assume it’s needed to work the gyro.

Probably the guy who labeled the board backwards and came up with a goofy way to rename them rather than admit the mistake.

I laughed out loud the first time I read the “names” of these pins.

Now for my own clarification.

  1. So it is just saying hook it up to T not R on the board? This has nothing to do with code?

  2. A call to Process_Gyro_Data() should be done when the ADC is updated. When and where should this be done? And I’m guessing it should look like this:

void Process_Data_From_Local_IO(void)
{
  /* Add code here that you want to be executed every program loop. */

}

Sooo…

void Process_Gyro_Data(void)
{

}

I’m guessing this is how it should be done. Just where in the code?

  1. I am using the new code. It should still work right? It starts the bias, waits, stops the bias, then sets them into variables.

  2. I am just ignoring this. :slight_smile:

Confirmation?

  1. It just instructs to hook up the gyro. You shouldn’t have to code anything but the gyro channel in gyro.h or just use the default of channel 1.

  2. Actually, just use something like this to call the processing of data:

void Process_Data_From_Master_uP(void)  // The slow loop
{
  Process_Gyro_Data();

}

The function is defined, you just need to call it is all.

  1. That’s correct.

Okay, so now I got the gyro code all up and going. I am now working on installing the ADC.

I get to the part where is says to make all the analog inputs = INPUT; So I have this code:

rc_ana_in01 = rc_ana_in02 = rc_ana_in03 = rc_ana_in04 = INPUT;
rc_ana_in05 = rc_ana_in06 = rc_ana_in07 = rc_ana_in08 = INPUT;
rc_ana_in09 = rc_ana_in10 = rc_ana_in11 = rc_ana_in12 = INPUT;
rc_ana_in13 = rc_ana_in14 = rc_ana_in15 = rc_ana_in16 = INPUT;

above the digital inputs section in User_Initialization(). it keeps giving me a syntax error on the top line. Help?

The analog pins can’t be configured as outputs, so that’s unnecessary.

But step 3 in the adc installation says:

  1. On the EDU-RC, all analog inputs must be configured as
    INPUTs in user_routines.c/User_Initialization().

That is what I did right?

Are you using the small EDU robot controller or the full size FRC robot controller?

-Kevin

The syntax error is because rc_ana_in01 is a constant (I think it resolves to 135). The compiler understandably doesn’t like code that tries to assign a value to a constant.

As others pointed out, the step you’re trying to follow is only for the EDU-RC mini controller.

Oh wow… totally skipped over that part.