Did anything changed with regard to the ADXRS450 gyro since last season? We got an error on the Driver Station saying it cannot find the gyro. Looking at the source code, it looks like it failed to validate the part ID:
// 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;
}
Thinking that the part may be defective, we ordered new gyro and it came yesterday and has the same error.
We still couldn’t figure out why the ADXRS450 gyro is not working. I stripped down an Iterative robot template code and just added the gyro code and it still said “cannot find the gyro on SPI port 0”.
package org.usfirst.frc.team492.robot;
import edu.wpi.first.wpilibj.ADXRS450_Gyro;
import edu.wpi.first.wpilibj.IterativeRobot;
/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the IterativeRobot
* documentation. If you change the name of this class or the package after
* creating this project, you must also update the manifest file in the resource
* directory.
*/
public class Robot extends IterativeRobot {
ADXRS450_Gyro gyro;
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
@Override
public void robotInit() {
gyro = new ADXRS450_Gyro();
}
/**
* This autonomous (along with the chooser code above) shows how to select
* between different autonomous modes using the dashboard. The sendable
* chooser code works with the Java SmartDashboard. If you prefer the
* LabVIEW Dashboard, remove all of the chooser code and uncomment the
* getString line to get the auto name from the text box below the Gyro
*
* You can add additional auto modes by adding additional comparisons to the
* switch structure below with additional strings. If using the
* SendableChooser make sure to add them to the chooser code above as well.
*/
@Override
public void autonomousInit() {
}
/**
* This function is called periodically during autonomous
*/
@Override
public void autonomousPeriodic() {
}
/**
* This function is called periodically during operator control
*/
@Override
public void teleopPeriodic() {
}
/**
* This function is called periodically during test mode
*/
@Override
public void testPeriodic() {
}
}
I do not think it is hardware related because we tried two ADXRS450 gyro’s, one of which completely brand new from AndyMark. We also tried two RoboRIO’s and got the same error. So the only thing left is the RoboRIO image. What is the latest RoboRIO image version? We have v8.
BTW, if we commented out the gyro, everything else work. We have the robot running on mecanum wheels and operating pneumatics. So the imaging process should be fine as well as the Java VM on the RoboRIO. I am running out of ideas on why it doesn’t work.
I even stripped down the ADXRS450_Gyro class code and discovered that the readRegister call below was returning 4 bytes of zeros.
// Validate the part ID
if ((readRegister(kPIDRegister) & 0xff00) != 0x5200) {
m_spi.free();
m_spi = null;
tracer.traceInfo("GyroTest", "Failed to find ADXRS450 gyro on SPI port %d.", port.value);
return;
}
So it was truly not finding the gyro. Is there anything trivial that I missed? Perhaps a jumper or config option that enables/disables SPI in the RoboRIO image? BTW, the jumper on the ADXRS450 gyro was jumped to CS0.
I tested our gyro on another team’s RoboRIO and it worked. So I know now that there is nothing wrong with the gyro. It’s running the same test code. So there is something wrong with our RoboRIO. Since it happens on both of our RoboRIOs, I am assuming it is more likely a configuration issue although I have checked that we have 2017_v8 image and v3.0f firmware version. Everything seems to check out fine. So I am puzzled on why the gyro is not working on our RoboRIOs with the same test code. I would like to check out if there is really hardware issues with the SPI bus on our two RoboRIOs. Any cheap SPI bus analyzer that I can get? Don’t want to get the $300 ones. Anybody has experience on the Bus Pirate sold by Sparkfun? https://www.sparkfun.com/products/12942
If the gyro failed to validate its ID, the SPI port object will be free and become null. Any method calls afterwards such as reset or calibration will cause NullPointerException. That’s how we found out that it did not work. Last season, ADXRS450_Gyro would throw an exception in the constructor if the gyro is “not found”. I actually prefer that because the failure will be pointing at the right place whereas now that it doesn’t throw an exception, the failure will come much later when we first access the gyro. Although the constructor does print an error to the console on not finding the gyro but we have a lot of output to the console too so the message got buried. It took us a while before we realized the NullPointerException was caused by the gyro was not recognized.