Coding a Basic PID Loop

I am trying to code a basic PID loop for my teams robot next year. We want to use a PID loop for controlling the drivetrain with the optical shaft encoders. I have coded something on replit but I don’t think it will work in reality (obviously changing the syntax a little). Unfortunately, I do not have a robot to test this on. Will this work? Is there anything I should change?
Click here for the replit link

1 Like

VEXCode? Pros? Robotc? Robotmesh? Please tell us what software you’re using and if you’re VEX IQ, V4, or V5.

this is what i used to make my first pid loop

it seems like you have 3 cases for if you overshoot your target, are below your target, or on your target. There should only be one case. The PID loop is something that just plugs and chugs, no special cases necessary. for a simple move forward or move backwards case.

I can’t really make sense of the code, so I’ll show you some sudo code.

i hope that helps. Ask if you need anymore help


I will be using VEXcode (C++) for the V5 system

There’s a lot of coding tutorials me and other people have made that are on the wiki :slight_smile:

1 Like

Here are two topics in which I helped @JD6 and @Eclipse7157A work through @Connor PID code tutorial. I don’t have much time now for interactive guidance, but I’m sure you’ll have the same questions as they did.

Just be sure to start with @Conners PID tutorial.