MCPcopy Create free account
hub / github.com/br3ttb/Arduino-PID-Library / SetTunings

Method SetTunings

PID_v1.cpp:102–122  ·  view source on GitHub ↗

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 ******************************************************************************/

Source from the content-addressed store, hash-verified

100 * be adjusted on the fly during normal operation
101 ******************************************************************************/
102void 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected