KAREL programming FANUC

  • Hello. need help. I want to move the extended axes of the robot. Has anyone encountered this problem before?

    shown in code for 6 axes



    PROGRAM TEST_KAREL


    %ENVIRONMENT TPE

    %ENVIRONMENT BYNAM

    CONST


    MAX_AXS = 9

    JNT_POS = 9

    XYZ_POS = 2


    VAR


    to_prog: STRING[27]

    open_id: INTEGER

    status: INTEGER

    position_no: INTEGER

    new_xyz: XYZWPREXT

    org_xyz: XYZWPREXT

    num_axs: INTEGER


    BEGIN


    to_prog = 'TEST_TP_1'


    OPEN_TPE (to_prog, TPE_RWACC, TPE_RDREJ, open_id, status)


    position_no = 3


    org_xyz = GET_POS_TPE (open_id, position_no, posn_typ, num_axs, status)

    FOR indx_axs= 1 TO num_axs DO

    jp_new [indx_axs] = jp_org[indx_axs] + jp_off [indx_axs]

    new_xyz.x = org_xyz.x +10

    new_xyz.y = org_xyz.y + 10

    new_xyz.z = org_xyz.z + 10

    new_xyz.w = org_xyz.w + 10

    new_xyz.p = org_xyz.p + 10

    new_xyz.r = org_xyz.r + 10

    SET_POS_TPE (open_id, position_no, new_xyz, status)


    CLOSE_TPE (open_id, status)


    END TEST_KAREL

  • Who wrote the program in the picture?

    It should be possible to use

    Code
    new_xyz.ext1=org_xyz.ext1+10

    And by the way, you shouldn't post a picture of a program code. Always post the code in some ASCII representation. Nobody here wants to type already existing code by looking onto a picture.

  • Кто написал программу на картинке?

    Должна быть возможность использовать

    Code
    new_xyz.ext1 = org_xyz.ext1 + 10

    И, кстати, не стоит размещать картинку программного кода. Всегда размещайте код в каком-либо представлении ASCII. Здесь никто не хочет набирать уже существующий код, глядя на картинку.

    tried it according to yours, as you need to indicate that this code is for extended axes

  • PROGRAM TEST_KAREL


    %ENVIRONMENT TPE

    %ENVIRONMENT BYNAM

    CONST


    MAX_AXS = 9

    JNT_POS = 9

    XYZ_POS = 2


    VAR


    to_prog: STRING[25]

    open_id: INTEGER

    status: INTEGER

    position_no: INTEGER


    jp_org : ARRAY [9] OF REAL

    jp_new : ARRAY [9] OF REAL


    prg_select: INTEGER

    arr_size : INTEGER

    indx : INTEGER


    indx_pos: INTEGER

    num_pos : INTEGER

    indx_axs: INTEGER

    num_axs : INTEGER

    pos_typ : INTEGER


    group_no: INTEGER


    org_jpos : JOINTPOS

    new_jpos : JOINTPOS

    posn_type: INTEGER

    org_xyz : XYZWPREXT

    new_xyz : XYZWPREXT


    BEGIN


    to_prog = 'TEST_TP_1'


    OPEN_TPE (to_prog, TPE_RWACC, TPE_RDREJ, open_id, status)


    group_no = 1

    position_no = 3


    GET_POS_TYP (open_id, indx_pos, group_no, posn_type, num_axs, status)


    WRITE ('get_pos_typ status', status,CR)


    SELECT pos_typ OF


    CASE (JNT_POS):


    SET_JPOS_TPE (open_id, indx_pos, new_jpos, status)


    WRITE ('indx_pos', indx_pos, 'new_jpos',CR, new_jpos,CR)


    ENDSELECT


    org_jpos = GET_JPOS_TPE (open_id, indx_pos, status)


    org_xyz = GET_POS_TPE (open_id , indx_pos, status)


    new_xyz.x = org_xyz.x +10

    new_xyz.y = org_xyz.y +0

    new_xyz.z = org_xyz.z +0

    new_xyz.w = org_xyz.w +0

    new_xyz.p = org_xyz.p +0

    new_xyz.r = org_xyz.r +0

    new_xyz_ext1 = org_xyz_ext1 + 10

    new_xyz_ext2 = org_xyz_ext2 + 10

    new_xyz_ext3 = org_xyz_ext3 + 10


    SET_POS_TPE (open_id, position_no, new_xyz, status)


    CLOSE_TPE (open_id, status)


    END TEST_KAREL


    Build error

    Translating D:\NikolaevAS\Desktop\untitled18.kl


    KTRANS Version V8.30 (Build 30 11/12/2019)

    Copyright (C) FANUC America Corporation, 1985 through 2016.

    All Rights Reserved.




    D:\NikolaevAS\Desktop\untitled18.kl(72)

    72 new_xyz_ext1 = org_xyz_ext1 + 10

    ^ ERROR

    Id must be defined before this use. Id: ORG_XYZ_EXT1


    D:\NikolaevAS\Desktop\untitled18.kl(73)

    73 new_xyz_ext2 = org_xyz_ext2 + 10

    ^ ERROR

    Id must be defined before this use. Id: ORG_XYZ_EXT2


    D:\NikolaevAS\Desktop\untitled18.kl(74)

    74 new_xyz_ext3 = org_xyz_ext3 + 10

    ^ ERROR

    Id must be defined before this use. Id: ORG_XYZ_EXT3


    D:\NikolaevAS\Desktop\untitled18.kl(76)

    76 SET_POS_TPE (open_id, position_no, new_xyz, status)

    ^ WARNING

    Argument will be passed by value. Id: NEW_XYZ



    ===============Translation not successful===============

    Build Failed: Error translating program: Code: 0xFFFFFFFF:

  • try replacing the underscores with periods in your new code that Hermann suggested using. His code uses a . instead of a _ in the variable name for the extended axis. new_xyz.ext1 = org_xyz.ext1 + 10

  • hi kawazaki02,

    i think you Need to add %ENVIRONMENT REGOPE on your Code.


    did not work. I don't know what to do anymore :frowning_face:


    PROGRAM TEST_KAREL


    %ENVIRONMENT TPE

    %ENVIRONMENT BYNAM

    %ENVIRONMENT REGOPE


    CONST


    MAX_AXS = 9

    JNT_POS = 9

    XYZ_POS = 2


    VAR


    to_prog: STRING[25]

    open_id: INTEGER

    status: INTEGER

    position_no: INTEGER


    jp_org : ARRAY [9] OF REAL

    jp_new : ARRAY [9] OF REAL


    prg_select: INTEGER

    arr_size : INTEGER

    indx : INTEGER


    indx_pos: INTEGER

    num_pos : INTEGER

    indx_axs: INTEGER

    num_axs : INTEGER

    pos_typ : INTEGER


    group_no: INTEGER


    org_jpos : JOINTPOS

    new_jpos : JOINTPOS

    posn_type: INTEGER

    org_xyz : XYZWPREXT

    new_xyz : XYZWPREXT

    org_xyz_ext : XYZWPREXT

    new_xyz_ext : XYZWPREXT



    BEGIN


    to_prog = 'TEST_TP_1'


    OPEN_TPE (to_prog, TPE_RWACC, TPE_RDREJ, open_id, status)


    group_no = 1

    position_no = 3


    GET_POS_TYP (open_id, indx_pos, group_no, posn_type, num_axs, status)


    WRITE ('get_pos_typ status', status,CR)


    SELECT pos_typ OF


    CASE (JNT_POS):


    SET_JPOS_TPE (open_id, indx_pos, new_jpos, status)


    WRITE ('indx_pos', indx_pos, 'new_jpos',CR, new_jpos,CR)


    ENDSELECT


    org_jpos = GET_JPOS_TPE (open_id, indx_pos, status)


    org_xyz = GET_POS_TPE (open_id , indx_pos, status)


    new_xyz.x = org_xyz.x +10

    new_xyz.y = org_xyz.y +0

    new_xyz.z = org_xyz.z +0

    new_xyz.w = org_xyz.w +0

    new_xyz.p = org_xyz.p +0

    new_xyz.r = org_xyz.r +0

    new_xyz_ext1 = org_xyz_ext1 + 10


    SET_POS_TPE (open_id, position_no, new_xyz, status)


    CLOSE_TPE (open_id, status)


    END TEST_KAREL




    ----------------------------------------------------------------------

    Translating D:\NikolaevAS\Desktop\untitled18.kl


    KTRANS Version V8.30 (Build 30 11/12/2019)

    Copyright (C) FANUC America Corporation, 1985 through 2016.

    All Rights Reserved.




    D:\NikolaevAS\Desktop\untitled18.kl(77)

    77 new_xyz_ext1 = org_xyz_ext1 + 10

    ^ ERROR

    Id must be defined before this use. Id: ORG_XYZ_EXT1


    D:\NikolaevAS\Desktop\untitled18.kl(79)

    79 SET_POS_TPE (open_id, position_no, new_xyz, status)

    ^ WARNING

    Argument will be passed by value. Id: NEW_XYZ



    ===============Translation not successful===============

    Build Failed: Error translating program: Code: 0xFFFFFFFF:

    ----------------------------------------------------------------------

  • Are you kidding us?

    You only had to mark the code in my post and copy it to your .kl file and it would have been worked. That's the reason why code has to be inserted into a code-tag.

    Here is the proof, (I have a newer compiler, may be that's the problem, but I don't think so):

    Result of Compiling:

    ----------------------------------------------------------------------

    Translating D:\......\test_karel.kl


    KTRANS Version V9.10 (Build 17 9/18/2019)

    Copyright (C) FANUC America Corporation, 1985 through 2017.

    All Rights Reserved.


    D:\.....\test_karel.kl(56)

    56 SET_POS_TPE (open_id, position_no, new_xyz, status)

    ^ WARNING

    Argument will be passed by value. Id: NEW_XYZ


    *** Translation successful, 698 bytes of p-code generated, checksum 12310. ***

    ----------------------------------------------------------------------

  • Are you kidding us?

    You only had to mark the code in my post and copy it to your .kl file and it would have been worked. That's the reason why code has to be inserted into a code-tag.

    Here is the proof, (I have a newer compiler, may be that's the problem, but I don't think so):

    thanks, I also compiled, but the additional axes did not move :frowning_face:

  • After each command always check the status variable. It tells you if the command actually worked or not. For example:

    Code
          OPEN_TPE (to_prog, TPE_RWACC, TPE_RDREJ, open_id, status)
          IF (status<>0)  THEN
            FORCE_SPMENU (TP_PANEL, SPI_TPUSER, 1)
            WRITE('Error while opening tp prog',CR)
            POST_ERR(status, '', 0, 2) --2 indicates ABORT; see Karel Manual
            ABORT
          ENDIF
  • The program has many issues, and in the first version it does'nt make real sense. Who wrote that?

    It compiles, but it has runtime errors and doesn't run till end.

    Here is a working one (only tested with one extended axis), BUT: there seems to be an issue in the KAREL system of fanuc. At least in my test equipment the value of extended axis 1 that comes from the funtion GET_POS_TPE has nothing to do with the real value.

    You can see the outputs of the WRITE statements on the User screen (MENU - 9 USER).

    And one more remark: Try to write programs on your own, read the karel manuals, learn to debug programs. jm2c.

    I'm out now.

  • thanks, everything worked

  • Hello everyone, I wrote the code. compiles. but when executing the program, it will throw an error. if you remove 47 and 75, then the program is executed well, without errors.

  • Delete your .pc and the .vr file it leaves behind from the controller, then recompile. The file will complie, but fail to load because there is a difference in declared varibles in the .vr file.

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

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

  • Once again the program is not correct.

    Writing programs doesn't mean to shuffle program statements found somewhere in the documentation or the internet, and hope that it will work.

    You should put the 'get_pos_typ' into the loop, otherwise you can leave it out, and assume for all position that the type is pt_rxyzwpr.


    1. means in line 46 there is a unitialized variable, looking into the code shows that the variable 'num_pos' is not initialized before using it.


    2. This is a problem of the compiler, if the program that you want to compile is selected on the virtual controller, he fails. Select a different program on the controller an compile again.


  • Thank you for your comment. I'm just learning to program in KAREL so far, so don't judge too three. I'll try to loop the program, unsubscribe about the results =)


    I just need a little support from knowledgeable people to learn from experienced )

  • Yes it is hard stuff to learn programming, it is hard stuff to learn programming a robot, but it is harder stuff to learn programming by programming a robot.

    And the next level is to learn programming on a fanuc robot with karel :astonished_face:, that will be a pain in the ass, because the debugging possiblities aren't that good.

    Good luck :upside_down_face:.

    As always I recommend to learn programming on a personal computer with a common programming language like C, Pascal, Basic, and then switch to a robot, and learn the robot specific things.

Advertising from our partners