Background programs

  • I'm getting stuck on setting up some background programs that I want to run on boot. One is a TP program, the other a KAREL program.


    I've tried adding each of them to the Cold Start Autoexec option under SYSTEM>CONFIG. No dice. Nothing happens when I cold boot the robot -- no errors show up in the alarm history, the programs just don't run.


    I also tried creating a CF file that would load and run both programs, and put it into the Autoexec option. Same (lack of) result.


    Then I tried going to SETUP>BG LOGIC. That got some result, at least -- an error! "Invalid item for mixed logic." Is the number after the program name supposed to be a line number?


    The odd thing is, I've been able to run both of these programs "normally" without issues. So there must be something specific to BG that doesn't like them, but I've got no idea what.

  • Hi SkyFire,

    in the BG_Logic you can not run TP an karel programs. You can also not call Programs in BG... I dont know the Logic of your programs.. but what are you trying to do with that?Maybe there is another way

  • The solution is BG_Logic for sure. Actually you can run TP programs in bg logic, but there are limitations, no motion commands, no WAIT instructions, older models doesn't let you use jumps etc. But bg will run continuously when the controller turned on.

  • These programs are purely I/O state machines -- no motion, no WAITs. Just endless loops. I need a background KAREL program b/c my custom web-page HMI is reading/writing values to KAREL variables using KCL URLs (for several reasons, we're trying to avoid using Fanuc's custom Ajax/ActiveX controls). My TP background program is mostly monitoring various station signals and updating status latches asynchronously with the actual motion program running "up front."

  • Autoexec will start the program once very early on bootup. So if the program runs quickly and exits you may not even notice that it ran.

    If you want to use Autoexec to start a Karel program on bootup and have it run continuously then you must create a loop in the main routine of the Karel code. You can either loop infinitely or use a FLAG to terminate the loop. Make sure to add a delay such as DELAY(50) at the end of the loop so that you don't bog down the processor.


    Also if your controller is using Hot Start then you need to put your program in the Hot Start Autoexec field instead of the Cold Start.

  • Yeah, my background TP and KAREL programs both have infinite internal loops.


    I created a "bootloader" TP program that just contains a 5sec wait, then consecutive RUN commands for the two background programs. If I run the bootloader by hand, everything works perfectly -- my background programs fire up and run forever. I can track them in STATUS>PROGRAM, and I have them pulsing some DOs so I can see them running.


    Thanks for the Hot Start hint -- I didn't realize my robot was defaulted to it. Once I turned off Hot Start, and cycled power, I got... partial success.


    Now, when I reboot, my KAREL program loads and runs forever. But my TP program loads, starts, and aborts on the first line (which is a LBL).


    I've got no idea why. The bootloader TP program and background TP program are both set to ***** motion group, and if I remove the bootloader from the AUTOEXEC and just run the bootloader by hand, both background programs start and run exactly as intended. I'm stumped here.

  • For your TP program, you will want to modify the abort and pause headers to 7. This will make it ignore pretty much all pause and abort requests, so I recommend adding in a register or some other method to stop the task if needed.


    I go over it in detail in this thread.


    Also I recommend keeping hot start on. The robot will lose its IO state and program position with it off upon reboot.

    Check out the Fanuc position converter I wrote here! Now open source!

    Check out my example Fanuc Ethernet/IP Explicit Messaging program here!

  • For your TP program, you will want to modify the abort and pause headers to 7.

    That would be the ABORT_REQUEST and PAUSE_REQUEST values in the .LS file, correct? (I'm currently writing all this "raw" in RoboGuide, pending the arrival of my real robot)


    Will this make the program proof against Abort All from the pendant?


    ...Actually, that's another question: Once I have these programs running in the background (as my KAREL program already is), how do I stop them? Right now, to make an edit to my KAREL background program, I have to remove my bootloader program from the Autoexec setting, then reboot the robot. There has to be a better way to do this.


    And regarding Autoexec... I'm probably missing something stupidly obvious, but there doesn't seem to be any way to set it to "none" -- I have to have a program selected. For the moment, I "cheated" by creating a TP program that contains nothing but a comment, and I swap that in to replace my bootloader when I don't want my background programs to start on boot. This works, but if there's a better way anyone knows to handle this, I'm all ears!

    Also I recommend keeping hot start on. The robot will lose its IO state and program position with it off upon reboot.

    For this particular application (small Collab robot working directly with humans, on a small simple process), I'm inclined to keep HS off, and just make it a standard procedure for the operators to push the robot Home and do a full Abort All and start from Main. But I'm not married to the idea -- I'll have to give this some thought, in my copious spare time. :icon_rofl:

  • ... Once I have these programs running in the background (as my KAREL program already is), how do I stop them? ....


    ...This will make it ignore pretty much all pause and abort requests, so I recommend adding in a register or some other method to stop the task if needed.


    I go over it in detail in Re: DCS automatic restart thread....

    Create a state in your statemachine in the Karel program that ends the inifinte loop. Or just read a flag/register or something else to stop the loop.

  • Create a state in your statemachine in the Karel program that ends the inifinte loop. Or just read a flag/register or something else to stop the loop.

    Please excuse me while I :wallbash: for being an idiot. I swear, I've lost half my IQ points this week, trying to learn TP, KAREL, iPendant Controls, the CRX Tablet Pendant, and all the fiddly Fanuc integration bits at the same time.

  • Guess who's back... back again....


    Well, my background programs are working well, and starting on boot... except for one lingering issue, that only showed up when I moved from RoboGuide to the real robot.


    I've added my BootLoader program to both the Hot and Cold Autoexec options under SYSTEM>CONFIG. And if I use the "shutdown" option on the pendant to set either Hot or Cold reboot, BootLoader runs on boot.


    HOWEVER! :justice: If I just switch off the main power on the cabinet, then switch back on, BootLoader does not run. However, my background programs that BootLoader RUNs get aborted in this scenario -- they're no longer present in STATUS>PROGRAM after the robot finishes recovering.


    I never saw this in RoboGuide b/c I just used the Cold Boot option all the time.


    So, if killing main power isn't a Hot or Cold reboot, what kind of reboot is it? And since I need to ensure my BootLoader always runs when the robot gets rebooted any way, for any reason (except a Controlled Start, obviously), how do I cover this particular contingency?


    I'm also unsure if this is behavior unique to this particular robot, as it's the new CRX, running 9.4 on an R30iB Mini Plus controller. One thing about this robot is that it won't reboot from the pendant -- you can select Hot or Cold or Controlled, but the pendant asks me to physically cycle power after making the selection. I'm curious as to whether this is a typical Fanuc behavior for some models, or if this robot is a special case.

  • Hmm. That seems different than the behavior I usually see.

    Is BootLoader a program that you created?

    Is BootLoader a TP program or a Karel program? Can you post the contents of the program?

    Is "Use HOT START" set to TRUE or FALSE?

  • It should be a hot start, assuming you have HOT START set. Odd that you aren't seeing your boot loader fire up.


    Regarding the requirement for the physical power cycle, I believe the Mate controllers lack a relay that allows them to cycle their own power.

    Check out the Fanuc position converter I wrote here! Now open source!

    Check out my example Fanuc Ethernet/IP Explicit Messaging program here!

  • BootLoader is my own TP program. I have two different state machines (one KAREL, one TP) that need to be started on boot. BootLoader basically contains just two RUN commands, one for each state machine.


    I think "use Hot Boot" is currently False, but I'll have to check. I put BootLoader into both Hot&Cold Autoexecs just to make sure all my bases are covered.


  • Would it be possible to convert your two state machines to BG logic, and just run it from there?

    I'm afraid not. At minimum, I need the KAREL program to work with my HMI -- the HMI is a web page accessing the KAREL variables via URL commands.


    I'm also using a fair number of Flags, and BG Logic can't use Flags (or so I've been told?).

  • BG can totally use flags. You just have to use the ...=(...) mixed logic format to toggle or set them. The BG logic example thread has a ton of examples.


    You could use the macro table tied to a flag to fire your KAREL program to update the HMI at various events, or just on a one shot on power on, or even use that method to start your existing programs. I think if you start them from the macro table, they won't show up when you hit the monitor softkey on the select menu, which may or may not be desired.


    Regarding your bootloader not loading, it may be worth a call to Fanuc on it. Their latest version of software is not known to be the most bug free in my experience.

    Check out the Fanuc position converter I wrote here! Now open source!

    Check out my example Fanuc Ethernet/IP Explicit Messaging program here!

  • I've got a call in to Fanuc, but no response so far.


    As a workaround, I'm looking at making my BootLoader part of one of my KAREL programs. Since I can remotely trigger a KAREL program, I'm thinking that I could have my HMI "start" button trigger a KAREL action that would check the run status of my background programs, and trigger them if they're not running. A bit kludgey, but it might work.


    Anyone know the KAREL equivalent of the RUN command? And whether it can be used to start TP programs?


    BG can use Flags? Darn, wish I'd known that a few weeks ago. Ah, well, call it a learning experience. :gaah:

Advertising from our partners