HELP: Auton Code Revision

So, I’m using quadrature encoders for my starstruck bot. I’m new to robotC, so I don’t know which functions I need to be using to control the encoders. The function, “forwardDistance”, is essentially meant to have the robot move a set amount of inches as inputted in the function by converting it to encoder ticks and then moving the motors for that much time. Below is what I have after staring at documentation for a while and googling how many encoder ticks 393’s have per rotation, and it seems correct. However, this code doesn’t work. The motors just run infinitely.

Please note before you read, most of the comments are for my teammates, who don’t know robotC.

#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, I2C_1,  hdleft,         sensorQuadEncoderOnI2CPort,    , AutoAssign )
#pragma config(Sensor, I2C_2,  hdright,        sensorQuadEncoderOnI2CPort,    , AutoAssign )
#pragma config(Sensor, I2C_3,  hdmid,          sensorQuadEncoderOnI2CPort,    , AutoAssign )
#pragma config(Motor,  port3,           hdmid,         tmotorVex393_MC29, PIDControl, encoderPort, I2C_3)
#pragma config(Motor,  port4,           hdleft,        tmotorVex393_MC29, PIDControl, driveLeft, encoderPort, I2C_1)
#pragma config(Motor,  port5,           hdright,       tmotorVex393_MC29, PIDControl, reversed, driveRight, encoderPort, I2C_2)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

// begin math functions

// begin robot movement functions
void resetEncoders() {
void forwardDistance(int tenthInch, int speed)  // never use 127 motor power, or pid won't be able to adjust

	//convert "tenthInch" to encoder ticks
	int goal = (61 * tenthInch) /10;
	//high torque motor ticks per rotation: 627, high speed: 392, turbo speed: 261 all for VEX 393 motors
	//circumference of 3.25" omni wheels = 10.20500"
	//10.20500" traveled per rotation, which also means 102 tenths of an inch traveled per rotation
	//627 ticks per rotation
	//61 ticks per inch

	moveMotorTarget(hdleft, goal, speed, true); // move hdleft motor until "goal" ticks, at "speed" speed, and coast to a stop (true part)
	moveMotorTarget(hdright, goal, speed, true);

	while(getMotorTargetCompleted(hdleft) == false || getMotorTargetCompleted(hdright) == false)
	} //idle loop to wait for moveMotorTarget to complete


/*NOTES FOR OTHER TEAMMATES: for the Forward and Backward functions, distance is in tenths of an inch.
If you want to go, say, 10.5 inches, you need to type in 105, because it is in tenths of an inch.
Also, never put in 127 as the speed because PID algorithms won't be able to adjust above that. Use 120 as a maximum and
try to keep it at 100 unless the speed is super necessary. */
task main()
//go forward for 12 inches at 100 power (highest power is 127)
forwardDistance(120, 100);
/* reset encoders to 0. (I think I need to reset the encoders, but I am not 100% sure with the
move motor target function, since it might already reset them) */


I tried your code and it worked on my system, a few things to check.

  1. make sure that the encoders are working by looking at the motors debug window when the program is running.
  2. make sure that you have not reversed any motors by connecting red to black wires anywhere, this would make the motor control and encoder counting to also be reversed.
  3. make sure you have the correct IME port assigned to the motor.
  4. use a recent version of ROBOTC, V4.54 or V4.55.