So I made a PID to keep the claws on my robot at all times. The PID works, as when i move the claws they stay equal but all my driver control ability is gone. Can someone check over my code to see if the PID loop interferes with other things? Thanks.
While you might have other problems, you have a while (true) loop within your other while (true) loop, so PID is continuously running, and you never break out of that inner while loop. You could do something along the lines of while (!vexRT[Btn6UXmtr2] == 1 && !vexRT[Btn6DXmtr2]) for your PID loop, so when you press a claw control button PID breaks out. This will, however, not align the sides when you’re pressing a button, so you’ll probably need to have a master and slave system instead of a sync system or somehow change your error when you’re pressing a button instead of setting motor speeds. We use a more bang bang approach to claw sync, which I can send you if you’re interested.
My teams use similar programming to hold the position of a lift. The idea is to have a global variable that holds the desired position. When the driver moves the lift it continues to set that variable equal to the sensor value. When the lift is not being run by the driver then the PID kicks in and evaluates the position of the lift relative to the global variable and holds it there.
You could later add some claw preset locations on your 7 or 8 block of buttons which sets the centerclawright and centerclawleft to specific positions.
Instead of wrapping the PID code in a while loop, make a separate task and start it inside the usercontrol task like below.
If you don’t know what a task is, it essentially runs side by side with another task (in this case, the usercontrol task). The reason why you have to run the PID loop alongside this in a task is because if you don’t, then you will constantly be running the PID in your while loop rather than running your other drive code as well.
Currently, your code in pseudocode is this:
task usercontrol() {
while(true) {
// driver control code
while(true) {
// PID code, and this loop runs forever while not allowing you to access your driver control code in the main part of the first while loop.
}
}
}
Also, remember to always put delays at the end of your tasks/loops, because otherwise you’ll run into some problems with one task always running and never the other.