View Full Version : Gyroscope Not Returning Degrees
We're programming a gyroscope on the robot and we're not getting a readout in degrees. The sensitivity is set to 0.007 (as referenced in the manual), the gyro is connected correctly and mounted on the robot. The readout we get is also not consistent because it decreases while stationary and we don't think it's drift. We tested sample code and read the manual (http://wpilib.screenstepslive.com/s/3120/m/7912/l/85772-gyros-to-control-robot-driving-direction) but we're still having a problem.
Joe Ross
09-12-2013, 18:45
the gyro is connected correctly and mounted on the robot.
How is it connected?
The readout we get is also not consistent because it decreases while stationary and we don't think it's drift.
Why don't you think it's drift? How fast is it decreasing? What does it do when you rotate the robot?
We tested sample code and read the manual (http://wpilib.screenstepslive.com/s/3120/m/7912/l/85772-gyros-to-control-robot-driving-direction) but we're still having a problem.
Please post the code you've tried.
How is it connected?
The rate header is connected to the analog breakout on port 1. We followed this guide from AndyMark. (http://files.andymark.com/am-2067/am-2067_wiring.pdf)
Why don't you think it's drift? How fast is it decreasing? What does it do when you rotate the robot?
The values it returns are inconsistent and simply unusuable. We are getting decimal values and after turning the robot a couple of times there would be no significant change. Sometimes it would jump and start increasing in the positive direction and go on indefinitely until the program is stopped. We don't think it's drift (or maybe it might be?) because we don't observe the values decreasing or increasing by a small margin. I will post a screenshot of the values on my next reply.
Please post the code you've tried.
The code we're trying is from Team 2945, found on the fourms. We modified it a little.
package com.github.manitourobotics.gyroscopetesting;
import edu.wpi.first.wpilibj.AnalogChannel;
import edu.wpi.first.wpilibj.Gyro;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.command.Scheduler;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboar d;
public class GyroscopeTesting extends IterativeRobot {
public void robotInit()
{
}
AnalogChannel gyroChannel = new AnalogChannel(1);
Gyro gyro = new Gyro(gyroChannel);
public void teleopInit()
{
gyro.reset();
}
public void teleopPeriodic()
{
gyro.setSensitivity(0.007);
double gyroAngle = gyro.getAngle();
SmartDashboard.putNumber("Gyro angle", gyroAngle);
System.out.println("Gyro Angle: " + gyroAngle);
Scheduler.getInstance().run();
}
}
Joe Ross
09-12-2013, 22:57
What voltage do you measure with a multimeter between the rate pin and ground? It should be approximately 2.5v.
I like the LabVIEW gyro wiring diagram (attached), as it's a little more clear which wire goes where on the analog breakout.
otherguy
10-12-2013, 13:04
I don't have the wpilib source avaialble, so I can't check to see if this should make any difference at all, but is there a reason you're setting the sensitivity repeatedly (in teleop periodic)?
The following is essentially what we've done every year with the gyro:
import edu.wpi.first.wpilibj.Gyro;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboar d;
public class GyroscopeTesting extends IterativeRobot {
Gyro gyro;
public void robotInit() {
gyro = new Gyro(1);
gyro.setSensitivity(0.0070);
gyro.reset();
}
public void teleopInit() {
}
public void teleopPeriodic() {
double gyroAngle = gyro.getAngle();
SmartDashboard.putNumber("Gyro angle", gyroAngle);
System.out.println("Gyro Angle: " + gyroAngle);
}
}
If that doesn't work then I'd start looking at wiring, or where I think Joe was heading with the voltage check on the rate pin, the sensor itself. The only time I've had a problem with the sensor though is when it was run over by the robot, which has happened more than once.
Thanks for the replies! After testing the gyro with a multimeter and on another cRIO unit, we discovered that the analog breakout was faulty and replaced it with another one. The gyro is working and we're getting a responsive and usable readout.
After testing the gyro with a multimeter and on another cRIO unit, we discovered that the analog breakout was faulty and replaced it with another one. The gyro is working and we're getting a responsive and usable readout.
Thank you for reporting the resolution of the problem. That's great forum etiquette. Reps to you.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.