1 Star 0 Fork 4

troy_ycd/GU_Drone

forked from Jiannan Zhao/GU_Drone 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
pid_control.py 872 Bytes
一键复制 编辑 原始数据 按行查看 历史
cqu_zjn 提交于 2021-09-09 15:49 . 新场景,旧settings
class PID:
def __init__(self, P, I, D):
self.Kp = P
self.Ki = I
self.Kd = D
self.sample_time = 0.00
self.dt = 0.3
self.clear()
def clear(self):
self.error = 0.0
self.PTerm = 0.0
self.ITerm = 0.0
self.DTerm = 0.0
self.last_error = 0.0
self.output = 0.0
def update(self, error):
delta_error = error - self.last_error
self.PTerm = self.Kp * error#比例
self.DTerm = delta_error / self.dt #微分
self.last_error = error
self.output = self.PTerm + (self.Ki * self.ITerm) + (self.Kd * self.DTerm)
return self.output
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 setSampleTime(self, sample_time):
self.sample_time = sample_time
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/ycd/gu_-drone.git
git@gitee.com:ycd/gu_-drone.git
ycd
gu_-drone
GU_Drone
master

搜索帮助