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

📄 pidform.frm

📁 此程序用于仿真PID调节的程序
💻 FRM
字号:
VERSION 5.00
Begin VB.Form PIDForm 
   Caption         =   "PID 仿真"
   ClientHeight    =   9375
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   14145
   LinkTopic       =   "Form1"
   ScaleHeight     =   9375
   ScaleWidth      =   14145
   Begin VB.CommandButton Command2 
      Caption         =   "暂停"
      Height          =   2055
      Left            =   10560
      TabIndex        =   10
      Top             =   7080
      Width           =   615
   End
   Begin VB.CommandButton Command1 
      Caption         =   "启动"
      Height          =   2055
      Left            =   9840
      TabIndex        =   9
      Top             =   7080
      Width           =   615
   End
   Begin VB.HScrollBar KPHScroll 
      Height          =   375
      Left            =   7680
      Max             =   100
      TabIndex        =   4
      Top             =   7680
      Value           =   1
      Width           =   1935
   End
   Begin VB.HScrollBar KDHScroll 
      Height          =   375
      Left            =   7680
      Max             =   100
      TabIndex        =   3
      Top             =   8760
      Width           =   1935
   End
   Begin VB.HScrollBar KIHScroll 
      Height          =   375
      Left            =   7680
      Max             =   100
      TabIndex        =   2
      Top             =   8280
      Value           =   1
      Width           =   1935
   End
   Begin VB.Timer Timer4 
      Enabled         =   0   'False
      Interval        =   200
      Left            =   2040
      Top             =   2520
   End
   Begin VB.PictureBox table 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00FFFFFF&
      FillColor       =   &H00FFFFFF&
      Height          =   5775
      Left            =   3960
      ScaleHeight     =   5715
      ScaleWidth      =   7155
      TabIndex        =   1
      Top             =   1200
      Width           =   7215
   End
   Begin VB.HScrollBar HScroll1 
      Height          =   375
      Left            =   7680
      Max             =   100
      TabIndex        =   0
      Top             =   7080
      Width           =   1935
   End
   Begin VB.Label KDLabel 
      Caption         =   "KD:"
      Height          =   375
      Left            =   6360
      TabIndex        =   8
      Top             =   8760
      Width           =   1215
   End
   Begin VB.Label KILabel 
      Caption         =   "KI:"
      Height          =   375
      Left            =   6360
      TabIndex        =   7
      Top             =   8160
      Width           =   1215
   End
   Begin VB.Label KPLabel 
      Caption         =   "KP:"
      Height          =   375
      Left            =   6360
      TabIndex        =   6
      Top             =   7680
      Width           =   1215
   End
   Begin VB.Label Label1 
      Caption         =   "Label1"
      Height          =   255
      Left            =   3960
      TabIndex        =   5
      Top             =   7200
      Width           =   3615
   End
End
Attribute VB_Name = "PIDForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim T As Integer
Dim realT As Single
Dim tempT(1 To 100) As Single
Dim receiveP As Integer

Dim UK As Single
Dim UK_1 As Single
Dim eK As Single
Dim eK_1 As Single
Dim eK_2 As Single
Dim Kp As Single
Dim Ki As Single
Dim Kd As Single
Dim Upk As Single
Dim Uik As Single
Dim Uik_1 As Single
Dim Udk As Single

Dim OK As Single
Dim OK_1 As Single
Dim OK_2 As Single



Private Sub Command1_Click()
 receiveP = 0
  
 initTable
 
 UK_1 = 0
 eK_1 = 0
 eK_2 = 0
 Uik_1 = 0
 
 OK_1 = 0
 OK_2 = 0



Timer4.Enabled = True
End Sub

Private Sub Command2_Click()
Timer4.Enabled = False
End Sub

Private Sub Form_Load()
  
 receiveP = 0
 
 HScroll1.Value = 50
 
 initTable
 
 UK_1 = 0
 eK_1 = 0
 eK_2 = 0
 Uik_1 = 0
 
 Kp = 0.1
 Ki = 0
 Kd = 0
 
 KPHScroll.Value = Kp * 100
 KIHScroll.Value = Ki * 100
 KDHScroll.Value = Kd * 100
 KDLabel.Caption = "KD设定: " + Str$(Kd)
 KPLabel.Caption = "KP设定: " + Str$(Kp)
 KILabel.Caption = "KI设定: " + Str$(Ki)
 
 
 OK_1 = 0
 OK_2 = 0
 
 End Sub
Private Sub KDHScroll_Change()
Kd = KDHScroll.Value / 100
KDLabel.Caption = "KD设定: " + Str$(Kd)
End Sub
Private Sub KIHScroll_Change()
Ki = KIHScroll.Value / 100
KILabel.Caption = "KI设定: " + Str$(Ki)
End Sub

