|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Gyro class issue?
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? |
|
#2
|
|||||
|
|||||
|
Re: Gyro class issue?
Quote:
|
|
#3
|
|||
|
|||
|
Re: Gyro class issue?
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); } } |
|
#4
|
|||||
|
|||||
|
Re: Gyro class issue?
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. |
|
#5
|
|||
|
|||
|
Re: Gyro class issue?
I made sure we weren't continuously resetting the gyro
|
|
#6
|
|||||
|
|||||
|
Re: Gyro class issue?
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.
|
|
#7
|
|||
|
|||
|
Re: Gyro class issue?
Is your gyro connected to input 0 or 1? You created your gyro on channel 1 but your analog input is on channel 0.
|
|
#8
|
|||
|
|||
|
Re: Gyro class issue?
Try replacing the first two lines of the class body with this:
Code:
AnalogInput ai1 = new AnalogInput(0); Gyro gyro = new Gyro(ai1); |
|
#9
|
|||
|
|||
|
Re: Gyro class issue?
Did you try calling gyro.initGyro() in your robotInit function before calling reset()?
|
|
#10
|
|||
|
|||
|
Re: Gyro class issue?
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. |
|
#11
|
|||
|
|||
|
Re: Gyro class issue?
Here's the code now. Still nothing. If I uncomment out the ai1.getVoltage I still get what looks like the proper voltage.
Code:
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);
}
|
|
#12
|
|||
|
|||
|
Re: Gyro class issue?
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).
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|