Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
'!TITLE "RobotProgram"
Sub Main
Dim g_eng As Object
Dim g_ctrl As Object
Dim g_robot As Object
Dim g_robotVar As Object
Dim g_haltFlag As Integer
'Connect RC: IP Setting depends on your RC setting
g_ctrl = cao.AddController("RC", "CaoProv.DENSO.RC8", "", "Server=")
'Create CaoRobot object
g_robot = g_ctrl.AddRobot("Arm")
'Argument used to check arm running status
g_robotVar = g_robot.AddVariable("@BUSY_STATUS")
'Get arm control authority
g_robot.Execute "Takearm"
'Start Motor
g_robot.Execute "Motor", Array(1,0)
Do While 1
Select Case I[0]
'Start motor if arm is stationary
Case 1
If g_robotVar.Value = False Then
g_robot.Execute "Motor", Array(1,0)
End If
I[0] = 0
'Stop motor if arm is stationary
Case 2
If g_robotVar.Value = False Then
g_robot.Execute "Motor", Array(0,0)
End If
I[0] = 0
'Stop Robot
Case 3
'Record robot stop
g_haltFlag = 1
I[0] = 0
'Start Motion
Case 4
'Do not run new operation instruction if arm is running
If g_robotVar.Value = True Then
I[0] = 0
Exit Do
End If
g_haltFlag = 0
'Run robot
g_robot.Move 1, "@P P10", "Next"
'Do not start new motion until previous motion is completed
Delay 100
Loop Until g_robotVar.Value = False
'Do not start new motion if robot has stopped
If g_haltFlag = 1 Then
I[0] = 0
Exit Do
End If
'Run Robot
g_robot.Move 1, "@P P11", "Next"
I[0] = 0
'Exit Loop
Case 5
'Stop Motor
g_robot.Execute "Motor", Array(0,0)
'Release arm control authority
g_robot.Execute "Givearm"
g_robot.Variables.Remove g_robotVar.Index
g_ctrl.Robots.Remove g_robot.Index
cao.Controllers.Remove g_ctrl.Index
Exit Do
End Select
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.