Upload
zohaibshabir
View
228
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Workspace learning
Citation preview
Dr J.Iqbal
Dr J.Iqbal
Things to Cover Robots
Teach pendent GP Tracks Create Path and Track
The CAD System Conveyor belt
Collision detection Introduction to VBA
Use of macro create box, delete and move Attaching macro with GP Introduction to Forms Moving of Conveyor belt
Dr J.Iqbal
Introduction to VBA
OVERVIEW VBA stands for Visual Basic for Applications. It is a
programming language that is produced by Microsoft.
VBA consists of Classes/objects, which are collections of Properties, Methods, and Events.
Properties are settings of an object that you can check or change.
Methods are actions the object can perform.
Events are things that happen to an object. An event is an action recognized by an object.
Dr J.Iqbal
Introduction to VBA Objects An object represents an instance of a class such as
Form, Control, or Component. In Visual Basic code, you must instantiate an object before you can apply one of the object's methods or change the value of one of its properties.
Instantiation is the process by which an instance of a class is created and assigned to an object variable. An example is shown below:
Dim x As New MyClass()
Dr J.Iqbal
Introduction to VBA Properties A property is an attribute of an object that defines one
of the object's characteristics, such as size, color, or screen location, or an aspect of its behavior, such as whether it is enabled or visible. To change the characteristics of an object, you change the values of its corresponding properties.
To set the value of a property, affix the reference to an object with a period, the property name, an equal sign (=), and the new property value.
Public Sub ChangeName(newTitle)
myForm.Text = newTitle
End Sub
Dr J.Iqbal
Introduction to VBA Methods A method is an action that an object can perform. For
example, Add is a method of the ComboBox object, because it adds a new entry to a combo box.
The following example demonstrates the Start method of a Timer component:
' Instantiates a Timer object.
Dim myTimer As New System.Windows.Forms.Timer() ' Invokes the Start method of myTimer.
MyTimer.Start
Dr J.Iqbal
Introduction to VBA Events An event is an action recognized by an object, such as
clicking the mouse or pressing a key, and for which you can write code to respond.
Events can occur as a result of a user action or program code, or they can be triggered by the system. You can also develop your own custom events to be raised by your objects and handled by other objects.
Dr J.Iqbal
Introduction to VBA OVERVIEW
VBA can be used in Workspace to create Macros, Behaviors, Tool Behaviors, and robot programs using Workspaces customizable robot language.
Programs or commands written in VBA can be used to access Workspace functionality via the Workspace Object Model.
The entire Object Model is included in the User Manual.
Dr J.Iqbal
When a command from the Workspace Object Model is executed within a VBA program it makes a call into the main Workspace executable. This way the user can access and manipulate data and functions within Workspace from a VBA program.
All macros and programs are constructed in the VBA Integrated Development Environment (IDE).
The IDE is built into Workspace and may be started within the Workspace environment. However, the IDE has its own help system, menu structure, and commands.
Introduction to VBA
Dr J.Iqbal
The IDE is divided into three main areas the Project Explorer, the Properties Window, and the Main Working Area.
The Project Explorer is located on the upper left-hand side of the screen below the icons. The Project Explorer window presents the user with a
hierarchical structure of all VBA projects, Workspace objects, modules and Class modules.
The Properties Window is located below the Project Explorer. The Properties Window displays the properties of the
selected object from the project explorer. It is divided into two columns, the first column displays the name of the property and the second column displays the value of the property.
Introduction to VBA
Dr J.Iqbal
The Main Working Area is the large gray section in the middle of the screen. The Main Working Area contains the object of interest, such
as opened VBA Modules, Watches, and UserForms.
A VBA module contains VBA declarations and procedures.
There are two types of modules, Code Modules and Class Modules.
The Object Browser lists all of the available Classes, their Properties, Methods, and Events, and the parameters for each.
Everything that the user creates and edits in the IDE is saved in the corresponding Workspace project.
Introduction to VBA
Dr J.Iqbal
Macros
OVERVIEW Macros are Code Modules that contain a series of Methods and
Properties arranged to achieve a desired goal.
Macros can be run from the Run Macros dialog box, from the Command Line, or as GP Actions.
Dr J.Iqbal
Create_mov_del.wsp EXAMPLE If there are any Workspace projects open, close them and open
a new project. Select Options \ Visual Basic Result: The IDE is opened. In the Project Explorer right click on the name of the VBA project
(it will have the same name as the Workspace Project). Select Insert \ Module. Result: A Code Module is opened and placed in the Main Working
Area. Click the mouse in the Code Module and type the line sub
mybox() and press enter. Result: The IDE adds the line End Sub automatically, and the cursor
is placed between the two lines. Note: mybox will be the name of the macro.
Dr J.Iqbal
Macro
Sub myBox()
ThisDocument.Box "box", 300, 300, 300
End Sub
Create Box
Dr J.Iqbal
Right click and select List Properties\Methods. Result: A Drop-Down Menu lists all of the available options. Select ThisDocument Result: ThisDocument is added to the macro. Type . Result: Another Drop-Down Menu appears listing the available options now. Select Box Result: Box is added after the period. Type in a space after Box. Result: A line of help appears listing all of the parameters for the method Box. Type box,100,100,100 ThisDocument.Box "box", 300, 300, 300 Select File \ Close and Return to Workspace Result: You are returned to the Workspace environment. Select Options \ Macros \ Run Result: The Macros dialog box is opened. Make sure Module1.mybox is highlighted and press Run. Result: The macro runs and creates a box named box with dimensions of
100mm per side. Select the box and delete it. In the command line section at the bottom of the screen type box Result: The macro is run again.
Dr J.Iqbal
Macro
Sub myBox()
ThisDocument.Box "box", 300, 300, 300
End Sub
Delete Box
Sub delete()
ThisDocument.CadObject(box").Delete
End Sub
Create Box
Dr J.Iqbal
Create delete Form.wsp
Dr J.Iqbal
Create_mov_delete form.wsp
Dr J.Iqbal
Use of forms Return to the IDE. Right click on the name of the project and select Insert \
UserForm. Result: A blank UserForm is opened in the Main Working Area On the Properties Window left click on (Name) and then
change the name to MoveBoxDialog. Now left click on Caption and change it to Enter Co-ordinates
for move Note: The Name is how the dialog box is identified within the code,
and the Caption is what is labeled on the title bar of the dialog box.
Left click on the UserForm. From the Tool Box to the left of the UserForm select Frame. Note: If you are not sure which icons in the Tool Box are for which
object, hold your mouse over the icon and a label will appear. The toolbox can be switched on and off from the View menu.
Left click the mouse near the top left-hand corner of the UserForm, and holding down the left mouse button drag the mouse to the lower right-hand corner of the UserForm.
Result: A Frame is created on the UserForm Note: A Frame is a visual means of grouping objects together.
Dr J.Iqbal
Change the Caption of the Frame to Co-ordinates Add a Textbox to the UserForm and position underneath the
Frames caption. Add a Label to the right of the Text Box. Left click inside of the Label and change the caption to X. Resize the Label so that it is just large enough for the X. Repeat steps the above four steps and label the other Text
Boxes Y and Z. Resize the Frame so that it contains just the three Text Boxes
and their Labels. Add a Command Button to the bottom of the UserForm. From the Properties Window change the Caption to OK. Add another Command Button and change its Caption to Cancel. Double click on the OK button on the UserForm. Result: A Code Module opens with the lines Private Sub
CommandButton1_Click() and End Sub written. This is called an event handler. The event is someone clicking on the OK button, and the code that goes between these lines will be executed after that event.
Type the following lines of code between the two already existing lines.
Dr J.Iqbal
Dim x As Double
Dim y As Double
Dim z As Double
Rem Get coordinates from the text boxes
x = TextBox1.Text
y = TextBox2.Text
z = TextBox3.Text
Rem Position the CAD object
ThisDocument.CADObject("box").MoveAbsolute x, y, z
Right click on MoveBoxDialog in the Project Explorer and select View Object.
Result: The UserForm Re-appears.
Double click on the Cancel button.
Add the line Hide between the two already existing lines.
Result: The UserForm is now complete. All that is left to do is to create the macro that displays it.
Dr J.Iqbal
Right click on Module1 in the Project Explorer and select View Code.
Result: Module1 is opened. Note: Different macros can be created in the same code
module. Type Sub MoveBoxAbsolute and press Enter. Right click and select List Properties\Methods. Select MoveBoxDialog Type . Select Show. Select File \ Close and Return to Workspace. Select Options \ Macros \ Run In the Macros dialog box select
Module1.MoveBoxAbsolute and press Run. Result: The UserForm you created appears. Enter 100 for x, y, and z and press OK. Result: The box moves to the location 100x, 100y, 100z Note: You can check this from the boxes Property page.
Dr J.Iqbal
Create_mov_delete form
Dr J.Iqbal
Use of Forms (create from text move delete.wsp)
Dr J.Iqbal
Create Box using form
Private Sub CommandButton2_Click()
Dim x As Double
Dim y As Double
Dim z As Double
x = TextBox4.Text
y = TextBox5.Text
z = TextBox6.Text
name = TextBox7.Text
ThisDocument.Box name, x, y, z
End Sub
Dr J.Iqbal
Private Sub CommandButton1_Click()
Dim x As Double
Dim y As Double
Dim z As Double
x = TextBox1.Text
y = TextBox2.Text
z = TextBox3.Text
name = TextBox7.Text
ThisDocument.CadObject(name).MoveAbsolute x, y, z
Rem x, y, z
End Sub
Move Absolute
Dr J.Iqbal
Move Relative
Private Sub MoveRelativeButton_Click()
name = TextBox7.Text
ThisDocument.CadObject(name).MoveRelative x, y, z
End Sub
Dr J.Iqbal
Delete Box
Private Sub deleteButton_Click()
name = TextBox7.Text
ThisDocument.CadObject(name).Delete
End Sub
Private Sub CancelButton_Click()
Hide
End Sub
Exit
Dr J.Iqbal
Attaching Macro with GPs
Example Stabuli Puma 761
Dr J.Iqbal
Create Box - Size 140,400,275 Location X=1100,y=700,z=600
Conveyor moving with ABB.wsp
Dr J.Iqbal
Dr J.Iqbal
Move Part Fwd Option Explicit
Dim Part As CadObject
Dim CartPos As New RCSCartPos
Dim rRobot As Robot
Public Sub MovePart()
'Declaration of the local variables
'The position properties of CartPos are assigned the objects target cartesian pos
CartPos.px = 1100 1100
CartPos.py = -100 700
CartPos.pz = 600 600
'Assign the object part with the CAD object to be moved
Set Part = ThisDocument.CadObject("workpiece")
'The object part is being accessed and the setObjectNextTarget method
'is used to set the object next target. The target is the cartesian
'position of CartPos
Part.SetObjectNextTarget CartPos
End Sub
Explicit
option force
you to
declare var
before using
Dr J.Iqbal
Move part back Public Sub MovePartBack()
'Declaration of the local variables
'The position properties of CartPos are assigned the objects target
cartesian pos
CartPos.px = 1100
CartPos.py = 700
CartPos.pz = 600
'Assign the object part with the CAD object to be moved
Set Part = ThisDocument.CadObject("workpiece")
'The object part is being accessed and the setObjectNextTarget method
'is used to set the object next target. The target is the cartesian
'position of CartPos
Part.SetObjectNextTarget CartPos
End Sub
Dr J.Iqbal
Moving Conveyor example.wsp
Dr J.Iqbal
Moving Conveyor Belt Public Sub MovePart()
'Declaration of the local variables
Dim Part As CadObject
Dim CartPos As New RCSCartPos
'The position properties of CartPos are assigned the objects target cartesian pos
CartPos.px = -10
CartPos.py = 700
CartPos.pz = 469
'Assign the object part with the CAD object to be moved
Set Part = ThisDocument.CadObject("Workpiece")
'The object part is being accessed and the setObjectNextTarget method
'is used to set the object next target. The target is the cartesian
'position of CartPos
Part.SetObjectNextTarget CartPos
End Sub
Dr J.Iqbal
Named View - Camera
View -> Named view -> saved view
Demo -> view camera.wsp
Dr J.Iqbal
Named View - Camera
Dr J.Iqbal
Named View - Camera
Dim rRobot As Robot
Sub viewall()
Set rRobot = ThisDocument.GetRobot("ABB IRB2400_10")
ThisDocument.MoveToNamedView "camera2", 1500
rRobot.Delay 4000
End Sub
Dr J.Iqbal
Named View - Camera Dim rRobot As Robot
Sub viewall()
Set rRobot = ThisDocument.GetRobot("ABB IRB2400_10")
ThisDocument.MoveToNamedView "camera2", 1500
rRobot.Delay 4000
End Sub
Sub viewside()
Set rRobot = ThisDocument.GetRobot("ABB IRB2400_10")
ThisDocument.MoveToNamedView "camera3", 1000
rRobot.Delay 10000
End Sub
Sub viewsmall()
Set rRobot = ThisDocument.GetRobot("ABB IRB2400_10")
ThisDocument.MoveToNamedView "camera5", 1000
rRobot.Delay 50000
End Sub
Dr J.Iqbal
Wspace. Wspacefolder.g10finalwithoutlang
Demo
Wspace. Demo