PID attempt (Advice and criticism welcome!)

Hello people’ on the Vex forum,

Recently, I’ve made a PID code (or P-loop!) to allow the robot to drive straight to the mobile goal so it will be accurate and not push the goal away. I wanted to post my code here, so I can get advice to make it smoother, see if there are any bugs, and criticism for the future.

If you need more screenshots of it, just ask!

Thank you!



Screenshot 2022-03-27 2.18.28 PM

My personal opinion is that if you are ready to implement PID, you should migrate towards a text-based programming language.

5 Likes

Well, it’s certainly not a PID loop, and I’m having a hard time really seeing where the P loop is.

You should always write code so that others can read and understand it without needing any inside knowledge. Using variables such as “S1-3” and “L/D” does not help (ie. they look like math expressions), it is also not good practice for the future when you transition to text as both would be invalid in C++.

7 Likes

Well is a great thing that you are trying to make your own pid loop, i recommend u to make a transition for v5 code pro, cause is more easy program difficult things like a control loop.

I dont know if you readed the documentation of pid control.
introduction_to_pid_controllers_ed2.pdf (400.2 KB)

Here is a good documentation that could help u, to make your own loop control, and i reccomend u to learn the basic stuff of c++,

1 Like

I’m not sure why you’re calling it a loop at all; I don’t see any loop.

But you said you wanted suggestions, so here are mine:

  1. Having a repeat 1 loop is the same as not having any loop; get completely rid of those two blocks. Then get rid of the break at the ends of them, too.
  2. If you must name your variables S1-3, T1-2, and L/D, at least put a comment explaining what they do! Please!
  3. Why is there a reference in that if statement to an S1-4 when no such input number exists?
  4. Why do you seem to be trying to have one input mean two things?
  5. Go watch some videos on PID until you understand what you’re trying to do.
5 Likes

Yeah… My brother helped me make some of this so you might see the nerdy bit of it.