What is PID? Just need clarification

See title. Can I have a basic explanation of what it is and what it does?

There are basic descriptions of both PID and odometry in the VRC Jargon article in the REC Library, as a starting point.

1 Like

introduction_to_pid_controllers_ed2.pdf (400.2 KB)

3 Likes

PID stands for Proportional, Integral, Derivative. Each of these words refer to a specific portion or a function of the loop. PID loops compare your target point to your actual location, then correct any errors to keep you on track. It repeats this process over and over in order to maintain consistent results. This is an extremely basic explanation, though, and therefore is missing some critical details. I recommend looking into it more if you believe it may be of some use. In VEX competitions, it’s most commonly used during Autonomous/Programming Skills, or for lift systems (such as in last years competition).

From ChatGPT…

PID stands for Proportional-Integral-Derivative, which is a control loop feedback mechanism widely used in control systems for controlling variables such as temperature, position, and speed.

In a PID system, the controller continuously calculates the error between the desired setpoint and the actual process variable, and then it uses three control terms to compute the control output:

  1. Proportional (P) control, which is proportional to the error. The larger the error, the larger the control output.
  2. Integral (I) control, which is proportional to the accumulated error over time. It helps to eliminate steady-state errors.
  3. Derivative (D) control, which is proportional to the rate of change of the error. It helps to dampen the control response and prevent overshoot.

The control output is the sum of these three control terms, which are combined and tuned to achieve the desired control performance. The goal is to keep the process variable as close to the setpoint as possible while minimizing overshoot, oscillation, and other undesirable behaviors.

6 Likes

I am indeed interested. Can you point me to some resources/how to code it?
(V5 C++, no access to Pro, no knowledge of Python)

1 Like

Alright. I am going to make the assumption that you are using line code (which is indeed possible without Pro). I would like to state that I myself have not created a PID loop, however, I have compiled a growing list of resources.

  • PID Beginner’s Guide • Renegade Robotics This link is from another robotics program (not mine), and it summarizes and explains PID quite well.
  • https://georgegillard.com/resources/documents This is a link you see quite often, for a very good reason. It is arguably one of the most helpful resources for PID loops ever, and was even written with VEX robotics in mind. It teaches you more of the theory as opposed to the exact coding syntax. I strongly recommend using this resource- I’ve been studying it in class for the past few days.
  • What is a PID controller? This is another forum post which I found massively helpful if you scroll through the replies.

The forums are an extremely valuable resource, so I have also spent hours scouring them and searching more and more. There is a recent forum about programming in block (if you choose to do so), however, it hasn’t had any exact answers. These resources should help you get the theory down, and over time syntax will eventually be learned. I do stress how the forums can help, as you get to see common errors, and even some of the direct code to get some advice.

Good luck, and happy programming.

1 Like

I used these resources to help me both figure out what a PID is and how to code it. The one from Connor at 1814D is extremely helpful.

Introduction to PID Control for VEX Robotics
Vex PID Control Loop Tutorial
C++ VEXCode V5 Text Tutorials - Autonomous PID and Multitasking

Here’s one resource

Keep in mind that it is still ongoing development.

PID is pretty much universal across programming languages. Here’s a good guide: https://georgegillard.com/resources/documents
introduction_to_pid_controllers_ed2.pdf (400.2 KB)

This is great, I understand it for once, but how would I code it?

If you find out let me know XD

In all seriousness, I’ve been scouring forums and looking at troubleshooted snippets. If I figure anything out, would you like me to let you know?

As someone who judges, I worry about forum posts where students ask for code/coding examples for advanced concepts. Especially in cases where the person asking the question isn’t ready to take a deep dive in learning the fundamentals. When I see links to code libraries, it also raises concerns. You should also look at this link to the Student Centered Policy. There’s a special section on programming, which calls out PID by name.

You don’t need PID control or odometry to have a decent, competitive robot at most competitions. You’re looking for more advanced concepts, hopefully to improve the performance of your already well designed, well built robot. You’d normally try this stuff because your auton is working OK, but you need to get over the last hump to have a truly great robot. I can tell you from experience that poorly implemented PID will make your robot (or product) worse. Is this the best place to spend your time? Only you can know this.

There have been a number of good links, videos, and even a beginner’s guide with math in the posts above. I’ll throw in a way to look at PID is as way to turn your measured error into a control output using math (not perfect term, but simple) that calculates the output based on 1. How far you are away (P) 2. How quickly you’re approaching where you want to be (D) and 3. A sum of your error over time (I). I first ran into these ideas in master’s level control systems courses at university, so these aren’t everyday concepts.

6 Likes

If you understand it, you should be able to code it. The georgegillard reference for PID even gives you psuedocode.
As someone who develops libraries including features like PID and odometry, I agree with everything @coachdoug80516 said. Last time I judged at a competition, there were many teams using odometry and PID, but they were all using pre-made libraries. Even though they understood how those concepts worked, none of them won the Think award. Taking other people’s code will not help you learn or improve as a programmer, and it certainly won’t help you during judging. Even if I were to give you code for PID, you would still have to figure out how to use it, tune constants, figure out your exit conditions, etc.
Please try to code it yourself, then come back with what you have and a description of what is not working about it.

3 Likes

I can give you psuedo-code but not completed code

  1. Calculate the value of sensors
  2. Find the error
  3. Update previous values
  4. Calculate PID values
  5. Do the thing with the PID values
  6. Update total error

Nice list. I’m always interested in how students implement these ideas. Out of curiosity, would you handle integrator windup? Startup jerk/slip? Do you use thread timing or a timer to handle when to output the updated control value? Does your PID have any feed-forward to handle things like an arm that has weight?

2 Likes

Usually I haven’t had any major problems with any of these or had to use them. I know how to prevent integral windup but I’ve never had a reason to use it.

Usually I call a function with a while loop that exits within a certain accuracy of the target. At the end of the loop I use a small timer (usually 10 msec)

There’s not really any reason for feedforward this year for an arm. I do use feedforward as a main part of my flywheel controller that only uses kp and feedforward.

3 Likes

The reason I can’t code it is because I don’t understand functions and pragma stuff.

I mean pragma isn’t really a big part of coding. Its just instructions for your compiler.

Functions are essential to programming and you really should learn how to use them: https://www.learncpp.com/cpp-tutorial/introduction-to-functions/

2 Likes