Integrated Motor Encoders

Hello, we were attempting to use the integrated motor encoders on our drive. However, the program doesn’t stop running the motor as if it isn’t working. Sorry if it is something silly. Our programmer is a bit rusty and hasn’t used the IME’s before. Please give us some help or some sample code. Here is our test program:

#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, I2C_1,  leftIEM,        sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Sensor, I2C_2,  ,               sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Motor,  port1,           frontleft,     tmotorVex393HighSpeed_HBridge, openLoop, encoderPort, I2C_1)
#pragma config(Motor,  port2,           frontright,    tmotorVex393HighSpeed_MC29, openLoop, encoderPort, I2C_2)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main
{
	wait1Msec(2000);


//Clear the encoders associated with the left and right motors
	nMotorEncoder[frontleft] = 0;
	nMotorEncoder[frontright] = 0;


//While less than 1000 encoder counts of the right motor
	while(nMotorEncoder[frontright] < 2)
	{
//Move forward at 80 power
		motor[frontleft] = 80;
		motor[frontright] = 80;
	}
}

I don’t know this for sure, but I’ll make my best educated guess at what I think is wrong, but don’t take my word for it. What I think you need to add after saying that if the encoder is less than 2, do this, is that you need to say if the encoder is greater than 2, stop the motors. Also have you tested in the debugger window’s to see how far “2” really is. “2” could be pretty far, you never know.

I’m fairly certain it is 2 ticks. so that should be like the smallest amount.

Okay, so maybe that’s not it. Did you try and see if adding the statement that if the encoder count is above 2, stop the motors?

2 encoder counts is no distance at all (with 4 inch wheels and 1:1 gearing it is 0.04 inches). 1000 counts is approximately 20 inches. Aiden has the right idea, you never stop the motors, try this.

Code:
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, I2C_1,  leftIEM,        sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Sensor, I2C_2,  ,               sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Motor,  port1,           frontleft,     tmotorVex393HighSpeed_HBridge, openLoop, encoderPort, I2C_1)
#pragma config(Motor,  port2,           frontright,    tmotorVex393HighSpeed_MC29, openLoop, encoderPort, I2C_2)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main
{
    wait1Msec(2000);

    //Clear the encoders associated with the left and right motors
    nMotorEncoder[frontleft] = 0;
    nMotorEncoder[frontright] = 0;


    //While less than 1000 encoder counts of the right motor
    while(nMotorEncoder[frontright] < 1000)
	{
        //Move forward at 80 power
	motor[frontleft] = 80;
	motor[frontright] = 80;
	}

    //Stop
    motor[frontleft] = 0;
    motor[frontright] = 0;

}

Ok, so I’ve tried all of this. it is still not working. The light on the encoder is solid green. Any other exceptions?

Ok, after some playing around, i believe I’ve figured it out. I think the 12C ports were switched. However, thank you everyone for the help!