Search code examples
gitkuka-krl

Using git with KRL (KUKA Robot Language) projects


I have some problems using git with my KRL projects and want to know if there are some workarounds to improve my workflow.

KRL is the programming language for industiral KUKA robots. It has a Basic-/Pascal-like syntax. A program consists of one or multiple modules. A module consists of two textfiles, one for the source code (.src) and one for declarations and definitions (.dat).

My first problem is that in each file the first lines build the header which looks like this:

&ACCESS RVO
&REL 175

Each header line starts with a & and has absolutely no meaning for the code. The worst part is this header changes constantly. So when I copy a file back from the robot controller into my repo git states that the file changed even though the source code is the same.

So my first question: Is there a way with filters or hooks to ignore all lines starting with a &?

My second problem is that the *.dat files are not only for declarations and definitions like header files in C-like languages, but also a storage for the values. This looks like this:

DECL E6POS XP1={X 319.710815,Y -488.601227,Z 1364.72363,A -73.5368805,B 88.6439896,C 10.5155058,S 6,T 26,E1 0.0,E2 0.0,E3 0.0,E4 0.0,E5 0.0,E6 0.0}
INT counter=123
REAL offset=0.123

I depend on the values because they store the positions and counters that need to stay persistent, but I don't care about them in my repo. Well not completely, they have to be in the files and in my repo but git shouldn't look for diffs in these lines.

So lets say I created a module in my repo and copy this module to the robot. Now I execute this module with the robot and have to overwrite a position value. This changes the value in the corresponding *.dat file. Everything works fine and after a few days I want to implement a counter. I can't just put a new integer definition into the locally available *.dat file, because this way I would overwrite the position value on the robot. So I have to copy the *.dat file from the robot controller into my repo first and define the new variable there. But of course git shows me that the file changed not only in the new line but also on the lines where the robot changed the values like the position. This makes reviews way harder, because I have lots of measurement and counter values that change constantly.

So to my second question: Is there a way to ignore everything after the = but only in *.dat files? This should work the same as with the & from the headers, so the values should be in the repo but I don't care about any diffs on these values.


Solution

  • Using filters you can ignore those lines.

    Lets say we have a filter on /scripts/krl_filter.sh:

    sed -e '/\&ACCESS/d' -e '/\&REL/d' -e '/\&PARAM/d' -e '/\&COMMENT/d'
    

    We set the filter into /.git/config

    [filter "krl"]
      clean = $PWD/scripts/krl_filter.sh
      smudge = cat
      required = true
    

    We apply it to the KRL-files .gitattributes

    *.src filter=krl
    *.dat filter=krl
    *.sub filter=krl
    

    Maybe you will see before commit the head lines as changed but once staged the changes or somehow else, the filter is applied

    *for the .dat files you could use a filter like this:

    sed -e 's/=[^=]*$/=/'
    

    For more information about ignoring lines in git check this: How to tell git to ignore individual lines, i.e. gitignore for specific lines of code