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

[R-30iB] Karel - reading and converting a 32-bit value

  • bidzej
  • September 29, 2015 at 10:23 AM
  • Thread is Resolved
  • bidzej
    Reactions Received
    23
    Trophies
    4
    Posts
    592
    • September 29, 2015 at 10:23 AM
    • #1

    Hello,

    I have a problem regarding a laser distance sensor connected to a robot over ProfiNet. I need to read the distance value and then make some calculations with it in Karel.
    The thing is that the sensor returns the distance as a 32-bit value and the robot only accepts 16-bit analog or group inputs. Any experience on converting a 32-bit value and then using it for calculations in a Karel program?

  • ESIELI
    Reactions Received
    10
    Trophies
    5
    Posts
    275
    • September 29, 2015 at 10:31 PM
    • #2
    Quote from bidzej


    Hello,

    I have a problem regarding a laser distance sensor connected to a robot over ProfiNet. I need to read the distance value and then make some calculations with it in Karel.
    The thing is that the sensor returns the distance as a 32-bit value and the robot only accepts 16-bit analog or group inputs. Any experience on converting a 32-bit value and then using it for calculations in a Karel program?

    Can you send it to a PLC then to the robot?
    or
    You can convert it from Profinet to Serial with a converter


    That's just some things I could think of real quick. I'm sure Fanuc has a better solution to cope with this.

  • trinket
    Trophies
    3
    Posts
    17
    • September 30, 2015 at 2:23 PM
    • #3

    What kind is your 32-bit value, REAL or INTEGER?

  • Nation
    Typical Robot Error
    Reactions Received
    542
    Trophies
    9
    Posts
    1,924
    • September 30, 2015 at 2:27 PM
    • #4

    If it is an integer, is it signed or unsigned?

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

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

  • trinket
    Trophies
    3
    Posts
    17
    • September 30, 2015 at 3:04 PM
    • #5
    Quote from Nation


    If it is an integer, is it signed or unsigned?

    You're right, of ccourse

  • Nation
    Typical Robot Error
    Reactions Received
    542
    Trophies
    9
    Posts
    1,924
    • September 30, 2015 at 10:30 PM
    • #6

    Since you wrote about pulling in the 32 bit number on group inputs, I went ahead and assumed it was unsigned.

    I wrote some code for parsing in a 32 unsigned integer. Unfortunately you can only get half way up until the karel code I wrote errors out (final 32 bit number must be less than 2,147,483,647) , as there is no way that I know of to declare in karel an unsigned integer.

    The code assumes that there are 4 group inputs (11-14) each holding one byte of information. This is then pulled in and combined in the karel code. Group input 11 is the least significant byte, and 14 is the most.

    Here is the code:

    Code
    PROGRAM ROB_FORUM
    %NOLOCKGROUP
    
    
    VAR
    GROUP_I				:ARRAY[4] OF BYTE
    RETURN_VAL,RESULT,STATUS 	:INTEGER
    BEGIN
    	GET_PORT_VAL(18,11,RETURN_VAL,STATUS)
    	GROUP_I[1]=RETURN_VAL
    	GET_PORT_VAL(18,12,RETURN_VAL,STATUS)
    	GROUP_I[2]=RETURN_VAL
    	GET_PORT_VAL(18,13,RETURN_VAL,STATUS)
    	GROUP_I[3]=RETURN_VAL
    	GET_PORT_VAL(18,14,RETURN_VAL,STATUS)
    	GROUP_I[4]=RETURN_VAL
    	RESULT=GROUP_I[1]+GROUP_I[2]*256+GROUP_I[3]*65536+GROUP_I[4]*16777216
    END ROB_FORUM
    Display More

    The constants in the result equation do the same thing as a lshift does in C (<<).

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

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

    Edited once, last by Nation (October 1, 2015 at 12:56 AM).

  • ESIELI
    Reactions Received
    10
    Trophies
    5
    Posts
    275
    • October 1, 2015 at 3:23 PM
    • #7
    Quote from Nation


    Since you wrote about pulling in the 32 bit number on group inputs, I went ahead and assumed it was unsigned.

    I wrote some code for parsing in a 32 unsigned integer. Unfortunately you can only get half way up until the karel code I wrote errors out (final 32 bit number must be less than 2,147,483,647) , as there is no way that I know of to declare in karel an unsigned integer.

    The code assumes that there are 4 group inputs (11-14) each holding one byte of information. This is then pulled in and combined in the karel code. Group input 11 is the least significant byte, and 14 is the most.

    Here is the code:

    Code
    PROGRAM ROB_FORUM
    %NOLOCKGROUP
    
    
    VAR
    GROUP_I				:ARRAY[4] OF BYTE
    RETURN_VAL,RESULT,STATUS 	:INTEGER
    BEGIN
    	GET_PORT_VAL(18,11,RETURN_VAL,STATUS)
    	GROUP_I[1]=RETURN_VAL
    	GET_PORT_VAL(18,12,RETURN_VAL,STATUS)
    	GROUP_I[2]=RETURN_VAL
    	GET_PORT_VAL(18,13,RETURN_VAL,STATUS)
    	GROUP_I[3]=RETURN_VAL
    	GET_PORT_VAL(18,14,RETURN_VAL,STATUS)
    	GROUP_I[4]=RETURN_VAL
    	RESULT=GROUP_I[1]+GROUP_I[2]*256+GROUP_I[3]*65536+GROUP_I[4]*16777216
    END ROB_FORUM
    Display More

    The constants in the result equation do the same thing as a lshift does in C (<<).


    Nation, I see you're using port type as "18". Where do you get the numbers for each port type?

  • Nation
    Typical Robot Error
    Reactions Received
    542
    Trophies
    9
    Posts
    1,924
    • October 1, 2015 at 4:24 PM
    • #8
    Quote from ESIELI


    Nation, I see you're using port type as "18". Where do you get the numbers for each port type?

    From the KLIOTYPS.KL file. If you have roboguide installed, do a search of your disk and you will find it.

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

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

  • ESIELI
    Reactions Received
    10
    Trophies
    5
    Posts
    275
    • October 1, 2015 at 6:22 PM
    • #9
    Quote from Nation

    From the KLIOTYPS.KL file. If you have roboguide installed, do a search of your disk and you will find it.


    Roboguide?? I wish.. lol My company is too cheap.

    Thanks

  • Latoff
    Trophies
    3
    Posts
    16
    • February 19, 2020 at 5:34 PM
    • #10

    Nation , but how would you do it vice versa in case you need to write XYZWPR value into the I/O (groups)?

  • Nation
    Typical Robot Error
    Reactions Received
    542
    Trophies
    9
    Posts
    1,924
    • February 19, 2020 at 6:55 PM
    • #11

    First, don't bump 5 year old threads. This would have been better as a new thread.

    Depends on the resolution you need. Since groups are INT based, I would just multiply the components of the position by 10 or 100, write to 6 groups, and then divide on the other side.

    Also, depends on your communication method. There are far better ways to get position data out of the robot than by group outputs.

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

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

  • Latoff
    Trophies
    3
    Posts
    16
    • February 19, 2020 at 7:18 PM
    • #12

    That is the deal i should keep it like that to allow later to be compatible with various comm. methods.

    Ok, still i need to get from REAL values integer. What is then the command for "Divide without remainder" or is the the way to parse the REAL values?

    If possible can you please mention the Karel commands for that

  • Latoff
    Trophies
    3
    Posts
    16
    • February 19, 2020 at 7:45 PM
    • #13

    Ok , at least the digits before comma i can extract via String parsing

    x : REAL (1025.395)

    CNV_REAL_STR(x,4,0,x_str)

    x_short=SUB_STR(x_str,2,3)

    SET_STR_REG(1,x_short,STATUS)

    CNV_STR_INT(x_short,result)

    result = 102 INTEGER

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