PID on Vex Code Making unlimited turns

I just started my pid and when the code takes a turn it keeps turning and won’t stop. Can’t seem to find the problem. Please help.9007K Dr_Cnt1catupultAtounGodMode.iqblocks (34.8 KB)

Can you post a picture of your code? I don’t have IQ blocks but would like to help.

Some things to make sure if is that you are turning the right direction, your constants are properly calibrated, and the gyro sensor is properly attached to your robot (and not upside down)

Whoops I forgot to post That it is solved. I solved it by placing the gyro back in the middle. Also if you want to put it at the end make sure it is attached to the base .

Now it is a different problem, The robot will go straight but won’t go as the certain distance we want it to. Any help is appreciated!!@!!!

are you meaning that when going forwards it is drifting to one side? or it just wont go forwards?

Code pictures

Here’s a video of issue 20220316_191653.mp4 - Google Drive

This isn’t PID, its just a P loop.
Also it seems like your kP is too low.
Increase kP until it drives straight, if it oscillates too much decrease kP

But, on the caption tape web site it says it is a pid??

“Create a my block for driveStraight. We are implementing a simple PID controller (technically, this is only a P controller)”
This is what it says on the website

Could you give an example of a pid?

A PID loop will have a Kp, Ki and Kd (Proportional, integral, and derivative)

1 Like

I would guess your “LeftBase position in degrees” is probably going negative rather than positive as your test (the while part) assumes.


Well After fixing that, the main problem is when the robot has to backwards. When I put a negative output the robot goes the other way but does not stop. I made a backwards p loop but it did not work. Instead it will go little big forward and stop then go little bit forward.

In the video, you have distance = 100 and velocity = -100. Then you say,

while (position < distance) {
  drive at speed velocity - output;

There are a couple of things wrong with this.

  1. If you get off course, you will not turn and correct course, you will just go slower, since both your motors’ speed are decreased. One or other of your motors need to be velocity + output in order for the wheels to have different speeds and the robot to turn.
  2. Your distance is 100 and your wheel position is 0, so your going-backwards-while-loop condition, position < distance, is never true. This seems like it would make the robot just sit there, though.
  3. Your kP is zero anyhow, so you’re multiplying your error by 0 so you’re not correcting for it at all.

How about you copy the code exactly, first. Or you could try to make your own loop, and then you might understand it better.

1 Like

That’s what I did I copied the code from the caption tape site. I am really confused on why it is not working.

It doesn’t match Caution Tape’s code.

Review your code very carefully and see if you can locate the discrepancy.

@Sharky_do There are multiple places in your code where you did not exactly replicate Caution Tape’s code. If you are going to copy code, not just the principle of code, you have to copy it line-for-line, since otherwise you won’t know where to start with fixing things.


More importantly, see the differences and then study the code so you understand why it works and your code didn’t.


Thanks, it now works. I think it was because my monitor brightness was too much and I was not reading correctly, My other monitor had my code on it I should have interchanged it.