Coding Help for Gyro

I tried during the season to make our Gyro work, but I never had any luck. We were using mecanum drive base and one or the other didn’t work with each other.

What model gyro were you using? How did you wire it? Were you using command-based robot?

We are using the ADXRS450 model that plugs into the RoboRio.

Here is an example for turning to a given angle with macanum wheels. This code uses a navx (an imu that contains both a gyro, accelerometer and other sensors). Just replace the navx (called AHRS in the code) with a Gyro. To create a gyro in java do this:

AnalogGyro gyro = new AnalogGyro(channel);

use gyro instead of ahrs and u are good to go.

So did you get the Gyro to work at all just feeding the Shuffleboard or other display the current Gyro Readings?

We havent gottent the gyro to work at all.

Is it externally wired or plugged directly into the Rio?

Also, can you share the relevant sections of your robot program so we can better diagnose the issue?

Its directly plugged into the roborio. I can get the code later.

okay sounds good.

The ADXRS450 is probably one of the last “3rd party” sensors still supported in the WPILib. In 2018 we used this gyro as a backup to our NavX micro. Your welcome to comb through the code. Here is a link to the RobotMap.java https://github.com/GraniteCityGearheads3244/2018_Super_Sir_Ants_A_Bot/blob/master/MRI_SuperSirAntsABot/src/org/usfirst/frc3244/SuperSirAntsABot2/RobotMap.java

You will see the relevant bits for this sensor

import edu.wpi.first.wpilibj.ADXRS450_Gyro;

public class RobotMap {

    ...
    public static ADXRS450_Gyro adrxs450_Gyro;
	...
}

public static void init() {
    	...
        

      //Create Gyro
        ...
        
        try{
        	DriverStation.reportWarning("Init ADXRS450_Gyro", false);
        	adrxs450_Gyro = new ADXRS450_Gyro();
        }catch (RuntimeException ex ) {
        	System.out.println("Hello from the adrxs450_Gyro runtimeExcept");
            DriverStation.reportError("Error instantiating adrxs450_Gyro:  " + ex.getMessage(), true);
        }

Then over in the Drive Subsystem there was a copy of the Gyro created

private ADXRS450_Gyro headingGyro_BCK = RobotMap.adrxs450_Gyro;

This pattern is less accepted these days with object injection all the rage but that year we followed the format Robotbuilder created.

1 Like

This is a fun little gyro to play with but I’m not sure if you can change its orientation. So your Roborio must be install flat relative to the ground and good practice is to keep the sensor in the center of the robot.

That year ours was flat but not center. But is was only used as a backup. We had our NavX not initiate one time the past season and in Autonomous our robot prematurely started the victory spin.