Integrated Encoders Not Stopping The Motors

Hi my name is Zach and I am trying to program my robot to turn with integrated encoders, but when I put in the program the encoders do not stop at the specified values. The motors will keep on going indefenitly. Here is my code I am working on.

#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, in2,    FIntakeLS,      sensorReflection)
#pragma config(Sensor, in3,    RIntakeLS,      sensorReflection)
#pragma config(Sensor, in4,    AutoPot,        sensorPotentiometer)
#pragma config(Sensor, in5,    AutoPot2,       sensorPotentiometer)
#pragma config(Sensor, dgtl1,  RUS,            sensorSONAR_mm)
#pragma config(Sensor, dgtl3,  FUS,            sensorSONAR_mm)
#pragma config(Sensor, dgtl5,  BLS,            sensorTouch)
#pragma config(Sensor, dgtl6,  SP,             sensorDigitalOut)
#pragma config(Sensor, I2C_1,  ,               sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Sensor, I2C_2,  ,               sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Sensor, I2C_3,  ,               sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Motor,  port1,           RRArmM,        tmotorVex393, openLoop, encoder, encoderPort, I2C_1, 1000)
#pragma config(Motor,  port2,           LFArmM,        tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port3,           RIntakeM,      tmotorVex393, openLoop)
#pragma config(Motor,  port4,           RRDriveM,      tmotorVex393, openLoop, reversed, encoder, encoderPort, I2C_2, 1000)
#pragma config(Motor,  port5,           RFDriveM,      tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port6,           LIntakeM,      tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port7,           LRDriveM,      tmotorVex393, openLoop, encoder, encoderPort, I2C_3, 1000)
#pragma config(Motor,  port8,           LFDriveM,      tmotorVex393, openLoop)
#pragma config(Motor,  port9,           LRArmM,        tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port10,          RFArmM,        tmotorVex393, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#pragma platform(VEX)

//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)

#include "Vex_Competition_Includes.c"   //Main competition background code...do not modify!

// Sets all left drive motors to *value* and all right drive motors to *value2*
void SetDriveMotors (int value, int value2)
{
	// these are on seperate lines incase some of the motors are flipped
	motor[LFDriveM] = motor[LRDriveM] = value;
	motor[RFDriveM] = motor[RRDriveM] = value2;
}
void pre_auton()
{
	bStopTasksBetweenModes = true;
	nMotorEncoder[RRArmM] = 0; 
	nMotorEncoder[RRDriveM] = 0;
	nMotorEncoder[LRDriveM] = 0;
}

task autonomous()
{
	while(nMotorEncoder[LRDriveM] < 1000)
	while(nMotorEncoder[RRDriveM] > -1000)
	{
		SetDriveMotors(-63, 63);
	}
}

I am not sure what I am doing wrong I have looked at sample programming to try to figure it out but I had no luck. If any one could help me that would be great.
Thank you,
Zach

You have to stop the motors manually in autonomous. Example: motor[insertmotorhere] = 0; when u want it to stop, so insert a stop for all ur motors after that line. (Sry for bad typing I’m on my phone :p)

Edit: check this thread out we had the same problem

https://vexforum.com/t/autonomous-code-not-working-in-competition-template-robotc/24782/1

Oh okay I did not know that I am new at programming and no worries thank you for your help:)

Okay that makes sensce thank you for the extra information

Okay I did stop the motors manually in the program but they keep on doing the samething. Is there something that I am missing that I do not realize?

task autonomous()
{
	nMotorEncoder[LRDriveM] = 0;
	nMotorEncoder[RRDriveM] = 0;
	while(SensorValue[LRDriveM] > -90)
		while(SensorValue[RRDriveM] > -90)
	{
		motor[LFDriveM] = 63;
		motor[LRDriveM] = 63;
		motor[RFDriveM] = 63;
		motor[RRDriveM] = 63;
	}
	motor[LFDriveM] = 0;
	motor[LRDriveM] = 0;
	motor[RFDriveM] = 0;
	motor[RRDriveM] = 0;
}

I’m on my phone as well, so I’m going to slack a bit in giving you useable code…

Your syntax is incorrect. You need to give the condition while(left encoder is off target and right encoder is off target) { doSomething(); }

so your condition should look something like this

while((SensorValue[LRDriveM]  > -90) && SensorValue[RRDriveM] > -90))
{
  // the code that goes inside loop
}

You may also want to take interest in a P controller (from PID)

I changed the code like you showed but I get an error where the while loop is

task autonomous()
{
	nMotorEncoder[LRDriveM] = 0;
	nMotorEncoder[RRDriveM] = 0;
	while((SensorValue[LRDriveM] > -90) && SensorValue[RRDriveM] > -90))
		
	{
		motor[LFDriveM] = 63;
		motor[LRDriveM] = 63;
		motor[RFDriveM] = 63;
		motor[RRDriveM] = 63;
	}
	motor[LFDriveM] = 0;
	motor[LRDriveM] = 0;
	motor[RFDriveM] = 0;
	motor[RRDriveM] = 0;
}

The error says, "Unexpected ‘)’ during parsing, what does that mean? What is a P controller? Sorry I am new at programming.

while(SensorValue[LRDriveM]  > -90 && SensorValue[RRDriveM] > -90)
{
  // the code that goes inside loop
}

It should be something like that. There were unneeded parenthesis in edjubah’s code.

Though, I prefer to use absolute value when working with encoders, because it’s just easier for me, and I won’t have to work with negatives.

while(abs(SensorValue[LRDriveM]  < 90) && abs(SensorValue[RRDriveM] < 90))
{
  // the code that goes inside loop
}

EDIT: I believe the motor sensor names that you must use are the ones in the I2C ports. I haven’t used the nMotorEncoder command myself, but I would suggest that you name the I2C Sensor ports accordingly and use SensorValue[I2C_1] (the I2C_1 will be renamed), rather than SensorValue[LRDriveM]

I find them useful in readability. Personal preference, but you are correct, they are unneeded.

PID is a method for controlling motors given sensor input. It works in such a way that any over drifting doesn’t happen and the motors slow down just before reaching target. P is part of the overall function, and if you’re willing to try it out, Google it. I’m on phone, so it’s a bit difficult for me to supply you a link.

Okay great everything works great now thank you for your guy’s help:)

My mistake. I misread the parenthesis. The thing that was wrong with your code was that you forgot the left parenthesis on the second sensorvalue.