91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 4KB
    文件類型: .py
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2021-05-10
  • 語言: Python
  • 標(biāo)簽: pid??python??

資源簡介

python code for PID controller method

資源截圖

代碼片段和文件信息

import?time


##PID?Library
class?PID(object):
????##Constants?used?in?some?of?the?functions?below
????pid_AUTOMATIC?=?1
????pid_MANUAL?=?0
????pid_DIRECT?=?0
????pid_REVERSE?=?1

????direction?=?0

????def?__init__(self?Setpoint?Kp?Ki?Kd?ControllerDirection):
????????self.mySetpoint?=?Setpoint
????????self.inAuto?=?0
????????self.myOutput=0
????????self.Kp?=?Kp
????????self.Ki?=?Ki
????????self.Kd?=?Kd
????????self.ControllerDirection?=?ControllerDirection
????????self.SetOutputLimits(0?255)
????????self.SampleTime?=?100
????????self.myInput=0
????????self.SetControllerDirection(self.ControllerDirection)
????????self.lastTime?=?int(round(time.time()?*?1000))?-?self.SampleTime

????def?Compute(self):
????????if?(self.inAuto?==?0):
????????????return?0
????????now?=?int(round(time.time()?*?1000))
????????timeChange?=?(now?-?self.lastTime)
????????if?(timeChange?>=?self.SampleTime):
????????????#?/*Compute?all?the?working?error?variables*/
????????????Input?=?self.myInput
????????????error?=?self.mySetpoint?-?Input
????????????self.ITerm?+=?(self.Ki?*?error)
????????????if?(self.ITerm?>?self.outMax):
????????????????self.ITerm?=?self.outMax
????????????elif?(self.ITerm?????????????????self.ITerm?=?self.outMin
????????????dInput?=?(Input?-?self.lastInput)

????????????#?/*Compute?PID?Output*/
????????????self.output?=?self.Kp?*?error?+?self.ITerm?-?self.Kd?*?dInput

????????????if?(self.output?>?self.outMax):
????????????????self.output?=?self.outMax
????????????elif?(self.output?????????????????self.output?=?self.outMin
????????????self.myOutput?=?self.output

????????????????#?/*Remember?some?variables?for?next?time*/
????????????self.lastInput?=?Input
????????????self.lastTime?=?now
????????????return?1

????????else:
????????????return?0

????def?SetTunings(self?Kp?Ki?Kd):

評論

共有 條評論