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

📄 frmmain.frm

📁 850运动控制卡的详细开发资料
💻 FRM
📖 第 1 页 / 共 3 页
字号:
Private Sub chkDemo_z_Click()
 Dim i As Integer
 
     If chkDemo_z.value = vbChecked Then
        m_bEnableDemo_z = True
        txtPulseCount_z.BackColor = &H80000005
        txtPulseCount_z.SetFocus
    
    Else
        m_bEnableDemo_z = False
        txtPulseCount_z.BackColor = &H8000000B
                sudden_stop cardno, 3
        
    End If
    txtPulseCount_z.Locked = Not m_bEnableDemo_z
End Sub

Private Sub chkSymmetryAcc_w_Click()
    If chkSymmetryAcc_w.value = vbChecked Then
        m_bEnableSymmetry_Acc_w = True
    Else
        m_bEnableSymmetry_Acc_w = False
    End If
End Sub

Private Sub chkSymmetryAcc_x_Click()
    If chkSymmetryAcc_x.value = vbChecked Then
        m_bEnableSymmetry_Acc_x = True
    Else
        m_bEnableSymmetry_Acc_x = False
    End If
End Sub

Private Sub chkSymmetryAcc_y_Click()
    If chkSymmetryAcc_y.value = vbChecked Then
        m_bEnableSymmetry_Acc_y = True
    Else
        m_bEnableSymmetry_Acc_y = False
    End If
End Sub

Private Sub chkSymmetryAcc_z_Click()
    If chkSymmetryAcc_z.value = vbChecked Then
        m_bEnableSymmetry_Acc_z = True
    Else
        m_bEnableSymmetry_Acc_z = False
    End If
End Sub



Private Sub Form_Load()
'   public variable is initialed here
    m_bEqualityVelocity = False
    m_bEnableCurve_S_Move = False
    m_nCard850Num = 0
    
    
    m_nStartV_x = 400
    m_nStartV_y = 400
    m_nStartV_z = 400
    m_nStartV_w = 400

    m_nRatio_x = 5
    m_nRatio_y = 5
    m_nRatio_z = 5
    m_nRatio_w = 5

    m_nVelocityAcc_x = 64
    m_nVelocityAcc_y = 64
    m_nVelocityAcc_z = 64
    m_nVelocityAcc_w = 64

    m_nVelocityDec_x = 64
    m_nVelocityDec_y = 64
    m_nVelocityDec_z = 64
    m_nVelocityDec_w = 64

    m_nDriveSpeed_x = 4000
    m_nDriveSpeed_y = 4000
    m_nDriveSpeed_z = 4000
    m_nDriveSpeed_w = 4000

    m_fAccTime_w = (m_nDriveSpeed_w - m_nStartV_w) / m_nVelocityAcc_w
    m_fAccTime_x = (m_nDriveSpeed_x - m_nStartV_x) / m_nVelocityAcc_x
    m_fAccTime_y = (m_nDriveSpeed_y - m_nStartV_y) / m_nVelocityAcc_y
    m_fAccTime_z = (m_nDriveSpeed_z - m_nStartV_z) / m_nVelocityAcc_z
    
    m_nLogicPos_x = 0
    m_nLogicPos_y = 0
    m_nLogicPos_z = 0
    m_nLogicPos_w = 0
    
    m_nCurrentSpeed_x = 0
    m_nCurrentSpeed_y = 0
    m_nCurrentSpeed_z = 0
    m_nCurrentSpeed_w = 0
    
 ' the variable of form level is initialed here
    m_bEnableDemo_w = False
    m_bEnableDemo_x = False
    m_bEnableDemo_y = False
    m_bEnableDemo_z = False
    
    m_bEnableSymmetry_Acc_w = False
    m_bEnableSymmetry_Acc_x = False
    m_bEnableSymmetry_Acc_y = False
    m_bEnableSymmetry_Acc_z = False
    
    m_bEnableCurve_S_Move = False
    

    cardno = 0
    Init850Card
    btnPMove.Enabled = True
    btnContinueMove.Enabled = True
   Timer1.Enabled = True
   
  
    
