Accessing Multiple Results from the SPEL+ Language
Some Vision Guide objects such as the Correlation and Blob objects have the ability to find multiple features with one object by using the NumberToFind property. The CurrentResult property is used to set which result will be displayed in the Results list if we examine the results in the [Object] window. It is also used to determine which result record to return results for. For example, if we want to get the Area result from the 3rd result returned from a Blob object, CurrentResult must be set to 3. You have already seen how this can be done from the [Object] window Properties list. Now let’s take a look at how to access multiple results from SPEL+.
Multiple result access from SPEL+ treats the result as an array where the result number is the subscript number next to the result to be obtained. The first example below shows how to get the 3rd Area result and put it in a variable called area from the SPEL+ Language.
VGet seqname.objname.Area(3), area
The 2nd example below shows how to get that same 3rd Area result but this time assign it as the value of the 3rd element in an array called area.
VGet seqname.objname.Area(3), area(3)
Variable names can also be used to represent the element in an array rather than fixed elements as in example #2 above. Notice that the variable called var is used as the subscript for the Area result.
VGet seqname.objname.Area(var), area(var)
The 4th example assumes that you have used a single vision object to find multiple like parts (let’s say up to 10). You would now like to pick these parts (let’s say they are pens) with a robot so you will need to store the X, Y, and U coordinates in array variables for the coordinate values of each of the parts found. The code below retrieves these coordinates using the RobotXYU result and puts them into X, Y and U arrays that could later be used for the robot to move to.
Function test
Boolean found(10)
Integer numfound, i
Real x(10), y(10), u(10)
Jump camshot 'move camera into position snap shot
VRun seq01 'run the vision sequence to find the pens
VGet seq01.blob01.NumberFound, numFound 'how many found
For i = 1 to numFound 'get robot coords
VGet seq01.blob01.RobotXYU(i), found(i), x(i), y(i), z(i)
Next i
'Add code for robot motion here……
Fend