最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python實現(xiàn)PID算法及測試的例子

 更新時間:2019年08月08日 11:53:31   作者:qq3163438396  
今天小編就為大家分享一篇python實現(xiàn)PID算法及測試的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

PID算法實現(xiàn)

import time

class PID:
  def __init__(self, P=0.2, I=0.0, D=0.0):
    self.Kp = P
    self.Ki = I
    self.Kd = D
    self.sample_time = 0.00
    self.current_time = time.time()
    self.last_time = self.current_time
    self.clear()
  def clear(self):
    self.SetPoint = 0.0
    self.PTerm = 0.0
    self.ITerm = 0.0
    self.DTerm = 0.0
    self.last_error = 0.0
    self.int_error = 0.0
    self.windup_guard = 20.0
    self.output = 0.0
  def update(self, feedback_value):
    error = self.SetPoint - feedback_value
    self.current_time = time.time()
    delta_time = self.current_time - self.last_time
    delta_error = error - self.last_error
    if (delta_time >= self.sample_time):
      self.PTerm = self.Kp * error#比例
      self.ITerm += error * delta_time#積分
      if (self.ITerm < -self.windup_guard):
        self.ITerm = -self.windup_guard
      elif (self.ITerm > self.windup_guard):
        self.ITerm = self.windup_guard
      self.DTerm = 0.0
      if delta_time > 0:
        self.DTerm = delta_error / delta_time
      self.last_time = self.current_time
      self.last_error = error
      self.output = self.PTerm + (self.Ki * self.ITerm) + (self.Kd * self.DTerm)
  def setKp(self, proportional_gain):
    self.Kp = proportional_gain
  def setKi(self, integral_gain):
    self.Ki = integral_gain
  def setKd(self, derivative_gain):
    self.Kd = derivative_gain
  def setWindup(self, windup):
    self.windup_guard = windup
  def setSampleTime(self, sample_time):
    self.sample_time = sample_time

測試PID算法

import PID
import time
import matplotlib
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import spline
#這個程序的實質(zhì)就是在前九秒保持零輸出,在后面的操作中在傳遞函數(shù)為某某的系統(tǒng)中輸出1

def test_pid(P = 0.2, I = 0.0, D= 0.0, L=100):
  """Self-test PID class

  .. note::
    ...
    for i in range(1, END):
      pid.update(feedback)
      output = pid.output
      if pid.SetPoint > 0:
        feedback += (output - (1/i))
      if i>9:
        pid.SetPoint = 1
      time.sleep(0.02)
    ---
  """
  pid = PID.PID(P, I, D)

  pid.SetPoint=0.0
  pid.setSampleTime(0.01)

  END = L
  feedback = 0

  feedback_list = []
  time_list = []
  setpoint_list = []

  for i in range(1, END):
    pid.update(feedback)
    output = pid.output
    if pid.SetPoint > 0:
      feedback +=output# (output - (1/i))控制系統(tǒng)的函數(shù)
    if i>9:
      pid.SetPoint = 1
    time.sleep(0.01)

    feedback_list.append(feedback)
    setpoint_list.append(pid.SetPoint)
    time_list.append(i)

  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)
  plt.figure(0)
  plt.plot(time_smooth, feedback_smooth)
  plt.plot(time_list, setpoint_list)
  plt.xlim((0, L))
  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.ylim((1-0.5, 1+0.5))

  plt.grid(True)
  plt.show()

if __name__ == "__main__":
  test_pid(1.2, 1, 0.001, L=80)
#  test_pid(0.8, L=50)

結(jié)果

以上這篇python實現(xiàn)PID算法及測試的例子就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python MySQLdb 執(zhí)行sql語句時的參數(shù)傳遞方式

    Python MySQLdb 執(zhí)行sql語句時的參數(shù)傳遞方式

    這篇文章主要介紹了Python MySQLdb 執(zhí)行sql語句時的參數(shù)傳遞方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03
  • pytorch geometric的GNN、GCN的節(jié)點分類方式

    pytorch geometric的GNN、GCN的節(jié)點分類方式

    這篇文章主要介紹了pytorch geometric的GNN、GCN的節(jié)點分類方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • python matlab庫簡單用法講解

    python matlab庫簡單用法講解

    在本篇文章里小編給大家整理了一篇關(guān)于python matlab庫簡單用法講解內(nèi)容,有需要的朋友們可以學習下。
    2020-12-12
  • Python獲取和設(shè)置代理的動態(tài)IP的方式

    Python獲取和設(shè)置代理的動態(tài)IP的方式

    在網(wǎng)絡(luò)世界中,代理和動態(tài)IP是非常常見的概念,尤其對于需要大規(guī)模訪問網(wǎng)站或者需要隱藏真實IP地址的應(yīng)用程序來說,更是必不可少的工具,本文將給大家介紹如何使用編程技術(shù)來實現(xiàn)動態(tài)IP的設(shè)置和管理,需要的朋友可以參考下
    2024-05-05
  • python如何獲取列表中每個元素的下標位置

    python如何獲取列表中每個元素的下標位置

    這篇文章主要介紹了python如何獲取列表中每個元素的下標位置,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-07-07
  • cmd輸入python命令無反應(yīng)的解決方案

    cmd輸入python命令無反應(yīng)的解決方案

    這篇文章主要介紹了cmd輸入python命令無反應(yīng)的解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-02-02
  • selenium+python自動化78-autoit參數(shù)化與批量上傳功能的實現(xiàn)

    selenium+python自動化78-autoit參數(shù)化與批量上傳功能的實現(xiàn)

    這篇文章主要介紹了selenium+python自動化78-autoit參數(shù)化與批量上傳,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-03-03
  • 在PyCharm中三步完成PyPy解釋器的配置的方法

    在PyCharm中三步完成PyPy解釋器的配置的方法

    今天小編就為大家分享一篇在PyCharm中三步完成PyPy解釋器的配置的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-10-10
  • TensorFlow實現(xiàn)Logistic回歸

    TensorFlow實現(xiàn)Logistic回歸

    這篇文章主要為大家詳細介紹了TensorFlow實現(xiàn)Logistic回歸的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-09-09
  • Pycharm中import torch報錯的快速解決方法

    Pycharm中import torch報錯的快速解決方法

    這篇文章主要介紹了Pycharm中import torch報錯的快速解決方法,很多朋友容易碰到這個問題,今天小編特此把解決方案分享到腳本之家平臺供大家參考,需要的朋友可以參考下
    2020-03-03

最新評論

宾川县| 项城市| 东阿县| 罗源县| 九江市| 韩城市| 北票市| 凤庆县| 雷州市| 辉南县| 石嘴山市| 庆城县| 金乡县| 达拉特旗| 桃源县| 双柏县| 伊金霍洛旗| 广宁县| 治多县| 关岭| 大同县| 句容市| 上高县| 山阳县| 黄大仙区| 长阳| 杂多县| 安新县| 云南省| 宣威市| 金溪县| 柳林县| 天等县| 乌海市| 三穗县| 大渡口区| 丁青县| 南通市| 武山县| 柳江县| 二手房|