motorTest/ViewModel/TextFile1.txt
2026-10-17 11:39:30 +08:00

380 lines
11 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'Global:全局变量,字符串变量需要以$结尾
'声明实数变量
Global Real Z_Limit 'Z轴限位值 全局变量
Global Real X_Limit 'X轴限位值 全局变量
Global Real Y_Limit 'Y轴限位值 全局变量
Global String getHand$
Global Real SpeedPar '速度参数
Global Real NetSts '接收到字符串的Lenght
Global String RecvString$ '接收到的数据
Global String RecvStr$(0) '接收到字符串的数组
Global String HandRL$ '接收到的左右标识 用于确定是左手点位还是右手点位
Global String HandRLTemp$ '上一次是左手还是右手
Global String ToolNum$ '使用的工具坐标系编号
Global Real CurRegion '当前区域
Global Real TarRegion '目标区域
Global Real BigRegion '大区域
Global Real UpHeight '每次移动的抬升高度
Function main
Z_Limit = 0
X_Limit = 800
Y_Limit = 890
UpHeight = 160
'错误处理标签 类似于try... cash
OnErr GoTo eErrCode
NetOpen '配置打开网络端口
MainInitPro '初始化机器人
'暂停或者等待1秒
'Wait 1
MoveToHome '回原点
ScanConnNet '扫描接收到的信息
'错误代码
eErrCode:
Integer errTask
'显示错误信息
Print "错误代码:", Err
Print "错误讯息:", ErrMsg$(Err)
'CloseNet #201 '断开201端口连接
'获取发生错误的任务编号 没有发生错误:0,一般任务错误:(1~32)
errTask = Ert
If errTask > 0 Then
Print "_", errTask
Print "_", Erl(errTask)
If Era(errTask) > 0 Then
Print "", Era(errTask)
EndIf
EndIf
labelExit:
Fend
'配置网络端口信息 并打开网络通讯端口
Function NetOpen
NetSts = ChkNet(201)
If (NetSts < 0) Then
CloseNet #201
Wait 0.5
SetNet #201, "192.168.1.1", 2000, CRLF, NONE, 0 '配置端口号,ip地址
OpenNet #201 As Server
WaitNet #201
Print #201, "START"
Print "配置完成!"
EndIf
Fend
'机器人初始化
Function MainInitPro
Reset '重置机器人
'如果当前机器人使能关闭,则开启
If Motor = Off Then
Motor On
SLock 1, 2, 3, 4, 5, 6
EndIf
'设置机器人为高速运行,Low:低速运行
Power High
'设置机器人的运行速度
Speed 10 'PTP动作速度
Accel 10, 10
' SpeedS 200
' AccelS 1500
Fend
'回原点
Function MoveToHome
Tool 0
CX(P100) = CX(P0)
CY(P100) = CY(P0)
CZ(P100) = CZ(P0)
CU(P100) = CU(P0)
CV(P100) = CV(P0)
CW(P100) = CW(P0)
XiangTong
Print #201, "MoveToHome"
Fend
'速度设置
Function SpeedSet
If (SpeedPar < 1) Then
SpeedPar = 1
EndIf
Speed SpeedPar
Accel SpeedPar, SpeedPar
SpeedS SpeedPar * 20
AccelS SpeedPar * 150
Fend
'接收到的信息
Function ScanConnNet
Do
NetSts = ChkNet(201)
If (NetSts > 0) Then
Input #201, RecvString$, HandRL$, ToolNum$ '从202端口接收字符串,并赋值到变量RecvString$
Print RecvString$, HandRL$
ParseStr RecvString$, RecvStr$(), "@" 'ParseStr (输入字符串$, 数组$(), 分隔字符$)
ParseStr RecvStr$(0), RecvStr$(), " "
ToolNum$ = "0"
Select RecvStr$(0)
Case "+X"
'执行运行速度调整操作
SpeedPar = Val(RecvStr$(1))
SpeedSet
If (Val(ToolNum$) > 0) Then
Tool Val(ToolNum$)
TMove XY(+(Val(RecvStr$(2))), 0, 0, 0)
Else
BMove XY(+(Val(RecvStr$(2))), 0, 0, 0)
EndIf
Print #201, "CPOK"
Case "-X"
'执行运行速度调整操作
SpeedPar = Val(RecvStr$(1))
SpeedSet
If (Val(ToolNum$) > 0) Then
Tool Val(ToolNum$)
TMove XY(-(Val(RecvStr$(2))), 0, 0, 0)
Else
BMove XY(-(Val(RecvStr$(2))), 0, 0, 0)
EndIf
Print #201, "CPOK"
Case "+Y"
'执行运行速度调整操作
SpeedPar = Val(RecvStr$(1))
SpeedSet
If (Val(ToolNum$) > 0) Then
Tool Val(ToolNum$)
TMove XY(0, +(Val(RecvStr$(3))), 0, 0)
Else
BMove XY(0, +(Val(RecvStr$(3))), 0, 0)
EndIf
Print #201, "CPOK"
Case "-Y"
'执行运行速度调整操作
SpeedPar = Val(RecvStr$(1))
SpeedSet
If (Val(ToolNum$) > 0) Then
Tool Val(ToolNum$)
TMove XY(0, -(Val(RecvStr$(3))), 0, 0)
Else
BMove XY(0, -(Val(RecvStr$(3))), 0, 0)
EndIf
Print #201, "CPOK"
Case "+Z"
'执行运行速度调整操作
SpeedPar = Val(RecvStr$(1))
SpeedSet
If (Val(ToolNum$) > 0) Then
Tool Val(ToolNum$)
TMove XY(0, 0, +(Val(RecvStr$(4))), 0)
Else
BMove XY(0, 0, +(Val(RecvStr$(4))), 0)
EndIf
Print #201, "CPOK"
Case "-Z"
'执行运行速度调整操作
SpeedPar = Val(RecvStr$(1))
SpeedSet
If (Val(ToolNum$) > 0) Then
Tool Val(ToolNum$)
TMove XY(0, 0, -(Val(RecvStr$(4))), 0)
Else
BMove XY(0, 0, -(Val(RecvStr$(4))), 0)
EndIf
Print #201, "CPOK"
Case "+U"
'执行运行速度调整操作
SpeedPar = Val(RecvStr$(1))
SpeedSet
If (Val(ToolNum$) > 0) Then
Tool Val(ToolNum$)
TGo XY(0, 0, 0, +(Val(RecvStr$(5))))
Else
BGo XY(0, 0, 0, +(Val(RecvStr$(5))))
EndIf
Print #201, "CPOK"
Case "-U"
'执行运行速度调整操作
SpeedPar = Val(RecvStr$(1))
SpeedSet
If (Val(ToolNum$) > 0) Then
Tool Val(ToolNum$)
TGo XY(0, 0, 0, -(Val(RecvStr$(5))))
Else
BGo XY(0, 0, 0, -(Val(RecvStr$(5))))
EndIf
Print #201, "CPOK"
Case "+V"
Tool Val(ToolNum$)
'执行运行速度调整操作
SpeedPar = Val(RecvStr$(1))
SpeedSet
Move Here +V(Val(RecvStr$(6)))
Print #201, "CPOK"
Case "-V"
Tool Val(ToolNum$)
'执行运行速度调整操作
SpeedPar = Val(RecvStr$(1))
SpeedSet
Move Here -V(Val(RecvStr$(6)))
Print #201, "CPOK"
Case "+W"
Tool Val(ToolNum$)
'执行运行速度调整操作
SpeedPar = Val(RecvStr$(1))
SpeedSet
Move Here +W(Val(RecvStr$(7)))
Print #201, "CPOK"
Case "-W"
Tool Val(ToolNum$)
'执行运行速度调整操作
SpeedPar = Val(RecvStr$(1))
SpeedSet
Move Here -W(Val(RecvStr$(7)))
Print #201, "CPOK"
Case "ReturnHere" '返回机器人当前坐标
Print #201, "RobotPos" + "," + Str$(CX(CurPos)) + "," + Str$(CY(CurPos)) + "," + Str$(CZ(CurPos)) + "," + Str$(CU(CurPos)) + "," + Str$(CV(CurPos)) + "," + Str$(CW(CurPos))
Case "MoveToHome" '回原定
MoveToHome
Case "UpTool" '创建或者更新工具坐标系
TLSet Val(ToolNum$), XY(Val(RecvStr$(2)), Val(RecvStr$(3)), 0, 0)
Print #201, "settoolok"
Case "RunPoint"
SoftCP On
'执行运行速度调整操作
SpeedPar = Val(RecvStr$(1))
SpeedSet
CX(P100) = Val(RecvStr$(2))
CY(P100) = Val(RecvStr$(3))
CZ(P100) = Val(RecvStr$(4))
CU(P100) = Val(RecvStr$(5))
CV(P100) = Val(RecvStr$(6))
CW(P100) = Val(RecvStr$(7))
Tool Val(ToolNum$)
XiangTong
WaitPos
SoftCP Off
'发送数据到201端口
Print #201, "RunPointOK"
Send
ElseIf NetSts < 0 Then
Call NetOpen
ElseIf NetSts = 0 Then
EndIf
Print #201, "RobotPos" + "," + Str$(CX(CurPos)) + "," + Str$(CY(CurPos)) + "," + Str$(CZ(CurPos)) + "," + Str$(CU(CurPos)) + "," + Str$(CV(CurPos)) + "," + Str$(CW(CurPos))
Loop
Fend
'获取当前位置区域
Function GetCurrPointRegion
Tool 0
Real curX, curY, curZ, curU, curV, curW
curX = CX(Here)
curY = CY(Here)
curZ = CZ(Here)
curU = CU(Here)
curV = CV(Here)
curW = CW(Here)
If (curX <= 0 And curY > 0 And J1Flag(Here) = 0) Then
CurRegion = 1
ElseIf (curX <= 0 And curY <= 0 And J1Flag(Here) = 0) Or (curX > 0 And curY <= 0 And J1Flag(Here) = 1) Then
CurRegion = 2
ElseIf (curX > 0 And curY > 0 And J1Flag(Here) = 0) Then
CurRegion = 3
ElseIf (curX > 0 And curY <= 0 And J1Flag(Here) = 0) Or (curX <= 0 And curY <= 0 And J1Flag(Here) = 1) Then
CurRegion = 4
EndIf
Fend
'同一区域
Function XiangTong
Real curX, curY, curZ, curU
Real tarX, tarY, tarZ, tarU
Real AbsX, AbsY, AbsZ, AbsU
curX = CX(Here)
curY = CY(Here)
curZ = CZ(Here)
curU = CU(Here)
tarX = CX(P100)
tarY = CY(P100)
tarZ = CZ(P100)
tarU = CU(P100)
AbsX = Abs(curX - tarX)
AbsY = Abs(curY - tarY)
AbsZ = Abs(curZ - tarZ)
AbsU = Abs(curU - tarU)
'如果当前位置高于Z限位
If curZ > Z_Limit Then
Go Here :Z(Z_Limit)
EndIf
If (curX >= -150 And tarX < -150) Or (curX <= -150 And tarX > -150) Then
Pass Here :Z(Z_Limit), P1, P100 :Z(Z_Limit), P100
Else
Jump P100 LimZ Z_Limit
EndIf
Fend