Could someone help me get my PID working for my lift? It currently causes it to “dance” by raising then lowering sporadically. We are using two potentiometers to measure the height of the two sides of the lift. The minimum height is 1030 and the maximum is 2450 on the pots. I feel it is the Gain variables being too high, since I am dealing with error of about 1400 at max.
I’m no expert on anything involving PID or code, but it seems to me that the following bit of code should go after the values read from the joystick controller, otherwise I think you could theoretically run a PID function with the values momentarily outside of your desired limits. But please take what I say with a grain of salt.
This is a different method of PID control in that you are making a percentage adjustment to the motor versus setting motor values.
Log the error against the component values to see what contribution each is doing and graph the line of “dancing” so youc an tune it down.
The integral is a max of 12% contribution which it will get there pretty quick without a wait in the loop. So overshoot and the i will wait a bit to calm down. This seems like a good max, but adjust the max integral value of 1200 as you set the i values to set the contribution to something nice. I think you could go up to 3000 with that i setting of 0.0001 to allow up to 33 motor power coming from the i contribution. (But let your tuning decide the real i value)
The P can only be 2450 away so that will contribute up to 50% to the motor max distance away. Your p value should go up. it should contribute max motor value nearly until you get to the destination.
The D is the change from last time and with a really quick turn around without a wait, you will probably not get more than 20 so that contributes less than 1% to your readings. So it is basically not there with this value.
Make those other changes and see the contribution from each area to the motor value as you approach the target (and then blow right by it). Use your tuning mechanism of choice but most start with P only.
The OP is still setting motor values, it’s just that the drive is calculated in the range +/- 1 first and then multiplied by the maximum control value (110) to move into the range +/-110. It’s the way I always do it as well, it makes the code more portable. All it really means is the the PID constants are smaller than they would have otherwise been.
I did not notice the copy paste error. I got the PID function running today after adding a slight delay. I spent about an hour and a half tuning it using a manual method found on the internet. It has a slight delay on the start up of the motors, but reaches and sustains height fairly well. I also tightened the dead band so it can correct severe leaning caused by movement or our intake. Thanks Guys!
so i had a minute to take a look at the code again, and i came across what could be another cut/paste typo in the motor speed assignment section of the code.
i’m not sure if your motor naming is different from what i’m expecting or if you’re crossing left and right proportional factors on the arm drive.
if i’m reading this correctly, this could cause significant issues with the motors fighting against each other.