雷泰DMC1480控制卡编程示例之四
'
' 主要演示功能: 直线插补
'
' 关键函数:
' 多轴直线函数
' d1000_start_t_line //相对
' d1000_start_ta_line //绝对
'
' 注意事项:
' DMC1000B不包含圆弧插补
'
' Writen by LEISAI-SUPPORT
' FAX: 0755 - 26402718
' TEL: 0755 - 26434329
' EMAIL: support@ https://www.doczj.com/doc/da19028705.html,
' HTTP: https://www.doczj.com/doc/da19028705.html,
'********************************************
'定义四个轴的常量
Const XCH As Integer = 0
Const YCH As Integer = 1
Const ZCH As Integer = 2
Const UCH As Integer = 3
Private Sub Command_Clear_Click()
For i = 0 To 4
d1000_set_command_pos i, 0
Next
End Sub
'自定义子函数
Private Function GetAxisPosi%(ByRef AxisArray() As Integer, ByRef posiArray() As Long)
Dim n As Integer
n = 0
If Check_X = 1 Then
AxisArray(n) = XCH
posiArray(n) = Val(Text_X.Text)
n = n + 1
End If
If Check_Y = 1 Then
AxisArray(n) = YCH
posiArray(n) = Val(Text_Y.Text)
n = n + 1
End If
If Check_Z = 1 Then
AxisArray(n) = ZCH
posiArray(n) = Val(Text_Z.Text)
n = n + 1
End If
If Check_U = 1 Then
AxisArray(n) = UCH
posiArray(n) = Val(Text_U.Text)
n = n + 1
End If
GetAxisPosi% = n
End Function
Private Sub Command_Run_Click()
Dim nStart, nMSpeed As Long
Dim fAccel As Double
Dim nNum As Integer
Dim AxisArray(4) As Integer
Dim posiArray(4) As Long
nNum = GetAxisPosi(AxisArray, posiArray)
If nNum < 2 Then
MsgBox "插补不能少于两个轴!", vbOKOnly, "提示"
Exit Sub
End If
nStart = Val(Text_Start.Text)
nMSpeed = Val(Text_MSpeed.Text)
fAccel = Val(Text_TAcc.Text)
Text_Num.Text = Str(nNum)
d1000_start_t_line nNum, AxisArray(0), posiArray(0), nStart, nMSpeed, fAccel
End Sub
Private Sub Command_Stop_Click()
If d1000_check_done(XCH)=0 Or d1000_check_done(YCH) = 0 Or
d1000_check_done(ZCH) = 0 Or d1000_check_done(UCH) = 0 Then '在运行d1000_decel_stop (XCH)
d1000_decel_stop (YCH)
d1000_decel_stop (ZCH)
d1000_decel_stop (UCH)
End If
End Sub
Private Sub Form_Load()
Dim nCard As Integer
nCard = d1000_board_init()
If nCard < 1 Then '控制卡初始化
MsgBox "未找到控制卡!", vbOKOnly, "警告"
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
d1000_board_close
End Sub
Private Sub Timer1_Timer()
Label_Pos.Caption = " 位置:" + Str(d1000_get_command_pos(XCH))
Label_Pos.Caption = Label_Pos.Caption + "," + Str(d1000_get_command_pos(YCH)) Label_Pos.Caption = Label_Pos.Caption + "," + Str(d1000_get_command_pos(ZCH)) Label_Pos.Caption = Label_Pos.Caption + "," + Str(d1000_get_command_pos(UCH))
End Sub
' 雷泰DMC1480控制卡编程示例之三
'
' 主要演示功能:
' 1. 控制卡的基本操作
' 2. 单轴驱动脉冲,驱动模式
' 3. T形和S形速度曲线选择
' 4. 减速或急停控制,外部减速停
' 5. 位置显示,位置清零及指定轴状态显示
' 6. 定长运动和连续运动选择
'
' 关键函数:
' 1. 控制卡的基本操作函数
' d1000_board_init , d1000_board_close
' 2. 单轴驱动,T形及S形选择
' d1000_set_pls_outmode 脉冲设置
' d1000_start_tv_move 梯形曲线单轴连续运动
' d1000_start_sv_move S形曲线单轴连续运动
' d1000_start_ta_move 梯形曲线单轴绝对坐标点位运动
' d1000_start_sa_move S形曲线单轴绝对坐标点位运动
' 3. 减速或急停
' d1000_decel_stop 当减速时间为0时为急停
' 4. 位置显示及状态显示
' d1000_get_abs_position
' d1000_set_position
' d1000_check_done
' d1000_get_axis_status
'
' 注意事项:
' 本例虽然只提供了四个驱动函数,实质上其它驱动函数都一致'
' Writen by LEISAI-SUPPORT
' FAX: 0755 - 26402718
' TEL: 0755 - 26434329
' EMAIL: support@ https://www.doczj.com/doc/da19028705.html,
' HTTP: https://www.doczj.com/doc/da19028705.html,
'********************************************
'定义四个轴的常量
Const XCH As Integer = 0
Const YCH As Integer = 1
Const ZCH As Integer = 2
Const UCH As Integer = 3
Dim nAxis As Integer '选择的驱动轴
Dim nSpeed As Integer 'S形或T形选择
Dim nMove As Integer '定长或连续选择
Private Sub Check_Dir_Click()
UpdateControl
End Sub
Private Sub Check_PLog_Click()
UpdateControl
End Sub
Private Sub Check_PMode_Click()
UpdateControl
End Sub
Private Sub Check_SD_Click()
UpdateControl
End Sub
Private Sub Command_Clear_Click()
For i = 0 To 4
d1000_set_command_pos i, 0
Next
End Sub
Private Sub Command_Run_Click()
Dim nStart, nMSpeed, nPulse As Long
Dim fAccel As Double
Dim nDir As Integer
If d1000_check_done(nAxis) = 0 Then '若在运行,则返回Exit Sub
End If
nStart = Val(Text_Start.Text)
nMSpeed = Val(Text_MSpeed.Text)
fAccel = Val(Text_TAcc.Text)
nPulse = Val(Text_Pulse.Text)
If Check_Dir = 1 Then
nDir = 1
Else
nDir = -1
End If
If Check_SD = 1 Then
d1000_set_sd nAxis, 1
Else
d1000_set_sd nAxis, 0
End If
If Check_PMode = 1 Then
If Check_PLog = 1 Then
d1000_set_pls_outmode nAxis, 1 'pulse/dir 模式,脉冲下降沿有效Else
d1000_set_pls_outmode nAxis, 0 'pulse/dir 模式,脉冲上升沿有效End If
Else
If Check_PLog = 1 Then
d1000_set_pls_outmode nAxis, 3 'CW/CCW模式,脉冲下降沿有效Else
d1000_set_pls_outmode nAxis, 2 'CW/CCW模式,脉冲上升沿有效End If
End If
If nMove = 0 Then '定长
If nSpeed = 0 Then 'S形
d1000_start_s_move nAxis, nPulse * nDir, nStart, nMSpeed, fAccel
Else
d1000_start_t_move nAxis, nPulse * nDir, nStart, nMSpeed, fAccel
End If
Else '连续
If nSpeed = 0 Then 'S形
d1000_start_sv_move nAxis, nStart, nMSpeed * nDir, fAccel
Else
d1000_start_tv_move nAxis, nStart, nMSpeed * nDir, fAccel
End If
End If
End Sub
Private Sub Command_Stop_Click()
If d1000_check_done(XCH) = 0 Or d1000_check_done(YCH) = 0 Or d1000_check_done(ZCH) = 0 Or d1000_check_done(UCH) = 0 Then '在运行d1000_decel_stop (XCH)
d1000_decel_stop (YCH)
d1000_decel_stop (ZCH)
d1000_decel_stop (UCH)
End If
End Sub
Private Sub Form_Load()
Dim nCard As Integer
nCard = d1000_board_init()
If nCard < 1 Then '控制卡初始化
MsgBox "未找到控制卡!", vbOKOnly, "警告"
End If
Check_PMode = 1
Check_PLog = 1
Check_Dir = 1
Check_SD = 1
UpdateControl
End Sub
Private Sub Form_Unload(Cancel As Integer)
d1000_board_close
End Sub
Public Sub UpdateControl()
If Check_PMode = 1 Then
Check_PMode.Caption = "脉冲+方向"
Else
Check_PMode.Caption = "脉冲+脉冲"
End If
If Check_PLog = 1 Then
Check_PLog.Caption = "脉冲下降沿有效"
Else
Check_PLog.Caption = "脉冲上升沿有效"
End If
If Check_SD = 1 Then
Check_SD.Caption = "减速:使能"
Else
Check_SD.Caption = "减速:禁止"
End If
If Check_Dir = 1 Then
Check_Dir.Caption = "驱动方向:正"
Else
Check_Dir.Caption = "驱动方向:负"
End If
End Sub
Private Sub Option_CM_Click()
nMove = 1
End Sub
Private Sub Option_M_Click()
nMove = 0
End Sub
Private Sub Option_S_Click()
nSpeed = 0
End Sub
Private Sub Option_T_Click()
nSpeed = 1
End Sub
Private Sub Option_U_Click()
nAxis = UCH
End Sub
Private Sub Option_X_Click()
nAxis = XCH
End Sub
Private Sub Option_Y_Click()
nAxis = YCH
End Sub
Private Sub Option_Z_Click()
nAxis = ZCH
End Sub
Private Sub Timer1_Timer()
Label_Pos.Caption = "状态:" + Str(d1000_get_axis_status(XCH))
Label_Pos.Caption = Label_Pos.Caption + "," + Str(d1000_get_axis_status(YCH))
Label_Pos.Caption = Label_Pos.Caption + "," + Str(d1000_get_axis_status(ZCH))
Label_Pos.Caption = Label_Pos.Caption + "," + Str(d1000_get_axis_status(UCH))
Label_Pos.Caption = Label_Pos.Caption + " 位置:" + Str(d1000_get_command_pos(XCH)) Label_Pos.Caption = Label_Pos.Caption + "," + Str(d1000_get_command_pos(YCH))
Label_Pos.Caption = Label_Pos.Caption + "," + Str(d1000_get_command_pos(ZCH))
Label_Pos.Caption = Label_Pos.Caption + "," + Str(d1000_get_command_pos(UCH))
End Sub