Go to Post Here is more data, Because we all love data. - Bochek [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 03-03-2016, 15:01
Maxwell777's Avatar
Maxwell777 Maxwell777 is offline
Is allowed to touch stuff now
AKA: Jackson Gray
FRC #0842 (Falcon Robotics)
Team Role: Programmer
 
Join Date: Aug 2013
Rookie Year: 2014
Location: Phoenix, AZ
Posts: 73
Maxwell777 has a spectacular aura aboutMaxwell777 has a spectacular aura aboutMaxwell777 has a spectacular aura about
Analog Gyro .getAngle() function occasionally giving massive random values

We're working in java, and we're running into an issue with our gyro. Occasionally we get large position spikes from the .getAngle() function. Not sure why. We're using the gyro in between threads, could it be an issue with the .getAngle() not being thread safe? I noticed that we don't (I think) get spikes in the main thread that the roborio runs by default, we only get spikes in other threads. It's been really annoying to debug because it only happens like once a minute or so.

I posted to Programming rather than to Java to see if this was an issue not just specific to java. I also can post code if needed, but for the most part it's fairly straight forward code. I was wondering if anyone has seen anything similar, or knows about things like this.

Thanks for any help in advance.
__________________
But why?
  #2   Spotlight this post!  
Unread 03-03-2016, 15:19
RyanN's Avatar
RyanN RyanN is offline
RyanN
AKA: Ryan Nazaretian
no team
Team Role: Mentor
 
Join Date: Jun 2006
Rookie Year: 2005
Location: Austin, TX
Posts: 1,128
RyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond repute
Re: Analog Gyro .getAngle() function occasionally giving massive random values

Look at your electrical connections. Analog Gyros will give some crazy numbers if they don't have a good connection.

I might be wrong here, but when you have no radial velocity, the analog gyro should output 2.5V, then increase or decrease depending on which way it's rotated.

If the connection isn't good, the controller won't see 2.5V and will give you widely varying numbers like what you're seeing.
__________________
Taking a break from mentoring for a few years. (Is that allowed?!?)

Controls Mentor
@rnazaretian

Previous teams:
Team Fusion, FRC 364
Garnet Squadron, FRC 4901

Last edited by RyanN : 03-03-2016 at 20:42.
  #3   Spotlight this post!  
Unread 03-03-2016, 17:12
Maxwell777's Avatar
Maxwell777 Maxwell777 is offline
Is allowed to touch stuff now
AKA: Jackson Gray
FRC #0842 (Falcon Robotics)
Team Role: Programmer
 
Join Date: Aug 2013
Rookie Year: 2014
Location: Phoenix, AZ
Posts: 73
Maxwell777 has a spectacular aura aboutMaxwell777 has a spectacular aura aboutMaxwell777 has a spectacular aura about
Re: Analog Gyro .getAngle() function occasionally giving massive random values

Quote:
Originally Posted by RyanN View Post
Look at your electrical connections. Analog Gyros will give some crazy numbers if they don't have a good connection.

I might be wrong here, but when you have no radial acceleration, the analog gyro should output 2.5V, then increase or decrease depending on which way it's rotated.

If the connection isn't good, the controller won't see 2.5V and will give you widely varying numbers like what you're seeing.
I've replaced the gyro, and it's still acting the same. Overall, the gyro acts normal, has a bit of drift and measures rotation fairly accurately, but every so often it'll spike, but still return to where it should be. I suspect it's software because (iirc) the gyro feeds us rate, and if we were to get a voltage spike, I doubt we'd read the same value as before the spike.
__________________
But why?
  #4   Spotlight this post!  
Unread 03-03-2016, 20:12
lethc's Avatar
lethc lethc is offline
#gkccurse
AKA: Becker Lethcoe
FRC #1806 (S.W.A.T.)
Team Role: Alumni
 
Join Date: Nov 2012
Rookie Year: 2013
Location: Smithville, MO
Posts: 119
lethc will become famous soon enough
Re: Analog Gyro .getAngle() function occasionally giving massive random values

Quote:
Originally Posted by Maxwell777 View Post
I've replaced the gyro, and it's still acting the same. Overall, the gyro acts normal, has a bit of drift and measures rotation fairly accurately, but every so often it'll spike, but still return to where it should be. I suspect it's software because (iirc) the gyro feeds us rate, and if we were to get a voltage spike, I doubt we'd read the same value as before the spike.
What about the wire going from the RoboRIO to the gyro? Are the connections good on the wire? Is it running next to any power wires for things like motors/batteries?
__________________
2016: Greater Kansas City Regional Finalists, Oklahoma Regional Winners, Tesla Semifinalists, IRI Quarterfinalists
2015: Greater Kansas City Regional Finalists, Oklahoma Regional Winners, Tesla Quarterfinalists, IRI Winners
2014: Central Illinois Regional Quarterfinalists, Greater Kansas City Regional Finalists, Newton Semifinalists
2013: Greater Kansas City Regional Winners, Oklahoma Regional Winners, Galileo Quarterfinalists
  #5   Spotlight this post!  
Unread 03-03-2016, 20:52
Peter Johnson Peter Johnson is offline
WPILib Developer
FRC #0294 (Beach Cities Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Redondo Beach, CA
Posts: 269
Peter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud of
Re: Analog Gyro .getAngle() function occasionally giving massive random values

Quote:
Originally Posted by Maxwell777 View Post
We're working in java, and we're running into an issue with our gyro. Occasionally we get large position spikes from the .getAngle() function. Not sure why. We're using the gyro in between threads, could it be an issue with the .getAngle() not being thread safe? I noticed that we don't (I think) get spikes in the main thread that the roborio runs by default, we only get spikes in other threads. It's been really annoying to debug because it only happens like once a minute or so.
Java AnalogGyro.getAngle() is indeed NOT thread-safe as currently written. If you are calling it from multiple threads with no locking protection you can get corrupted results. I'll get a patch submitted that adds "synchronized" to the various AnalogGyro methods, but in the meantime you can add locking yourself around all calls to AnalogGyro and see if that fixes the problem for you.
__________________
Author of cscore - WPILib CameraServer for 2017+
Author of ntcore - WPILib NetworkTables for 2016+
Creator of RobotPy - Python for FRC

2010 FRC World Champions (294, 67, 177)
2007 FTC World Champions (30, 74, 23)
2001 FRC National Champions (71, 294, 125, 365, 279)
  #6   Spotlight this post!  
Unread 04-03-2016, 00:11
Maxwell777's Avatar
Maxwell777 Maxwell777 is offline
Is allowed to touch stuff now
AKA: Jackson Gray
FRC #0842 (Falcon Robotics)
Team Role: Programmer
 
Join Date: Aug 2013
Rookie Year: 2014
Location: Phoenix, AZ
Posts: 73
Maxwell777 has a spectacular aura aboutMaxwell777 has a spectacular aura aboutMaxwell777 has a spectacular aura about
Re: Analog Gyro .getAngle() function occasionally giving massive random values

Quote:
Originally Posted by Peter Johnson View Post
Java AnalogGyro.getAngle() is indeed NOT thread-safe as currently written. If you are calling it from multiple threads with no locking protection you can get corrupted results. I'll get a patch submitted that adds "synchronized" to the various AnalogGyro methods, but in the meantime you can add locking yourself around all calls to AnalogGyro and see if that fixes the problem for you.
Thanks! I'll try that out. I figured that .getAngle() was thread safe because it returned a primitive type and I didn't think that there was anything too crazy running in the background. Do you know if any other common wpilib stuff that isn't thread safe? I might start going around and locking everything I can lol
__________________
But why?
  #7   Spotlight this post!  
Unread 04-03-2016, 02:56
Peter Johnson Peter Johnson is offline
WPILib Developer
FRC #0294 (Beach Cities Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Redondo Beach, CA
Posts: 269
Peter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud of
Re: Analog Gyro .getAngle() function occasionally giving massive random values

Quote:
Originally Posted by Maxwell777 View Post
Thanks! I'll try that out. I figured that .getAngle() was thread safe because it returned a primitive type and I didn't think that there was anything too crazy running in the background. Do you know if any other common wpilib stuff that isn't thread safe? I might start going around and locking everything I can lol
Generally speaking, it should be thread-safe except for setup-type functions. E.g. it's not safe to call gyro calibrate() in a separate thread from gyro getAngle(). That said, most robot code doesn't use threads outside of PIDController so there are probably other places where locking may have been missed.
__________________
Author of cscore - WPILib CameraServer for 2017+
Author of ntcore - WPILib NetworkTables for 2016+
Creator of RobotPy - Python for FRC

2010 FRC World Champions (294, 67, 177)
2007 FTC World Champions (30, 74, 23)
2001 FRC National Champions (71, 294, 125, 365, 279)
Closed Thread


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 00:17.

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