资源简介
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.outMin):
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.outMin):
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):
- 上一篇:python项目监控
- 下一篇:模仿百度以图搜图功能/淘宝的拍立淘功能
相关资源
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
- 量化交易(附python常见函数的使用方
- python 名字用字排行
评论
共有 条评论