- Intelligent IoT Projects in 7 Days
- Agus Kurniawan
- 171字
- 2021-07-02 18:25:53
How it works
First, we define our PID parameters:
P = 1.4
I = 1
D = 0.001
pid = PID.PID(P, I, D)
pid.SetPoint = 0.0
pid.setSampleTime(0.01)
total_sampling = 100
feedback = 0
feedback_list = []
time_list = []
setpoint_list = []
After that, we compute the PID value during sampling. In this case, we set the desired output values as follows:
- Output 1 for sampling from 20 to 60
- Output 0.5 for sampling from 60 to 80
- Output 1.3 for sampling more than 80
for i in range(1, total_sampling):
pid.update(feedback)
output = pid.output
if pid.SetPoint > 0:
feedback += (output - (1 / i))
if 20 < i < 60:
pid.SetPoint = 1
if 60 <= i < 80:
pid.SetPoint = 0.5
if i >= 80:
pid.SetPoint = 1.3
time.sleep(0.02)
feedback_list.append(feedback)
setpoint_list.append(pid.SetPoint)
time_list.append(i)
The last step is to generate a report and save it into a file called result.png:
time_sm = np.array(time_list)
time_smooth = np.linspace(time_sm.min(), time_sm.max(), 300)
feedback_smooth = spline(time_list, feedback_list, time_smooth)
fig1 = plt.gcf()
fig1.subplots_adjust(bottom=0.15)
plt.plot(time_smooth, feedback_smooth, color='red')
plt.plot(time_list, setpoint_list, color='blue')
plt.xlim((0, total_sampling))
plt.ylim((min(feedback_list) - 0.5, max(feedback_list) + 0.5))
plt.xlabel('time (s)')
plt.ylabel('PID (PV)')
plt.title('TEST PID')
plt.grid(True)
print("saving...")
fig1.savefig('result.png', dpi=100)
推薦閱讀
- 大話PLC(輕松動漫版)
- Building a RESTful Web Service with Spring
- Interactive Data Visualization with Python
- Instant 960 Grid System
- TradeStation交易應用實踐:量化方法構建贏家策略(原書第2版)
- PLC應用技術(三菱FX2N系列)
- Microsoft Dynamics AX 2012 R3 Financial Management
- Python全棧數據工程師養成攻略(視頻講解版)
- BeagleBone Robotic Projects(Second Edition)
- 視窗軟件設計和開發自動化:可視化D++語言
- Python編程基礎教程
- 生成藝術:Processing視覺創意入門
- 中小企業網站建設與管理(靜態篇)
- C語言學習手冊
- 計算機教學研究與實踐:2017學術年會論文集