ADXRS450 Gyro not sending angles

We’ve attempting to use a ADXRS450 Gyro (The gyro that came with the FRC kit), but unfortunately we cannot read the gyro angle in our main code. I created a test code that only has the gyro code and it sends the gyro angle to the Smartdashboard, but the number doesn’t change from 0.

package org.usfirst.frc.team5132.robot;

import edu.wpi.first.wpilibj.ADXRS450_Gyro;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;

public class Robot extends IterativeRobot {

private ADXRS450_Gyro gyro = new ADXRS450_Gyro();

public void robotInit() {
gyro.reset();
gyro.calibrate();

}

public void teleopPeriodic() {
double angle = gyro.getAngle();
SmartDashboard.putNumber(“Gyro angle”, angle);
}
}

Does anyone see an issues with this?

Did you try using System.out.println() to see if it was a SmartDashboard fault? Also, have you checked your wiring?

It’s connected directly on the RIO in the SPI port so I can’t imagine it would be a wiring issue.
How do I view the console where the angle should be printing out? The only console where it could print out gets terminated by the Rio after deploying.

Nevermind, I found the console.
It just printed out 0 repeatedly, regardless of if I moved the robot.

So, when we were testing out the gyro, I know that it was the wiring that got us. Your code looks fine, so I can’t imagine it’s that. Do you have another gyro you can test with?

The gyro is directly plugged in the SPI port on the Rio, so I’m not sure if there is wiring to mess up there.
No we don’t have another gyro to test with. We’ve tried it on two separate RIOs, though.

If this helps, we just got an error on out main code that says
“ERROR 1 could not find ADXRS450 gyro on SPI port 0 org.usfirst.frc5132.Nick.Robot.<init>(Robot.java:65)”

Sorry for the triple post, but I cant edit my previous posts.
We fixed that issue, but the issue with the angles still persists.

The way you constructed the gyro in your programming it defaults to CS0 SPI port so make sure the jumper is between the CS0 pin and the one below it on the Gyro. Also, the ADXRS450 gyro is a one axis gyro and since its plugged straight into the RoboRIO, the RIO needs to be parallel to the ground for the gyro to read correct angle changes. These are problems we came across while testing.

Good luck.

We found that as soon as this error came up, our gyro was dead no matter what we did to it. We’re on our third gyro because the last two started not being found and we couldn’t figure out for the life of us why.

The jumper is in the correct position. I’m 99% sure that the gyro is completely broken as we’ve tried it on two separate RoboRIO’s with the sample code and with my own custom code. The gyro is already parallel with the floor.

Our team has the same problem of the RoboRio not finding the ADXRS450 gyro. We have tried 3 different gyros, two of them are brand new. In fact, we asked a nearby team to test our gyro and they have no problem seeing it with the same test code I provided them. So the problem is not with the gyro but with our control system. At first, I thought there must be a problem with the RoboRio but we have a second RoboRio and it has the same result. So I wouldn’t believe both RoboRios have gone bad the same way. The only conclusion I drew was that our RoboRio may have a config issue although I can’t figure out what because I checked firmware version, OS image version and everything seem to be identical to the RoboRio of the nearby team. Eventually, we gave up finding the culprit and just ordered the navX gyro and that works beautifully.

We tried our gyro on three separate RoboRios and it still did not work. We also gave up and ordered a NavX MXP and it’s working beautifully for us aswell.

I am glad you got that resolved by switching to NavX. However, I still want to find out why although it’s not urgent anymore. We now have 3 of those ADXRS450 gyros and I hate to see them unused. Anybody has any suggestion/explanation why the ADXRS450_Gyro class failed to read the ID register? It read all zeros instead of the expected value of 0x5200.


  /**
   * Constructor.
   *
   * @param port The SPI port that the gyro is connected to
   */
  public ADXRS450_Gyro(SPI.Port port) {
    m_spi = new SPI(port);
    m_spi.setClockRate(3000000);
    m_spi.setMSBFirst();
    m_spi.setSampleDataOnRising();
    m_spi.setClockActiveHigh();
    m_spi.setChipSelectActiveLow();

    // Validate the part ID
    if ((readRegister(kPIDRegister) & 0xff00) != 0x5200) {
      m_spi.free();
      m_spi = null;
      DriverStation.reportError("could not find ADXRS450 gyro on SPI port " + port.value,
          false);
      return;
    }

    m_spi.initAccumulator(kSamplePeriod, 0x20000000, 4, 0x0c00000e, 0x04000000, 10, 16,
        true, true);

    calibrate();

    HAL.report(tResourceType.kResourceType_ADXRS450, port.value);
    LiveWindow.addSensor("ADXRS450_Gyro", port.value, this);
  }