1 Star 0 Fork 5

Lxy/PID-Example

forked from 辰汐/PID-Example 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
PID-Test.py 3.16 KB
一键复制 编辑 原始数据 按行查看 历史
辰汐 提交于 2023-04-12 15:04 . update
import dearpygui.dearpygui as dpg
from PID import Pid
dpg.create_context()
# creating data
datax_test = []
datay_test = []
def update_data_test():
global datax_test, datay_test
Sp = dpg.get_value("Sp")
Kp = dpg.get_value("Kp")
Ki = dpg.get_value("Ki")
Kd = dpg.get_value("Kd")
datax_test = list(range(5))
datay_test = [0 for _ in range(5)]
# update data
pid = Pid(Kp, Ki, Kd, Sp)
for i in range(5, 100):
datax_test.append(i)
datay_test.append(pid.calculate())
dpg.set_value("series_TestModel", [datax_test, datay_test])
dpg.fit_axis_data("x_axis_TestModel")
dpg.fit_axis_data("y_axis_TestModel")
with dpg.window(tag="Primary Window", height=-1):
with dpg.theme(tag="plot_theme_TestModel"):
with dpg.theme_component(dpg.mvLineSeries):
dpg.add_theme_color(
dpg.mvPlotCol_Line, (255, 255, 50), category=dpg.mvThemeCat_Plots
)
dpg.add_theme_style(
dpg.mvPlotStyleVar_Marker,
dpg.mvPlotMarker_Square,
category=dpg.mvThemeCat_Plots,
)
dpg.add_theme_style(
dpg.mvPlotStyleVar_MarkerSize, 3, category=dpg.mvThemeCat_Plots
)
with dpg.plot(label="Simulate", height=400, width=-1):
# optionally create legend
dpg.add_plot_legend()
# REQUIRED: create x and y axes
dpg.add_plot_axis(dpg.mvXAxis, label="x", tag="x_axis_TestModel")
dpg.add_plot_axis(dpg.mvYAxis, label="y", tag="y_axis_TestModel")
# series belong to a y axis
dpg.add_line_series(datax_test, datay_test, parent="y_axis_TestModel", tag="series_TestModel")
# dpg.set_axis_limits("x_axis_TestModel", -10, 110)
# dpg.set_axis_limits("y_axis_TestModel", -10, 510)
dpg.bind_item_theme("series_TestModel", "plot_theme_TestModel")
with dpg.group(horizontal=True):
dpg.add_text("Set Point")
dpg.add_slider_int(
tag="Sp", default_value=350, max_value=500, width=-1, callback=update_data_test
)
with dpg.group(horizontal=True):
dpg.add_text("Kp")
dpg.add_slider_float(
tag="Kp",
default_value=0.04,
min_value=-1,
max_value=1,
width=-1,
callback=update_data_test,
)
with dpg.group(horizontal=True):
dpg.add_text("Ki")
dpg.add_slider_float(
tag="Ki",
default_value=0.7,
min_value=-2,
max_value=2,
width=-1,
callback=update_data_test,
)
with dpg.group(horizontal=True):
dpg.add_text("Kd")
dpg.add_slider_float(
tag="Kd",
default_value=0.015,
min_value=-2,
max_value=2,
width=-1,
callback=update_data_test,
)
update_data_test()
dpg.create_viewport(title="PID Simulate", width=700, height=550)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.set_primary_window("Primary Window", True)
dpg.start_dearpygui()
dpg.destroy_context()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/moker1234/pid-example.git
git@gitee.com:moker1234/pid-example.git
moker1234
pid-example
PID-Example
master

搜索帮助