资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

python实现PID算法及测试的例子-创新互联

PID算法实现

创新互联从2013年开始,是专业互联网技术服务公司,拥有项目成都做网站、成都网站设计、成都外贸网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元静乐做网站,已为上家服务,为静乐各地企业和个人服务,联系电话:18982081108
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


网站名称:python实现PID算法及测试的例子-创新互联
网站URL:http://cdkjz.cn/article/cdedei.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220