End Sub

Private Sub Init850Card()

 
    Const nCoefficient = 8000000
   Dim count As Integer
    
   count = adt850_initial
   

   
    

    
    If count < 1 Then
    
       MsgBox "控制卡未安装"
       
    '   End
       
   End If
    
    Dim nValue As Long
              set_command_pos cardno, 1, 0
              set_command_pos cardno, 2, 0
              set_command_pos cardno, 3, 0
              set_command_pos cardno, 4, 0

  
'------------------倍率=8000000/R-----------------------------------------
'函数set_range()中的最后一个参数 由R=8000000/倍率来确定.
'------------------设置倍率参数-------------------------------------------
            
            nValue = nCoefficient / m_nRatio_x
            set_range cardno, 1, nValue

            nValue = nCoefficient / m_nRatio_y
            set_range cardno, 2, nValue

            nValue = nCoefficient / m_nRatio_z
            set_range cardno, 3, nValue

            nValue = nCoefficient / m_nRatio_w
            set_range cardno, 4, nValue


            If Not m_bEqualityVelocity Then       '加/减速运动
                Dim bMode_Acc As Byte
   
                
               bMode_Acc = IIf(m_bEnableCurve_S_Move, 1, 0)
               
                
'---------------设为梯形/S形加减速.0为梯形,1为S形----------------------

                set_ad_mode cardno, 1, bMode_Acc
                set_ad_mode cardno, 2, bMode_Acc
                set_ad_mode cardno, 3, bMode_Acc
                set_ad_mode cardno, 4, bMode_Acc

'---------------对每轴设置,对称加减速/非对称加减速,0为对称,1为非对称----------------
 
                
                bMode_Acc = IIf(m_bEnableSymmetry_Acc_x, 1, 0)
                
                set_dec1_mode cardno, 1, bMode_Acc

                
                bMode_Acc = IIf(m_bEnableSymmetry_Acc_y, 1, 0)
                
                set_dec1_mode cardno, 2, bMode_Acc

               
                bMode_Acc = IIf(m_bEnableSymmetry_Acc_z, 1, 0)
                set_dec1_mode cardno, 3, bMode_Acc

              
                bMode_Acc = IIf(m_bEnableSymmetry_Acc_w, 1, 0)
                
                set_dec1_mode cardno, 4, bMode_Acc

'-----------------------采用自动减速方式-------------------------------------------------
                Dim j As Integer
                For j = 1 To 4
                    set_dec2_mode cardno, j, 0
                Next j

'-----------------------设置每轴的加速度-----------------------------------------------
'------------加速度的实际值为nValue=m_nVelocityAcc_x*125*m_nRatio_x--------------------
                set_acc cardno, 1, m_nVelocityAcc_x

'------------加速度的实际值为nValue=m_nVelocityAcc_y*125*m_nRatio_y--------------------
                set_acc cardno, 2, m_nVelocityAcc_y

'------------加速度的实际值为nValue=m_nVelocityAcc_z*125*m_nRatio_z--------------------
                set_acc cardno, 3, m_nVelocityAcc_z

'------------加速度的实际值为nValue=m_nVelocityAcc_w*125*m_nRatio_w--------------------
                set_acc cardno, 4, m_nVelocityAcc_w

'-----------------------设置每轴的减速度-----------------------------------------------
'------------减速度的实际值为nValue=m_nVelocityDec_x*125*m_nRatio_x--------------------
                set_dec cardno, 1, m_nVelocityDec_x
                
'------------减速度的实际值为nValue=m_nVelocityDec_y*125*m_nRatio_y--------------------
                set_dec cardno, 2, m_nVelocityDec_y

'------------减速度的实际值为nValue=m_nVelocityDec_z*125*m_nRatio_z--------------------
                set_dec cardno, 3, m_nVelocityDec_z

'------------减速度的实际值为nValue=m_nVelocityDec_w*125*m_nRatio_w--------------------
                set_dec cardno, 4, m_nVelocityDec_w

'-----------------------如果是S形加速运动,设置速度增加率.-----------------------------
                If m_bEnableCurve_S_Move Then
                
                  
            
                    Dim nAccValue As Long
                    If m_bEnableDemo_x Then
                       If m_fAccTime_x = 0 Then Exit Sub
                    nValue = m_nVelocityAcc_x / m_fAccTime_x
                    nAccValue = 62500000 * m_nRatio_x / nValue
                    set_acac cardno, 1, nAccValue
                    End If
                   If m_bEnableDemo_y Then
                       If m_fAccTime_y = 0 Then Exit Sub
                    nValue = m_nVelocityAcc_y / m_fAccTime_y
                    nAccValue = 62500000 * m_nRatio_y / nValue
                    set_acac cardno, 2, nAccValue
                    End If
                   If m_bEnableDemo_z Then
                       If m_fAccTime_z = 0 Then Exit Sub
                    nValue = m_nVelocityAcc_z / m_fAccTime_z
                    nAccValue = 62500000 * m_nRatio_z / nValue
                    set_acac cardno, 3, nAccValue
                    End If
                   If m_bEnableDemo_w Then
                       If m_fAccTime_w = 0 Then Exit Sub
                    nValue = m_nVelocityAcc_w / m_fAccTime_w
                    nAccValue = 62500000 * m_nRatio_w / nValue
                    set_acac cardno, 4, nAccValue
                    End If
                End If


            End If




End Sub
Private Function EnableWindow(ByVal bEnable As Boolean)
    chkCurve_S.Enabled = bEnable
    chkSymmetryAcc_x.Enabled = bEnable
    chkSymmetryAcc_y.Enabled = bEnable
    chkSymmetryAcc_z.Enabled = bEnable
    chkSymmetryAcc_w.Enabled = bEnable
    frmeMoveType.Enabled = bEnable
        
End Function



Private Sub optnAccMove_Click()
 Dim bEnable As Boolean
 
  bEnable = True
  m_bEqualityVelocity = False
 
  EnableWindow bEnable
  
   
End Sub

Private Sub optnEqualityMove_Click()

 Dim bEnable As Boolean
 
    bEnable = False
    m_bEqualityVelocity = True
 
    EnableWindow bEnable

End Sub

Private Sub StopAllAxis()

                If m_bEnableDemo_x = True Then sudden_stop cardno, 1
                If m_bEnableDemo_y = True Then sudden_stop cardno, 2
                If m_bEnableDemo_z = True Then sudden_stop cardno, 3
                If m_bEnableDemo_w = True Then sudden_stop cardno, 4
End Sub

Private Sub SetAllAxisLogicPos()

                If m_bEnableDemo_x = True Then set_command_pos cardno, 1, 0
                If m_bEnableDemo_y = True Then set_command_pos cardno, 2, 0
                If m_bEnableDemo_z = True Then set_command_pos cardno, 3, 0
                If m_bEnableDemo_w = True Then set_command_pos cardno, 4, 0
   
End Sub

Private Sub CheckAxisStatus()
    
    Dim state As Long
    Dim value As Long
    
    state = -1
    
    
            If m_bEnableDemo_x = True Then
                While (state <> 0)
                    value = get_status(cardno, 1, state)
                    
                Wend
                state = -1
            End If

            If m_bEnableDemo_y = True Then
                While (state <> 0)
                    value = get_status(cardno, 2, state)
                    
                Wend
                state = -1
            End If

            If m_bEnableDemo_z = True Then
                While (state <> 0)
                    value = get_status(cardno, 3, state)
                   
                Wend
                 state = -1
            End If

            If m_bEnableDemo_w = True Then
                While (state <> 0)
                    value = get_status(cardno, 4, state)
                    
                Wend
                state = -1
            End If
    
