error when using multiple trigger when distance DO X=X+1

  • Hello there,


    KRC4 , kuka OPC V8.3.21 HF1 , KR240 , workvisual 4.0.26


    In one of my program, I'm using "trigger when distance" to keep track of which point has been reached by the robot.


    $advance = 2


    But, when doing like this, the variable programStepNbr is only incremeted once when the robot reaches P3.


    The only way I could make it work was to change TRIGGER WHEN DISTANCE = 1 DELAY = 0 DO programStepNbr=programStepNbr+1 by TRIGGER WHEN DISTANCE = 1 DELAY = 0 DO programStepNbr=7 , 8 , 9 and so on.


    I suspect it'is due to the advance run (again). Is there an explanation why ?


    Also, sometimes it can happen that 2 following points have the same coordinates (because while programming we put more points than necessary to create the trajectory). How will the "trigger when distance" behave?


    Thank you in advance

  • it does exactly what is supposed to do... synchronize action with next motion where DISTANCE decides if it is begin or end of that motion.

    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

  • For two points programmed at the same location in space, if each point has an identical TRIGGER command associated with it, the TRIGGERs will probably fire at the same time, but be sequenced by their order -- Probably, the first TRIGGER that the main run pointer encounters will fire first, with the second queued immediately behind it.


    TRIGGER statements are used to 'bypass' the Advance Run Pointer, so I doubt that's your issue. Normally, I would have said that you shouldn't be using a mathematical expression in the DO section of the TRIGGER, but it seems like it's working at least once... odd.


    My best suggestion at the moment is to create a small subroutine that performs the incrementing math, and call that subroutine from each TRIGGER (you will need to explicitly add the PRIO=-1 argument as well). I suspect this will resolve your issue.

  • panic mode , the trigger when distance is working fine, the issue that I have is that, in my example, after playing the 3 ptp points, my variable pragramstepNbr is incremented only once, while it should have been incremented 3 time.


    SkyeFire, thank you, I just tried using a subroutine and now it is working as it should be. Looks like it is indeed due to the mathematical expression in the trigger when distance.


    Anyway, thank you guys!

  • maybe... it depends on when and where your variable programStepNbr is used or if you are monitoring it correctly (refresh?)

    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

  • panic mode, the variable is local (defined in the .dat), but for the sake of debugging I removed it from the .dat and made it global (in config.dat). It is only used in this program, not in the sps.
    I didn't do anything else other than using a subprogram with the increment inside to solve the issue.


    and regarding the monitoring, I'm using the built-in variable display on the KCP (I'm working in auto-ext mode).


    Also, while debugging,I saw that if I put a wait sec between points , then there is no problem with the variable increment.

  • [size=1em]your $ADVANCE must be 3 or greater.[/size]
    [size=1em]this means all triggers are initialized while first motion is taking place. at THIS moment value is zero for your variable (and each trigger takes a note of it).[/size]


    [size=1em]so each trigger does work but... each of them takes variable value from the moment of initialization, then adds 1 to it. so in this specific example, they all get same result.[/size]


    [size=1em]the best solution is to not do calculations, just do an assignment:[/size]


    [size=1em]trigger .... DO programStepNr = 1[/size]
    [size=1em]trigger .... DO programStepNr = 2[/size]
    [size=1em]trigger .... DO programStepNr = 3[/size]
    [size=1em]etc.[/size]



    [size=1em]EDIT:[/size]



    [size=1em]I am fascinated how often people try to monitor or micromanage each and every motion of the robot, for example have PLC check and bless each and every robot instruction. i find this just crazy, if that is the goal, why not use mxAutomation? even if this had value that i don't see, amount of work and [/size][size=2px]maintainability[/size][size=1em] of programs are not favorable[/size][size=1em]. it would be much simpler to monitor changes of $POS_FOR to increment some "motion counter" variable automatically, without sprinkling entire program(s) with TRIGGER commands or IO instrctions. and that would work with ANY robot program... just saying. or how about $PRO_IP1, or more specifically $PRO_IP1.SNR and $PRO_IP1.SNR_C[/size]

    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

    Edited once, last by panic mode ().

  • panic mode ok it makes sense now.


    Regarding your comment, if it was a simple motion program I agree with you, but in this case it is a program with motions , collision detection and tool operation inside(which is not a simple gripper). The whole program can be interrupted, so we need to keep track of which step of the program - being a simple motion or a tool operation - was in progress to react accordingly.


    I'm sure there is most certainly an easier way to manage this. I will take a look at those system variables you suggested to see if it can be helpful in our current program structures.

Advertising from our partners