1. Home
    1. Dashboard
    2. Search
  2. Forum
    1. Unresolved Threads
    2. Members
      1. Recent Activities
      2. Users Online
      3. Team Members
      4. Search Members
      5. Trophys
  3. Articles
  4. Blog
  5. Videos
  6. Jobs
  7. Shop
    1. Orders
  • Login or register
  • Search
This Thread
  • Everywhere
  • This Thread
  • This Forum
  • Articles
  • Pages
  • Forum
  • Blog Articles
  • Products
  • More Options
  1. Robotforum - Support and discussion community for industrial robots and cobots
  2. Forum
  3. Industrial Robot Support and Discussion Center
  4. Fanuc Robot Forum
  5. Manuals, Software and Tools for Fanuc Robots (you should look here first before posting)
Your browser does not support videos RoboDK Software for simulation and programming
Visit our Mainsponsor
IRBCAM
Robotics Channel
Robotics Training
Advertise in robotics
Sponsored Ads

BGLOGIC code that I have found useful

  • flatcurve
  • December 16, 2010 at 9:35 PM
  • Thread is Resolved
  • flatcurve
    Reactions Received
    18
    Trophies
    3
    Posts
    58
    • December 16, 2010 at 9:35 PM
    • #1

    So, I've only been using BGLOGIC for a couple months now. In my opinion, this is something that FANUC should teach in their advanced TPP class, because it's extremely useful. If it wasn't for the suggestion of somebody here, I never would have discovered this feature on my own. I guess they expect people to read their manual cover to cover, but there isn't enough coffee in the world to keep me awake if I tried that. I've managed to take a lot of heat off of our PLC programmer, and I've already developed a few routines that I've found almost universally useful.

    So as a way of saying thanks, here are a couple code snippets I thought I'd share.

    One shots are used when you only want something to happen for one scan of the program. This can be used to replace macros that are triggered by inputs. Why would you want to do that? Well, input macros don't work in T1 or T2.

    One Shot Method A
    F[1]=(OFF)
    IF (DI[1] AND !F[2]),F[1]=(ON)
    F[2]=(DI[1])
    Now F[1] can be used at any point to test for a one shot condition before the end of the BG program

    One Shot Method B
    IF (DI[1] AND !F[1]),...
    (Repeat above IF instruction when needed before next line)
    F[1]=(DI[1])

    One Shot Output Toggle
    This is handy for using a single input (like a push button or sensor) to toggle an output on and off
    IF (DI[1] AND !F[1]),DO[1]=(!DO[1])
    F[1]=(DI[1])

    Output Strobe
    We put three color stack lights on our controllers, and I use this routine to make the yellow light flash when I turn on F[1]
    IF (F[1] AND !F[3]),F[2]=PULSE,0.2sec
    IF (F[1] AND !F[2]),F[3]=PULSE,0.2sec
    IF (!F[1]),F[2]=(OFF)
    IF (!F[1]),F[3]=(OFF)
    DO[1:Light]=(F[2])

    If anybody wants to add, feel free!

  • pepioto
    Guest
    • June 27, 2011 at 10:49 AM
    • #2

    I work with fanuc M410 ib and i can´t do this instruction with ROBOGUIDE soft where can i download or buy the BGLOGIC?
    And if you can showme pictures that it makes useful with a simulation it will be cool.

    Thanxs

  • robodog
    Trophies
    3
    Posts
    13
    • June 28, 2011 at 5:06 PM
    • #3

    i use back ground logic alot ansd i dont think you would be able to do it with roboguide because it is mixed logic, (non motion). but then again i have never used roboguide i do all of my programming at the TP. I found it very useful to take the place of karel which i hate!!! soo much easier just to open up your BGlogic progrqam and edit it right there at the TP instead of having to compile and recompile... ect

    Edited once, last by robodog (September 19, 2011 at 2:06 PM).

  • flatcurve
    Reactions Received
    18
    Trophies
    3
    Posts
    58
    • July 14, 2011 at 3:30 PM
    • #4

    It does work with roboguide, however it has caused a few crashes in my experience. Since I predominantly use it to monitor discrete i/o, I usually don't bother running it in simulation.

  • mani_mech031
    Reactions Received
    1
    Trophies
    3
    Posts
    6
    • September 15, 2011 at 12:25 PM
    • #5
    Quote from flatcurve


    One shots are used when you only want something to happen for one scan of the program. This can be used to replace macros that are triggered by inputs. Why would you want to do that? Well, input macros don't work in T1 or T2.

    One Shot Method A
    F[1]=(OFF)
    IF (DI[1] AND !F[2]),F[1]=(ON)
    F[2]=(DI[1])
    Now F[1] can be used at any point to test for a one shot condition before the end of the BG program

    One Shot Method B
    IF (DI[1] AND !F[1]),...
    (Repeat above IF instruction when needed before next line)
    F[1]=(DI[1])

    One Shot Output Toggle
    This is handy for using a single input (like a push button or sensor) to toggle an output on and off
    IF (DI[1] AND !F[1]),DO[1]=(!DO[1])
    F[1]=(DI[1])

    Output Strobe
    We put three color stack lights on our controllers, and I use this routine to make the yellow light flash when I turn on F[1]
    IF (F[1] AND !F[3]),F[2]=PULSE,0.2sec
    IF (F[1] AND !F[2]),F[3]=PULSE,0.2sec
    IF (!F[1]),F[2]=(OFF)
    IF (!F[1]),F[3]=(OFF)
    DO[1:Light]=(F[2])

    Display More

    ho flat can you clearly explain i am little bit confused about this logic..... :waffen100: thanks in advance :icon_smile:

  • flatcurve
    Reactions Received
    18
    Trophies
    3
    Posts
    58
    • September 15, 2011 at 5:52 PM
    • #6

    Background Logic programs are scan routine programs that constantly run in the background. They are executed one line at a time, from start to finish, repeatedly. If you know anything about PLC programming, they are very similar to the way those programs are structured and run. You can only use assignment statements in background logic programs. This means that you can not use motion instructions, branching statements (jump, label, call, run, etc...), timers, WAIT instructions or macros.

    So basically you are limited to setting registers, I/O and system variables. And the only conditional statement you can use is the mixed logic IF statement: IF (...)

    All of this is to keep the program simple so that it can be executed quickly. In my experience, if you're dealing with less than 16 inputs and 16 outputs, background logic is a good way to avoid using a PLC in the workcell if you don't have to. Anything more than that would probably be better suited to either the PMC option or a PLC. For me, the primary way I use it is to set up run conditions that must be met before the robot can be operated in automatic.

    A "one shot" is probably the most valuable tool you can use when doing this sort of programming. Remember that this program is repeatedly scanning (looping) in the background. We use a one shot to make something happen for only one scan. For example, let's say we have a button connected to an input (DI[1]). Every time we push the button, we want to add 1 to the value of a register (R[1]).

    IF (DI[1), R[1]=R[1]+1

    The problem with this code though is that the program is repeating every 8ms. Unless you have very quick hands, it's likely that the button will be held down for more than one scan of the program, resulting in more than 1 being added the the register. So to fix it, we have to use a one shot:

    F[1]=(OFF)
    IF (DI[1] AND !F[2]),F[1]=(ON)
    F[2]=(DI[1])
    IF (F[1]), R[1]=R[1]+1

    And here's how it works scan by scan:

    First scan with DI[1] on:
    F[1]=(OFF) ;We always turn this flag off at the start of the cycle
    IF (DI[1] AND !F[2]),F[1]=(ON) ;If DI[1] is on, and F[2] is off, we want to turn F[1] on
    F[2]=(DI[1]) ;Now we want to set F[2] to the same state as DI[1]. This means that on the next "scan", the condition in the previous line will not be met.
    IF (F[1]), R[1]=R[1]+1 ;If we've gotten this far, and we see that F[1] is on, that means we know it's the first scan where we've seen DI[1] on

    Second scan with DI[1] on:
    F[1]=(OFF) ;Again, this flag gets turned off to avoid repeating any of those assignments again
    IF (DI[1] AND !F[2]),F[1]=(ON) ;This time around F[2] is on, so this condition is not met, and F[1] stays off
    F[2]=(DI[1]) ;This holds F[2] on until we see DI[1] turn off.
    IF (F[1]), R[1]=R[1]+1 ;This line will not execute

    First scan with DI[1] off:
    F[1]=(OFF)
    IF (DI[1] AND !F[2]),F[1]=(ON) ;DI[1] is off, and F[2] is still on from the last cycle. Condition still not met.
    F[2]=(DI[1]) ;Now F[2] is turned off. The next time DI[1] comes on, the above condition will be met again.
    IF (F[1]), R[1]=R[1]+1


    Basically it all comes down to order of execution. If you put things in the right order, you can do practically anything. Earlier I said that I prefer to use BG Logic with less than 16 inputs and outputs, but I have used it as a cell controller on a system that had 32 inputs and 48 outputs. It controlled everything from the notification lights, an exit conveyor, a couple of pneumatic cylinders, a small printer and another robot. All with background logic. I would have preferred a PLC or even just the PMC option, but the customer beat us up on price and the budget didn't allow it.

    Here's a chunk of code from one of the four BG Logic programs running on that system that uses all sorts of one shots and cascading logic:

    Code
    1:  F[69:PrntMaint]=(!DI[26:PrntrRunPos]) ;
       2:   ;
       3:  !Cycle Printer & Shear ;
       4:  IF (DI[14:LblReelEmpty]),F[19:ReelLockout]=(ON) ;
       5:  IF (DI[15:ManualPrint] AND DI[27:PrntrMaintPos] AND !DI[14:LblReelEmpty]),F[19:ReelLockout]=(OFF) ;
       6:  IF (DI[12:LblShtl_Retr] AND F[9:PrntrInCycle]),F[17:ManTrig]=(OFF) ;
       7:  IF (DI[15:ManualPrint] AND !F[18:ManTrigPB_OS] AND DI[27:PrntrMaintPos] AND !F[19:ReelLockout]),F[17:ManTrig]=(ON) ;
       8:  F[18:ManTrigPB_OS]=(DI[15:ManualPrint]) ;
       9:  IF (F[17:ManTrig] AND F[13:LabelPresent] AND DI[27:PrntrMaintPos] AND !F[9:PrntrInCycle]),DO[16:LblSlideVac]=(OFF) ;
      10:  IF (F[17:ManTrig] AND F[13:LabelPresent] AND DI[27:PrntrMaintPos] AND !F[9:PrntrInCycle]),F[13:LabelPresent]=(OFF) ;
      11:  F[24:AutoPTrigRdy]=(F[23:AutoPTrigAllow] AND DI[26:PrntrRunPos]) ;
      12:  F[12:PrntAutoTrig]=(F[17:ManTrig] OR F[24:AutoPTrigRdy]) ;
      13:  F[10:PrntTrigOS]=(OFF) ;
      14:  IF (F[19:ReelLockout]),F[12:PrntAutoTrig]=(OFF) ;
      15:  IF (!F[10:PrntTrigOS] AND !F[9:PrntrInCycle] AND F[12:PrntAutoTrig] AND DI[12:LblShtl_Retr] AND !F[13:LabelPresent]),F[10:PrntTrigOS]=(ON) ;
      16:  IF (F[10:PrntTrigOS]),F[9:PrntrInCycle]=(ON) ;
      17:  IF (F[9:PrntrInCycle] AND F[10:PrntTrigOS]),F[14:TrigPrntr]=(ON) ;
      18:  IF (F[9:PrntrInCycle] AND F[14:TrigPrntr]),F[66:ShearDelay]=PULSE,0.6sec ;
      19:   ;
      20:  IF (F[9:PrntrInCycle] AND F[14:TrigPrntr] AND F[66:ShearDelay]),DO[12:TriggerPrinter]=PULSE,0.3sec ;
      21:   ;
      22:  IF (F[9:PrntrInCycle] AND F[14:TrigPrntr] AND !F[66:ShearDelay]),F[11:PrntFinished]=(ON) ;
      23:  IF (F[9:PrntrInCycle] AND F[14:TrigPrntr] AND !F[66:ShearDelay]),F[14:TrigPrntr]=(OFF) ;
      24:   ;
      25:  IF (F[9:PrntrInCycle] AND F[11:PrntFinished] AND DI[10:ShearOpen] AND !F[15:ShearClosed]),DO[14:CloseShear]=(ON) ;
      26:  IF (F[9:PrntrInCycle] AND F[11:PrntFinished] AND DI[10:ShearOpen] AND !F[15:ShearClosed]),DO[16:LblSlideVac]=(ON) ;
      27:  IF (F[9:PrntrInCycle] AND F[11:PrntFinished] AND DO[14:CloseShear] AND DI[11:ShearClosed] AND !F[15:ShearClosed]),F[15:ShearClosed]=(ON) ;
      28:  IF (F[9:PrntrInCycle] AND F[11:PrntFinished] AND DO[14:CloseShear] AND DI[11:ShearClosed] AND F[15:ShearClosed]),DO[14:CloseShear]=(OFF) ;
      29:  IF (F[9:PrntrInCycle] AND F[11:PrntFinished] AND DI[10:ShearOpen] AND F[15:ShearClosed] AND !F[16:ShearDone]),F[16:ShearDone]=(ON) ;
      30:  IF (F[9:PrntrInCycle] AND F[16:ShearDone] AND DI[12:LblShtl_Retr] AND !DO[15:LblSlideExtend]),DO[15:LblSlideExtend]=(ON) ;
      31:  IF (F[9:PrntrInCycle] AND F[16:ShearDone] AND DI[13:LblShtl_Ext] AND DO[15:LblSlideExtend]),F[13:LabelPresent]=(ON) ;
      32:  IF (F[13:LabelPresent] AND F[9:PrntrInCycle]),F[15:ShearClosed]=(OFF) ;
      33:  IF (F[13:LabelPresent] AND F[9:PrntrInCycle]),F[16:ShearDone]=(OFF) ;
      34:  IF (F[13:LabelPresent] AND F[9:PrntrInCycle]),F[11:PrntFinished]=(OFF) ;
      35:  IF (F[13:LabelPresent] AND F[9:PrntrInCycle]),F[9:PrntrInCycle]=(OFF) ;
      36:  IF (!F[13:LabelPresent] AND !F[9:PrntrInCycle] AND DI[13:LblShtl_Ext]),DO[15:LblSlideExtend]=(OFF) ;
    Display More

    This code basically triggers a printer to print a label, cut the label with a shear, move the cut label with a small slide so that the robot can pick it, and tells the robot that there's a label present. Once the robot picks it, it turns off the label present flag which starts the print cycle again automatically. All of this happens in under a second while the robot is off applying the label. It also has allowances for a manual push button trigger so that the printer can be set up and tested in a maintenance mode. This is the primary reason I used BG Logic instead of a macro. Because BG Logic runs all the time, whether the robot is paused, in automatic, or in teach mode. This means maintenance personnel don't need to mess with the teach pendant as much. From a support standpoint, I prefer that whenever possible.

    Like I said, you can do anything with it.

  • zhouchunzhang012
    Trophies
    3
    Posts
    2
    • October 18, 2011 at 5:34 PM
    • #7

    Nb! :bravo:

  • Sergei Troizky
    Reactions Received
    67
    Trophies
    6
    Posts
    650
    • October 31, 2011 at 11:32 PM
    • #8

    Changing the startup default Joint jogging coordinates to World:

    IF (!F[1:BOOT DONE]),$JCR_GRP[1].$JOG_COORD=(2) ;
    F[1:BOOT DONE]=(ON)

    Do it well right away. It will become bad by itself.

    Edited once, last by Sergei Troizky (June 7, 2014 at 1:57 AM).

  • Robo1
    Trophies
    3
    Posts
    11
    • April 3, 2013 at 5:54 AM
    • #9

    Hello Flatcurve,

    I read your post and really interesting to use it on one of our application. However, i'm having couple of questions. Hope you can guide me through this process.

    1. Is BG Logic written in the TP program?
    2. I would like to accomplish the logic below, could you help with the code how it should be written?

    If input 1 OFF and input 2 OFF don't do anything
    If Input 1 ON and Input 2 OFF then turn on output 1 for 500 milisecond
    If input 1 Off and input 2 On then ouput 1 stay off.
    (They are all Digital I/O)

    Thanks in advance for your help.
    Thank you,

  • andreic
    Reactions Received
    24
    Trophies
    4
    Posts
    280
    • May 10, 2013 at 1:55 PM
    • #10

    Hi Robo1,

    You can setup BGLOGIC from Menu -> Setup -> BGLOGIC where you can choose your BGLOGIC program.

    To accomplish the logic you need:
    IF (DI[1] AND !DI[2]),DO[1]=PULSE,0.5sec. Put this in a TP program and add it's name in setup menu.

  • DuhbCakes
    Guest
    • July 15, 2013 at 11:07 PM
    • #11

    This will allow you to toggle a digital output from a DCS CPC zone without using safe I/O. obviously by using a single channel output, it is no longer a safety signal but it is useful for protecting equipment.

    : IF ($DCSS_PSTAT.$STATUS_CPC[1]=0),DO[1:Clear Transfer DCS]=(ON) ;
    : IF ($DCSS_PSTAT.$STATUS_CPC[1]=1),DO[1:Clear Transfer DCS]=(OFF) ;

    This will monitor if someone has jogged the robot. i use it for auto recovery. The bit can be cleared by moving to a point in a program, ether in auto or T1.

    : DO[1:Robot Jogged]=($MOR_GRP[1].$JOGGED) ;

  • amanmani
    Trophies
    3
    Posts
    6
    • September 24, 2013 at 8:30 PM
    • #12

    Very useful post

    I wish to create a user alarm when a certain DI gets on but I am not able to write User alarm in BG logic as I am getting syntax error .
    Please help me guys I am a newbie and wish to learn

    Thanks in advance !!!!! :help:

  • Sergei Troizky
    Reactions Received
    67
    Trophies
    6
    Posts
    650
    • December 11, 2013 at 4:25 AM
    • #13

    STEP mode indicator output:
    DO[n]=($SSR.$SINGLESTEP)

    Do it well right away. It will become bad by itself.

  • Sergei Troizky
    Reactions Received
    67
    Trophies
    6
    Posts
    650
    • December 11, 2013 at 3:54 PM
    • #14
    Quote from flatcurve


    One Shot Method A
    F[1]=(OFF)
    IF (DI[1] AND !F[2]),F[1]=(ON)
    F[2]=(DI[1])
    Now F[1] can be used at any point to test for a one shot condition before the end of the BG program

    One Shot Method B
    IF (DI[1] AND !F[1]),...
    (Repeat above IF instruction when needed before next line)
    F[1]=(DI[1])

    Display More

    The most simple way to generate one shot is using the PULSE instruction with no time specified.
    In BG Logic, this generates a single scan pulse.
    Note, that in normal (non background) execution this will generate a pulse of default $DEFPULSE duration.

    Do it well right away. It will become bad by itself.

    Edited once, last by Sergei Troizky (December 11, 2013 at 3:55 PM).

  • flatcurve
    Reactions Received
    18
    Trophies
    3
    Posts
    58
    • December 20, 2013 at 6:58 PM
    • #15
    Quote from Sergei Troizky


    The most simple way to generate one shot is using the PULSE instruction with no time specified.
    In BG Logic, this generates a single scan pulse.
    Note, that in normal (non background) execution this will generate a pulse of default $DEFPULSE duration.

    also note that the PULSE command does not work in FAST mode (guaranteed 8msec scan time) so if you need edge detection in a fast bg program, you gotta do it like this:

    F[1]=(DI[1] AND !F[2])
    F[2]=(DI[1])

  • Sergei Troizky
    Reactions Received
    67
    Trophies
    6
    Posts
    650
    • May 4, 2014 at 7:28 PM
    • #16

    Automatically disable/enable UOP when TP is On/Off:
    $OPWORK.$UOP_DISABLE=(UO[8:TP_Enabled])
    The instruction must be created as Registers ...=(...), not as Miscellaneous>Parameter Name.
    The background program must be set (in its Detail) to ignore pause conditions.

    Do it well right away. It will become bad by itself.

  • bidzej
    Reactions Received
    23
    Trophies
    4
    Posts
    592
    • July 18, 2014 at 12:17 PM
    • #17

    As we're talking about scan time for BGLOGIC program - how fast does BGLOGIC for R-30iB work? I'd like to implement a control system for a simple palletizing application using only BGLOGIC (instead of PMC) and I'm afraid that if the program is too long and complex, there may be situations when i. e. a pulsed signal from a sensor is omitted.

    I see that it's possible to set the scan time for 8msec, but - if I understand correctly - this limits functionality of BGLOGIC, so I'd like to use standard mode...

  • flatcurve
    Reactions Received
    18
    Trophies
    3
    Posts
    58
    • July 25, 2014 at 12:10 AM
    • #18

    Scan time is still 8msec (12msec on mate controllers) but the amount of items processed per ITP greatly increased in v8 of HandlingTool. (540 vs. 300) An item is data, an operator or an instruction. So the following is a 3 item statement:

    F[1]=(DI[1])

    Item 1: F[1]
    Item 2: =
    Item 3: (DI[1])

    My general rule of thumb is to use a PLC if I have more than 32 outputs to control. Obviously there's also considerations for what those outputs are doing. But if you think you might have pulsed inputs shorter than your scan time (x2), you should just use a PLC regardless.

  • bidzej
    Reactions Received
    23
    Trophies
    4
    Posts
    592
    • July 25, 2014 at 8:19 AM
    • #19

    Thanks, that expains a lot! :merci:

  • diglo
    Reactions Received
    7
    Trophies
    3
    Posts
    142
    • December 2, 2014 at 1:56 PM
    • #20

    Tell if a bit is set in a positive integer value:
    Example: test 4th bit: 2^(4-1)=8

    Code
    F[1]=((R[1] DIV 8 MOD 2)>0)

    Example: test 5th bit: 2^(5-1)=16

    Code
    F[1]=((R[1] DIV 16 MOD 2)>0)


    To test

    Single-instruction timer:
    125 is for 1 Second ,because 8ms = 1/125 of a second. Test it against your BGLOGIC scan speed.

    Code
    R[1]=((R[1]+1)  MOD 125 );
     IF (R[1]=0), stuff to do each interval ;

Advertising from our partners

IRBCAM
Robotics Channel
Robotics Training
Advertise in robotics
Advertise in Robotics
Advertise in Robotics

Job Postings

  • Anyware Robotics is hiring!

    yzhou377 February 23, 2025 at 4:54 AM
  • How to see your Job Posting (search or recruit) here in Robot-Forum.com

    Werner Hampel November 18, 2021 at 3:44 PM
Your browser does not support videos RoboDK Software for simulation and programming

Tag Cloud

  • abb
  • Backup
  • calibration
  • Communication
  • CRX
  • DCS
  • dx100
  • dx200
  • error
  • Ethernet
  • Ethernet IP
  • external axis
  • Fanuc
  • help
  • hmi
  • I/O
  • irc5
  • IRVIsion
  • karel
  • kawasaki
  • KRC2
  • KRC4
  • KRC 4
  • KRL
  • KUKA
  • motoman
  • Offset
  • PLC
  • PROFINET
  • Program
  • Programming
  • RAPID
  • robodk
  • roboguide
  • robot
  • robotstudio
  • RSI
  • safety
  • Siemens
  • simulation
  • SPEED
  • staubli
  • tcp
  • TCP/IP
  • teach pendant
  • vision
  • Welding
  • workvisual
  • yaskawa
  • YRC1000

Thread Tag Cloud

  • abb
  • Backup
  • calibration
  • Communication
  • CRX
  • DCS
  • dx100
  • dx200
  • error
  • Ethernet
  • Ethernet IP
  • external axis
  • Fanuc
  • help
  • hmi
  • I/O
  • irc5
  • IRVIsion
  • karel
  • kawasaki
  • KRC2
  • KRC4
  • KRC 4
  • KRL
  • KUKA
  • motoman
  • Offset
  • PLC
  • PROFINET
  • Program
  • Programming
  • RAPID
  • robodk
  • roboguide
  • robot
  • robotstudio
  • RSI
  • safety
  • Siemens
  • simulation
  • SPEED
  • staubli
  • tcp
  • TCP/IP
  • teach pendant
  • vision
  • Welding
  • workvisual
  • yaskawa
  • YRC1000
  1. Privacy Policy
  2. Legal Notice
Powered by WoltLab Suite™
As a registered Member:
* You will see no Google advertising
* You can translate posts into your local language
* You can ask questions or help the community with your knowledge
* You can thank the authors for their help
* You can receive notifications of replies or new topics on request
* We do not sell your data - we promise

JOIN OUR GREAT ROBOTICS COMMUNITY.
Don’t have an account yet? Register yourself now and be a part of our community!
Register Yourself Lost Password
Robotforum - Support and discussion community for industrial robots and cobots in the WSC-Connect App on Google Play
Robotforum - Support and discussion community for industrial robots and cobots in the WSC-Connect App on the App Store
Download