PID Stops After Overshoot

I’m trying to tune pid, but with the code I have, my robot just stops after it overshoots rather than trying to reverse and come back to the position it stops there. I’m not sure why this is happening. Any help would be appreciated.

https://github.com/Trishul-creator/Autonomous-Project-32630B (my code)

Make sure that your github repository is public, since when I click the link it takes me to a 404 page, which means that you either included the wrong link or your repository is private. You can make a repository public by following the instructions at Setting repository visibility - GitHub Docs.

I got it to start oscilating, now what do I do ?

Still need you to make the repository, public. We are getting a 404 error.

It should work now I think.

You need to turn up kD until it stops oscillating. Documents is helpful for tuning PID. I would also recommend making a benchmark for your PID (e.g.: turn 12.5°, turn 45°, turn 90°, etc and measure time for each turn) and set goals for the time of each movement (e.g.: under 1 second for turns up to 180°).

I got that, but now my angular movement is only correcting at the end when my robot reaches the position. I think my code should be correct now

It also gets inaccurate because it drives diagonal and then corrects, while I want it to go straight all the way. help would be highly appreciated

I think this is the problem you’re having: when the robot is really far away from the target at the beginning, the error is really big, so the PID returns really large values for the output power, commanding both sides of the drivetrain to drive at much more than one hundred percent. This means that when it tries to correct its heading, the values change for each side of the drivetrain, but they still remain at over hundred percent, so the robot still only moves forward at full speed. When the robot is near the end, it slows down enough so that the heading correction can take place because both sides of the drivetrain are moving at less than one hundred percent.

The way I fixed this in my code is by checking if the total output power is greater then a hundred percent, and making the forward output something like 100 - heading output if so.

2 Likes

Yeah, I realized that my robot doesn’t even completely go to 100 % velocity at 100 %, so 100 % and 90 % both stay the same, so my robot isn’t turning while it’s going. Thank you so much for the response !

2 Likes