Hi everyone, I’ve been trying to implement a strafing PID for the past few days and I’ve really hit a stump. Whenever I run this program, the robot 1) moves extremely slowly, 2) overshoots its target, 3) doesn’t work when I input different values as the parameter. Like when I call it in autonomous, I’ve just been running it with an input of 12 (inches), and it never works when I call anything else (like 6 inches). When changing the input for the first time, I got a segfault error (PROS system daemon) and my robot hasn’t been consistent ever since. At least before, the exit point of the PID loop was consistent and so were the paths. Any help would be appreciated. Thanks

Extra info:

I’ve had to multiply the input voltage by 2 because without a scaling factor like that the voltage input would be way too small and the bot would barely move. Also, the exit part of the loop where it checks for the moveError value (just below the integral) seems to have no effect on the stopping point of the bot, as I’ve tried different values ranging from 2 to 500 with all generating the same exact path.

```
double move_kP = 2.0;
double move_kI = 0.0;
double move_kD = 0.0;
double move_Error = 0;
double move_lastError = 0;
double move_intg = 0;
double move_deriv = 0;
double move_totalError =0;
bool atTarget = false;
//use inches for coords
void strafeBot(double distn){
middleencoder.reset();
double enc_val = middleencoder.get();
double dist_to_tick = distn*41.669;
while (!atTarget){
/////////// STRAFE PID
//Proportional
move_Error = dist_to_tick-enc_val;
//Derivative
move_deriv = move_Error-move_lastError;
//Integral
if(abs(move_Error) < 300){
move_totalError += move_Error;
} else {
move_totalError = 0;
}
if(abs(move_Error) <= 2){
atTarget = true;
}
double updated_voltage = move_kP*move_Error + move_kI*move_totalError + move_kD*move_deriv;
// float input_voltage = (updated_dist/dist)*50;
driveF.moveVoltage(-updated_voltage*2);
driveB.moveVoltage(updated_voltage*2);
move_lastError = move_Error;
pros::delay(10);
}
driveF.moveVoltage(0);
driveB.moveVoltage(0);
}
```