Gyro Sensor Calibration and Reading

We noticed that our gyro sensor was not producing accurate readings, so we decided to test it in a test document. Here is the code we used; once we put the code in the test document, we tried to recalibrate the sensor by setting the SensorType to none and then back. However, after we did that, in the debug window, the gyro sensor reading on longer shows up.

#pragma config(Sensor, in1, gyro, sensorGyro)
#pragma config(Sensor, dgtl1, right, sensorQuadEncoder)
#pragma config(Sensor, dgtl3, left, sensorQuadEncoder)
#pragma config(Motor, port1, ChassisR, tmotorVex393HighSpeed_HBridge, openLoop)
#pragma config(Motor, port2, ChassisRR, tmotorVex393HighSpeed_MC29, openLoop, reversed)
#pragma config(Motor, port3, ChassisRRR, tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor, port4, ArmL, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, ArmT, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, ClawL, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, ClawR, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port8, ChassisLLL, tmotorVex393HighSpeed_MC29, openLoop, reversed)
#pragma config(Motor, port9, ChassisLL, tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor, port10, ChassisL, tmotorVex393HighSpeed_HBridge, openLoop, reversed)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

task main()
SensorType[gyro] = sensorNone;
SensorType[gyro] = sensorGyro;
while (SensorValue[gyro] <= 900) {
motor[ChassisL] = -127;
motor[ChassisLL] = -127;
motor[ChassisLLL] = -127;
motor[ChassisR] = 127;
motor[ChassisRR] = 127;
motor[ChassisRRR] = 127;

I’m not sure if it would cause it to not produce any values, but I can tell you that it probably won’t turn exactly 90* that way. When you initialize a gyroscope, you should always specify a SensorScale. I think the default value is somewhere around 186, but you’re going to have to figure out the value that produces the most accurate results. I know mine is around 135.

Right after you initialize your gyroscope and calibrate it, you should have something like this:

SensorScale[gyro] = x;

Where x is the value you’ve figured out by testing.

@Mystellianne Thanks for the advice! We have implemented it and it works great.

Two great posts to read. QCC2 seemed to have solved the gyro pretty well. Go look at their code and try some of what they do with the gyro.

They put a scale factor on the Gyro as it works directly out of the box it needs some work.

Based upon some Vamfun work…

QCC2 in action for this code:

I just wanted to clarify one thing here to not confuse the readers:
SensorScale[gyro] is something very different from the 1.511 scaling factor the QCC2 mentions.

The former is using the RobotC built-in infrastructure for the gyro. RobotC firmware does the calibration and integration on its own and the value you write into SensorScale just adjusts to the sensitivity of the particular device you have.

The latter is a (supposedly) fixed voltage scaling done by an amplifier on the gyro board, an implementation detail that shouldn’t really be material to the way you calibrate the gyro. Also, the code QCC2 and @jmmckinney uses basically skips the RobotC firmware support for gyro and implement the whole calibration, deadband and integration on their own, using the port as a generic analog port.