pid code for driving robot in straight line


I want my robot to go specific distance in a straight line and I came across this code.

Has anyone tried this code verbatim? Is it reliable? Does it work?

Ya that looks just fine, not too different than what most people here do.

thanks, @tabor473 ! I too tried it just now and seems to work okay.

keep in mind that if you are using IMEs reference the encoder directly (SensorValue[encodername]) one side (typically right) will be reversed and encoder values will go the opposite direction. If you use nMotorEncoder[motorname] the reverse is accounted for.