How to monitor certain conditions using Karel in the "background"?

  • Dear all.

    I'd like to run a Karel program somehow in parallel to normal TP programs. In Karel program I want to monitor certain conditions (few IFs inside), and react for them (sets few flags). But my Karel program needs to be running all the time, like in the BG logic.

    When I make a loop inside (LBL:: and GOTO LBL), then RUN it parallel from TP program my controller stucks completelly and only cycle power helps.

    Could you please help me how to make it without any problems?

    Thanks a lot for help.

  • Yes, it seems like BG Logic is the best tool for this.

    If you must use KAREL then you can use a CONDITION which will continuously monitor an IF statement. However, your KAREL program will have to be running for the CONDITIONS to be active. This means you need to loop infinitely in the KAREL program. Don't forget to add a DELAY in your loop or it will lock up the controller as you described.

  • If you do go the Karel route, make sure to add a small delay at the beginning or end of your loop. If you don't do this you'll very quickly eat up your CPU. TP programs running continually with no motion groups always required a wait statement until a few versions ago (v7 or maybe earlier) else they would lockup the CPU as well.

    Edited once, last by pdl: fixed typo ().

  • Thanks a lot for advice - I'll try to add delay. Tomorrow I'll test it myself (need to fight with it :smiling_face: and if not succed I'll post the program and explain exactly what I want to do.


    Adding one more thing: can't use BG Logic because I want to read a system variable (string), and then if it is a predefined by me certain string, I want to set flags. Using BG Logic there is no possibility to read a string and write it into SR[x] and than finally run in in BG. That would be the easiest but Fanuc doesn't allow for that :frowning_face:

  • Gents, delay helped (my controller doesn;t stuck) but not really succeded - I have the following listing:


    name_lbl::

    GET_VAR(entry,'*SYSTEM*','$TP_DEFPROG',name_prog,status)

    IF status = 0 THEN

    IF name_prog = 'TEST987' THEN

    FLG[2] = ON

    ELSE

    ENDIF

    ELSE

    ENDIF

    DELAY 500

    GOTO name_lbl


    When I run the following program in cold and hot start (config) I got once F[2] = ON when system starts. Then when I switch F[2] = OFF it stays off all the time :frowning_face:


    And what I exactly need - I want to monitor $DEF_PROG - when somebody chooses defined by me name of the certain program (above it's TEST987), I want to set the flag.

    Could you please help and advise what I do wrong?

    Thanks a lot for your suggestions.

  • Where is the instruction to turn F[2] OFF?

    I don't see it anywhere in the code.


    Nevermind, I misread your post. Have you verified that the Karel program is still running?

    You could output the current value of name_prog to the USER screen for debugging.

    WRITE TPDISPLAY(name_prog,CR)

    Edited once, last by jmd2777: Error ().

  • Where is the instruction to turn F[2] OFF?

    I don't see it anywhere in the code.

    I already worte, but maybe was not enough precise - I leave the TEST987 program, enter different one, then I turn off manually F[2] = OFF (Menu -> I/O -> etc.). Finally I choose the program TEST987 (SELECT -> choose TEST987 -> ENTER), and finally my F[2] still remains off, ever after entering the program TEST987.

    The program probabbly starts, because I got the F[2] = ON after making cycle power.

    But anyway, I'll add the instruction to write the TP screen, as you've suggested and I'll see what's going on.

    Thanks a lot for your comment and help.

Advertising from our partners