ITG3200 Gyroscope

Code we found on github for this specific gyro: https://github.com/bussell/SparkFun6Dof/blob/master/GyroITG3200.java

Problem: I can’t seem to convert the “16 bit in 2’s complement format” readings from the method “getRotationZ()” in the gyro class to be just degrees.

My team only cares about getting “pitch” rotation which is Z.

Anyone have tips or advice to make a method that will get degrees from the getRotationZ() method?

Email to me if you can help so I can reply faster!

[email protected]

My guess is that it does output in degrees. 16 bit 2s complement is fancy way to say “short” as far as Java is concerned. Presumably 1 degree = 1 on the short, 100 degrees = 100 etc.

Our team used the ITG3200 last season. It was a challenge to work with due to the following:

  • We typically wanted our measurements in degrees and the sensor reports readings in degrees/second (we ended up using a thread to accumulate values reported by the sensor).
  • The sensor did not tend to report zero when sitting idle. This error (bias) needed to be determined at start up while the robot was stationary and then taken into consideration with each reading.

In any case, here is the code we came up with that worked reasonably well for the ITG-3200 when we wanted to detect if the robot was tipping or needed to perform an operation like “make a 90 degree turn”:

As far as the answer to your original question, I think you can use the following to convert the raw 16 bit values to degrees/second (not degrees):

rawAxisValue / 14.375 - axisBias

Where rawAxisValue is the 16 bit signed integer (short) read from the sensor for your z axis and axisBias is the average error reported by the axis when the robot is stationary (when you wish that the sensor reported 0 but discover it does not).

Good luck and I hope that helps.

So I see in your code it says it has a method for getAngle(). Has your team already converted the rate from short to degrees? If so I’ll definitely look into the code of it and will probably use it along with giving your team credit :smiley: thanks.

Yes, the code mentioned does contain both the methods to convert the short into degrees/second and then convert the degrees/second values into degrees (by accumulating over time in a background thread). Just to reiterate, it is not possible to directly convert the short values read from the sensor into degrees as its unit of measurement is degrees/second.

Please feel free to use as much or as little of the code as you want.

As a side note.

We are looking at the BNO055 sensor (Adafruit has a break out board for this one). This chip has an onboard accumulator and it is possible to get degrees directly from the chip instead of accumulating values in a Java thread. It also appears very stable when the robot isn’t moving (almost zero drift when sitting still).

We are still exploring the BNO055 and may not get it worked out for this season. However, if you are interested in this 9 DOF sensor, there is another thread with working sample code provided by “otherguy” at:

http://www.chiefdelphi.com/forums/showthread.php?t=138414&highlight=bno055

Where do I get this “RotationTracker” interface that your code uses? I can’t seem to find it or its called something else in the FRC lib jars?

You should be able to find the RotationTracker source in the same directory as the GyroItg3200 source out at github: