ROBT 3341 ActiveRobot Tutorial
Objective:
The objectives of this tutorial are to learn how ActiveRobot commands can be used from within
Visual Basic to control the CRS robot.
At the completion of the tutorial, you should be able to:
create a user interface using Visual Basic
control the CRS robot using commands from the ActiveRobot Library
transfer files from the CRS controller to the PC using ActiveRobot Explorer
teach robot positions using ActiveRobot Terminal
Preparation:
Review the “BASIC Programming Quick Reference” and the ActiveRobot manuals.
Read over the lab to gain an understanding of what the code will do
Note:
Before using an ActiveRobot application to control the CRS robot, control of the robot must be
passed from the pendant to the terminal.
Brent Dunn/ BCIT Page 1 of 11
ROBT 3341 ActiveRobot Tutorial
Create an ActiveRobot Application
1. Start Visual Basic
2. In the New Project dialog box, click Standard EXE then click Open.
3. On the Project menu, click References.
4. In the Available References list, check off CRS ActiveRobot Type Library then click OK.
Create the User Interface
In Visual Basic, you start by laying out the elements for the user interface.
Brent Dunn/ BCIT Page 2 of 11
ROBT 3341 ActiveRobot Tutorial
5. On the Toolbox, double-click on the CommandButton to add a command button to the form.
Add 3 more command buttons and arrange them on the form.
6. Right-click on the bottom command button then click Properties.
The Properties dialog box displays.
7. In the Properties dialog box, change the following properties:
(Name) = cmdOK
Caption = OK
8. Change the other command button properties.
Name Caption
cmdGripOpen Open Gripper
cmdGripClose Close Gripper
cmdJogAxis1 Jog Axis 1
Brent Dunn/ BCIT Page 3 of 11
ROBT 3341 ActiveRobot Tutorial
Naming Conventions in Visual Basic
Use a naming convention to keep track of controls and make the code easier to follow. A
standard convention is to use a 3 letter prefix that indicates the type of control. For example:
Prefix Control Example
cmd a command button cmdCancel
txt a text box txtTemperature
lbl a label lblPosition
9. Change the Form's Caption
Right-click on a blank area of the form then click Properties from the shortcut menu
Change the Caption property to My Robot Program
Write the Code for the Buttons
1. Right-click anywhere on the form then click View Code.
2. In the Editor window, type:
Option Explicit 'force programmer to declare all variables
Dim Robot As New CRSRobot 'create a robot object
3. In the list of controls, click cmdOK.
Brent Dunn/ BCIT Page 4 of 11
ROBT 3341 ActiveRobot Tutorial
A blank subroutine is created.
Notice the name of the subroutine. This subroutine will run whenever the control named
cmdOK receives a Click event.
4. Add code to the subroutine.
Private Sub cmdOK_Click()
Set Robot = Nothing 'free up memory used by the robot object
End 'end the program
End Sub
5. Return to the form.
On the View menu, click Project Explorer
In the project Explorer window, right-click on Form1 then click View Object.
6. Create the code for the grip open and grip close buttons.
Double-click on the Open Gripper button. This creates a new blank subroutine for the
default event of a control. In this case, the default event is the click event.
Brent Dunn/ BCIT Page 5 of 11
ROBT 3341 ActiveRobot Tutorial
In the subroutine that is created, type the code:
Robot.GripperOpen 40
Create a new subroutine for the Close Gripper button and add the code to close the
gripper.
7. Create an event handler subroutine for the Jog Axis 1 button and add the following code:
Robot.Joint 1,5 'jog joint 1 by 5 degrees
8. Save the program.
On the File menu, click Save Project. Save the project in the d:\robt3341 directory.
Use the default name for the form but give the project a meaningful name.
Test the program
1. On the Run menu, click Start.
2. Click the open and close gripper buttons.
3. Click the Jog Axis button.
4. Click OK to end the program.
Add user input
Add a text box to allow the user to set the jog amount.
1. Return to the form.
2. On the Toolbox, double-click on a textbox to add it to the form then:
Move and resize the textbox
In the textbox properties (right-click on the textbox then click Properties), change the
Name to txtJogAngle and delete the contents of the Text property.
3. In the code window, change the code for the Jog Axis button event handler.
Brent Dunn/ BCIT Page 6 of 11
ROBT 3341 ActiveRobot Tutorial
Private Sub cmdJogAxis1_Click()
Dim angle As Double 'declare variable
angle = CDbl(txtJogAngle) 'read value and convert to double
Robot.Joint 1, angle 'jog axis 1
End Sub
Note: The name of a text box refers to its value. CDbl converts the text from the text box
to a double (real) number.
4. Run the program again. Try entering different angles. Click OK when done.
Add output display
Add a button and label to list the current robot position.
1. Add a CommandButton to the form and set its properties:
Name - cmdGetPosition
Caption - Position
2. Add a Label and set its properties:
Name - lblPosition
Caption - should be blank
3. Add code to display the coordinates in the label when the user clicks the Position button.
Private Sub cmdGetPosition_Click()
Dim loc As New CRSLocation
Set loc = Robot.WorldLocation(ptActual)
lblPosition = CStr(loc.x) & "," & CStr(loc.y) & "," & CStr(loc.z)
End Sub
Note: CStr converts a real number to a string so the numbers can be joined into a string
with commas between the coordinates. The & joins strings together. To format numbers
(control number of decimals, etc.), use Format instead of CStr e.g Format(loc.x, "#.00").
4. Run the program and test the function.
Add input error checking
1. Add code to the JogAxis1 button to handle blank or invalid entries in the angle textbox.
Private Sub cmdJogAxis1_Click()
Dim angle As Double 'declare variable
If IsNumeric(txtJogAngle) Then 'angle is not blank and is a number
angle = CDbl(txtJogAngle) 'read value and convert to double
Robot.Joint 1, angle 'jog axis 1
Else
MsgBox "The angle must be a numeric value"
Brent Dunn/ BCIT Page 7 of 11
ROBT 3341 ActiveRobot Tutorial
txtJogAngle.SetFocus 'put cursor in angle textbox
End If
End Sub
2. Run the program.
Try a blank value, abc, 10, etc. for the angle.
Use taught locations
1. Go to terminal mode(use ActiveRobot terminal)and start a new application (ash mynewapp).
2. Set up a pick and a place location for one of the blocks.
3. Teach 2 locations named Pick and Place.
4. Exit ash and the terminal.
5. Transfer the v3 file to the PC.
Start ActiveRobot explorer.
Locate the application folder you just created on the CRS controller.
Drag and drop the v3 file from the folder to the same folder as your Visual Basic project
files on the local computer.
Rename the file points.v3.
Close ActiveRobot explorer.
6. Add another command button to the form.
7. Add code for the Pick & Place button.
Private Sub cmdPickPlace_Click()
Dim v3File As New CRSV3File
Dim locPick As New CRSLocation
Dim locPlace As New CRSLocation
'open the V3 file and read the locations
v3File.Open App.Path & "\points.v3"
Brent Dunn/ BCIT Page 8 of 11
ROBT 3341 ActiveRobot Tutorial
Set locPick = v3File.Location("pick")
Set locPlace = v3File.Location("place")
v3File.Close
'do the pick and place cycle
Robot.Speed = 25
Robot.GripperOpen
Robot.GripperFinish
Robot.Approach locPick, 2
Robot.MoveStraight locPick
Robot.Finish
Robot.GripperClose 50
Robot.GripperFinish
Robot.DepartStraight 2
Robot.Approach locPlace, 2
Robot.MoveStraight locPlace
Robot.Finish
Robot.GripperOpen
Robot.GripperFinish
Robot.DepartStraight 2
Robot.Ready
End Sub
Note: The v3 file must be in the same folder as the application (App.Path & "\points.v3").
8. Run the program. Try the Pick & Place button.
Avoiding Nesting Errors
If a second command is issued to the robot while one command is already being processed, an
error will occur (you cannot instruct the robot to move to point 1 then in the middle of the move,
tell it to move to point 4). In an ActiveRobot application, this can occur if the user presses
another command button while the current command is running. For example, when you click
Pick & Place, Visual Basic executes the commands in the click event subroutine then returns to
the form. If you click the Grip Open button while Pick & Place is running, an error will occur.
To handle the error:
Write an error handler
Wait in each subroutine until the robot has completed its motion
Disable all other buttons on the form while moving
Enter the following code, run the program, and make any necessary corrections.
Private Sub cmdPickPlace_Click()
Dim v3File As New CRSV3File
Dim locPick As New CRSLocation
Dim locPlace As New CRSLocation
On Error GoTo Error_Handler
'open the V3 file and read the locations
Brent Dunn/ BCIT Page 9 of 11
ROBT 3341 ActiveRobot Tutorial
v3File.Open App.Path & "\points.v3"
Set locPick = v3File.Location("pick")
Set locPlace = v3File.Location("place")
v3File.Close
'do the pick and place cycle
Robot.Speed = 25
Robot.GripperOpen
Robot.GripperFinish
Robot.Approach locPick, 2
Robot.MoveStraight locPick
Robot.Finish
Robot.GripperClose 50
Robot.GripperFinish
Robot.DepartStraight 2
Robot.Approach locPlace, 2
Robot.MoveStraight locPlace
Robot.Finish
Robot.GripperOpen
Robot.GripperFinish
Robot.DepartStraight 2
Robot.Ready
Call EnableButtons
Exit Sub
Error_Handler:
MsgBox "Error occurred:" & Err.Description
End Sub
'disable all buttons on the form
Private Sub DisableButtons()
cmdPickPlace.Enabled = False
cmdGetPosition.Enabled = False
cmdGripClose.Enabled = False
cmdGripOpen.Enabled = False
cmdOK.Enabled = False
End Sub
'enable all buttons on the form
Private Sub EnableButtons()
cmdPickPlace.Enabled = True
cmdGetPosition.Enabled = True
cmdGripClose.Enabled = True
cmdGripOpen.Enabled = True
cmdOK.Enabled = True
End Sub
Note: It is good practice to place an error handling routine in all subroutines. In general, an error
handling routine consists of a On Error Goto LabelName statement at the start of the program
then a label and a method to handle the error. In the error handler, you can check what error
occurred using:
Err.Number - the error number
Err.Description - a string description of the error
Brent Dunn/ BCIT Page 10 of 11
ROBT 3341 ActiveRobot Tutorial
Problem
Write a VB program that will implement the following task using ActiveRobot:
1) wait for a block to be detected on the slide by the optical sensor (the block can be
placed manually))
2) activate the slide to move the block to the robot pickup location
3) pickup the block using the robot arm, and move to the ready position
4) drop the block
5) repeat the sequence, starting at step 1
Brent Dunn/ BCIT Page 11 of 11