Issue with PID Loop in Vex Code

Recently, I’ve been trying to incorporate a PID loop into my code for smooth and accurate turning. I have been using as a guide to learn what to do, and other various resources on the web and this forum. However, I’ve run into a problem.

Gillard’s guide states that, when first adjusting kp, you should change it until the machine oscillates only a little bit. It does this by using “motor power” in RobotC and other languages similar to it, so that when it overshoots the motor power turns negative and turns the other way, so it oscillates. In Vex Code, it seems like any type of running of the motors requires you to input a directiontype before putting in any other parameters, whether it’s percent or voltage.

Because of this, the robot cannot oscillate once it overshoots, because it only has a directiontype of forward, and not just a motorpower value where direction doesn’t matter. I was wondering if anyone has created a turning PID loop in Vex Code V5 and would care to share what they did, or if someone could guide me towards the correct way to do it? Thanks!

You should still be able to use negative values regardless of direction. It’s how your drive motors work. You have some (or at least we do) in reverse so they go forward during positive inputs but still move backwards even if the specific motor is set to fwd or rev. So it shouldn’t matter if the motor is set to fwd or reverse, it will still take positive and negative values and act accordingly.


Our team uses positive and negative numbers to control the direction. We just use direction::type fwd in all of our drive motor commands. It works for us.