PID control and how to stop the motor

Hello, I’m a new user of VEX robotics. Saturday, I have a tournament on Saturday,
My base does with encoder does not go straight during the autonomous mode, so I used the PID control from this site. http://www.robotc.net/wikiarchive/Tutorials/Arduino_Projects/Mobile_Robotics/VEX/Using_encoders_to_drive_straight,
However, the motor does not stop; it infinitely goes forward; I cannot figure out.
This is my motor setting

I try to change some code, and the code now looks like this. but it also does not work.

void forwardStraight(int distance, int masterPower)
{
int tickGoal = 6.94*distance; // circumference_cm * distance

//This will count up the total encoder ticks despite the fact that the encoders are constantly reset.
//int totalTicks = 0;

//Initialise slavePower as masterPower - 5 so we don’t get huge error for the first few iterations. The
//-5 value is based off a rough guess of how much the motors are different, which prevents the robot from
//veering off course at the start of the function.
int slavePower = masterPower - 10;

int error = 0;

int kp = 3;

SensorValue[LMIDEN] = 0;
SensorValue[RMIDEN] = 0;

//Monitor ‘totalTicks’, instead of the values of the encoders which are constantly reset.
while(abs(SensorValue[LMIDEN])<tickGoal&&abs(SensorValue[RMIDEN])<tickGoal)
{
//Proportional algorithm to keep the robot going straight.
motor[LMID] = masterPower;
motor[RMID] = -slavePower;

error = SensorValue[LMIDEN] - SensorValue[RMIDEN];

slavePower += error / kp;


wait1Msec(100);

//Add this iteration's encoder values to totalTicks.

// totalTicks+= SensorValue[LMIDEN];
}
motor[LMID] = 0; // Stop the loop once the encoders have counted up the correct number of encoder ticks.
motor[RMID] = 0;
}

task autonomous(){

forwardStraight(190,110)

}

I am so desperately need a help :persevere::joy:

Add a print statement inside your control loop. This should make it clear if the loop is exiting or not.

I never see you actually update masterpower.

Also it seems that a lot of your comments refer to code that doesn’t exist anymore.

Thank you for your reply!.. I am so glad by your comment!
However, my team does not use LCD display, and I do not know how to implement the LCD display.
Also, I do not understand the reason need to update the value of the masterPower… Does the PID control require updating the masterMotor’s power?

If you never stop the master motor, the slave motor will just keep following it indefinitely. So you got code that makes it go straight. You need to tell it to stop at some point.