Subscribe by Email

Your email:

Custom-Tailored Solutions

Current Articles | RSS Feed RSS Feed

The Power of Scripting for Solving Machine Vision Applications

  
  
  
  
  

 Many moderate to advanced vision applications require scripting (writing lines of programming code) to solve.  Scripting in IMPACT® can be done using three methods. 

  1. The Basic tool in Vision Program Manager (VPM)
  2. The Basic control in Control Panel Manager (CPM)
  3. The Scriptor control in CPM

Below you will find a brief overview of each of these scripting environments.  Please note that this is only an overview and represents a small portion of IMPACT’s programming capabilities. 

 

#1: The Basic tool in VPM allows you to write lines of Basic language code in an editor.  You can write if-then statements, create loops, modify strings, etc.  When the lines of code are written and the “Compile” button is clicked, the variables become listed as linkable variables in the properties area.  The variables can link to data from other tools.  They can be data types Boolean, integer, real, string or an array (list) version of any of these. 

script image 1 resized 600

Although the data types are limited to the eight listed above, they can be easily converted and combined into other more complex data types using Data Instance and Data Set tools.  With the Basic tool, Data Instance ,and Data Set tool working together, the sky is the limit.  The screen shot below shows a list of tasks the basic tool can help you with.  I pulled this list from our user’s forum.  (http://www.pptvision.com/support_ppt_forum.html)

describe the image

 

My favorite code example (Scaling a Shape) can be  used to scale a shape.  This code loops through the perimeter points of a blob or other human-made shape and moves the points closer to or further from the shape’s centroid.   The shape is then re-compiled in a Data Instance tool and used as a region of interest for another tool. 

It is worth noting that the Basic  tool is executed during runtime and, although it is relatively quick, it does consume some processing time. 

#2.  The Basic control in CPM is used in a similar fashion. However, it runs in CPM so it does not take any processing time from the camera.  It is very typical to use the Basic control for tasks like incrementing counters in the HMI, compiling data for a table or chart, modifying strings for a text file or image save, or making a custom calculator tool for the HMI user. 

Variables are created by clicking the “Compile” button after the code is written.  For linking the variables to VPM tool properties or other CPM control properties, the variables can be dragged and dropped to and from these properties. 

The Basic code can be run in a number of ways.  It can run automatically anytime a variable changes, or it can run by invoking the “Run” method on the Basic control.  This means it can run when a button is clicked, an image is update, a file is saved, etc. 

This screen shot shows an example of code that calculates a Pass percent and Fail percent that are then displayed in another control.

script image 3 resized 600

#3.  The Scriptor control in CPM is intended to give the HMI developer unlimited flexibility in CPM.  This control has an editor window to write code.  This control also runs in CPM so, it also does not draw from the camera’s processing time.  This control does require you to know the basics of Java, but with, a little study, you can learn enough Java to be effective.  In the Scriptor control, variables are not created for drag and drop linking like in the Basic control.  Properties are modified using the text in the lines of code you write.  For example, this line of code sets the properties of a table in Control Panel 1. Specifically the properties of Table 10, Row 2, Column 1.

 Scriptor.setProperty("Panel 1.Table10.Row2,Column1",stringArray[2]);

Here is a list of topics from the forum, using the Scriptor Control, that users have written about. 

script image 4 resized 600

Also, it is worth noting that the Scriptor control can execute methods (cause other Controls to run) and read and write to and from other IMPACT vision processing tools.  This control’s run method can be invoked from the event of any other control such as a button click.

The screen shot below shows example code that will wait for the user to click a check box when it runs.

script image 5 resized 600

Now that you have a broad understanding of the scripting possibilities within IMPACT®, you have a better understanding of the power and flexibility of VPM and CPM.  If you are interested in learning more, please download the IMPACT Software Suite and explore on your own, or contact us at http://www.pptvision.com/contact_us.html

You might also consider

Comments

Currently, there are no comments. Be the first to post one!
Post Comment
Name
 *
Email
 *
Website (optional)
Comment
 *

Allowed tags: <a> link, <b> bold, <i> italics