SetTunings(...)************************************************************* * This function allows the controller's dynamic performance to be adjusted. * it's called automatically from the constructor, but tunings can also * be adjusted on the fly during normal operation ******************************************************************************/
| 100 | * be adjusted on the fly during normal operation |
| 101 | ******************************************************************************/ |
| 102 | void PID::SetTunings(double Kp, double Ki, double Kd, int POn) |
| 103 | { |
| 104 | if (Kp<0 || Ki<0 || Kd<0) return; |
| 105 | |
| 106 | pOn = POn; |
| 107 | pOnE = POn == P_ON_E; |
| 108 | |
| 109 | dispKp = Kp; dispKi = Ki; dispKd = Kd; |
| 110 | |
| 111 | double SampleTimeInSec = ((double)SampleTime)/1000; |
| 112 | kp = Kp; |
| 113 | ki = Ki * SampleTimeInSec; |
| 114 | kd = Kd / SampleTimeInSec; |
| 115 | |
| 116 | if(controllerDirection ==REVERSE) |
| 117 | { |
| 118 | kp = (0 - kp); |
| 119 | ki = (0 - ki); |
| 120 | kd = (0 - kd); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | /* SetTunings(...)************************************************************* |
| 125 | * Set Tunings using the last-rembered POn setting |
nothing calls this directly
no outgoing calls
no test coverage detected