-
-
Save clope031/20377441a475d2e6ce25b806851cbfcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports ORiN2.interop.CAO | |
Public Class Robot | |
Dim g_eng As CaoEngine | |
Dim g_ctrl As CaoController | |
Dim g_robot As CaoRobot | |
Dim g_robotvar As CaoVariable | |
Dim g_haltFlag As Boolean | |
Private Sub Command1_Click(sender As System.Object, e As System.EventArgs) Handles Command1.Click | |
'Start motor if arm is stationary | |
If g_robotvar.Value = False Then | |
g_robot.Execute("Motor", New Object() {1, 0}) | |
End If | |
End Sub | |
Private Sub Command2_Click(sender As System.Object, e As System.EventArgs) Handles Command2.Click | |
'Stop motor if arm is stationary | |
If g_robotvar.Value = False Then | |
g_robot.Execute("Motor", New Object() {0, 0}) | |
End If | |
End Sub | |
Private Sub Command3_Click(sender As System.Object, e As System.EventArgs) Handles Command3.Click | |
'Stop Robot | |
g_robot.Halt("") | |
'Record robot stop | |
g_haltFlag = True | |
End Sub | |
Private Sub Command4_Click(sender As System.Object, e As System.EventArgs) Handles Command4.Click | |
'Do not run new operation instruction if arm is running | |
If g_robotvar.Value = True Then | |
Exit Sub | |
End If | |
g_haltFlag = False | |
'Run robot | |
g_robot.Move(1, "@P P10", "NEXT") | |
'Do not start next motion until previous motion is completed | |
Do Until g_robotvar.Value = False | |
Application.DoEvents() | |
Loop | |
'Do not start next motion if robot has stopped | |
If g_haltFlag = True Then | |
Exit Sub | |
End If | |
'Run robot | |
g_robot.Move(1, "@P P11", "NEXT") | |
End Sub | |
Private Sub Robot_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load | |
g_eng = New CaoEngine | |
'Connect RC: IP Setting depends on your RC Setting | |
g_ctrl = g_eng.Workspaces.Item(0).AddController("RC8", "caoProv.DENSO.RC8", "", "WPJ=") | |
'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 | |
Command1_Click(sender, e) | |
End Sub | |
Private Sub Robot_FormClosed(sender As System.Object, e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed | |
'Stop Motor | |
Command2_Click(sender, e) | |
'Release arm control authority | |
g_robot.Execute("GiveArm") | |
'Delete robot variable object | |
g_robot.Variables.Clear() | |
System.Runtime.InteropServices.Marshal.ReleaseComObject(g_robotvar) | |
g_robotvar = Nothing | |
'Delete robot arm object | |
g_ctrl.Robots.Clear() | |
System.Runtime.InteropServices.Marshal.ReleaseComObject(g_robot) | |
g_robot = Nothing | |
'Delete controller object | |
g_eng.Workspaces.Item(0).Controllers.Remove(g_ctrl.Index) | |
System.Runtime.InteropServices.Marshal.ReleaseComObject(g_ctrl) | |
g_ctrl = Nothing | |
'Delete engine object | |
System.Runtime.InteropServices.Marshal.ReleaseComObject(g_eng) | |
g_eng = Nothing | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment