Can't get angles from gyro

We can’t get any angles from our ADXRS450 gyro. It only prints 0 and the turnDegrees function only turn to one side (because the angle is 0). The little connector is between the middle pin and SP0. We have tried 3 roborio’s and 2 gyro’s but still couldn’t manage to make it work. The code is below.

package frc.robot;

import edu.wpi.first.wpilibj.ADXRS450_Gyro;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.SpeedControllerGroup;
import edu.wpi.first.wpilibj.VictorSP;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;

public class Robot extends TimedRobot {
SpeedControllerGroup left = new SpeedControllerGroup(new VictorSP(0), new VictorSP(1));
SpeedControllerGroup right = new SpeedControllerGroup(new VictorSP(2), new VictorSP(3));
private final DifferentialDrive m_robotDrive = new DifferentialDrive(left, right);
private final Joystick m_stick = new Joystick(0);

ADXRS450_Gyro gyro;
double kP = 0.03;
double angle;
boolean turned = true;
int mustTurnDegree = 0;

@Override
public void robotInit() {
gyro = new ADXRS450_Gyro();
gyro.calibrate();
}

@Override
public void autonomousInit() { }

@Override
public void autonomousPeriodic() { }

@Override
public void teleopInit() {
gyro.reset();
turned = true;
}

public void turnDegrees(int degree) {
if(turned)return;
angle = gyro.getAngle() % 360;
if(angle-10 > degree)m_robotDrive.arcadeDrive(0.8, (angle - degree)*kP);
else if(angle+10 < degree)m_robotDrive.arcadeDrive(0.8, (angle + degree)*kP);
else turned = true;
}

@Override
public void teleopPeriodic() {
System.out.println(gyro.getAngle());
m_robotDrive.arcadeDrive(m_stick.getY()*0.8, m_stick.getX()*0.8);

if(m_stick.getRawButton(1))turned = true;
if(m_stick.getPOV() != -1){
  turned = false;
  mustTurnDegree = m_stick.getPOV();
}
if(!turned)turnDegrees(mustTurnDegree);

}

@Override public void testPeriodic() { }
}

When you look at the constructor for the gyro class it has two constructors which one is the one you use and one that requires the SPI port try the one that uses the SPI port http://first.wpi.edu/FRC/roborio/release/docs/java/edu/wpi/first/wpilibj/ADXRS450_Gyro.html

Have you updated to roborio image v13? There was a known issue in the kickoff release causing those gyros to not work.

The image can be found in the ni update 2019.1.0, and using that requires updating to wpilib 2019.2.1.

3 Likes

This sounds like the v12 Rio AutoSPI bug introduced at kick off. Let me know if updating to v13 doesn’t help. We also have a few user guides for all supported programming languages here: wiki.analog.com/first

Edit to add: you will also need to update wpilib to 2019.2.1.

1 Like

The new roborio version solved, thanks!

1 Like