When I run this function it will run fine. However, when I run this function with another PID function the program will run the first function but then it stops without doing anything else. Did I do something wrong? Whenever I run simple movement commands without the PID stuff it all works fine. Then when I add the PID back in though the program won’t exit the while loop I have set up and the shaft encoders don’t reset and I’m not sure why Could my integral be too low(the motors are sent a small amount of power after the robot stops moving so I’m guessing the integral is a little low).
Any help/suggestions as to what I could do or fix is appreciated, as well as any improvements
Remember error gets smaller and smaller so it will always be less than target. You are running PID fine but your exit condition doesn’t work. I would suggest
While(abs(error) <20) to ensure you actually are able to exit.
Having the PID loop in a task can help with these issues. Then you have a global variable to turn it on and off and make the error a global variable to be read as well. Going to a small error may mean you just saw it fly by and your PID loop turns off prematurely. This way, you stay on the PID until you
while(PID_on == true)
{
In your auton or driver function play with the PID_on variable and the precision
target= 300;
PID_on = true;
//use what you want here
target_precision = 20;
maxTime = 2500;
//now wait for it.... You could make this into a function.....
clearTimer(T2);
// loop around for you to be within range or if you don't kick out with a timer and move on.
while (abs(PID_error) > target_precision || time1[T2] > maxTime)
{
wait1Msec(20);
}
From what I can see everything is fine but when I try to run this it just goes forward a small distance(no matter how high I set the target) and then It won’t run anything else; then if I take out the forward function and put some others in it won’t run at all
The moveLeftBaseForwards and the moveRightBaseForwards commands are written like this:
Any help as to why this is happening would be helpful. Ever since I started using this PID stuff the program seems to be acting really spotty. Earlier today I ran it and it worked fine then without even closing the compiler I ran it again and it didn’t work at all
Thank you both for responding too