From: kyz Date: Wed, 12 Jun 2024 10:02:26 +0000 (+0800) Subject: 增加目标流量算法查看工具 X-Git-Url: http://kyz.pub/gitweb/?a=commitdiff_plain;h=8cbb0df105c820b84e096433abc62645d29244a3;p=yn%2Fweldingcontroller.git 增加目标流量算法查看工具 --- diff --git a/tools_v2/flow_algo/dump.csv b/tools_v2/flow_algo/dump.csv new file mode 100644 index 0000000..6fca4d9 --- /dev/null +++ b/tools_v2/flow_algo/dump.csv @@ -0,0 +1,80 @@ +1,5,2.5,1.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5 +2,10,6,2.5,1.5,1.5,1.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5 +3,15,8,3.5,2.5,1.5,1.5,1.5,1.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5 +4,20,11,6,3.5,2.5,2.5,1.5,1.5,1.5,1.5,1.5,0.5,0.5,0.5,0.5,0.5 +5,25,13,7,4.5,3.5,2.5,2.5,1.5,1.5,1.5,1.5,1.5,1.5,0.5,0.5,0.5 +6,30,16,8,6,3.5,3.5,2.5,2.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5 +7,35,18,9,6,4.5,3.5,2.5,2.5,2.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5 +8,40,21,11,7,6,4.5,3.5,2.5,2.5,2.5,2.5,1.5,1.5,1.5,1.5,1.5 +9,45,23,12,8,6,4.5,3.5,3.5,2.5,2.5,2.5,2.5,1.5,1.5,1.5,1.5 +10,50,26,13,9,7,6,4.5,3.5,3.5,2.5,2.5,2.5,2.5,1.5,1.5,1.5 +11,55,28,14,10,7,6,4.5,3.5,3.5,3.5,2.5,2.5,2.5,2.5,1.5,1.5 +12,60,31,16,11,8,7,6,4.5,3.5,3.5,3.5,2.5,2.5,2.5,2.5,2.5 +13,65,33,17,11,9,7,6,4.5,4.5,3.5,3.5,2.5,2.5,2.5,2.5,2.5 +14,70,36,18,12,9,8,6,6,4.5,3.5,3.5,3.5,2.5,2.5,2.5,2.5 +15,75,38,19,13,10,8,7,6,4.5,4.5,3.5,3.5,3.5,2.5,2.5,2.5 +16,80,41,21,14,11,9,7,6,6,4.5,4.5,3.5,3.5,3.5,2.5,2.5 +17,85,43,22,15,11,9,8,7,6,4.5,4.5,3.5,3.5,3.5,3.5,2.5 +18,90,46,23,16,12,10,8,7,6,6,4.5,4.5,3.5,3.5,3.5,3.5 +19,95,48,24,16,12,10,8,7,6,6,4.5,4.5,3.5,3.5,3.5,3.5 +20,100,51,26,17,13,11,9,8,7,6,6,4.5,4.5,3.5,3.5,3.5 +21,105,53,27,18,14,11,9,8,7,6,6,4.5,4.5,4.5,3.5,3.5 +22,110,56,28,19,14,12,10,8,7,7,6,6,4.5,4.5,3.5,3.5 +23,115,58,29,20,15,12,10,9,8,7,6,6,4.5,4.5,4.5,3.5 +24,120,61,31,21,16,13,11,9,8,7,7,6,6,4.5,4.5,4.5 +25,125,63,32,21,16,13,11,9,8,7,7,6,6,4.5,4.5,4.5 +26,130,66,33,22,17,14,11,10,9,8,7,6,6,6,4.5,4.5 +27,135,68,34,23,17,14,12,10,9,8,7,7,6,6,4.5,4.5 +28,140,71,36,24,18,15,12,11,9,8,8,7,6,6,6,4.5 +29,145,73,37,25,19,15,13,11,10,9,8,7,7,6,6,4.5 +30,150,76,38,26,19,16,13,11,10,9,8,7,7,6,6,6 +31,155,78,39,26,20,16,13,12,10,9,8,8,7,6,6,6 +32,160,81,41,27,21,17,14,12,11,9,9,8,7,7,6,6 +33,165,83,42,28,21,17,14,12,11,10,9,8,7,7,6,6 +34,170,86,43,29,22,18,15,13,11,10,9,8,8,7,7,6 +35,175,88,44,30,22,18,15,13,11,10,9,8,8,7,7,6 +36,180,91,46,31,23,19,16,13,12,11,10,9,8,7,7,7 +37,185,93,47,31,24,19,16,14,12,11,10,9,8,8,7,7 +38,190,96,48,32,24,20,16,14,12,11,10,9,8,8,7,7 +39,195,98,49,33,25,20,17,14,13,11,10,9,9,8,7,7 +40,200,101,51,34,26,21,17,15,13,12,11,10,9,8,8,7 +41,205,103,52,35,26,21,18,15,13,12,11,10,9,8,8,7 +42,210,106,53,36,27,22,18,16,14,12,11,10,9,9,8,8 +43,215,108,54,36,27,22,18,16,14,12,11,10,9,9,8,8 +44,220,111,56,37,28,23,19,16,14,13,12,11,10,9,8,8 +45,225,113,57,38,29,23,19,17,15,13,12,11,10,9,9,8 +46,230,116,58,39,29,24,20,17,15,13,12,11,10,9,9,8 +47,235,118,59,40,30,24,20,17,15,14,12,11,10,10,9,8 +48,240,121,61,41,31,25,21,18,16,14,13,11,11,10,9,9 +49,245,123,62,41,31,25,21,18,16,14,13,12,11,10,9,9 +50,250,126,63,42,32,26,21,18,16,14,13,12,11,10,9,9 +51,255,128,64,43,32,26,22,19,16,15,13,12,11,10,10,9 +52,260,131,66,44,33,27,22,19,17,15,14,12,11,11,10,9 +53,265,133,67,45,34,27,23,19,17,15,14,13,12,11,10,9 +54,270,136,68,46,34,28,23,20,17,16,14,13,12,11,10,10 +55,275,138,69,46,35,28,23,20,18,16,14,13,12,11,10,10 +56,280,141,71,47,36,29,24,21,18,16,15,13,12,11,11,10 +57,285,143,72,48,36,29,24,21,18,16,15,13,12,11,11,10 +58,290,146,73,49,37,30,25,21,19,17,15,14,13,12,11,10 +59,295,148,74,50,37,30,25,22,19,17,15,14,13,12,11,10 +60,300,151,76,51,38,31,26,22,19,17,16,14,13,12,11,11 +61,305,153,77,51,39,31,26,22,20,17,16,14,13,12,11,11 +62,310,156,78,52,39,32,26,23,20,18,16,15,13,12,12,11 +63,315,158,79,53,40,32,27,23,20,18,16,15,14,13,12,11 +64,320,161,81,54,41,33,27,23,21,18,17,15,14,13,12,11 +65,325,163,82,55,41,33,28,24,21,19,17,15,14,13,12,11 +66,330,166,83,56,42,34,28,24,21,19,17,16,14,13,12,12 +67,335,168,84,56,42,34,28,24,21,19,17,16,14,13,12,12 +68,340,171,86,57,43,35,29,25,22,19,18,16,15,14,13,12 +69,345,173,87,58,44,35,29,25,22,20,18,16,15,14,13,12 +70,350,176,88,59,44,36,30,26,22,20,18,16,15,14,13,12 +71,355,178,89,60,45,36,30,26,23,20,18,17,15,14,13,12 +72,360,181,91,61,46,37,31,26,23,21,19,17,16,14,13,13 +73,365,183,92,61,46,37,31,27,23,21,19,17,16,15,14,13 +74,370,186,93,62,47,38,31,27,24,21,19,17,16,15,14,13 +75,375,188,94,63,47,38,32,27,24,21,19,18,16,15,14,13 +76,380,191,96,64,48,39,32,28,24,22,20,18,16,15,14,13 +77,385,193,97,65,49,39,33,28,25,22,20,18,17,15,14,13 +78,390,196,98,66,49,40,33,28,25,22,20,18,17,16,14,14 +79,395,198,99,66,50,40,33,29,25,22,20,18,17,16,15,14 +80,400,201,101,67,51,41,34,29,26,23,21,19,17,16,15,14 diff --git a/tools_v2/flow_algo/flow_algo.py b/tools_v2/flow_algo/flow_algo.py new file mode 100644 index 0000000..54d9d11 --- /dev/null +++ b/tools_v2/flow_algo/flow_algo.py @@ -0,0 +1,189 @@ +import csv +import flow_algo_ui as ui_flow_algo +from collections import deque +from re import L +import sys +import os +import math + +import numpy as np +import pyqtgraph as pg + +from PyQt5.QtCore import * +from PyQt5.QtGui import * +from PyQt5.QtWidgets import * + +import json +import time +import crcmod +import struct +import intelhex + +#生成CRC16-MODBUS校验码 +#crc16 = crcmod.mkCrcFun(0x18005, rev=True, initCrc=0xFFFF, xorOut=0x0000) +from collections import deque + +class App( QDialog, ui_flow_algo.Ui_Dialog ): + def __init__( self ): + super().__init__() + self.setupUi(self) + + self.vs_factor.valueChanged.connect( lambda:self.on_slider_value_changed( "factor")) + self.vs_curr.valueChanged.connect( lambda:self.on_slider_value_changed( "current")) + + self.vs_curr.setValue( 5 ) + self.vs_factor.setValue(2) + self.label_curr.setText( str( self.vs_curr.value())) + self.label_factor.setText( str(self.vs_factor.value()) ) + + self.curves = {} + self.draw_image( frame =self.frame_factor, title=u"节气因子", y_name=u"流量L/min", x_name=u"电流A", curve_name=u"电流-流量", color="green") + self.draw_image( frame =self.frame_curr, title=u"焊接电流", y_name=u"流量L/min", x_name=u"节气因子", curve_name=u"节气因子-流量", color = "blue") + + dump_path = 'dump.csv' + + self.flow_list = [] + + with open( dump_path, "r" ) as f: + dump_reader = csv.reader(f) + + for r in dump_reader: + flow_item = {} + _, curr, *flow = r + flow_item["curr"] = int(curr) + flow_item["flow"] = list(map( float, flow )) + self.flow_list.append( flow_item ) + + for i in self.flow_list: + print( i ) + + self.vs_factor_2.valueChanged.connect( lambda:self.on_slider_value_changed_2( "factor")) + self.vs_curr_2.valueChanged.connect( lambda:self.on_slider_value_changed_2( "current")) + + self.vs_curr_2.setValue( 5 ) + self.vs_factor_2.setValue(2) + self.label_curr_2.setText( str( self.vs_curr_2.value())) + self.label_factor_2.setText( str(self.vs_factor_2.value()) ) + + self.curves_2 = {} + self.draw_image( frame =self.frame_factor_2, title=u"YN节气因子", y_name=u"流量L/min", x_name=u"电流A", curve_name=u"电流-流量", color = "red" ) + self.draw_image( frame =self.frame_curr_2, title=u"YN焊接电流", y_name=u"流量L/min", x_name=u"节气因子", curve_name=u"节气因子-流量", color = "yellow" ) + + self.vs_factor_2.setMinimum(1) + self.vs_factor_2.setMaximum(10) + self.vs_factor_2.setSingleStep(1) + self.vs_factor_2.setPageStep(1) + + def on_slider_value_changed( self, slider ): + factor = self.vs_factor.value() + curr = self.vs_curr.value() + if slider == "factor": + self.label_factor.setText( str( factor )) + x = list( range( 5, 400+1, 5 )) + y = list( map( lambda x: self.calc_target_flow( factor=factor, curr=x ), x )) + self.curves[u"节气因子"]["plot"].setTitle( u"节气因子-{}".format(factor) ) + self.curves[u"节气因子"]["curve"].setData( np.array( x), np.array( y)) + else: + self.on_slider_value_changed_2( slider ) + + self.label_curr.setText( str( curr)) + x = list(range(2,30+1, 2)) + y = list( map( lambda x: self.calc_target_flow( factor=x, curr=curr ), x )) + self.curves[u"焊接电流"][u"plot"].setTitle( u"焊接电流-{}".format(self.label_curr.text())) + self.curves[u"焊接电流"][u"curve"].setData( np.array( x), np.array( y)) + self.groupBox.setTitle( u"客户算法 -- 节气因子 {} + 焊接电流 {} A -> 目标流量 {} L/min".format( self.label_factor.text(), self.label_curr.text(), self.calc_target_flow() )) + + def calc_target_flow( self, factor=0, curr=0 ): + if factor == 0: + factor = int(self.label_factor.text()) + if curr == 0: + curr = int(self.label_curr.text()) + for r in self.flow_list: + if curr <= r["curr"]: + return r['flow'][factor//2-1] + return 0 + + def on_slider_value_changed_2( self, slider ): + factor = self.vs_factor_2.value() + #curr = self.vs_curr_2.value() + curr = self.vs_curr.value() + if slider == "factor": + self.label_factor_2.setText( str( factor )) + x = list( range( 5, 400+1, 5 )) + y = list( map( lambda x: self.calc_target_flow_2( factor=factor, curr=x ), x )) + self.curves[u"YN节气因子"]["plot"].setTitle( u"节气因子-{}".format(factor) ) + self.curves[u"YN节气因子"]["curve"].setData( np.array( x), np.array( y)) + else: + self.label_curr_2.setText( str( curr)) + x = list(range(1,10+1, 1)) + y = list( map( lambda x: self.calc_target_flow_2( factor=x, curr=curr ), x )) + self.curves[u"YN焊接电流"][u"plot"].setTitle( u"焊接电流-{}".format(self.label_curr_2.text())) + self.curves[u"YN焊接电流"][u"curve"].setData( np.array( x), np.array( y)) + self.groupBox_2.setTitle( u"YN算法 -- 节气因子 {} + 焊接电流 {} A -> 目标流量 {} L/min".format( self.label_factor_2.text(), self.label_curr_2.text(), self.calc_target_flow_2() )) + + def calc_target_flow_2( self, factor=0, curr=0 ): + if factor == 0: + factor = int(self.label_factor_2.text()) + if curr == 0: + curr = int(self.label_curr_2.text()) + # max400A - factor 1..10 --- 10..110L/min + flow_400A = 10+(factor-1)*10; + # curr 0..400 -- 0.5L -- flow_400A + flow = 0.5 + flow_400A *curr//400 + print( " ------ fact[{}] + curr[{}] --> flow[{}] -- [{}]".format( factor, curr, flow, 0.25*curr*0.1*factor )) + Flow = factor * curr *0.025 +0.5 + return flow + + def draw_image(self, frame, title, y_name, x_name, curve_name, color="red" ): + win = pg.GraphicsLayoutWidget(frame) + QVBoxLayout(frame).addWidget(win) + p_curr = win.addPlot(title=title) + p_curr.showGrid(x=True,y=True) + p_curr.setLabel(axis="left",text=y_name) + p_curr.setLabel(axis="bottom",text=x_name) + p_curr.setTitle( title) + p_curr.addLegend() + self.curves[title] = { "plot":p_curr, "curve":p_curr.plot(pen=color,name=curve_name) } + return + + #self.curve1 = p.plot(pen="r",name="焊接电流") + self.curve_valve_curr = p_curr.plot(pen="r",name="比例阀控制电流") + verticalLayout_flow = QVBoxLayout(self.frame_flow) + win_flow = pg.GraphicsLayoutWidget(self.frame_flow) + verticalLayout_flow.addWidget(win_flow) + p_flow = win_flow.addPlot(title="动态波形图") + p_flow.showGrid(x=True,y=True) + p_flow.setLabel(axis="left",text="气体流量 L/min") + p_flow.setLabel(axis="bottom",text="时间 (s)") + p_flow.setTitle("1.目标流量 2.实际流量") + p_flow.addLegend() + self.curve_flow_target = p_flow.plot(pen="r",name="1.目标流量") + self.curve_flow = p_flow.plot(pen="g",name="2.实际流量") + + #curr raw disp + verticalLayout_curr_raw = QVBoxLayout(self.frame_curr_raw) + win_curr_raw = pg.GraphicsLayoutWidget(self.frame_curr_raw) + verticalLayout_curr_raw.addWidget(win_curr_raw) + p_curr_raw = win_curr_raw.addPlot(title="动态波形图") + p_curr_raw.showGrid(x=True,y=True) + p_curr_raw.setLabel(axis="left",text="电流 A") + p_curr_raw.setLabel(axis="bottom",text="时间 (0.1ms/10KHz)") + p_curr_raw.setTitle("1.焊接电流") + p_curr_raw.addLegend() + self.curve_curr_raw = p_curr_raw.plot(pen="yellow",name="焊接电流") + + self.valve_curr_y = [] + self.flow_target_y = [] + self.flow_x = [] + self.flow_y = [] + self.curr_raw_x = [] + self.curr_raw_y = [] + +if __name__ == "__main__": + app = QApplication(sys.argv) # 创建一个QApplication,也就是你要开发的软件app + x = App() + x.show() + #App().show() + sys.exit(app.exec_()) # 使用exit()或者点击关闭按钮退出QApplication + + \ No newline at end of file diff --git a/tools_v2/flow_algo/flow_algo.ui b/tools_v2/flow_algo/flow_algo.ui new file mode 100644 index 0000000..32a4c2d --- /dev/null +++ b/tools_v2/flow_algo/flow_algo.ui @@ -0,0 +1,360 @@ + + + Dialog + + + + 0 + 0 + 1225 + 827 + + + + Dialog + + + + + 10 + 10 + 591 + 811 + + + + 客户算法 + + + + + 39 + 60 + 541 + 351 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + 220 + 40 + 361 + 21 + + + + 2 + + + 30 + + + 2 + + + 2 + + + Qt::Horizontal + + + QSlider::NoTicks + + + 2 + + + + + + 210 + 420 + 371 + 21 + + + + 5 + + + 400 + + + 5 + + + Qt::Horizontal + + + QSlider::NoTicks + + + + + + 40 + 440 + 541 + 361 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + 40 + 40 + 121 + 16 + + + + 节气因子( 2-30 ): + + + + + + 170 + 40 + 21 + 16 + + + + 2 + + + + + + 40 + 420 + 121 + 16 + + + + 焊接电流(5-400): + + + + + + 170 + 420 + 21 + 16 + + + + 5 + + + + + + 400 + 10 + 181 + 21 + + + + [从设备导出数据,查表显示] + + + + + + + 610 + 10 + 591 + 811 + + + + 轶诺算法 + + + + + 39 + 60 + 541 + 351 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + 220 + 40 + 361 + 21 + + + + 2 + + + 30 + + + 2 + + + 2 + + + Qt::Horizontal + + + QSlider::NoTicks + + + 2 + + + + + false + + + + 210 + 420 + 371 + 21 + + + + 5 + + + 400 + + + 5 + + + Qt::Horizontal + + + QSlider::NoTicks + + + + + + 40 + 440 + 541 + 361 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + 40 + 40 + 121 + 16 + + + + 节气因子( 1-10 ): + + + + + + 170 + 40 + 21 + 16 + + + + 1 + + + + + false + + + + 40 + 420 + 121 + 16 + + + + 焊接电流(5-400): + + + + + false + + + + 170 + 420 + 21 + 16 + + + + 5 + + + + + + 310 + 10 + 271 + 21 + + + + [ 目标流量 = 节气因子 x 电流 x 0.025 + 0.5 ] + + + + + + +