Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
geekincode
PID_Research
提交
a1f5c66e
P
PID_Research
项目概览
geekincode
/
PID_Research
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PID_Research
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a1f5c66e
编写于
11月 01, 2021
作者:
geekincode
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新Draw_PID.py, PID_control.py
上级
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
132 addition
and
0 deletion
+132
-0
Draw_PID.py
Draw_PID.py
+53
-0
PID_control.py
PID_control.py
+79
-0
未找到文件。
Draw_PID.py
0 → 100644
浏览文件 @
a1f5c66e
import
numpy
as
np
import
matplotlib
import
matplotlib.pyplot
as
plt
from
matplotlib
import
style
fig
,
axes
=
plt
.
subplots
()
a
=
np
.
linspace
(
0
,
240
,
240
)
b
=
np
.
linspace
(
160
,
161
,
240
)
a1
=
np
.
linspace
(
0
,
240
,
240
)
b1
=
np
.
linspace
(
200
,
201
,
240
)
x
=
np
.
linspace
(
0
,
240
,
240
)
y1
=
[
0
]
target
=
160
t_error
=
0
d_error
=
0
y
=
0
Kp
=
0.07
Ki
=
0.003
#设置PID参数
Kd
=
0.5
def
draw_PID
():
global
fig
,
axes
,
a
,
b
,
a1
,
b1
,
x
,
y1
,
target
,
d_error
,
y
,
Kp
,
Ki
,
Kd
,
t_error
for
i
in
range
(
len
(
x
)
-
1
):
error
=
target
-
y
y
=
y
+
error
*
Kp
t_error
=
t_error
+
error
y
=
y
+
t_error
*
Ki
if
i
!=
0
:
y
=
y
+
(
error
-
d_error
)
*
Kd
#y = y - 3
y1
.
append
(
y
)
d_error
=
error
axes
.
plot
(
a1
,
b1
,
color
=
'gray'
,
label
=
'top'
)
axes
.
plot
(
a
,
b
,
color
=
'skyblue'
,
label
=
'Target'
)
axes
.
plot
(
x
,
y1
,
color
=
'lightcoral'
,
label
=
'Output'
)
axes
.
set
(
ylabel
=
'Y Ax'
,
xlabel
=
'X Ax'
,
title
=
'PID_control (P I D)'
,
ylim
=
[
-
2
,
320
],
xlim
=
[
-
2
,
240
])
axes
.
legend
()
plt
.
show
()
fig
,
axes
=
plt
.
subplots
()
y1
=
[
0
]
y
=
0
#初始化
if
__name__
==
"__main__"
:
#__main__为主程序脚本文件名,__name__为该程序文件名
draw_PID
()
#当主程序为当前程序文件时,执行该段代码
PID_control.py
0 → 100644
浏览文件 @
a1f5c66e
#from Draw_PID import draw_PID
import
Draw_PID
import
tkinter
as
tk
def
function
():
#print(e1.get(),e2.get())
Draw_PID
.
Kp
=
eval
(
e1
.
get
())
Draw_PID
.
Ki
=
eval
(
e2
.
get
())
Draw_PID
.
Kd
=
eval
(
e3
.
get
())
Draw_PID
.
draw_PID
()
def
e1press1
(
self
):
e1
.
config
(
bg
=
'skyblue'
)
def
e1press2
(
self
):
e1
.
config
(
bg
=
'white'
)
def
e2press1
(
self
):
e2
.
config
(
bg
=
'skyblue'
)
def
e2press2
(
self
):
e2
.
config
(
bg
=
'white'
)
def
e3press1
(
self
):
e3
.
config
(
bg
=
'skyblue'
)
def
e3press2
(
self
):
e3
.
config
(
bg
=
'white'
)
window
=
tk
.
Tk
()
window
.
title
(
'PID_control'
)
window
.
geometry
(
'500x300'
)
# 这里的乘是小x
# 第4步,在图形界面上设定标签
var
=
tk
.
StringVar
()
# 将label标签的内容设置为字符类型,用var来接收hit_me函数的传出内容用以显示在标签上
var
.
set
(
'white'
)
bgcolor
=
'white'
l1
=
tk
.
Label
(
window
,
text
=
'Kp:'
,
font
=
(
'Arial Black'
,
12
),
width
=
3
,
height
=
1
)
l1
.
place
(
relx
=
0.25
,
rely
=
0.03
)
l2
=
tk
.
Label
(
window
,
text
=
'Ki:'
,
font
=
(
'Arial Black'
,
12
),
width
=
3
,
height
=
1
)
l2
.
place
(
relx
=
0.25
,
rely
=
0.13
)
l3
=
tk
.
Label
(
window
,
text
=
'Kd:'
,
font
=
(
'Arial Black'
,
12
),
width
=
3
,
height
=
1
)
l3
.
place
(
relx
=
0.25
,
rely
=
0.23
)
e1
=
tk
.
Entry
(
window
,
show
=
None
,
bg
=
'white'
,
font
=
(
'Arial'
,
10
))
#显示成明文形式
e1
.
place
(
relx
=
0.35
,
rely
=
0.05
)
e1
.
bind
(
'<Enter>'
,
e1press1
)
e1
.
bind
(
'<Leave>'
,
e1press2
)
e2
=
tk
.
Entry
(
window
,
show
=
None
,
bg
=
'white'
,
font
=
(
'Arial'
,
10
))
#显示成明文形式
e2
.
place
(
relx
=
0.35
,
rely
=
0.15
)
e2
.
bind
(
'<Enter>'
,
e2press1
)
e2
.
bind
(
'<Leave>'
,
e2press2
)
e3
=
tk
.
Entry
(
window
,
show
=
None
,
bg
=
'white'
,
font
=
(
'Arial'
,
10
))
#显示成明文形式
e3
.
place
(
relx
=
0.35
,
rely
=
0.25
)
e3
.
bind
(
'<Enter>'
,
e3press1
)
e3
.
bind
(
'<Leave>'
,
e3press2
)
# 第5步,在窗口界面设置放置Button按键Draw_PID.Kp
b
=
tk
.
Button
(
window
,
text
=
'Show PID'
,
font
=
(
'Arial'
,
12
),
width
=
10
,
height
=
1
,
bg
=
'lightcoral'
,
command
=
function
)
b
.
place
(
relx
=
0.4
,
rely
=
0.75
)
# 第6步,主窗口循环显示
window
.
mainloop
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录