Log in

View Full Version : Gyro class issue?


acastagna
27-01-2015, 15:07
I'm using an Analog Devices ADW22307 gyro and haven't been able to get a reading out of it using the gyro class.

We are programming in Java and the code is:

Gyro gyro = new Gryro(1);
...
gyro1.reset();
angle1 = gyro.getAngle()


When we try to print the value to the SmartDash we get nothing. We tried several other gyros with no luck. We tried defining an analog input channel to directly get the voltage output from the gyro, and that works. The voltage is 2.45V when the gyro is stationary as expected, and then we see it increase or decrease if rotated the gyro, so it seems the gyro itself is working.

Has anyone else run into this problem?

notmattlythgoe
27-01-2015, 15:09
I'm using an Analog Devices ADW22307 gyro and haven't been able to get a reading out of it using the gyro class.

We are programming in Java and the code is:

Gyro gyro = new Gryro(1);
...
gyro1.reset();
angle1 = gyro.getAngle()


When we try to print the value to the SmartDash we get nothing. We tried several other gyros with no luck. We tried defining an analog input channel to directly get the voltage output from the gyro, and that works. The voltage is 2.45V when the gyro is stationary as expected, and then we see it increase or decrease if rotated the gyro, so it seems the gyro itself is working.

Has anyone else run into this problem?

Can we see a larger portion of your code?

Ben Wolsieffer
27-01-2015, 15:10
Are you resetting the gyro each time you get the angle? You only should call reset() when you want to reset the angle back to 0 (ie. after it has drifted a lot).

acastagna
27-01-2015, 15:21
Here it is. We can plug the gyro into AI port 1 and get voltage readings. When we plug it into port 0, we get nothing. We switching ports, eliminating the analog channel, and using other gyros.

import edu.wpi.first.wpilibj.smartdashboard.*;
import edu.wpi.first.wpilibj.Gyro
import edu.wpi.first.wpilibj.AnalogInput

public class Robot extends IterativeRobot
{

Gyro gyro = new gyro(1);
AnalogInput ai1 = new AnalogInput(0);
double angle1, voltage1;

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

public void autnoomousPeriodic()
{
}

public void teleopPeriodic()
{
angle1 = gyro.getAngle();
voltage1 = ai1.getAverageVoltage();
SmartDashboard.putString("DB/String 6","gyro = "+angle1);
SmartDashboard.putString("DB/String y","ai1 = "+voltage1);
}

}

notmattlythgoe
27-01-2015, 15:22
You need to set the sensitivity of the gyro using setSensitivity() so it knows how to convert from voltage to angle. This needs to be in volts/degree/second, this number can usually be found on the gyro's datasheet.

It is defaulting to 0, that is why you are getting a voltage but no angle.

acastagna
27-01-2015, 15:23
I made sure we weren't continuously resetting the gyro

notmattlythgoe
27-01-2015, 15:25
Also, if you can use the code tags when posting in the forums it will make your code easier to read. To do this place [code] at the beginning of the code and /code in the brackets at the end.

Ben Wolsieffer
27-01-2015, 15:33
Is your gyro connected to input 0 or 1? You created your gyro on channel 1 but your analog input is on channel 0.

Ben Wolsieffer
27-01-2015, 15:34
Try replacing the first two lines of the class body with this:
AnalogInput ai1 = new AnalogInput(0);
Gyro gyro = new Gyro(ai1);

heuristics
27-01-2015, 15:50
Did you try calling gyro.initGyro() in your robotInit function before calling reset()?

acastagna
27-01-2015, 15:51
I added gyro.setSensitivity(0.007) in robotInit

and I also tried defining the gyro as:

AnalogInput ai1 = new AnalogInput(0);
Gyro gyro = new Gyro(ai1);


Still nothing.

acastagna
27-01-2015, 16:01
Here's the code now. Still nothing. If I uncomment out the ai1.getVoltage I still get what looks like the proper voltage.



import edu.wpi.first.wpilibj.smartdashboard.*;
import edu.wpi.first.wpilibj.Gyro
import edu.wpi.first.wpilibj.AnalogInput

public class Robot extends IterativeRobot
{

AnalogInput ai1 = new AnalogInput(0);
Gyro gyro = new gyro(ai1);

double angle1, voltage1;

public void robotInit()
{
gyro.initGyro();
gyro.reset();
gyro.setSensitivity(0.007);
}

public void autnoomousPeriodic()
{
}

public void teleopPeriodic()
{
angle1 = gyro.getAngle();
// voltage1 = ai1.getAverageVoltage();
SmartDashboard.putString("DB/String 6","gyro = "+angle1);
}