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

📄 motordriver.frm

📁 VB控制三维云台PID调节源程序
💻 FRM
📖 第 1 页 / 共 2 页
字号:
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   0
         TabIndex        =   2
         Top             =   0
         Width           =   855
      End
      Begin VB.Label Label31 
         BackColor       =   &H80000018&
         Caption         =   "桔色:罗盘值"
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   7.5
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   0
         TabIndex        =   1
         Top             =   240
         Width           =   855
      End
      Begin VB.Shape Shape1 
         BorderColor     =   &H80000018&
         DrawMode        =   14  'Copy Pen
         FillColor       =   &H00004080&
         FillStyle       =   0  'Solid
         Height          =   255
         Left            =   720
         Shape           =   3  'Circle
         Top             =   720
         Width           =   255
      End
   End
   Begin VB.Label Label26 
      Caption         =   "Angle of given roll:"
      Height          =   375
      Left            =   3960
      TabIndex        =   61
      Top             =   1680
      Width           =   2175
   End
   Begin VB.Label Label1 
      BackColor       =   &H80000004&
      Caption         =   "Yaw:"
      Height          =   255
      Left            =   120
      TabIndex        =   59
      Top             =   840
      Width           =   1455
   End
   Begin VB.Label Label2 
      Caption         =   "Roll:"
      Height          =   255
      Left            =   3600
      TabIndex        =   58
      Top             =   840
      Width           =   1455
   End
   Begin VB.Label Label3 
      Caption         =   "Pitch:"
      Height          =   255
      Left            =   7560
      TabIndex        =   57
      Top             =   840
      Width           =   1455
   End
   Begin VB.Label Label4 
      Caption         =   "单位:度"
      Height          =   495
      Left            =   7680
      TabIndex        =   56
      Top             =   360
      Width           =   855
   End
   Begin VB.Label Label5 
      Caption         =   "Time:"
      Height          =   255
      Left            =   120
      TabIndex        =   55
      Top             =   0
      Width           =   735
   End
   Begin VB.Label Label6 
      Caption         =   "Angle of given yaw:"
      Height          =   255
      Left            =   120
      TabIndex        =   54
      Top             =   1680
      Width           =   2535
   End
   Begin VB.Label Label10 
      Caption         =   "controlU"
      Height          =   375
      Left            =   3000
      TabIndex        =   53
      Top             =   0
      Width           =   1335
   End
   Begin VB.Label Label7 
      Caption         =   "PP:"
      Height          =   375
      Left            =   7320
      TabIndex        =   52
      Top             =   2760
      Width           =   615
   End
   Begin VB.Label Label8 
      Caption         =   "PI"
      Height          =   375
      Left            =   7320
      TabIndex        =   51
      Top             =   3120
      Width           =   495
   End
   Begin VB.Label Label9 
      Caption         =   "PD"
      Height          =   495
      Left            =   7320
      TabIndex        =   50
      Top             =   3480
      Width           =   615
   End
   Begin VB.Label Label11 
      Caption         =   "VP:"
      Height          =   375
      Left            =   7320
      TabIndex        =   49
      Top             =   4080
      Width           =   615
   End
   Begin VB.Label Label12 
      Caption         =   "VI:"
      Height          =   375
      Left            =   7320
      TabIndex        =   48
      Top             =   4440
      Width           =   615
   End
   Begin VB.Label Label13 
      Caption         =   "VD"
      Height          =   375
      Left            =   7320
      TabIndex        =   47
      Top             =   4800
      Width           =   495
   End
   Begin VB.Shape Shape3 
      Height          =   495
      Left            =   1080
      Top             =   3360
      Width           =   1215
   End
   Begin VB.Label Label27 
      Caption         =   "0"
      Height          =   255
      Left            =   2640
      TabIndex        =   46
      Top             =   3600
      Width           =   375
   End
   Begin VB.Label Label28 
      Caption         =   "270"
      Height          =   255
      Left            =   1440
      TabIndex        =   45
      Top             =   4800
      Width           =   375
   End
   Begin VB.Label Label29 
      Caption         =   "180"
      Height          =   255
      Left            =   240
      TabIndex        =   44
      Top             =   3600
      Width           =   375
   End
   Begin VB.Label Label30 
      Caption         =   "90"
      Height          =   255
      Left            =   1440
      TabIndex        =   43
      Top             =   2640
      Width           =   495
   End
End
Attribute VB_Name = "form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Public Yaw, Pitch, Roll As Integer
Public singleEP As Single, singleSumEP As Single, singleLastEP As Single, singleLastEPP As Single
Public singleU As Single, lastV As Single, lastVV As Single
Public flag As Boolean
Private strReceiveBuff As String

Private Sub Form_Load()
If MSComm2.PortOpen = False Then
    MSComm2.PortOpen = True
End If
If MSComm1.PortOpen = False Then
    MSComm1.PortOpen = True
End If
    strReceiveBuff = ""
    singleLastEP = 0
    singleEP = 0
    singleSumEP = 0
    singleU = 0
    lastV = 0
    lastVV = 0
    singleLastEPP = 0
    flag = False
    brake1 = False
    brake2 = False
End Sub

Private Sub Form_Unload(Cancel As Integer)
    If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
    If MSComm2.PortOpen = True Then MSComm2.PortOpen = False
End Sub

Private Sub HScroll1_change()
    'singleEP = HScroll1.Value - Val(txtYaw.Text)
    'If singleEP > 180 Then singleEP = singleEP - 360
    'If singleEP < -180 Then singleEP = singleEP + 360
    Text1.Text = CStr(HScroll1.Value)
    Text2.Text = CStr(CInt(Yaw))
    Text3.Text = CStr(CInt(singleEP))
    Label6.Caption = "Angle to Rotate:" & CStr(HScroll1.Value)
    Line1.X2 = 840 * Cos(-HScroll1.Value * 6.283 / 360) + 840
    Line1.Y2 = 840 * Sin(-HScroll1.Value * 6.283 / 360) + 840
End Sub

Private Sub HScroll1_Scroll()
    'singleEP = HScroll1.Value - Val(txtYaw.Text)
    'If singleEP > 180 Then singleEP = singleEP - 360
    'If singleEP < -180 Then singleEP = singleEP + 360
    Text1.Text = CStr(HScroll1.Value)
    Text2.Text = CStr(CInt(Yaw))
    Text3.Text = CStr(CInt(singleEP))
    Label6.Caption = "Angle to Rotate:" & CStr(HScroll1.Value)
    Line1.X2 = 840 * Cos(-HScroll1.Value * 6.283 / 360) + 840
    Line1.Y2 = 840 * Sin(-HScroll1.Value * 6.283 / 360) + 840
End Sub

Private Sub HScroll2_Change()
    singleEP = HScroll2.Value - Val(txtRoll.Text)
    Text1.Text = CStr(HScroll2.Value)
    Text2.Text = CStr(CInt(Roll))
    Text3.Text = CStr(CInt(singleEP))
    Label26.Caption = "Angle of given roll:" & CStr(HScroll2.Value)
    Line1.X2 = 840 * Cos(HScroll2.Value * 6.283 / 360) + 840
    Line1.Y2 = 840 * Sin(-HScroll2.Value * 6.283 / 360) + 840
End Sub

Private Sub HScroll2_Scroll()
    singleEP = HScroll2.Value - Val(txtRoll.Text)
    Text1.Text = CStr(HScroll2.Value)
    Text2.Text = CStr(CInt(Roll))
    Text3.Text = CStr(CInt(singleEP))
    Label26.Caption = "Angle of given roll:" & CStr(HScroll2.Value)
    Line1.X2 = 840 * Cos(HScroll2.Value * 6.283 / 360) + 840
    Line1.Y2 = 840 * Sin(-HScroll2.Value * 6.283 / 360) + 840
End Sub

Private Sub HScrollPD_Change()
    Text9.Text = CStr(HScrollPD.Value / 10)
End Sub

Private Sub HScrollPI_Change()
    Text8.Text = CStr(HScrollPI.Value)
End Sub

Private Sub HScrollpp_Change()
    Text7.Text = CStr(HScrollpp.Value / 50)
End Sub

Private Sub HScrollVP_Change()
   Text10.Text = HScrollVP.Value
   If HScrollVP < 16 Then
        MSComm1.Output = "^11 0" & Hex(HScrollVP.Value) & Chr(13)
   Else
        MSComm1.Output = "^11 " & Hex(HScrollVP.Value) & Chr(13)
   End If
   
End Sub

Private Sub HScrollVI_Change()
    Text11.Text = HScrollVI.Value
    If HScrollVI < 16 Then
        MSComm1.Output = "^0F 0" & Hex(HScrollVI.Value) & Chr(13)
   Else
        MSComm1.Output = "^0F " & Hex(HScrollVI.Value) & Chr(13)
   
   End If
End Sub
Private Sub HScrollVD_Change()
    Text12.Text = HScrollVD.Value
    If HScrollVD < 16 Then
        MSComm1.Output = "^10 0" & Hex(HScrollVD.Value) & Chr(13)
   Else
        MSComm1.Output = "^10 " & Hex(HScrollVD.Value) & Chr(13)
   End If
End Sub


Private Sub Speed_Change()
    If Speed.Value > 0 Then
        If Speed.Value < 16 Then
            MSComm1.Output = "!A0" & Hex(Abs(Speed.Value)) & Chr(13)
        Else
            MSComm1.Output = "!A" & Hex(Abs(Speed.Value)) & Chr(13)
        End If
    Else
        If Speed.Value > -16 Then
            MSComm1.Output = "!a0" & Hex(Abs(Speed.Value)) & Chr(13)
        Else
            MSComm1.Output = "!a" & Hex(Abs(Speed.Value)) & Chr(13)
        End If
    End If
End Sub

Private Sub MSComm2_OnComm()
    Dim strBuff, strBuff1 As String
    Dim i, j, k As Integer
    
    strBuff = MSComm2.Input
    k = Len(strBuff)
    For i = 1 To k
        strBuff1 = Mid(strBuff, i, 1)
        Select Case strBuff1
        Case Chr(13)
        Case Chr(10)
            '**********   receive one Chr     **************
            Doevent
            '*****************   **********
            strReceiveBuff = ""
        Case Else
            strReceiveBuff = strReceiveBuff & strBuff1
        End Select
    Next
End Sub
Private Sub Doevent()

    Dim i, j, k, ilen As Integer
    Dim str1 As String
    Dim lngT As Long
    
    ilen = Len(Trim(strReceiveBuff))
    i = InStr(1, strReceiveBuff, ",")
    j = InStr(i + 1, strReceiveBuff, ",")
    If (i = 0 Or j = 0) Then Exit Sub
    str1 = Mid(strReceiveBuff, 1, i - 1)
    Yaw = CInt(360 - Val(str1))
    'Line2.X2 = 840 * Cos(-Yaw * 6.283 / 360) + 840
    'Line2.Y2 = 840 * Sin(-Yaw * 6.283 / 360) + 840
    
    str1 = Mid(strReceiveBuff, i + 1, j - i - 1)
    Pitch = Val(str1)
    str1 = Mid(strReceiveBuff, j + 1, ilen)
    Roll = Val(str1)
    Line2.X2 = 840 * Cos(Roll * 6.283 / 360) + 840
    Line2.Y2 = 840 * Sin(-Roll * 6.283 / 360) + 840
    
    txtYaw.Text = Format(Yaw, "0.0")
    'txtPitch.Text = Format(Pitch, "0.0")
    txtRoll.Text = Format(Roll, "0.0")
    lngT = timeGetTime
    txtTimeBox.Text = CStr(lngT)
    
End Sub

Private Sub Timer2_Timer()
    Call getU
    'Call improvedPID
    Label10.Caption = CInt(singleU)
    Speed.Value = CInt(singleU)
End Sub

Private Sub txtRoll_Change()
    singleEP = HScroll2.Value - Val(txtRoll.Text)
    Text1.Text = CStr(HScroll2.Value)
    Text2.Text = CStr(CInt(Roll))
    Text3.Text = CStr(CInt(singleEP))
End Sub

Private Sub txtYaw_Change()
       
    'singleEP = HScroll1.Value - Val(txtYaw.Text)
    'If singleEP > 180 Then singleEP = singleEP - 360
    'If singleEP < -180 Then singleEP = singleEP + 360
    'Text1.Text = CStr(HScroll1.Value)
    'Text2.Text = CStr(CInt(Yaw))
    'Text3.Text = CStr(CInt(singleEP))
    
End Sub







⌨️ 快捷键说明

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