KRL KRC2 Compilation Errors

  • Hi,


    I have written some code in KRL, which is having following files-



      • Library.dat

      • Library.src

      • MyModule.dat

      • MyModule.src


    KUKA is showing some compilation errors, which are below-
    [list type=decimal]

    • Declaration not in declaration section

    • Pos. integer, "]" or "," expected

    • END/ENDFCT/ENDDAT inadmissible here

    • Operand or expression expected

    • Name expected

    • Incorrect end of control structure

    • Both sides of the value assignment are not compatible

    • INT. constant not equal to 0 expected

    • Instruction not in instruction section

    [/list]


    Following are the details of each file-


    Library.dat- This file is having all of the constants used all over the program
    Library.src- This file is having module and functions
    MyModule.dat- This file is for PTP variables (Used by KRC)
    MyModule.src- This is the main file which is having PTP motions calculated using library file


    I am attaching the screenshot of the errors for better understanding.


    Please help me to rectify these errors.


    -
    Thanks

  • Place your Ad here!
  • your screenshots don't help, everything is truncated - you may want to post actual code, rather than screenshots. there is no correlation between code and error message displayed in same screenshot. there is tons of syntax errors...



    and as you have been told, get a copy of Programming Manual for System Integrators. it covers syntax, instructions etc.


    example:
    picture1, you have declared function of type REAL[][], kuka 2D arrays use syntax "REAL[,]". besides return types can only be simple types. to return array use argument passed by reference, something like


    Code
    def double(whatever[]:out)
    decl real whatever[]
    decl int n
    
    
    for n=1 to 10
       whatever[n]=2*whatever[n]
    endfor
    end


    you declare function called multiply, with one argument called "mat" which is not used/declared correctly/consistently.
    you use it as a simple type (with no square brackets, passed by Value) but have it declared as a 2D array.


    picture 2 shows what looks like DAT file, then in line 32 you are declaring an array of type REAL and trying to assign value using invalid syntax.
    arrays can be declared and initialized in DAT file but not in same line and you cannot use aggregate (curly braces) and initialization must be directly after declaration line such as


    Code
    DECL REAL myVal[4]
    myVal[1]=0
    myVal[2]=0
    myVal[3]=0
    myVal[4]=0


    etc


    then you have something like
    SUM += whatever ; wrong syntax, cannot use "sum +=" or "temp++" in KRL

  • Hi PM,


    I tried to implement your suggestions and looked into the manual for System Integrators. I got some more errors. I am attaching the screenshot of the errors. Below is the content of library module file


    library.src


    library.dat

  • Hi JonHopper,


    Thank you for the quick response.. I am following "KUKA System Software 8.2 Operating and Programming Instructions for System Integrators" manual, which is not having complete information about the KRL coding.


    I got your point, which is correct but due to insufficient manual, I am unable to do it. I would be thankful of you if you can figure out those errors. Also there are some errors which says "Declaration not in declaration section".


    Please help.



    Thank you

  • manuals tell you what ca be used and how, for everything else it is safe to assume that it is not supported.
    this forum and your robot have tons of code which is a great resource. they supplement but do not replace formal training.
    you are working on a new platform, it is a good idea to test things gradually (one line at a time), and debug/fix every errors as they are encountered - not write several files and then try to sort out dozens of errors.


    i see a bit of progress but you still struggle with arrays and passing values (IN = byVal, OUT = byRef).
    function can return result by value but arrays can only be passed by reference so i would try something like (not tested, just an idea)


    1) read pinned topic: READ FIRST...

    2) if you have an issue with robot, post question in the correct forum section... do NOT contact me directly

    3) read 1 and 2

  • I got your point, which is correct but due to insufficient manual, I am unable to do it. I would be thankful of you if you can figure out those errors. Also there are some errors which says "Declaration not in declaration section".


    Check the "Manuals and Software" sub-forum. There are copies of the Expert Programming Manuals from KSS 5.2, which (in my opinion) is superior at explaining a lot of the syntax of KRL. KRL has changed very little since then, so the 5.2 manual won't lead you astray.


    As for "Declaration not in declaration section": DECL lines must immediately follow the DEF line. Any executable code inherently closes the "Declaration section." So any and all DECLs must fall between the DEF line and the first line of executable code. Since the standard KUKA INI fold includes executable code (subroutine calls qualify as executable), if you have such an INI fold, any DECLs must precede it.


    Speaking of which, the INI fold is only necessary for modules which include motions. If you are creating a module whose only contents will be non-motion executable code, the INI fold can be discarded. For non-motion modules, you should select the "Expert Module" template when creating the module, rather than the standard "Module" template.

  • sometimes you may want to look at the line directly above or open fold (if present).
    your declarations in lines 8 and 9 are in right place, but the line 7 has problems.

    1) read pinned topic: READ FIRST...

    2) if you have an issue with robot, post question in the correct forum section... do NOT contact me directly

    3) read 1 and 2

  • Hi,


    Thank you so much for the amazing support and help. Really appreciable. I am following the suggested manuals. I got following two issues while developing a function which multiplies two matrices and returns it-
    [list type=decimal]

    • Return value: string constant array invalid

    • Operand or expression expected

    [/list]
    Please see the attached screenshots for more info in above issues (Also code is listed below).


    I have some questions regarding this-


      • How to return an array from a function?

      • How to use a function in a program?

      • Can we have DEF and DEFFCT in a single module file?

      • Can we refer the variable in another variable which is declared in the data list file? Are the following lines in data list file correct?

    Code
    CONST INT row = 3
    CONST INT col = 1
    CONST REAL calib[row,col]


      • Can we declare an array, whose dimensions are defined in data list file?


    Code
    DEF Library( )
    REAL ans[row,col]



    Below is the code-
    library.src


    library.dat


    -
    Thanks

  • This is detailed in the manual.


    You cannot declare an array with variables for the dimensions. For a subroutine to receive an array, the array must be declared only the number dimensions, but no magnitudes thereof. The receiving array is dynamically re-sized to match the magnitude of the statically sized array in the calling routine.
    To send or receive a routine, empty braces [] must be used. For a multi-dimensional array, the commas must be added: [,] or [,,].


    So:

    Code
    DEF Blah (_Array1d[] :IN, _Array2d[,] :IN, Array3d[,,])
    DECL REAL _Array1d[], _Array2d[,], _Array3d[,,]
    END


    DECL REAL Array[Variable1, variable2] is NOT valid.


  • As per PM post, I was trying to create a function which returns a 2D array-


    This shows following compilation errors-


      • Return value: string constant array invalid in RETURN mul[,]

      • Operand or expression expected in following line

    Code
    REAL input[3,1], ans[3,1]
    input[1,1]=1
    input[2,1]=2
    input[3,1]=3
    ans[,]=multiply(input[,])



    What is missing here? :icon_confused:

    So:

    Code
    DEF Blah (_Array1d[] :IN, _Array2d[,] :IN, Array3d[,,])
    DECL REAL _Array1d[], _Array2d[,], _Array3d[,,]
    END


    I am confused a bit. The manual says "Arrays may only be transferred as OUT parameters". Please see the attached screenshot for more info.

  • weeeeellll.... this is simply meant as a nudge in the right direction. also in example I offered as a possible workaround, there are missing square brackets. (told you I had not tested it... :angel: ).



    Note: when using array, you need to always use brackets. if you are specifying an array element, you also need to provide index(es). If you mean entire array, index(es) are omitted but square brackets are still needed. And if array is multidimensional, you must use commas (even if omitting indexes).




    btw,... I still did not test it (it's not my job... :beerchug:)



    about your last question "what is missing here?".


    I am not exactly a computer science teacher but since you clearly don't understand this yet, I will sacrifice a bit more of my time in hope we get this done and move on.


    For any programmer it should be obvious that following two declarations are very different:

    Code
    DECL REAL G
    DECL REAL H[3,1]


    While they both use REAL type to store and interpret information, one of them is a single variable and the other is a 2D array. For example they have very different memory requirements. Your code samples continually show that you are trying to use them as if they are same thing. For example you declare function multiply with return type REAL (single variable) then inside it your RETURN line is trying to jam entire 2D array (result) into that single REAL variable. Don't do that..! :baseball:


    ...and you also forgot to include ENDFCT... :hi-bye:



    About byVal/byRef.... (clear throat). This is a rather basic and important concept in programing, therefore it is one of essential things to grasp. You mentioned that you know some C, C# and Java. Maybe this helps:
    http://msdn.microsoft.com/en-us/library/9t0za5es.aspx


    When passing parameters (to subroutine or function) one can do so either:


    a) by Value - all you get is a copy of value of some external variable. this means regardless what you do with it (your copy), there is NO effect the external variable (because you are dealing with a copy and that means you are manipulating different memory location...).


    b) by Reference - you get pointer to a memory location of some external variable. this means you can read AND write that external variable directly. this of course is a much more efficient because external variable may be using large block of memory, and you still only need to pass its address, not the content.




    in KRL, syntax for 'by Value' is :IN and for [i]'by Reference' is [i]:OUT.


    just because it says OUT, it is not "strictly an output", it is just indication that you can not just read (read you can always) but you may also MODIFY external value (even if it is an array!). programming languages use byRef to pass large data blocks (because of performance and better use of resources). this is why your idea of returning array will never work (at least in KRL). in other words, you can forget using assignments like


    Code
    ans[,]=multiply(input[,])


    you may get it to work using something like:

    Code
    matrixMultiply(calib[,],mat[,],mul[,])



    here is a small example in a form of robot program arg_test.src showing the difference between byVal/byRef. But you are welcome to try the equivalent in any other programming language:


    1) read pinned topic: READ FIRST...

    2) if you have an issue with robot, post question in the correct forum section... do NOT contact me directly

    3) read 1 and 2

    Edited once, last by panic mode ().

  • PM, I know most of the things told by you. Actually earlier I tried writing DEFFCT REAL[,] multiply(mat[,]:out) but this was showing lots of errors. I don't have the list of those errors.


    By the way thank you so much for such a detailed description.


    I got some more understanding on my doubts. Can you please re verify it (By saying yes or no)-


      • Ques: How to return an array from a function? Ans: Since arrays are large data blocks, so it is advisable not to create a function for them. we should create subroutine instead of function in case of array

      • Ques: Can we have DEF and DEFFCT in a single module file? Ans: Yes we can have.



    Thank you :dance:

  • Looks like these compilation errors are never going to eliminate :icon_confused:


    I am trying to define a 2D array in data list file in following manner-


      This shows me following compilation error-
      [list type=decimal]

      • Array index entered inadmissible here


    [/list]
    I noticed that above error is displayed for 2D array ONLY where column index is not equal to 1 Why so :icon_eek:


    Please see the attached files for more info.


    -
    Thanks

  • That's crazy :waffen100:


    Well, I am trying to use FOR loop with some pre-defined increment. Below is the code-

    Code
    FRAME relFrame
    ; Rotate alpha from 0 to 370 degree
    FOR alpha = 0 TO 370 STEP alphaStep
      relFrame = {X 0,Y 0,Z 0,A 0,B 0,C 0}
      ; Some calculations has been done to compute following values
      relFrame.Z = ZKorr
      relFrame.B = BKorr
      relFrame.C = CKorr
      PTP_REL relFrame
    ENDFOR


    This shows me following error-
    INT. constant not equal 0 expected


    Variable alphaStep is defined in library.dat file in following manner-
    Library.dat

    Code
    ; Increment in alpha
    GLOBAL CONST INT alphaStep=2


    What I am missing here?

  • Hm. I'm not certain. Don't recall every running into this before. Try taking the CONST out, and see what happens. And try moving the variable to the .DAT file of this module, rather than making it global. What you have should work -- I'm just suggesting poking it with a stick to narrow down exactly what the compiler doesn't like.


    Or... the error list says the error occurs in Column 30. By my count, that in the middle of the AlphaStep variable. Maybe for some reason it's seeing the "Step" part of the variable name as a reserved KRL keyword? Normally that's not an issue. But try changing the variable name to something totally innocuous, like BlahBlah, and see what happens.

    Edited once, last by SkyeFire ().

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account
Sign up for a new account in our community. It's easy!
Register a new account
Sign in
Already have an account? Sign in here.
Sign in Now

Advertising from our partners