|
Re: Analog Gyro .getAngle() function occasionally giving massive random values
Quote:
Originally Posted by Maxwell777
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)
|