My PID isn't working VEXcode PRO V5

image
image
image
image

Hello everyone!
When I start a timed-run my robot starting to accelerate smoothly and then it doesn’t stop. It just continues until the timed-run(15s) sequence finish. What can cause the problem?

I see an extra else statement in the part where you edit the integral value. It might not be the core of the problem though

Thanks for your reply :blush: ,
But actually, I put that part in both photos to get people to understand the code :sweat_smile:

You set the preverror to 0 near the end of the code, it might make derivative too big since every time your basically adding the error to it as preverror is 0

Yes, it is a big mistake thank you but when I deleted them nothing happened :confused: The problem still goes…

Do you want to try outputting the value of distSpeed - diffSpeed? maybe it’s somehow always positive so it doesn’t stop

1 Like

I might be blind, which is very possible but I don’t see a brake from the while loop, making go on to infinity. Add a break like:
if (error<10) (or whatever value)
{
break;
}
Near the end of your code in the while loop

Edit: typo

image
image
Like this right ?

When I start timed-run, I see 0.000 on the brain.

image
Like this ?

When I do this, just right motor turns slowly.

I was meaning to print the motor power in the while loop to see how it changes. Maybe one of them is too big and makes the power always positive

image
image

I think I’m printing values wrong. Again there is a bunch of zeros on my brain and they are not changing :confused:

So copy your Brain.Screen.Print into the PID loop right after the right / left motor Power. This will print the motor value every time it updates so it can be easier to find the issue.

If they’re all positive, try printing distSpeed and diffSpeed and find the issue

2 Likes

Your driveStraight function has a while loop that appears to have no exit condition.

No, you would have to have an if statement, with a condition. Currently, your code will break after the left motor and right motors spin for a very small amount of time. To properly use a break you need an if statement. eg.

if (condition) the condition could be anything like error == 0, or error < 10.
{
break; this basically just gets the code out of the while loop.
}

1 Like

image
Like this ?

I think I found the problem. My leftEncoder and rightEncoder variables was out of the driveStraight function. So I wrote them in to the function. Right now Yes! Our robot tries to set error to 0. But error is changing constantly between 60.000 , -60.000. Forward, backward, fordward, bacward. I think I need to configure my kP, kI and kD.

Yes, just like that. Everything else seems pretty good.

1 Like

Dear friends, thank you for all your replies. The problem has solved. The big step to the solution was outputting the distError numbers on brain. The mistakes were exit condition and Encoder variables. Have a good day :blush:

2 Likes