SHARE
TWEET

Untitled

a guest Mar 26th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import math
  2. import matplotlib.pyplot as plt
  3. def Nalej(tp, a, beta, setpoint, no_of_steps):
  4.         Kp = 5
  5.         Td = 0.2
  6.         Ti = 0.2
  7.  
  8.         data = []
  9.         data_to_second = []
  10.         result = 10 #h0 - poziom przy starcie regulacji
  11.         errorList = []
  12.         for i in range(no_of_steps):
  13.             error = setpoint - result
  14.             errorList.append(error)
  15.             sumOfError = sum(errorList)
  16.             result = tp * ((1 / a) * PID(Kp, Td, Ti, 0.7, error, sumOfError, errorList[-1]) - (beta / a) * math.sqrt(result)) + result
  17.             data.append(result)
  18.  
  19.         result = 0;
  20.         for i in range(no_of_steps):
  21.             error = setpoint - result
  22.             errorList.append(error)
  23.             sumOfError = sum(errorList)
  24.             result = tp * ((1 / a) * PID(0.5*Kp, 0.5*Td, 0.5*Ti, 0.7, error, sumOfError, errorList[-1]) - (beta / a) * math.sqrt(result)) + result
  25.             data_to_second.append(result)
  26.  
  27.         plt.plot(data,label='Nastawy')
  28.        # plt.plot(data_to_second,label='Nastawy/2')
  29.         plt.legend(loc='best')
  30.         plt.title('Nastawy: P: %s | I: %s | D: %s ' % (Kp,Td,Ti))
  31.         plt.axhline(setpoint,linewidth=0.5,color='r')
  32.         plt.show()
  33.  
  34. def PID(kp, td, ti, tp, error,errorSum, prevError):
  35.     signal = kp * ((error + (tp / ti) * errorSum + (td/ti) * (error - prevError)))
  36.     return signal * 0.1
  37.  
  38. Nalej(0.2, 2, 0.25, 1, 100)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top