Skip to content

Instantly share code, notes, and snippets.

@clope031
Created May 15, 2020 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clope031/f8871d8eba667327559215896e03eb14 to your computer and use it in GitHub Desktop.
Save clope031/f8871d8eba667327559215896e03eb14 to your computer and use it in GitHub Desktop.
'!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=192.168.0.1")
'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
g_robot.Halt
'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
Do
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
Loop
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment