⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 是一款DA板卡的控制界面的原代码. 用VISUAL BASIC编程
💻 FRM
📖 第 1 页 / 共 4 页
字号:
     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 + -