?? form1.frm
字號:
ScrollBar2.Value = CInt(CSng(SV) * 100)
bt_run.Enabled = True '控制按鈕初始化設置
bt_exit.Enabled = True
bt_refresh.Enabled = False
Command1.Caption = "修改" '設置按鈕初始化設置
Command2.Enabled = False
show_value '參數顯示
edit_sv = CStr(Format(SV, strformat))
edit_man = CStr(Format(MV, strformat))
change_forbid '各編輯框不允許被修改
drawCoordinate
'-----------------------------------關閉定時器---------------------------
Timer2.Enabled = False
End Sub
Private Sub Form_Load()
MsgBox "軟件說明:" + Chr(13) + " 1) 要求1024×768的分辨率" + Chr(13) + " 2) 為正常顯示,運行時請保持最大化狀態" + Chr(13) + Chr(13) + "開發工具:VB6.0 軟件制作:仰燕蘭", 0 + 48 + 0 + 0, "版本信息"
seconds = 0: minutes = 0
End Sub
Private Sub Option1_Click() ' Auto_control mode
cmode = 1
Command1.Enabled = True ' permite change the value of items
ScrollBar1.Enabled = False
edit_man.Enabled = False
Label17.Caption = "當前模式:自動"
End Sub
Private Sub Option2_Click() ' Man_control mode
cmode = 2
Command1.Enabled = True
Command2.Enabled = False
edit_man.Enabled = True
ScrollBar1.Enabled = True
ScrollBar1.Value = 100 * MV0
MV = MV0
edit_man.Text = CStr(Format(MV, strformat))
Label17.Caption = "當前模式:手動"
End Sub
Private Sub ScrollBar1_Change() ' Man_control Value
MV = CSng(ScrollBar1.Value) / 100
edit_man.Text = CStr(Format(MV, strformat))
End Sub
Private Sub ScrollBar2_Change()
SV = CSng(ScrollBar2.Value) / 100
edit_sv.Text = CStr(Format(SV, strformat))
End Sub
Private Sub Timer2_Timer() 'Ts timer
'-------------------------------------------------軟件定時
N_sh = N_sh + 1: Nc = Nc + 1: N = N + 1
'timer2.enabled=false
'-------------------------------------------------輸出采集,Ts
sample_pocess
If N_sh = 1 / Ts Then '-------------顯示刷新,1s
N_sh = 0
'---------------------------------------------顯示過程參數顯
show_MV.Caption = CStr(Format(MV0, strformat))
show_PV.Caption = CStr(Format(PV0, strformat))
show_SV.Caption = CStr(Format(SV, strformat))
'---------------------------------------------畫運行曲線red-SV; blue-PV; yel-MV
Y_SV = CInt(SV / 8 * 4000)
Y_PV = CInt(PV0 / 8 * 4000)
Y_MV = CInt(MV0 / 8 * 4000) '定終點縱坐標
Picture1.DrawMode = 13 '定畫筆著色模式
Picture1.DrawStyle = 0 '定畫筆線型
'----------------------------------------畫SV曲線,red,solid--------------
Picture1.DrawWidth = 2
Picture1.ForeColor = &HFF
x2(0) = x1(0) + Tab1: y2(0) = 4800 - Y_SV '*
Picture1.Line (x1(0), y1(0))-(x2(0), y2(0))
x1(0) = x2(0): y1(0) = y2(0)
'-----------------------------------------畫PV曲線,blue,solid--------------
Picture1.DrawWidth = 2
Picture1.ForeColor = &HFF0000
x2(1) = x1(1) + Tab1: y2(1) = 4800 - Y_PV '*
Picture1.Line (x1(1), y1(1))-(x2(1), y2(1))
x1(1) = x2(1): y1(1) = y2(1)
'-----------------------------------------畫MV曲線,土黃,solid--------------
Picture1.DrawWidth = 2
Picture1.ForeColor = &HC0C0&
x2(2) = x1(2) + Tab1: y2(2) = 4800 - Y_MV '*
Picture1.Line (x1(2), y1(2))-(x2(2), y2(2))
x1(2) = x2(2): y1(2) = y2(2)
'--------------------------------------------運行時間顯示
runtime.Caption = CStr(Format(minutes, "00")) + ":" + CStr(Format(seconds, "00"))
seconds = seconds + 1
If (seconds = 60) Then
minutes = minutes + 1
seconds = 0
End If
'---------------------------------------------運行時間已滿,停止運行
If (minutes = totaltime) Then
bt_refresh.Enabled = True
If bt_run.Caption = "停止運行" Then bt_run_Click
bt_run.Enabled = False
Timer2.Enabled = False
MsgBox "本次運行結束!" + Chr(13) + "點擊“重置”按鈕開始新的運行。", 0 + 64 + 0 + 0, "運行信息"
End If
'---------------------------------------------控制計算
If N = Tc / Ts / Ts Then
pid_control
N = 0
End If
ElseIf Nc = Tc / Ts Then
pid_control
Nc = 0
End If
End Sub
Private Sub sample_pocess()
Dim mvn As Single
Dim i As Integer
MV_his(delay - 1) = MV0 '更新MV_his的歷史值,存儲值依次左移
For i = 0 To delay - 2
MV_his(i) = MV_his(i + 1)
Next i
If count2 > delay - 1 Then
mvn = MV_his(0)
Else
mvn = 0#
End If
PV0 = PV1 * Exp(-Ts / Tp) + Kpp / Tp * mvn
PV1 = PV0
If count2 < delay Then '初始運行階段結束,停止計數
count2 = count2 + 1
End If
End Sub
Private Sub pid_control()
Dim dMV, mvn, kk As Single
'*****************************************************************************
' 自動模式
'*****************************************************************************
If cmode = 1 Then
e0 = SV - PV0
'----------------------------------------變增益控制-----------------------
If Abs(e0) > el Then
kk = 1
Else
kk = K
End If
'-----------------------------------------增量式標準PID控制----------------
'dMV = Kp * (e0 - e1 + (Tc / Ti) * e0 + (Td / Tc) * (e0 + e2 - 2 * e1))
'-----------------------------------------增量式不完全微分PID控制----------
Un = Td / (Tc + Td / m) * (e0 - e1 + Un_1 / m)
dMV = (e0 - e1) + (Tc / Ti) * e0 '比例項+積分項
dMV = kk * Kp * (dMV + (Un - Un_1))
mvn = MV1 + dMV
'------------------------------------------輸出限幅-----------------------
If mvn > MH Then
MV0 = MH
ElseIf mvn < ML Then
MV0 = ML
Else
MV0 = mvn
End If
'--------------------------------------------為下一次遞推準備----------------
MV1 = MV0: e1 = e0: Un_1 = Un
'*****************************************************************************
' 手動模式
'*****************************************************************************
ElseIf cmode = 2 Then
MV0 = MV
End If
End Sub
Private Sub show_value()
PID(0).Text = CStr(Format(Kp, strformat))
PID(1).Text = CStr(Format(Ti, strformat))
PID(2).Text = CStr(Format(Td, strformat))
edit_Tc.Text = CStr(Format(Tc, strformat))
edit_Ts.Text = CStr(Format(Ts, strformat))
edit_K.Text = CStr(Format(K, strformat))
Obj_L.Text = CStr(Format(L, strformat))
Obj_Tp.Text = CStr(Format(Tp, strformat))
Obj_Kp.Text = CStr(Format(Kpp, strformat))
edit_MH.Text = CStr(Format(MH, strformat))
edit_ML.Text = CStr(Format(ML, strformat))
End Sub
Private Sub load_value()
If PID(0).Text = "" Or PID(1).Text = "" Or PID(2).Text = "" Or edit_Tc.Text = "" Or edit_Ts.Text = "" Or edit_K.Text = "" Or Obj_L.Text = "" Or Obj_Tp.Text = "" Or Obj_Kp.Text = "" Or edit_MH.Text = "" Or edit_ML.Text = "" Then
MsgBox "有參數未設定,請設定完全!", 0 + 48 + 0 + 0, "參數設置錯誤"
show_value
Else
Kp = CSng(PID(0).Text)
Ti = CSng(PID(1).Text)
Td = CSng(PID(2).Text)
Tc = CSng(edit_Tc.Text)
Ts = CSng(edit_Ts.Text)
K = CSng(edit_K.Text)
If CSng(Obj_L.Text) < 0.2 * CSng(Obj_Tp.Text) Then
MsgBox "必須滿足 L>=0.2*Tp ", 0 + 48 + 0 + 0, "參數設置錯誤"
Obj_L.Text = CStr(Format(L, strformat))
Obj_Tp.Text = CStr(Format(Tp, strformat))
Else
L = CSng(Obj_L.Text)
Tp = CSng(Obj_Tp.Text)
End If
Kpp = CSng(Obj_Kp.Text)
MH = CSng(edit_MH.Text)
ML = CSng(edit_ML.Text)
End If
End Sub
Private Sub change_allow()
PID(0).Enabled = True
PID(1).Enabled = True
PID(2).Enabled = True
If bt_run.Caption = "開始運行" Then
edit_Tc.Enabled = True
edit_Ts.Enabled = True
edit_K.Enabled = True
Obj_L.Enabled = True
Obj_Tp.Enabled = True
Obj_Kp.Enabled = True
Else
edit_Tc.Enabled = False
edit_Ts.Enabled = False
edit_K.Enabled = False
Obj_L.Enabled = False
Obj_Tp.Enabled = False
Obj_Kp.Enabled = False
End If
edit_MH.Enabled = True
edit_ML.Enabled = True
End Sub
Private Sub change_forbid()
PID(0).Enabled = False
PID(1).Enabled = False
PID(2).Enabled = False
edit_Tc.Enabled = False
edit_Ts.Enabled = False
edit_K.Enabled = False
Obj_L.Enabled = False
Obj_Tp.Enabled = False
Obj_Kp.Enabled = False
edit_MH.Enabled = False
edit_ML.Enabled = False
End Sub
Private Sub drawCoordinate()
Dim strtemp As String
Dim temp As Single
Dim i, j As Integer
Dim x, y As Long
j = 1
'-----------------------------------------繪制坐標系 5235×9555---------
'--- // 起點:(500,4800) // 間隔:Tab2 ---
' 顯示坐標軸
Picture1.AutoRedraw = True
Picture1.DrawStyle = 0: Picture1.DrawWidth = 2
Picture1.ForeColor = &H0&
Picture1.Line (10800, 4800)-(500, 4800)
Picture1.Line -(500, 250)
Picture1.Line -(400, 500) 'up ^
Picture1.Line (500, 250)-(600, 500) ' |
Picture1.Line (10800, 4800)-(10550, 4700)
Picture1.Line (10800, 4800)-(10550, 4900) 'left ->
' 顯示網格和刻度
Picture1.DrawStyle = 2: Picture1.DrawWidth = 1
Picture1.DrawMode = 13
Picture1.ForeColor = &H808080
strtemp = CStr(Format(0, "##0"))
Twip2Pixel 560, 4800, strtemp, 1
For i = 1000 To 10500 Step Tab2 ' X軸
Picture1.Line (i, 250)-(i, 4800)
If j < CInt(10000 / Tab2) Then '*
strtemp = CStr(Format(Tab2 / Tab1 * j, "##0")) '*
Twip2Pixel (i + 60), 4800, strtemp, 1
End If
j = j + 1
Next i
Twip2Pixel 10600, 4800, "(s)", 1
j = 9
strtemp = CStr(Format(0, "0.00"))
Twip2Pixel 500, 4800, strtemp, 0
For i = 300 To 4300 Step 500 ' Y軸
Picture1.Line (500, i)-(10500, i)
If j < 9 Then
strtemp = CStr(Format(j, "0.00"))
Twip2Pixel 500, i, strtemp, 0
End If
j = j - 1
Next i
End Sub
Private Sub Twip2Pixel(ByVal i As Long, ByVal j As Long, ByVal strtemp As String, ByVal flag As Integer)
Dim x, y As Long
If flag = 0 Then '縱軸
x = (i - 60 - Len(strtemp) * Picture1.TextWidth("8")) / Screen.TwipsPerPixelX
y = (j - Picture1.TextHeight("8")) / Screen.TwipsPerPixelY
Else '橫軸
x = (i - Len(strtemp) * Picture1.TextWidth("8")) / Screen.TwipsPerPixelX
y = (j + 240 - Picture1.TextHeight("8")) / Screen.TwipsPerPixelY
End If
TextOut Picture1.hdc, x, y, strtemp, Len(strtemp)
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -