New Vex Coder problems with PID

Hi! I am a new vex coder (both to c++ and vex) here using PROS and coding a PID controller. I have watched tutorials and read videos all about PID, so I have a general understanding of it, but am not sure how to apply it to a robot. Since the team plans on using odometry to calculate the robot’s position, I give it some parameters and put the PID in a function, changing the left and right velocities/voltage. The goal angle is the angle the robot should be once it gets to the goal, but I was wondering if that is really a good idea to do during movement. I don’t think this is the best option, and just trying to turn the robot so it can get to the goal is probably a better idea. How do I do this? Should I set the goal angle to the angle the robot should take to get to the goal position? Sorry if it is better to just research online, but a friend said vex forums can be a good helper. Thanks!


Assuming it is a holonomic chassis, code looks correct, as long as odometry works as expected.

I would add check for integral windup and move saturation check after the turn angle motor power correction.

Also, for derivative calculation, I would use actual time instead of the assumption that function will get called at regular intervals.

1 Like

Considering the output in your function is forward + turn and forward - turn, I’m going to guess that your robot is an inline chassis. In my experience, I have not used a PID to turn while moving to the point at the same time using an inline. I have always just turned to face the target point first, drive to the point, and then turn again to face the target heading.
However, you can calculate the angle needed to get to the point using the atan2 function in the c++ std library, so it is not needed to have it as another parameter.

One thing you may want to keep in mind with your PID function…

Please correct me if I am wrong about that.

I have made a few functions/PIDs similar to yours, and the reason that this could matter is when you need to exit your PID, your error will never get below zero (and sometimes not even zero). Of course this doesn’t mean that it is impossible to detect when your PID is done, it just means that you might have to detect that differently.

I don’t know if you are aware of this, but I just thought I would let you know. :+1: