Need Help With PID Code

Hello. I’m hoping to learn how to do a PID code for V5. Would anyone mind showing me, please.

There are two main ways to do PID with V5. The easiest way is to use the built in PID in the V5 motors. To do this, just use driveFor() function.

The other way is to create a custom PID controller. The basic idea is to grab the motor position with an encoder, find the error between it and the target you want, and then make that error proportional to your motor’s output. Here is a good video explaining the basic theory.


I would discourage this for anything regarding the chassis because you cannot tune it. Rather, start with a p-loop and work forwards from there. It’s much more simple and yields very similar results. Integrated PID works extremely well for holding the position of an arm or things of that nature but not the chassis.

1 Like

If you PM me, I can try to explain PID control to you along with it’s applications in robotics.

The chassis pid document is kind of not clear, i also have questions:

  1. factory pid does not need feed forward, then what is the default kF. Does kF value controls the power of the chassis?
  2. when we set max power/voltage/speed , what parameters of pid gets changed? does kF change?
  3. We have 3 pids in chassis. which pid does setPosPID change?
  4. are those default pdi parameters usable ( not have to be optimized)? or we always have to tune pid in order to get pid functioning.


Are you telling me you don’t want a heavy robot to awkwardly slam on the breaks when it has a lot of inertia and essentially no kd?

There are a ton of good pid posts at various levels on the forum, and it would be nice if someone curated them at some point because PIDs are one of the most robotics-typical things you get to do in vex. is a good resource in general but also for PIDs, not specific to V5. Then task for you will be relating each step to the equivalent command in V5, but that isn’t too bad.

Just remember that tuning the pid is probably one of the most challenging parts because not many places give you a procedure. There are some algorithms for calculating it based on oscillation periods, but simply put, just make kd and ki=0 until kp gets to its destination quickly with limited oscillation. Then tune in kd, leaving kp alone. Then tune ki if you event wanna take that bumpy road of windup.