End Sub



Private Sub Timer1_Timer()
 Dim value As Long
 
    m_nLogicPos_x = 0
    m_nLogicPos_y = 0
    m_nLogicPos_z = 0
    m_nLogicPos_w = 0
    
    m_nCurrentSpeed_x = 0
    m_nCurrentSpeed_y = 0
    m_nCurrentSpeed_z = 0
    m_nCurrentSpeed_w = 0
     
     
     get_command_pos cardno, 1, m_nLogicPos_x
     get_speed cardno, 1, m_nCurrentSpeed_x

 
 
     get_command_pos cardno, 2, m_nLogicPos_y
     get_speed cardno, 2, m_nCurrentSpeed_y
 
 

      get_command_pos cardno, 3, m_nLogicPos_z
      get_speed cardno, 3, m_nCurrentSpeed_z

 
 
      get_command_pos cardno, 4, m_nLogicPos_w
     get_speed cardno, 4, m_nCurrentSpeed_w
 
 
 txtLogicPos_x.Text = CStr(m_nLogicPos_x)
 txtCurrentSpeed_x.Text = CStr(m_nCurrentSpeed_x * m_nRatio_x)
 
 txtLogicPos_y.Text = CStr(m_nLogicPos_y)
 txtCurrentSpeed_y.Text = CStr(m_nCurrentSpeed_y * m_nRatio_y)
 
 txtLogicPos_z.Text = CStr(m_nLogicPos_z)
 txtCurrentSpeed_z.Text = CStr(m_nCurrentSpeed_z * m_nRatio_z)
 
 txtLogicPos_w.Text = CStr(m_nLogicPos_w)
 txtCurrentSpeed_w.Text = CStr(m_nCurrentSpeed_w * m_nRatio_w)
 
 '驱动状态
 Dim state_x As Long
 Dim state_y As Long
 Dim state_z As Long
 Dim state_w As Long
 
 get_status cardno, 1, state_x
 get_status cardno, 2, state_y
 get_status cardno, 3, state_z
 get_status cardno, 4, state_w
 '驱动完成
 If state_x = 0 And state_y = 0 And state_z = 0 And state_w = 0 Then
          
          btnPMove.Enabled = True
          btnContinueMove.Enabled = True
          btnExit.Enabled = True
          btnClear.Enabled = True
          btnDetailSetting.Enabled = True
          optnAccMove.Enabled = True
          optnEqualityMove.Enabled = True
          chkDemo_x.Enabled = True
          chkDemo_y.Enabled = True
          chkDemo_z.Enabled = True
          chkDemo_w.Enabled = True
          If m_bEnableDemo_x Then txtPulseCount_x.Enabled = True
          If m_bEnableDemo_y Then txtPulseCount_y.Enabled = True
          If m_bEnableDemo_z Then txtPulseCount_z.Enabled = True
          If m_bEnableDemo_w Then txtPulseCount_w.Enabled = True
          If Not m_bEqualityVelocity Then EnableWindow True
       Else  '驱动进行中
        
          btnPMove.Enabled = False
          btnContinueMove.Enabled = False
          btnDetailSetting.Enabled = False
          btnExit.Enabled = False
          btnClear.Enabled = False
          optnAccMove.Enabled = False
          optnEqualityMove.Enabled = False
          
          chkDemo_x.Enabled = False
          chkDemo_y.Enabled = False
          chkDemo_z.Enabled = False
          chkDemo_w.Enabled = False
         
          
          EnableWindow False
          
          txtPulseCount_x.Enabled = False
          txtPulseCount_y.Enabled = False
          txtPulseCount_z.Enabled = False
          txtPulseCount_w.Enabled = False
          End If
      
End Sub



⌨️ 快捷键说明

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