How to write Karel programs?

  • Since I started working with Fanuc robots three weeks ago I've heard a lot of people mention Karel. I understand that Karel is Fanuc's robot programming language, but what is involved in actually using Karel? Is there a compiler that you need to get to convert Karel code to a file that can be loaded onto the robot controller? Is there anything you need for the robot controller, or is it all software for your PC?


    Also, what can you do with Karel that you can't already do with the iPendant? I get that Karel would make writing large programs easier, but are there any functions that can only be implemented in Karel?


    Thanks!

  • Warning: long answer ahead. I just thought I'd take the opportunity to highlight some of the benefits of Karel, as it doesn't seem like there are that many 'supporters' here on the board.


    Short version: you need: a text editor, option R632, roboguide or winolpc (ktrans.exe and related support files, really), the manual(s) and a way to transfer binaries to your controller (ftp, usb, cf).


    [hr]


    longer version:



    Since I started working with Fanuc robots three weeks ago I've heard a lot of people mention Karel. I understand that Karel is Fanuc's robot programming language, but what is involved in actually using Karel? Is there a compiler that you need to get to convert Karel code to a file that can be loaded onto the robot controller? Is there anything you need for the robot controller, or is it all software for your PC?


    You need four things to do any Karel development:
    [list type=decimal]

    • a text editor

    • a 'compiler'

    • controller support

    • a brain

    [/list]
    1) can be any editor really. People here on the board have been using UltraEdit, Notepad++, vim, notepad and even the editor built into Roboguide. Syntax highlighting and completion depend on support by the editor for such things, and the availability of a suitable dictionary / language definition file (see here for files for Notepad++ fi). The Roboguide editor also supports highlighting.


    2) The controller only really executes something called p-code which is a form of byte code not unlike that of Smalltalk or Java. Karel sources (.kl) are converted into binaries (.pc) using ktrans.exe (on the command line) or using Roboguide (which uses the same libraries 'under the hood'). Final step is to copy those binaries to your controller. Roboguide can do this for you (send to robot), you could use ftp (which is what Roboguide does) or a usb stick / memory card. There's no magic, it's just a set of binary files that need to be copied to the right place on the controller.


    3) is most important: without the proper options, you'll not be able to use anything you've produced in 1 and 2. As far as I know, you'll need option "R632 - KAREL" on your controller (at least, that is the nr it has on my R-30iA. May be different for older controllers). The dependency resolution during install of your controller should have installed all other necessary Karel bits.


    Don't take 4) too serious :). Apart from information on Karel in general, having a small amount of programming experience really helps. Common sense too, as well as any Karel reference guides you can get your hands on. MARRC75KR07091E should be the document nr for the "KAREL Reference Manual", which I think may be considered the "bible" of Karel programming. Karel isn't difficult however, and you should not be discouraged by its sometimes archaic syntax or limitations.



    Also, what can you do with Karel that you can't already do with the iPendant? I get that Karel would make writing large programs easier, but are there any functions that can only be implemented in Karel?


    Thanks!


    With regards to motion (at least on R-30iA+), Karel is at a disadvantage compared to TP: apparently the motion planners on the Karel side haven't seen much development for at least a couple of years. Fanuc advises (read: almost requires) you to program al motion in TP. Karel can use things like Position and Integer registers to communicate and 'parametrise' motions programmed in TP programs.


    With some difficulty, you could probably get TP to do most of the things Karel supports. Karel is however a relatively high-level structured programming language (similar to Pascal), whereas I'd compare TP to assembly. Complex logic, data structures, information hiding and separation of concerns are much, much easier to use and implement with Karel. As soon as your application grows beyond a mere "pick up here, place there" kind of thing, I tend to go for Karel (however: motion is still TP).


    One thing that TP cannot do, is socket (network) and serial communication: you'll always need to use Karel for that. If your project requires you to communicate with a vision system, or an rfid scanner, or anything that isn't already supported by Fanuc or an mfg that provides you with stuff to install on your robot (and you don't want to use a fieldbus), Karel can be used to implement an interface. Karel also includes support for vector math, terminal IO, interaction with the IO subsystem, creating menus and forms (think the textual GUIs on the TP you're familiar with, with dropdowns, input validation and real-time updating of display items) and dictionaries (allowing you to create multi-lingual programs).


    Finally: of course Karel has its flaws, and some serious ones at that. Compared to many modern programming languages (even those used in other industrial robot controllers), its syntax is archaic, imposes ridiculous constraints (12-character identifier limit, strict requirements on file layout, no support for hexadecimal, no generic byte-buffer type, no proper string support, etc) and there is no support for conveniences like macros, proper include path / library infrastructure or a sane debugger.


    hth,




    PS: as one other example of something that Karel can do that TP cannot: (dynamic) web page generation. Afaik, the entire irVision interface is built on this. Even the pages part of the default web server option use it. A recent posting on this board (KAREL unit testing framework) shows how you can exploit this to implement some rather complex functionality.

    Edited once, last by rf103 ().

  • My understanding from going to the Fanuc facility in Detroit Karel is a program that Fanuc makes to benefit integrator's. Karel is a real pain to work with and has no perks that basic TP does not have. So to say the least try to avoid it.

  • Well I understand the economics, but as I said, there are definitely things that TP cannot do. Good luck trying to use serial ports, socket communication, ftp or file sharing with TP. Also: vector math.

    Edited once, last by rf103 ().

  • Karel is an extremely powerful programming language for the Fanuc Robots. It will let you do anything that you would dream about. It is almost as powerful as any PC programming language. It is derived from Pascal and is very similar to that.
    The Karel source code files has the extension .kl and are pure ASCII files that can be read in any text editor like Wordpad or Notepad. When the source codes are compiled, they are transformed to .pc files that cannot be decompiled, and therefore not be read by anybody.
    There is a compiler in Roboguide as well as an editor. if your Cell browser, under the robot controller there is a tab called "Files" if you right click on that tab, you can ADD a new file, and select KAREL source file. When you do that an editor window opens, and you are able to enter you first Karel code :winking_face:
    It is absolutely worthwhile to look into this incredible programming option.
    /Flemming

  • so .PC files are impossible to de-compile? as i have this exact issue where i need to decompile a 20 year old Karel file to edit some new jobs into it.

  • I don't need to provide you with any proof, and you don't need to believe me.


    The decompiler I wrote about is not (yet) commercially available, so I cannot refer you to it.


    And I don't see how I can prove to you that it exists without it being available (as there is no point in posting some source code and a pc file).


    I wrote my post to let you know that what has been claimed to be impossible for many years is in fact not impossible.


  • so .PC files are impossible to de-compile? as i have this exact issue where i need to decompile a 20 year old Karel file to edit some new jobs into it.


    No se hasta donde sea posible, pero tal vez puedes hacer un programa en karel para que llame a ese programa que quieres des-compilar para que imprima el texto


    "I do not know where it's possible, but maybe you can do a program in karel to call that program you want to un-compile to print the text"


  • Actualmente estoy trabajando con un robot de soldadura, el cual tiene funciones de oscilación, Tendrás alguna idea de donde puedo encontrar las funciones de oscilación para modificarlas??
    Lo que trato de hacer es ver que tareas hace esta función de oscilación para entender como funciona. De esta manera podría crear mi propio tipo de oscilación.



    "I am currently working with a welding robot, which has oscillating functions. Will you have any idea where I can find the oscillation functions to modify them?
    What I try to do is see what tasks this oscillation function does to understand how it works. This way I could create my own type of oscillation."

  • It is not possible to access and read the Karel programs. So, if you want a coustomized waving you should to programing it by yourself... :bawling:


    I think the best option in this case would be contact Fanuc...

  • Hello.

    As far as I understand the above, to work with Karel , you need to install an additional "R632 - KAREL". Then you can work calmly. But what if I need to transmit the coordinates of objects using the camera, what is the best way to transmit them? Need something else to deliver?

    Thank.

Advertising from our partners