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

2D array data in Karel

  • zhaoxiang chen
  • April 7, 2021 at 9:56 PM
  • Thread is Unresolved
  • zhaoxiang chen
    Trophies
    3
    Posts
    43
    • April 7, 2021 at 9:56 PM
    • #1

    Hi guys,

    currently, I am looking for a proper way to define and use 2D array in KAREL program.

    the general concept is that,

    array[i,j]:

    10

    11 5

    7 13 14,

    and 13 will be read and use when i=3 and j=2,

    is there anyone happen to know how to program this?

    best regards,

    Chen

  • Go to Best Answer
  • jmd2777
    Reactions Received
    34
    Trophies
    4
    Posts
    193
    • April 7, 2021 at 10:50 PM
    • #2

    To declare the array:

    two_d_array: ARRAY[3,3] OF INTEGER--2D Array

    To access elements in the array:

    two_d_array[3,2]=13

  • zhaoxiang chen
    Trophies
    3
    Posts
    43
    • April 8, 2021 at 3:05 PM
    • #3
    Quote from jmd2777

    To declare the array:

    two_d_array: ARRAY[3,3] OF INTEGER--2D Array

    To access elements in the array:

    two_d_array[3,2]=13

    hi jmd2777,

    thank you for your reply.

    once the 2D array is created by Karel, is it possible to read the values with for-loops in TP program?

    for instance, using two registers represent i and j in for-loops in TP program, and in each loop a specific value corresponding to the index can be read from the array.

    regards,

    Chen

  • jmd2777
    Reactions Received
    34
    Trophies
    4
    Posts
    193
    • April 8, 2021 at 3:27 PM
    • #4

    Chen,

    I don't know how to access a Karel variable in a TP program. One alternative is to have the Karel program read the registers storing i and j. Then the Karel program could copy the value from the 2D array into a register.

    So in your TP program you would set i and j register value. Then call the Karel program, or if the Karel program is always running you could turn on a FLAG that indicates you want to get a new value and the Karel program would see the FLAG and retrieve the value from the 2D array and store it in a register.

  • zhaoxiang chen
    Trophies
    3
    Posts
    43
    • April 8, 2021 at 3:57 PM
    • #5
    Quote from jmd2777

    Chen,

    I don't know how to access a Karel variable in a TP program. One alternative is to have the Karel program read the registers storing i and j. Then the Karel program could copy the value from the 2D array into a register.

    So in your TP program you would set i and j register value. Then call the Karel program, or if the Karel program is always running you could turn on a FLAG that indicates you want to get a new value and the Karel program would see the FLAG and retrieve the value from the 2D array and store it in a register.

    JM,

    i agree with your strategy, but still have one concern that:

    once the 2D array[i,j] is created in KAREL program, is it saved permanently ? or it is only existing when karel program is running?

  • pdl
    Reactions Received
    266
    Trophies
    9
    Posts
    1,506
    • April 8, 2021 at 4:19 PM
    • #6

    Use the translator directive %CMOSVARS

    If %CMOSVARS is specified in the program, then all static variables by default will be created in permanent memory.

    If %CMOSVARS is not specified, then all static variables by default will be created in temporary memory.

  • jmd2777
    Reactions Received
    34
    Trophies
    4
    Posts
    193
    • April 8, 2021 at 4:25 PM
    • Best Answer
    • #7

    Chen,

    The variable is permanent. You may have noticed that after deleting a KAREL program named kar_prog from the robot, there is still a file named kar_prog.vr. That .vr file stores the KAREL variables. If you delete the .vr file, then the KAREL variable values will be lost.

    2 things that may help:

    1. The KAREL command GET_VAR can access variables from other KAREL programs. For example, you could have 2 KAREL programs: A) create_2d_array and B) get_2d_array_value. You could call get_2d_array_value from your TP program. It would use GET_VAR to access the 2D array in create_2d and then copy the value to a register.

    2. There is a convenient way to check the value of your KAREL variables from the Teach Pendant. Go to Select screen, select a KAREL program and press Enter key. Press Data button->Type->KAREL Vars. You will be able to see the KAREL variables for the currently selected program.

  • zhaoxiang chen
    Trophies
    3
    Posts
    43
    • April 8, 2021 at 4:31 PM
    • #8
    Quote from jmd2777

    Chen,

    The variable is permanent. You may have noticed that after deleting a KAREL program named kar_prog from the robot, there is still a file named kar_prog.vr. That .vr file stores the KAREL variables. If you delete the .vr file, then the KAREL variable values will be lost.

    2 things that may help:

    1. The KAREL command GET_VAR can access variables from other KAREL programs. For example, you could have 2 KAREL programs: A) create_2d_array and B) get_2d_array_value. You could call get_2d_array_value from your TP program. It would use GET_VAR to access the 2D array in create_2d and then copy the value to a register.

    2. There is a convenient way to check the value of your KAREL variables from the Teach Pendant. Go to Select screen, select a KAREL program and press Enter key. Press Data button->Type->KAREL Vars. You will be able to see the KAREL variables for the currently selected program.

    thank you for your help, that is really helpful.

  • zhaoxiang chen
    Trophies
    3
    Posts
    43
    • April 8, 2021 at 4:38 PM
    • #9
    Quote from pdl

    Use the translator directive %CMOSVARS

    If %CMOSVARS is specified in the program, then all static variables by default will be created in permanent memory.

    If %CMOSVARS is not specified, then all static variables by default will be created in temporary memory.

    hi pdl,

    thanks for your reply,

    for creating a .DT file in Karel, i make file path as MC: xxx.dt, it works well in roboguide, but have not tried in real controller, do you have any experience or suggestion about choosing the memory device?

    regards,

    Chen

  • pdl
    Reactions Received
    266
    Trophies
    9
    Posts
    1,506
    • April 8, 2021 at 11:06 PM
    • #10

    What is the data you're collecting and what is it used for? How often will this data change?

  • zhaoxiang chen
    Trophies
    3
    Posts
    43
    • April 9, 2021 at 10:26 AM
    • #11
    Quote from pdl

    What is the data you're collecting and what is it used for? How often will this data change?

    pdl,

    i am trying to collect calculation result in KAREL program, so that the file can be export with USB. and the calculation is one time job only, not a realtime job which need to write and read hundred of thousands times.

    regards,

    Chen

  • zhaoxiang chen
    Trophies
    3
    Posts
    43
    • April 9, 2021 at 10:35 AM
    • #12
    Quote from pdl

    Use the translator directive %CMOSVARS

    If %CMOSVARS is specified in the program, then all static variables by default will be created in permanent memory.

    If %CMOSVARS is not specified, then all static variables by default will be created in temporary memory.

    i used %CMOSVARS in program, but once i restart roboguide, the calculated variables are removed. the data karel variables are reset. do you know what is the reason for that?

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

  • What is the best way to store data

    • RookieWithRobots
    • October 14, 2019 at 1:53 PM
    • Fanuc Robot Forum
  • system variables for userframe position

    • zhaoxiang chen
    • July 22, 2020 at 4:35 PM
    • Fanuc Robot Forum
  • Karel server for constant input data updating

    • dcrb
    • March 8, 2021 at 4:16 PM
    • Fanuc Robot Forum
  • Custom Log File

    • Kahless01
    • September 17, 2020 at 6:34 PM
    • Fanuc Robot Forum
  • Load position registers and registers from KAREL dataset

    • RoboDrillx
    • January 2, 2020 at 10:32 PM
    • Fanuc Robot Forum
  • Karel array of string

    • PP1727
    • January 2, 2020 at 1:04 PM
    • Fanuc Robot Forum
  • Best way to handle big array

    • RookieWithRobots
    • March 25, 2019 at 5:11 PM
    • Fanuc Robot Forum
  • KAREL INTP-311 (Uninitialized data) while using var_1 FROM prog: ARRAY

    • odojak1715
    • March 29, 2019 at 8:45 AM
    • Fanuc Robot Forum
  • KAREL: Getting a list of all files in folder

    • maSu
    • February 16, 2018 at 3:41 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