Continuously switching between 4 positions.

  • Hi,


    I plan to continuously switch between four positions like that:

    - First I create a variable called COUNTER and assign it a value of 1.

    - In the same program I create an IF statemet...
    IF COUNTER < 4

    COUNTER = COUNTER + 1
    ELSE
    COUNTER = 1
    ENDIF


    In my mind this would result in the counter going 1 - 2 - 3 - 4 - 1 - 2 - 3 - 4 ... moving every time the program is run.

    - Then in the same program I use a SWITCH statement to create cases depending on the COUNTER.

    SWITCH COUNTER

    CASE 1

    PTP_1

    CASE 2

    PTP_2
    CASE 3

    PTP_3
    CASE 4

    PTP_4
    ENDSWITCH


    Will this work and if so, is it reasonable?

    Edited once, last by Koppel ().

  • I use a PLC to run different programs... but only one uses the counter.

    If I declare the variable COUNTER as a global variable... and use it without a loop... and the same program is run between different programs, will it work?


    I am guessing that each time the program is run, the global variable gets a new value. The other programs don't use or change that value, but the one that does should do it in increments.


    Does it need to be a global variable, since only one program is using it?
    But the one program is closed and opened again and again... it will always use the first declared value.

    I could declare the variable inside CONFIG.DAT ... when will it then use the assigned value? During controller reboot?
    "DECL GLOBAL INT MYVARIABLE = 0"

  • no need, this could be runtime variable (declared in SRC).

    declaration in $CONFIG.DAT would be without keyword GLOBAL

    declaration in SRC would be before first command (top of the program) and without keyword GLOBAL. Also in this case initialization is done in separate line... after declaration section.

    1) read pinned topic: READ FIRST...

    2) if you have an issue with robot, post question in the correct forum section... do NOT contact me directly

    3) read 1 and 2

  • If you declare and initialize the variable in the DAT file accompanying the SRC it will keep the value of the counter but you must take care in situations where program was interrupted (e.g. the robot was reset) to start from the counter value you want.

  • The IF statement won't quite work, as shown:

    Code
    IF COUNTER < 4 THEN
      COUNTER = COUNTER + 1
    ELSE
      COUNTER = 1
    ENDIF

    (You were also missing the THEN part)

    The issue is, if COUNTER reaches 4, it will become 5 and the rest of the program will run with that value until this IF is encountered again.

    The usual practice would be:

    Code
    COUNTER = COUNTER + 1
    IF COUNTER > 4 THEN
      COUNTER = 1
    ENDIF
  • If I just type something simple inside a SRC program directly with the smartpad, it gives me an error:

    "Instruction unknowntok() inadmissible (Module:Test Line :19)

    Any ideas?

    Even if I have just:

    LOOP

    PTP_1

    PTP_2

    ENDLOOP

    I just created a new module that creates the SRC and DAT file with the two HOME and END rows already in it.

    Why is it giving me this error? Its just two points inside an endless loop.
    EDIT: I try to execute the program in the T1 mode... if this is relevant.

    Edited once, last by Koppel ().

  • Ok. Thank you SkyFire... normally I use SELECT, teach a few positions, reset the program, hold down the deadman switch and press the play button to slowly go through the sequence of points that I have teached.


    I am happy to hear that it should not be impossible to write a program with just the SmartPad.
    With simple things it takes too much effort to do it in WorkVisual and then export it to the controller... I saw this as an alternative.

  • PTP_1 is not a valid command. what you see is not what you get. KRL hides a lot of info. before you can run, you need to learn to walk. use inline form instructions.



    The IF statement won't quite work, as shown:

    Code
    IF COUNTER < 4 THEN
      COUNTER = COUNTER + 1
    ELSE
      COUNTER = 1
    ENDIF

    ...

    The issue is, if COUNTER reaches 4, it will become 5 and the rest of the program will run with that value until this IF is encountered again.

    really?


    how...?


    in his example ELSE statement will take care of it....


    1) read pinned topic: READ FIRST...

    2) if you have an issue with robot, post question in the correct forum section... do NOT contact me directly

    3) read 1 and 2

  • LOOP

    PTP_1

    PTP_2

    ENDLOOP


    About the obove thing giving me an error... I know the PTP_1 is not a valid command. I had real In-Line form points inside the loop so no problem there.

    The problem was that I used the "SELECT" button to write the loop into the *:SRC and not the "OPEN" button.
    And SkyeFire cleared up this error for me and after that everything worked.

  • The tricky bit there is that Select mode will let you perform some edits, but they're limited to single-line edits -- the moment you move the cursor off that line, even just using the arrow keys, the system will immediately re-compile. And putting in an IF without an ENDIF generates a compilation error.


    So as a general rule, use Select if you're going to use Inline Forms (Motion, TouchUp buttons, etc), but any time you're going to type raw KRL code, use Open.

Advertising from our partners