For some context, I am using an inertial sensor for my turn PID loop, and I am trying to determine the K values for them. I followed the recommended way of tuning by first setting Ki
and Kd
to 0 and increasing Kp
till you have a steady oscillation, then Increasing Kd
until the oscillation is stopped, then adding Ki
. This method sort of works but the big problem I keep running into after tuning those values on 90 degrees, is when I try small turns like 5 degrees (Which is a turn we need to make for auto) it undershoots (I think cause the Ki
is too low but if I increase it, it will overshoot) and for 180 it overshoots. I also tried using the Ziegler-Nichols method
of tuning but that didn’t work either (Probably cause it’s not meant for drive-base PID tuning). I ended up having 2 sets of K values for different target angles but that doesn’t really work either (They don’t complete all the time). I’m just not sure how I can get 1 set of K values that will work on every target angle Any ideas on what I am doing wrong or if there is a better way to do this? Any help or suggestions are welcome cause I am completely lost.
Here are my current values
if (TurnTarget <= 65 && TurnTarget >= -65) {
TkP = .25; // .25
TkI = .00000025; // .000000005
TkD = .22; // .22
} else {
TkP = .25; // .25
TkI = .00000002; //0.0
TkD = .21; // .21
}
And here is the part of the PID that starts and stops the motors
if ( (TurnPower <= .3 && TurnPower >= -.3) && (TurnError <= 1 && TurnError >= -1) ) {
R1.stop(brake);
L1.stop(brake);
R2.stop(brake);
L2.stop(brake);
startTurnPID = false;
this_thread::yield();
} else {
R1.spin(fwd, TurnPower * -1, volt);
L1.spin(fwd, TurnPower, volt);
R2.spin(fwd, TurnPower * -1, volt);
L2.spin(fwd, TurnPower, volt);
}