Encoder auton help

we just started using integrated encoders for our four drive motors. I have never messed with programming encoders for autonomous, and currently this is what I have as an attempt at a program to drive forward

#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, I2C_1,  frontright,     sensorQuadEncoderOnI2CPort,    , AutoAssign )
#pragma config(Sensor, I2C_2,  frontleft,      sensorNone)
#pragma config(Sensor, I2C_3,  backleft,       sensorNone)
#pragma config(Sensor, I2C_4,  backright,      sensorNone)
#pragma config(Motor,  port1,           BaseLift,      tmotorVex393_HBridge, openLoop)
#pragma config(Motor,  port2,           LeftDrive,     tmotorVex393_MC29, PIDControl, driveLeft, encoderPort, I2C_1)
#pragma config(Motor,  port3,           RightDrive,    tmotorVex393_MC29, PIDControl, reversed, driveRight, encoderPort, I2C_1)
#pragma config(Motor,  port4,           LiftLeft,      tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port5,           LiftRight,     tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port6,           LiftLeftt,     tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port7,           LiftRightt,    tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port8,           FourBar,       tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port9,           FourBarr,      tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port10,          Intake,        tmotorVex393_HBridge, openLoop)
#pragma config(MotorPidSetting,  port2,  50, 10, 1000, 12, 10,   0, 0, 0)
#pragma config(MotorPidSetting,  port3,  50, 10, 1000, 12, 10,   0, 0, 0)


task autonomous()
{
	resetMotorEncoder(RightDrive);
	resetMotorEncoder(LeftDrive);

	while (true)
	{
		moveMotorTarget(LeftDrive, 1000, 100, true);
		moveMotorTarget(RightDrive, 1000, 100, true);

	}
}

could someone tell me why it does not work

thanks in advance

What isn’t working? It looks like you’re running the left drive only (swing turn) until you’ve swung far enough that the encoder has added 1000 to its count. Then you’re stopping that motor (and holding it to enforce the swing turn) and running the right drive to do the same. Presumably it’s working fine, but this isn’t what you want it to do? What do you want it to do? Are you trying to drive straight forward until both encoders have added 1000 to their counts?

I do want it to go straight, how would I go about writing that so it reads both values? Thanks

Oh, and what I didn’t mention is that, since you’ve wrapped this in while(true), your robot is going to repeat this pair of swing turns forever (or field control or something else stops it).

So, first dump the while(true). That’s for things like repeatedly checking a remote control.

If you’re using natural language, you can use

moveStraightForRotations(rotations, rightEncoder, leftEncoder);

If not, you can quickly do something like

set both motors to 100
while(rightEncoderValue < 1000){
wait1Msec(10)
}
set both motors to 0

Now, if you want to make sure it’s going straight instead of just trusting putting in matching values will work, inside that while loop and in place of the wait1Msec(10), you can check the other encoder. If it’s falling behind or moving ahead, adjust one of the motor speeds to compensate.

ok so now I have this

task autonomous()
{
	resetMotorEncoder(RightDrive);
	resetMotorEncoder(LeftDrive);
	
		moveStraightForRotations(1,frontright,frontleft);
		stop();
	
}

I want it to stop after one rotation, but it keeps going infinitely.

thanks again

I would guess it’s not identifying the motors properly. I don’t work in RobotC myself. The API makes it look like stop(); should work, but I haven’t found there what identifies which motors matter. Have you tried

stopMotor(chooseAMotor);

once for each motor that is driving?