代码拉取完成,页面将自动刷新
同步操作将从 辰汐/PID-Example 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
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()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。