From edf63276f213367a8ab73356a854c46e21024b27 Mon Sep 17 00:00:00 2001 From: lzbsuzhou <18816292771@163.com> Date: Sat, 1 Sep 2018 23:19:15 +0800 Subject: [PATCH 1/2] change the computing method of PTerm in PID.py and do some changes the test file --- PID.py | 4 +++- __pycache__/PID.cpython-36.pyc | Bin 0 -> 3483 bytes test_pid.py | 9 +++++---- 3 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 __pycache__/PID.cpython-36.pyc diff --git a/PID.py b/PID.py index 6eef0f7..0cdca77 100644 --- a/PID.py +++ b/PID.py @@ -79,6 +79,8 @@ def update(self, feedback_value): delta_time = self.current_time - self.last_time delta_error = error - self.last_error + self.PTerm = self.Kp * error + if (delta_time >= self.sample_time): self.PTerm = self.Kp * error self.ITerm += error * delta_time @@ -96,7 +98,7 @@ def update(self, feedback_value): self.last_time = self.current_time self.last_error = error - self.output = self.PTerm + (self.Ki * self.ITerm) + (self.Kd * self.DTerm) + self.output = self.PTerm + (self.Ki * self.ITerm) + (self.Kd * self.DTerm) def setKp(self, proportional_gain): """Determines how aggressively the PID reacts to the current error with setting Proportional Gain""" diff --git a/__pycache__/PID.cpython-36.pyc b/__pycache__/PID.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a97f9196a0aa3c10a22ee51018e175b5ab80feb8 GIT binary patch literal 3483 zcmb_fPjB4D6(_me6-BM&*p{6%P1*^NqFU5hS#8h)i@Gst0fC@I5NZQKwrU89Gs_)` zOR~eE6s=e2!9ErF0_i!I9(w7w$QQ_gKu$RX{Q^Do)ZZKKawWq7d8>*mWk@7TEQ!@k^N=3wC&+$6$izF;h!Eaz*<*)IZn0}?13sD?-QUL#qiGFogU@w0xNBgWlVv&vU*Roi?oPKJ zk<^88m?)d%W$m&B3scUbOpHb{l2Es3Of*N{e|P|6d5?uY%w(#o_TdwuCRKZ{o_5XT z8}kUIGBsSquE3yG_gtpD%meta;#CI@i+g*vT8AFSS~WnBTB-}MgHgN&0MpdQu{$j? z(R7uJV+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bojE@AtKwf1s-iQpQEC`#)R2eqjIr literal 0 HcmV?d00001 diff --git a/test_pid.py b/test_pid.py index 761f261..565c870 100644 --- a/test_pid.py +++ b/test_pid.py @@ -50,7 +50,7 @@ def test_pid(P = 0.2, I = 0.0, D= 0.0, L=100): pid = PID.PID(P, I, D) pid.SetPoint=0.0 - pid.setSampleTime(0.01) + pid.setSampleTime(0.1) END = L feedback = 0 @@ -66,7 +66,7 @@ def test_pid(P = 0.2, I = 0.0, D= 0.0, L=100): feedback += (output - (1/i)) if i>9: pid.SetPoint = 1 - time.sleep(0.02) + time.sleep(0.01) feedback_list.append(feedback) setpoint_list.append(pid.SetPoint) @@ -90,5 +90,6 @@ def test_pid(P = 0.2, I = 0.0, D= 0.0, L=100): plt.show() if __name__ == "__main__": - test_pid(1.2, 1, 0.001, L=50) -# test_pid(0.8, L=50) \ No newline at end of file + test_pid(0.5, 0.1, 0.001, L=200) + test_pid(1, 0.1, 0.001, L=200) + test_pid(1, 0.5, 0.001, L=200) \ No newline at end of file From 65b2956d79ff67bf6fae45ff59fc79d7950a64e0 Mon Sep 17 00:00:00 2001 From: lzbsuzhou <18816292771@163.com> Date: Sat, 1 Sep 2018 23:24:55 +0800 Subject: [PATCH 2/2] change the computing method of PTerm in PID.py and do some changes the test file --- PID.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PID.py b/PID.py index 0cdca77..5ec4bdf 100644 --- a/PID.py +++ b/PID.py @@ -82,7 +82,7 @@ def update(self, feedback_value): self.PTerm = self.Kp * error if (delta_time >= self.sample_time): - self.PTerm = self.Kp * error + # self.PTerm = self.Kp * error self.ITerm += error * delta_time if (self.ITerm < -self.windup_guard):