Private Sub KPHScroll_Change()
Kp = KPHScroll.Value / 100
KPLabel.Caption = "KP设定: " + Str$(Kp)
End Sub
Private Sub HScroll1_Change()
T = HScroll1.Value
initTable
Label1.Caption = "设定温度: " + Str$(T) + "   " + " 当前温度: " + Str$(OK)
End Sub

Private Sub Timer4_Timer()


eK = T - OK

Upk = Kp * eK
Uik = Ki * eK + Uik_1
Udk = Kd * (eK - eK_1)

UK = Upk + Uik + Udk

OK = UK_1 + OK_1 / (1 + OK_1 ^ 2)

OK_2 = OK_1
OK_1 = OK

UK_1 = UK
eK_2 = eK_1
eK_1 = eK
Uik_1 = Uik


 receiveP = receiveP + 1
  tempT(receiveP) = OK
   
 
  
 If receiveP = 100 Then                                 '显示数据左移一位
   For i = 1 To 99
       tempT(i) = tempT(i + 1)
   Next
    
    receiveP = 99
 End If
     
  initTable                                             '数据显示刷新
  drawTable
  Label1.Caption = "设定温度: " + Str$(T) + "   " + " 当前温度: " + Str$(OK)


End Sub

Public Sub drawTable()
Dim width As Single
Dim height As Single
Dim oriX As Single
Dim oriY As Single
Dim aimX As Single
Dim aimY As Single
Dim oldx As Single
Dim oldy As Single
Dim tempStr As String
Dim widthStr As Single
Dim heightStr As Single


width = table.width
height = table.height
oriX = width / 12
oriY = 7 * height / 8
oldx = oriX
oldy = oriY


disNumber = 100

For i = 1 To receiveP - 1        '画温度曲线
    oldx = i * 10 * width / (12# * disNumber) + oriX
    oldy = oriY - tempT(i) * 6 * height / (8 * 100)
    aimX = (i + 1) * 10 * width / (12# * disNumber) + oriX
    aimY = oriY - tempT(i + 1) * 6 * height / (8 * 100)
    table.Line (oldx, oldy)-(aimX, aimY), vbBlue
    Next
   
 
oldx = oriX                      '恢复0水平线
aimX = 11 * width / 12
oldy = oriY
aimY = oldy
table.DrawStyle = 0
table.Line (oldx, oldy)-(aimX, aimY), vbBlack

End Sub

Public Sub initTable()
Dim width As Single
Dim height As Single
Dim oriX As Single
Dim oriY As Single
Dim aimX As Single
Dim aimY As Single
Dim oldx As Single
Dim oldy As Single
Dim tempStr As String
Dim widthStr As Single
Dim heightStr As Single

table.Cls

width = table.width
height = table.height
oriX = width / 12
oriY = 7 * height / 8
oldx = oriX
oldy = oriY

aimX = 11 * width / 12
aimY = oldy
table.Line (oldx, oldy)-(aimX, aimY)


aimX = oriX
aimY = height / 8
table.Line (oldx, oldy)-(aimX, aimY)


oldx = oriX
aimX = 11 * width / 12

oldy = oriY - T * 6 * height / (8 * 100)
aimY = oldy
table.Line (oldx, oldy)-(aimX, aimY), vbRed


oldx = oriX
aimX = oldx + 50
For i = 1 To 10
    oldy = oriY - i * 6 * height / (8 * 10)
    aimY = oldy
    table.Line (oldx, oldy)-(aimX, aimY)
    tempStr = i & "0"
    widthStr = TextWidth(tempStr)
    heightStr = TextHeight(tempStr)
    table.CurrentX = oldx - widthStr - 50
    table.CurrentY = oldy - heightStr / 2
    table.Print tempStr
    Next i
    
table.CurrentX = width / 5
table.CurrentY = height / 20
tempStr = "温度"
heightStr = TextHeight(tempStr)
table.CurrentY = table.CurrentY - heightStr / 2
table.CurrentX = table.CurrentX - 1000
table.Print tempStr
    

disNumber = 100

oldy = oriY
aimY = oldy - 50
For i = 1 To 10
    oldx = oriX + i * 10 * width / (12 * 10)
    aimX = oldx
    table.Line (oldx, oldy)-(aimX, aimY)
    tempStr = i * disNumber / 10
    widthStr = TextWidth(tempStr)
    heightStr = TextHeight(tempStr)
    table.CurrentX = oldx - widthStr / 2
    table.CurrentY = oldy + heightStr / 2
    table.Print tempStr
    Next


End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -