Go to Post Oh man... 20% skinnier, 40% dorkier, ... if that's what turns into one of our best mentors, I REALLY need to find a new hobby. ;) - Rich Kressly [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 27-01-2015, 15:07
acastagna acastagna is offline
Registered User
FRC #1493
 
Join Date: Jan 2012
Location: Albany High School
Posts: 34
acastagna is an unknown quantity at this point
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?
Reply With Quote
  #2   Spotlight this post!  
Unread 27-01-2015, 15:09
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,713
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Gyro class issue?

Quote:
Originally Posted by acastagna View Post
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?
Reply With Quote
  #3   Spotlight this post!  
Unread 27-01-2015, 15:10
Ben Wolsieffer Ben Wolsieffer is offline
Dartmouth 2020
AKA: lopsided98
FRC #2084 (Robots by the C)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Manchester, MA (Hanover, NH)
Posts: 520
Ben Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud of
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).
__________________



2016 North Shore District - Semifinalists and Excellence in Engineering Award
2015 Northeastern University District - Semifinalists and Creativity Award
2014 Granite State District - Semifinalists and Innovation in Control Award
2012 Boston Regional - Finalists
Reply With Quote
  #4   Spotlight this post!  
Unread 27-01-2015, 15:21
acastagna acastagna is offline
Registered User
FRC #1493
 
Join Date: Jan 2012
Location: Albany High School
Posts: 34
acastagna is an unknown quantity at this point
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);
}

}
Reply With Quote
  #5   Spotlight this post!  
Unread 27-01-2015, 15:22
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,713
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
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.
Reply With Quote
  #6   Spotlight this post!  
Unread 27-01-2015, 15:23
acastagna acastagna is offline
Registered User
FRC #1493
 
Join Date: Jan 2012
Location: Albany High School
Posts: 34
acastagna is an unknown quantity at this point
Re: Gyro class issue?

I made sure we weren't continuously resetting the gyro
Reply With Quote
  #7   Spotlight this post!  
Unread 27-01-2015, 15:25
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,713
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
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.
Reply With Quote
  #8   Spotlight this post!  
Unread 27-01-2015, 15:33
Ben Wolsieffer Ben Wolsieffer is offline
Dartmouth 2020
AKA: lopsided98
FRC #2084 (Robots by the C)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Manchester, MA (Hanover, NH)
Posts: 520
Ben Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud of
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.
__________________



2016 North Shore District - Semifinalists and Excellence in Engineering Award
2015 Northeastern University District - Semifinalists and Creativity Award
2014 Granite State District - Semifinalists and Innovation in Control Award
2012 Boston Regional - Finalists
Reply With Quote
  #9   Spotlight this post!  
Unread 27-01-2015, 15:34
Ben Wolsieffer Ben Wolsieffer is offline
Dartmouth 2020
AKA: lopsided98
FRC #2084 (Robots by the C)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Manchester, MA (Hanover, NH)
Posts: 520
Ben Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud of
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);
__________________



2016 North Shore District - Semifinalists and Excellence in Engineering Award
2015 Northeastern University District - Semifinalists and Creativity Award
2014 Granite State District - Semifinalists and Innovation in Control Award
2012 Boston Regional - Finalists
Reply With Quote
  #10   Spotlight this post!  
Unread 27-01-2015, 15:50
heuristics heuristics is offline
Registered User
FRC #3634
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Trumbull, CT
Posts: 21
heuristics is on a distinguished road
Re: Gyro class issue?

Did you try calling gyro.initGyro() in your robotInit function before calling reset()?
Reply With Quote
  #11   Spotlight this post!  
Unread 27-01-2015, 15:51
acastagna acastagna is offline
Registered User
FRC #1493
 
Join Date: Jan 2012
Location: Albany High School
Posts: 34
acastagna is an unknown quantity at this point
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.
Reply With Quote
  #12   Spotlight this post!  
Unread 27-01-2015, 16:01
acastagna acastagna is offline
Registered User
FRC #1493
 
Join Date: Jan 2012
Location: Albany High School
Posts: 34
acastagna is an unknown quantity at this point
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);
 }
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 08:36.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi