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

📄 tracking.frm

📁 vb 调用matlab方法实例
💻 FRM
📖 第 1 页 / 共 2 页
字号:
VERSION 5.00
Begin VB.Form main_form 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Tracking system demonstration"
   ClientHeight    =   6975
   ClientLeft      =   915
   ClientTop       =   1005
   ClientWidth     =   10275
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   Moveable        =   0   'False
   ScaleHeight     =   6975
   ScaleWidth      =   10275
   Tag             =   "f1"
   Begin VB.Frame control_frame 
      Height          =   6735
      Left            =   7200
      TabIndex        =   0
      Top             =   120
      Width           =   2895
      Begin VB.CommandButton INFO_Button 
         Caption         =   "INFO"
         Height          =   495
         Left            =   1440
         TabIndex        =   39
         Top             =   4440
         Width           =   1215
      End
      Begin VB.CheckBox check_zoom 
         Caption         =   "Zoom"
         Height          =   255
         Left            =   240
         TabIndex        =   38
         Top             =   4560
         Width           =   1095
      End
      Begin VB.HScrollBar select_e 
         Height          =   255
         Left            =   120
         TabIndex        =   36
         Top             =   2280
         Visible         =   0   'False
         Width           =   2175
      End
      Begin VB.HScrollBar select_p 
         Height          =   255
         Left            =   120
         TabIndex        =   33
         Top             =   1680
         Visible         =   0   'False
         Width           =   2175
      End
      Begin VB.HScrollBar select_R4 
         Height          =   255
         Left            =   120
         TabIndex        =   29
         Top             =   3120
         Visible         =   0   'False
         Width           =   2175
      End
      Begin VB.OptionButton select_Ptr2 
         Caption         =   "Dive"
         Height          =   195
         Left            =   240
         TabIndex        =   11
         Top             =   3000
         Width           =   2535
      End
      Begin VB.HScrollBar select_R3 
         Height          =   255
         Left            =   120
         TabIndex        =   26
         Top             =   2520
         Visible         =   0   'False
         Width           =   2175
      End
      Begin VB.HScrollBar select_R2 
         Height          =   255
         Left            =   120
         TabIndex        =   23
         Top             =   1920
         Visible         =   0   'False
         Width           =   2175
      End
      Begin VB.HScrollBar select_R1 
         Height          =   255
         Left            =   120
         TabIndex        =   21
         Top             =   1320
         Visible         =   0   'False
         Width           =   2175
      End
      Begin VB.TextBox text_Mtime 
         Alignment       =   2  'Center
         BackColor       =   &H8000000B&
         Height          =   225
         Left            =   2040
         MaxLength       =   3
         TabIndex        =   18
         Text            =   "60"
         Top             =   3960
         Width           =   495
      End
      Begin VB.CommandButton Quit_Button 
         Caption         =   "Quit"
         Height          =   495
         Left            =   1560
         TabIndex        =   15
         Top             =   6000
         Width           =   1215
      End
      Begin VB.CommandButton Clear_Button 
         Caption         =   "Clear"
         Height          =   495
         Left            =   120
         TabIndex        =   14
         Top             =   6000
         Width           =   1215
      End
      Begin VB.CommandButton Process_Button 
         Caption         =   "Process"
         Height          =   615
         Left            =   120
         TabIndex        =   13
         Top             =   5160
         Width           =   2655
      End
      Begin VB.OptionButton select_Ptr3 
         Caption         =   "Rescue"
         Height          =   255
         Left            =   240
         TabIndex        =   12
         Top             =   3360
         Width           =   2535
      End
      Begin VB.OptionButton select_Ptr1 
         Caption         =   "Straight"
         Height          =   255
         Left            =   240
         TabIndex        =   10
         Top             =   2640
         Value           =   -1  'True
         Width           =   2415
      End
      Begin VB.HScrollBar select_Pvel 
         Height          =   255
         Left            =   120
         TabIndex        =   7
         Top             =   1920
         Width           =   2175
      End
      Begin VB.HScrollBar select_Rvel 
         Height          =   255
         Left            =   120
         TabIndex        =   4
         Top             =   1320
         Width           =   2175
      End
      Begin VB.ComboBox selectMode 
         Height          =   315
         Left            =   120
         TabIndex        =   2
         Text            =   "Rocket & Plane"
         Top             =   480
         Width           =   2295
      End
      Begin VB.Label text_e 
         Alignment       =   2  'Center
         BackColor       =   &H80000009&
         BorderStyle     =   1  'Fixed Single
         Height          =   255
         Left            =   2400
         TabIndex        =   37
         Top             =   2280
         Visible         =   0   'False
         Width           =   375
      End
      Begin VB.Label label_Or 
         Caption         =   "Choose r value"
         Height          =   255
         Index           =   2
         Left            =   120
         TabIndex        =   35
         Top             =   2040
         Visible         =   0   'False
         Width           =   2655
      End
      Begin VB.Label text_p 
         Alignment       =   2  'Center
         BackColor       =   &H80000009&
         BorderStyle     =   1  'Fixed Single
         Height          =   255
         Left            =   2400
         TabIndex        =   34
         Top             =   1680
         Visible         =   0   'False
         Width           =   375
      End
      Begin VB.Label label_Or 
         Caption         =   "Choose p value"
         Height          =   255
         Index           =   1
         Left            =   120
         TabIndex        =   32
         Top             =   1440
         Visible         =   0   'False
         Width           =   2655
      End
      Begin VB.Label label_Or 
         Caption         =   "Orbit equation used r=p/(1+e*cos(a))"
         Height          =   255
         Index           =   0
         Left            =   120
         TabIndex        =   31
         Top             =   1080
         Visible         =   0   'False
         Width           =   2655
      End
      Begin VB.Label text_R4 
         Alignment       =   2  'Center
         BackColor       =   &H80000009&
         BorderStyle     =   1  'Fixed Single
         Height          =   255
         Left            =   2400
         TabIndex        =   30
         Top             =   3120
         Visible         =   0   'False
         Width           =   375
      End
      Begin VB.Label Label_R 
         Caption         =   "Choose Rocket 4 Velocity"
         Height          =   255
         Index           =   3
         Left            =   120
         TabIndex        =   28
         Top             =   2880
         Visible         =   0   'False
         Width           =   2655
      End
      Begin VB.Label text_R3 
         Alignment       =   2  'Center
         BackColor       =   &H80000009&
         BorderStyle     =   1  'Fixed Single
         Height          =   255
         Left            =   2400
         TabIndex        =   27
         Top             =   2520
         Visible         =   0   'False
         Width           =   375
      End
      Begin VB.Label Label_R 
         Caption         =   "Choose Rocket 3 Velocity"
         Height          =   255
         Index           =   2
         Left            =   120
         TabIndex        =   25
         Top             =   2280
         Visible         =   0   'False
         Width           =   2655
      End
      Begin VB.Label text_R2 
         Alignment       =   2  'Center
         BackColor       =   &H80000009&
         BorderStyle     =   1  'Fixed Single
         Height          =   255
         Left            =   2400
         TabIndex        =   24
         Top             =   1920
         Visible         =   0   'False
         Width           =   375
      End
      Begin VB.Label text_R1 
         Alignment       =   2  'Center
         BackColor       =   &H80000009&
         BorderStyle     =   1  'Fixed Single
         Height          =   255
         Left            =   2400
         TabIndex        =   22
         Top             =   1320
         Visible         =   0   'False
         Width           =   375
      End
      Begin VB.Label Label_R 
         Caption         =   "Choose Rocket 2 Velocity"
         Height          =   255
         Index           =   1
         Left            =   120
         TabIndex        =   20
         Top             =   1680
         Visible         =   0   'False
         Width           =   2655
      End
      Begin VB.Label label_Mtime 
         Caption         =   "Maximal simulation time"
         Height          =   255
         Left            =   120
         TabIndex        =   17
         Top             =   3960
         Width           =   1815
      End
      Begin VB.Label label_traj 
         Caption         =   "Choose Plane Trajectory"
         Height          =   255
         Left            =   120
         TabIndex        =   9
         Top             =   2280
         Width           =   2655
      End
      Begin VB.Label text_Pvel 
         Alignment       =   2  'Center
         BackColor       =   &H8000000E&
         BorderStyle     =   1  'Fixed Single
         Height          =   255
         Left            =   2400
         TabIndex        =   8
         Top             =   1920
         Width           =   375
      End
      Begin VB.Label label_Pvel 
         Caption         =   "Choose Plane Velocity"
         Height          =   255
         Left            =   120
         TabIndex        =   6
         Top             =   1680
         Width           =   2655
      End
      Begin VB.Label text_Rvel 
         Alignment       =   2  'Center
         BackColor       =   &H80000009&
         BorderStyle     =   1  'Fixed Single
         Height          =   255
         Left            =   2400
         TabIndex        =   5
         Top             =   1320
         Width           =   375
      End
      Begin VB.Label demonstration_label 
         Caption         =   "Select a demonstration mode"
         Height          =   255
         Left            =   120
         TabIndex        =   1
         Top             =   240
         Width           =   2655
      End
      Begin VB.Label Label_R 
         Caption         =   "Choose Rocket 1 Velocity"
         Height          =   255
         Index           =   0
         Left            =   120
         TabIndex        =   19
         Top             =   1080
         Visible         =   0   'False
         Width           =   2655
      End
      Begin VB.Label label_Rvel 
         Caption         =   "Choose Rocket Velocity"
         Height          =   255
         Left            =   120
         TabIndex        =   3
         Top             =   1080
         Width           =   2655
      End
   End
   Begin VB.PictureBox Window 
      BackColor       =   &H8000000A&
      Height          =   6615
      Left            =   120
      ScaleHeight     =   6555
      ScaleWidth      =   6915
      TabIndex        =   16
      Top             =   240
      Width           =   6975
   End
End
Attribute VB_Name = "main_form"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim ax As Variant
Dim pi As Double

Sub demo1()

  axParameters = zeros(1, 3)
  dataP_x = zeros(1, 9)
  dataP_y = zeros(1, 9)
  dataP = zeros(2, 9)
  dataR_x = zeros(1, 7)
  dataR_y = zeros(1, 7)
  dataR = zeros(2, 7)

  vel_R = select_Rvel.Value
  vel_P = select_Pvel.Value
  
  xR = 0   'initialization of Plane & Rocket coordinates
  yR = 0
  xP = 0
  yP = 150
  
  xRold = xR
  yRold = yR
  xPold = xP
  yPold = yP

  velX = 0      'init. of rocket velocity
  velY = vel_R

  d = 100
  t = 0
  dt = 0.2

  omega = 0.1 * vel_P / 15
  R_ = 150


  maxT = str2num(text_Mtime).Simple
   If IsEmpty(maxT) Then
        maxT = 60
        text_Mtime.Text = 60
   End If
     
  hold ("on")
  axParameters(1, 1) = -3
  axParameters(1, 2) = 200
  axParameters(1, 3) = -3
  axParameters(1, 4) = 300
  axis (axParameters)
  vbrefresh
  
  'Plane graphical data
    dataP_x(1, 1) = 0
    dataP_x(1, 2) = -1.2
    dataP_x(1, 3) = 0
    dataP_x(1, 4) = 3
    dataP_x(1, 5) = 2
    dataP_x(1, 6) = 3
    dataP_x(1, 7) = 2
    dataP_x(1, 8) = 3
    dataP_x(1, 9) = 5
    dataP_y(1, 1) = 0
    dataP_y(1, 2) = 1.2
    dataP_y(1, 3) = 0
    dataP_y(1, 4) = 0
    dataP_y(1, 5) = 0 + 2
    dataP_y(1, 6) = 0
    dataP_y(1, 7) = 0 - 2
    dataP_y(1, 8) = 0
    dataP_y(1, 9) = 0
  
  
     dataP(1, 1) = 0
     dataP(1, 2) = -1.2
     dataP(1, 3) = 0
     dataP(1, 4) = 3
     dataP(1, 5) = 2
     dataP(1, 6) = 3
     dataP(1, 7) = 2
     dataP(1, 8) = 3
     dataP(1, 9) = 5
     dataP(2, 1) = 0
     dataP(2, 2) = 1.2
     dataP(2, 3) = 0
     dataP(2, 4) = 0
     dataP(2, 5) = 0 + 2
     dataP(2, 6) = 0
     dataP(2, 7) = 0 - 2
     dataP(2, 8) = 0
     dataP(2, 9) = 0
  
 Plane = mline(plus(dataP_x, xP), plus(dataP_y, yP), "erasemode", "none", "Color", "blue", "LineWidth", 1)
 vbrefresh
 
'Rocket graphical data
   
    dataR_x(1, 1) = 0
    dataR_x(1, 2) = -2.5
    dataR_x(1, 3) = -3.5
    dataR_x(1, 4) = -2.5
    dataR_x(1, 5) = -3.5
    dataR_x(1, 6) = -3.5
    dataR_x(1, 7) = -3.5
    dataR_y(1, 1) = 0
    dataR_y(1, 2) = 0
    dataR_y(1, 3) = 1
    dataR_y(1, 4) = 0
    dataR_y(1, 5) = -1
    dataR_y(1, 6) = 0
    dataR_y(1, 7) = 0
  
  
    dataR(1, 1) = 0
    dataR(1, 2) = -2.5
    dataR(1, 3) = -3.5
    dataR(1, 4) = -2.5
    dataR(1, 5) = -3.5
    dataR(1, 6) = -3.5
    dataR(1, 7) = -3.5
    dataR(2, 1) = 0
    dataR(2, 2) = 0
    dataR(2, 3) = 1
    dataR(2, 4) = 0
    dataR(2, 5) = -1
    dataR(2, 6) = 0
    dataR(2, 7) = 0

 Rocket = mline("XData", plus(dataR_x, xR), "YData", plus(dataR_y, yR), "Color", "red", "LineWidth", 2, "erasemode", "none")
      

' Variables initialization
 P = zeros(2, 2)
 R = zeros(2, 2)
 
 trace_Px = zeros(1, 2)
 trace_Py = zeros(1, 2)
 trace_Rx = zeros(1, 2)
 trace_Ry = zeros(1, 2)


 Do While (d > 3) And (t < maxT)
   ' Plane trajectory calculations
    If select_Ptr1.Value = True Then
        xP = vel_P * t
        yP = yP
      ElseIf select_Ptr2.Value = True Then
        teta = omega * t
        xP = R_ * Cos(pi / 2 - teta)
        yP = R_ * Sin(pi / 2 - teta)
      ElseIf select_Ptr3.Value = True Then
        teta = omega * t
        xP = R_ * Cos(teta - pi / 2)
        yP = 2 * R_ + R_ * Sin(teta - pi / 2)
   End If
      
   xR = xR + velX * dt
   yR = yR + velY * dt
   
   ' distance bitween P. & R. calculation
   dx = xR - xP
   dy = yR - yP
   d = (dx ^ 2 + dy ^ 2) ^ 0.5

   ' Turn the rocket face to plane
   velX = -vel_R * dx / d
   velY = -vel_R * dy / d
   t = t + dt
   
   If dx = 0 Then
       alphaR = pi / 2 * sign(dy).Simple
     Else
       alphaR = atan(dy / dx).Simple
       'If (alphaR < 0) And (dy < 0) And (dx > 0) Then
       '    alphaR = alphaR + pi
       'ElseIf (alphaR > 0) And (dy > 0) And (dx > 0) Then
       '    alphaR = alphaR + pi
       'End If
   End If

   If (xPold - xP) = 0 Then
        alphaP = pi / 2 * sign(yPold - yP).Simple
     Else
        alphaP = atan((yPold - yP) / (xPold - xP)).Simple
        'If (alphaP < 0) And ((yPold - yP) < 0) And ((xPold - xP) > 0) Then
        '   alphaP = alphaP + pi
        'ElseIf (alphaP > 0) And ((yPold - yP) > 0) And ((xPold - xP) > 0) Then
        '   alphaP = alphaP + pi
        'End If
   End If
   
   
      P(1, 1) = mcos(alphaP)
      P(1, 2) = msin(alphaP)
      P(2, 1) = uminus(msin(alphaP))
      P(2, 2) = mcos(alphaP)
      P = inv(P)
    
      R(1, 1) = mcos(alphaR)
      R(1, 2) = msin(alphaR)

⌨️ 快捷键说明

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