Help with PID controllers

Hello everyone!

I am Luke - one of the team members on 323X. We are a first year team, and no one on our team has even seen vex prior to this season. I say that only to emphasize how much of noobs we are. I just started coding a couple weeks ago, and I feel like I’ve been picking it up pretty well.

At the last few meetings, I’ve been talking with the rest of my team about what we want to do before the world championship. We all agreed that we need some sort of straightening code. We also agreed that we need to have some sort of code that will keep the lift from falling, even when there is pressure applied to it. I have been reading some threads and seen that people have used PID controllers for those two things as well as several other things that we would like to do.

I have a vague understanding of what PID controllers do, but I have no clue how to use them. What I’m looking for is an in depth explanation of what they do, how they work, what they can be used for, and how to correctly use them.

We are using RobotC and the Vex Cortex, so please only reply with answers regarding that. We have potentiometers and integrated motor encoders. Thanks in advance for your help!

P.S. I did write code that did what we wanted it to…sorta. It didn’t work as well as the code that teams like 323Z (who I know for a fact are using PID controllers) have written. If you would like, please comment and I can include both functions that I wrote.

This tutorial does a really good job explaining how a PID controller works. If you’re still confused, just keep looking at explanations online until you understand.

Can you post your code? Generically PID is easy, finding bugs difficult without code, and tuning can only be done by you.

You can try starting just with proportional and work up form there. The proportional is fairly easy to understand and gets you there fairly well.

Proportional code will essentially say how far away am I and apply a signal to the motor relative to that error. So as you get close, it has nothing left. The trouble is you can under or over-shoot. Look at the graphs in the later posts fo the first link.

Start here:
https://vexforum.com/t/simple-p-controller-for-arm-position/23699/1

Then move on to here for PID:
https://vexforum.com/t/a-pid-controller-in-robotc/20105/1

To clarify, the code I wrote does not use PID controllers, but I know they are what I need.

From my experience I would say just make a PID controller (follow a template from the thread I’ll post below) and the understanding will come with that. I tried learning PID for about 3 years (not constantly, just reading about it every now and then) and I had no success. I understood the concept of P and error and how the error used to figure out the motor speed value, but nothing more than that.

Follow the tutorial from this thread and you will understand it. It basically spells it out for you and helped me tremendously. George from Free Range wrote it and the way he wrote it is excellent. He doesn’t over complicate any of it and it is easy to understand.

My suggestion is follow the template from the tutorial and the understanding will come as you make the program. Don’t destroy your brain trying to understand PID while just reading about it (I made this mistake), make one for yourself and give it a shot.

I also learned how to do it with George’s tutorial. Here is the link since the one on the first page of that thread is broken.