Is there a way to add a counter to a program to count cycles? If so how would you word it in the program as an if statement? For example. If the counter equals 20 call the following program, if its under 20 skip over it.
Counters
- mcminn
- Thread is marked as Resolved.
-
-
It's quite simple.
First, declare an Integer variable in the .DAT file of the module:
The initial value is important so that the count will be remembered even when the program is cancelled, or the robot is rebooted.Then, in the SRC file:
The counter can be reset simply by using
-
Im still having some issues entering the counter. I have been able to enter in all the information into the programs without any error messages but I'm obviously still doing something wrong. Is there a way to view your counter so you know what its number it is at? Do I need a command like CycleCounter=+1 at the bottom of my program?
I'm also having a hard time understanding how to declare an Integer Variable in the .DAT file of the module. To get there do I go through Program-File-Datalist? If so do I just enter the "DECL INT CycleCounter = 0" at the bottom?
Just a simple breakdown of how I have the program as of now which might help you understand what I'm trying to explain.
INI
PTP HOME
LOOPIF CycleCounter==20 THEN;
SubProgram()
ENDIFSubProgram1()
ENDLOOP -
Is there a way to view your counter so you know what its number it is at? Do I need a command like CycleCounter=+1 at the bottom of my programYes add CycleCounter=CycleCounter+1 before the ENDLOOP.
Also I would add CycleCounter=0 at the start to reset the count when you first run the program.
Just put INT CycleCounter=0 in the dat file, at the start or end doesn't matter.
You can see the value of it when the program is loaded by MONITOR>VARIABLE>SINGLE and typing the name there.
Sent using Tapatalk 2.
-
Thanks guys, the help was very much appreciated.