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

Passing arguments to called program in Karel

  • TitusLepic
  • December 12, 2019 at 11:06 PM
  • Thread is Unresolved
  • TitusLepic
    Reactions Received
    112
    Trophies
    6
    Posts
    442
    • December 12, 2019 at 11:06 PM
    • #1

    I'm trying to display a yes/no menu from Karel. From TP, it would look like this:

    CALL MHPRMPTY(2,37)

    I can call MHPRMPTY from Karel using CALL_PROG but I can't figure out how to pass the arguments and I can't find anything about it in the karel reference manual. Any help would be appreciated. Thanks.

  • jay
    Reactions Received
    25
    Trophies
    3
    Posts
    82
    • December 13, 2019 at 12:39 AM
    • #2

    As far as I know there is no way to pass TPE arguments from KAREL. Maybe there is a secret builtin for that.

    You could write a simple wrapper that uses registers e.g.

    MHPRMPTY_WRAPPER.TP:

    CALL MHPRMPTY(R[x],R[y]) ;

    Then just set R[x] and R[y] from KAREL before using CALL_PROG.

    ONE Robotics Company

  • MIRobotGuy
    Reactions Received
    8
    Trophies
    3
    Posts
    34
    • December 18, 2019 at 12:25 PM
    • #3

    This will work. I have used this in the past.

    Code
    PROGRAM TPP_ARG
    %COMMENT = 'TPP Arg to Karel'
    
    VAR
      arg : INTEGER
    
      -- Dummy Variables for Karel Built-Ins
      Dummy_Int : INTEGER
      Dummy_Rel : REAL
      Dummy_Str : STRING[10]
      STATUS : INTEGER
    
    --------------------------------------------------------------------------
    ---                          Main Program                              ---
    --------------------------------------------------------------------------
    BEGIN
    -- Use the Get-Parameter Built-In to read the TPP Arguement
    --          |-- Parameter Number (Arguement Number)
    --          |  |-- Data Type (1-INTEGER, 2-REAL, 3-STRING)
    --          |  |   |-- value of the parameter if the data_type is INTEGER
    --          |  |   |       |-- value of the parameter if the data_type is REAL
    --          |  |   |       |          |-- value of the parameter if the data_type is STRING
    --          V  V   V       V          V        V-- return status
    GET_TPE_PRM(1, 1, arg, Dummy_Rel, Dummy_Str, STATUS)
    
    -- Display Arguement Value on the Teach Pendant
    WRITE('value of arguement:', arg, CR)
    
    --------------------------------------------------------------------------
    END TPP_ARG
    Display More

    +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+

    MI Robot Guy

  • Bill Lin
    Trophies
    3
    Posts
    8
    • December 27, 2019 at 3:40 PM
    • #4
    Quote from MIRobotGuy

    This will work. I have used this in the past.

    Code
    PROGRAM TPP_ARG
    %COMMENT = 'TPP Arg to Karel'
    
    VAR
      arg : INTEGER
    
      -- Dummy Variables for Karel Built-Ins
      Dummy_Int : INTEGER
      Dummy_Rel : REAL
      Dummy_Str : STRING[10]
      STATUS : INTEGER
    
    --------------------------------------------------------------------------
    ---                          Main Program                              ---
    --------------------------------------------------------------------------
    BEGIN
    -- Use the Get-Parameter Built-In to read the TPP Arguement
    --          |-- Parameter Number (Arguement Number)
    --          |  |-- Data Type (1-INTEGER, 2-REAL, 3-STRING)
    --          |  |   |-- value of the parameter if the data_type is INTEGER
    --          |  |   |       |-- value of the parameter if the data_type is REAL
    --          |  |   |       |          |-- value of the parameter if the data_type is STRING
    --          V  V   V       V          V        V-- return status
    GET_TPE_PRM(1, 1, arg, Dummy_Rel, Dummy_Str, STATUS)
    
    -- Display Arguement Value on the Teach Pendant
    WRITE('value of arguement:', arg, CR)
    
    --------------------------------------------------------------------------
    END TPP_ARG
    Display More

    that' great!:smiling_face:

  • rankingofficer
    Reactions Received
    2
    Trophies
    3
    Posts
    8
    • October 21, 2021 at 11:24 AM
    • #5

    Below I show you how to pass arguments from Karel to Karel, not sure if you can pass arguments from Karel to TP.

    In Karel you cannot pass arguments from one Karel program to another Karel program exactly like you do in a TP program eg CALL GET_AREA(2,5);

    The answer is to use the ROUTINE function. This function is surprisingly well explained in the Karel reference manual.

    The examples below show the basic concept:

    Program MATH_LIB

    ROUTINE GET_AREA(length: REAL; width: REAL; area: REAL)

    BEGIN

    area = length * width

    END GET_AREA

    BEGIN

    --Main body of program.

    -- Can be empty

    END MATH_LIB


    Program TEST

    VAR

    area: REAL

    --declare the routine like it is a variable

    ROUTINE GET_AREA(length: REAL; width: REAL; area: REAL) FROM MATH_LIB

    BEGIN

    GET_AREA(2,2,area) -- pass 'area' by reference

    WRITE(’Area = ’, area, CR) -- Print: Area = 4

    END TEST

    Note you can also make the ROUTINE return a value, instead of passing a variable by reference. eg.

    ROUTINE GET_AREA(length: REAL; width: REAL) : REAL

    VAR area: REAL

    BEGIN

    area = length * width

    RETURN (area)

    RETURN (length * width) -- Maybe this works too

    END GET_AREA

    Program TEST2

    VAR

    area: REAL

    ROUTINE GET_AREA(length: REAL; width: REAL) : REAL FROM MATH_LIB

    BEGIN

    area = GET_AREA(2,2) -- Returns a number

    WRITE(’Area = ’, area, CR) -- Print: Area = 4

    END TEST2

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