A counter can easily be added to a robot program using a B (Byte), I (Integer) or D (Double) Variable. The choice of which type of Variable depends on how many items need to be counted. The range for each variable type is shown below.
Variable Type | Range |
B (Byte) | 0-255 |
I (Integer) | -32768-32767 |
D (Double) | -2147483648 - 2147483647 |
After choosing the Variable type, set the variable to 0 at the beginning of the program using the “Set” instruction, and then use the “Increment” command to increment the value when desired. For example, the code below shows a simple Label/Jump structure that will loop through a few motions and write a few I/Os. The Variable B010 is set to 0 at the top of the program, and then incremented each loop. Thus, B010 will contain the number of loops which have executed.
In some cases, the Variable should be incremented by more than 1 each loop (e.g. if picked parts are being counted and multiple picks can occur at once). For this, simply use the “Add” command to increment the desired amount. For example, to add 2 to B010, Line 10 could be changed to the following:
Comments
0 comments
Please sign in to leave a comment.