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
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

Bit Mask operation

  • CPh
  • October 16, 2019 at 9:47 AM
  • Thread is Unresolved
  • CPh
    Reactions Received
    2
    Trophies
    3
    Posts
    51
    • October 16, 2019 at 9:47 AM
    • #1

    Hello,

    I want to use a bit mask on a register in a IF to check some conditions.. Do you know if it is possible to do that in a TP program or should I need to call Karel ?

  • HawkME
    Reactions Received
    568
    Trophies
    10
    Posts
    3,268
    • October 16, 2019 at 12:44 PM
    • #2

    There is no bitwise functions that I am aware of in TP.

    What is the purpose you you wanting to do this? We may be able to help you find a different solution.

  • dha
    Reactions Received
    28
    Trophies
    6
    Posts
    397
    • October 16, 2019 at 2:14 PM
    • #3

    You can do it in KAREL

  • CPh
    Reactions Received
    2
    Trophies
    3
    Posts
    51
    • October 16, 2019 at 3:34 PM
    • #4
    Quote from HawkME

    What is the purpose you you wanting to do this? We may be able to help you find a different solution.

    I have a register, R[200] in which I set alarms.

    Then I use this register to find which alarms are activated.

    When R[200] == 1, I want to call a sub-program to display a notification.

    When R[200] == 2 (10), I want to stop the program

    When R[200] == 3 (11), I want to stop the program

    In my program I will write something like below:

    Code
    IF (R[200] AND 1) THEN JMP LBL[10:Warning]
    ELSEIF (R[200] AND 2) THEN JMP LBL[11:STOP]
    ENDIF

    I don't know if it's really clear..

    If the previous code doesn't work I think it will be possible to use the operator DIV and MOD to check if a bit is set !

    Code
    R[1] = R[200] DIV 2
    R[1] = R[1] MOD 2
    IF R[1] == 0 => bit 2 is equal to 0
    IF R[1] == 1 => bit 2 is equal to 1 

    I am going to try that :smiling_face:

  • Fabian Munoz
    Reactions Received
    133
    Trophies
    9
    Articles
    1
    Posts
    1,517
    • October 16, 2019 at 7:16 PM
    • #5

    Hi


    Somewhere in your program you set R200 to a value, lets say R[200]=1

    Then, somewhere else you ask the questions about the value of R200

    IF R[200] = 1 , JMP LBL (30)

    IF R[200] =2 , JMP LBL (33)

    So, in LBL(33) you do something and from there you go home or jump back to other part of the program

    If you want to stop the program you could

    LBL 11

    !Stop program

    !Wait R111= 999

    You program will wait forever until an arbitrary register = 999 or you can wait for an input that you will never use OR send an output to the PLC to stop you

    Retired but still helping

  • I3ooI3oo
    Reactions Received
    5
    Trophies
    3
    Posts
    77
    • October 16, 2019 at 8:23 PM
    • #6

    Your program is only hard if the system can have multiple alarms at once. If this is the case then you could just do the following:

    Code
    1=Bad Thing
    2=Worse Thing
    4=Really bad thing
    8=Worst thing possible
    Code
    IF R[200] >= 8 THEN
    R[200]=R[200]-8
    CALL WORST_THING_POSSIBLE
    END IF
    IF R[200] >=4 THEN
    R[200]=R[200]-4
    CALL REALLY_BAD_THING
    END IF
    IF R[200] >= 2 THEN
    R[200]=R[200]-2
    CALL WORSE_THING
    END IF
    IF R[200] >= 1 THEN
    R[200]=R[200]-1
    CALL BAD_THING
    END IF
    Display More

    At the start of your program you would need to set R[200]=0. Then when ever a new alarm is added it would be R[200]=R[200]+Current alarm number

  • HawkME
    Reactions Received
    568
    Trophies
    10
    Posts
    3,268
    • October 16, 2019 at 10:06 PM
    • #7

    A few other options to consider that may be easier for other people to read and troubleshoot your code.

    Option 1: is to use Group Outputs. A group output creates an integer, up to 16 bits. You can map the same bits to DO's or Flags. Then you have the option to look at each bit or the total integer value.

    Option 2: Forget using integers or registers. Instead just reserve a block of Flags or DO's (boolean IO type). Each flag represents 1 alarm and can be set or examined independently. If you wanted to scan through all of them you could do so with a For Loop, or an incrementing BG Logic program.

    My honest opinion is that using individual Flags or DO's would be much easier for another programmer to make sense of then to come up with a complex round-a-bout bitmask operation.

  • CPh
    Reactions Received
    2
    Trophies
    3
    Posts
    51
    • October 18, 2019 at 2:18 PM
    • #8

    Thank you for your feedback, I will consider these options :smiling_face:

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

Similar Threads

  • The system doesn't boot!!!

    • PaulSola
    • February 11, 2019 at 10:48 PM
    • ABB Robot Forum
  • Fanuc Challenge Define are (cube, sphere) using Ref Pos

    • Fabian Munoz
    • October 27, 2016 at 11:10 PM
    • Fanuc Robot Forum
  • Communication going between cognex and fanuc robot

    • pramtekkar
    • June 5, 2019 at 4:42 PM
    • Fanuc Robot Forum
  • Binary operations on integer variable

    • qojote
    • December 5, 2018 at 11:15 AM
    • Universal Robots
  • Kawasaki UX150 A55 Help required to return to life

    • Nzhuhu
    • July 10, 2018 at 2:13 PM
    • Kawasaki Robot Forum
  • Controlling Table Position From Controller

    • ablant527
    • April 4, 2018 at 11:26 PM
    • Fanuc Robot Forum
  • Simultaneous operation of Robot input and robot motion

    • spsid13
    • April 19, 2016 at 9:40 PM
    • Fanuc Robot Forum
  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