Log in

View Full Version : gyro.getAngle() only outputs 0.0


owltheory
31-01-2014, 23:27
Greetings all,

With two weeks left, I hope everyone's robots are coming along well.

We're in the process of getting our sensors to work in Java, but we seem to have hit a wall when it comes to the gyro. As the title suggests, when we call the getAngle() method, all we consistently get is 0.0. We've tripled checked wiring based on this document, and we've tried multiple analog breakouts and multiple gyro sensors. We know the analog breakout works because we've gotten a rangefinder sensor to work off of the same unit. Based on this, I've concluded it has something to do with the programming. We are using java, the 2014 library (haven't checked for an update yet, but I don't think that would be the issue), and the cRio is running the 2014 image.

We're out of ideas and hoping you can help.

I attached the relevant snippets of code, but I can attach the whole class if necessary. We're planning to use the gyro for direction-sensitive mecanum drive.


Gyro gyro;

public void robotInit()
{
...
gyro = new Gyro(1); // We've checked the port number
...
}

public void teleopInit()
{
gyro.reset();
}

public void teleopPeriodic()
{
System.out.println(gyro.getAngle());
}


Which yields a continuous stream of "0.0\n", regardless of how the gyro is moved.

We appreciate any help you can offer, and let me know if you need more information.

tStano
01-02-2014, 00:57
It doesn't appear you've set the scale of the gyro. I believe you need to call the method gyro.setSensitivity(double voltsPerDegreePerSecond) in order to make things work.

Sensitivity is a constant that should be on your gyro spec sheet and it is measure in volts per degree per second.

mschwab013
01-02-2014, 01:37
The sensitivity has a default setting and shouldn't need need to be specified by the user

The problem could be due to GetAngle() not being capitalized. I hope you figure it out soon. Good luck!

owltheory
01-02-2014, 09:25
I believe you need to call the method gyro.setSensitivity(double voltsPerDegreePerSecond) in order to make things work.

Thanks for the tip, we'll give that a shot. I think we tried it with a bogus value just to see what would happen, but we'll try to find the actual value and give it a shot.

The problem could be due to GetAngle() not being capitalized. I hope you figure it out soon. Good luck!
Thanks for the suggestion, we'll give that shot too, but I didn't see anything in the javadoc about that method being static. Have you capitalized the method in the past?

I also looked over the example that I originally posted an realized that it stores the value in variable before printing it. I wouldn't think that this would make a difference either, but we're running out of options.

Thanks for the help, I'll keep you updated.

Bryan Herbst
01-02-2014, 10:24
Thanks for the suggestion, we'll give that shot too, but I didn't see anything in the javadoc about that method being static. Have you capitalized the method in the past?

You are correct- "getGyro()" should be lowerCamelCase. If you try to use "GetGryo()," NetBeans will tell you that the method doesn't exist.

UpperCamelCase is correct if you are using C++, which it sounds like you are not.

owltheory
01-02-2014, 18:57
Correct; GetGyro() does not work. But I figured it out.

Someone decided we needed to put a gyro.free() in there, and this was the reason it was happening.

Took that out and the gyro began working immediately. Thanks for taking the time to reply.