Quadrature Encoder Values Not Working

We are using ROBOTC version 3.54 and the Cortex. We wrote a very simple function for autonomously driving straight.

Our robot has four wheels, each with a quadrature shaft encoder.

The issue we found was that only one of the three encoders were functioning. When we first ran our program, the left encoders went up to around 250, then froze (and would flicker back and forth up to 10 encoder ticks, even though we were powering the motors to which they were connected on full). One of the right encoders worked (the back one), however, the front one remained stuck at 0. We know this from running it in the ROBOTC debugger.

We cannot seem to get past these values. For the most part, all the encoder values seem to freeze, or just flicker back and forth a couple of ticks (even when we’re turning it fully, multiple times over). Only the port in which the back right motor was initially connected seems to function.

While we could theoretically make our drive straight function work, we also have a turning function, which depends on all four encoders.

Here is our code, however, I do not believe there are any issues with it (and it compiles fine, so there shouldn’t be any syntax errors):

void driveStraight(int distance, int speed) {
	SensorValue[driveRightFront] = 0;
	SensorValue[driveRightBack]  = 0;
	SensorValue[driveLeftFront]  = 0;
	SensorValue[driveLeftBack]   = 0;


	motor[driveRightFront] = speed;
	motor[driveRightBack]  = speed;
	motor[driveLeftFront]  = speed;
	motor[driveLeftBack]   = speed;

	if (distanceTicks > 0) {
		while (SensorValue[driveLeftFront] < distanceTicks);
	else if (distanceTicks < 0) {
		while (SensorValue[driveLeftFront] > distanceTicks);

	motor[driveRightFront] = 0;
	motor[driveRightBack]  = 0;
	motor[driveLeftFront]  = 0;
	motor[driveLeftBack]   = 0;

My team and I have been trying to debug the issue for a while now (at least a couple hours straight, and we have a competition tomorrow). We’ve tried everything we can think of.

We have confirmed all the settings/configuration for the motors/sensors are correct.
We have tried swapping encoders.
We have tried different ports.
We have tried restarting everything, multiple times.
We have tried redownloading firmware.
We have eliminated any kind of cabling issue (we ensured each was connected properly, and we even went through with an encoder one at a time).

If we were to guess, we’d guess that it’s an error with the Cortex.

Any ideas would be appreciated, it’s getting late, and we have a competition first thing tomorrow morning. Thanks.

To clarify, are you using the Shaft Encoders (the dedicated sensor in red plastic), or the newer Integrated Motor Encoder (the ones that connect to the back of the 2-wire motors)?

I noticed that you’re using the same name for both the motors and encoders:

SensorValue**driveRightFront**] = 0;
SensorValue**driveRightBack**]  = 0;
SensorValue**driveLeftFront**]  = 0;
SensorValue**driveLeftBack**]   = 0;


motor**driveRightFront**] = speed;
motor**driveRightBack**]  = speed;
motor**driveLeftFront**]  = speed;
motor**driveLeftBack**]   = speed;

If you’re using the Shaft Encoders, they should have different names in the Motors and Sensors Setup, with the Encoders configured on the DIGITAL Tab.

If you’re using the Integrated Encoders, you should use the nMotorEncoder] command to access their values, instead of the SensorValue] command.