KRL code to save robot Positions timestamped in a text file. (KRC4)

  • Hello,
    It been a while since I programed in KRL, and going through the docs available for me didn't help.
    I have a program that iterates through a list of positions in a linear fashion. I want to save the positions and the exact time (Date +Time)when robot reach one of them in a .txt or .dat file, that I can fetch later on my USB key.
    The pseudo-code would look like this:


    Code
    START
    LIN P1 
    SavePositionAndTime(File txtFile, P1 E6POS)
    LIN P2
    SavePositionAndTime(File txtFile, P2 E6POS)
    ...
    etc
    END


    Where SavePositionAndTime() function would look like this:

    Code
    START
    IF txtFile EXISTS THEN
      APPEND ("TimeStamp" +":" + "P1")
    ELSE 
    Create txtFile AND SAVE ("TimeStamp" +":" + "P1")
    END



    Any help or suggestion is appreciated.



    The setup is:
    KSS 8.x
    KRC4 controller
    KR 1000 Robot

  • what you are looking for is documented in CREAD/CWRITE manual (use latest version of manual, early version had errors).
    bunch of examples (and some issues) have been discussed.

    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 again,


    The program works now, I need just one thing. I checked this thread that has what I want, but I cannot get the timestamp in milliseconds.
    http://www.robot-forum.com/rob…-file-with-date-and-hour/
    Here's a snippet of my code:



    Code
    for i = 1 to 100
    logPointTime(i)
    ;wait sec 1
    endfor



    The result looks like this:

  • Hi all, currently testing on:


    KSS 8.6.6

    KR 10 R1100-2


    I'm attempting something similar as the above. Attempting to get the workflow in place before it becomes more difficult, but I have a sub file recording the XYZABC of the robot and a timer that is written to a text file with CWRITE. It all seems to work well, except that the timer variable will increase sporadically (maybe when the timer variable is identical to the previous);


    Microsoft-Teams-image.png


    The Sub:




    the KRL is very simple:


    Any ideas what's causing the timer to add additional numbers. The code ends at 5232ms by the timer, but the last recorded timer variable is 5232066..?

  • how does the data look like if you hide the last digit in marked range?

    also notice that this is the last digit from previous line...


    there are two problems here:

    1. you are not clearing string before you write to it. this is the root problem. KRL does not have actual STRING data type. character array is used as a crutch... that means there are some side effects including one that rest of the string is not erased when shorter value is written.


    DECL CHAR NAME[10]


    NAME[]="PETER PAN" ; now name is 'PETER PAN'

    NAME[]="BOB" ; now name is 'BOBER PAN'


    2. you need to learn to debug and not draw wrong conclusions when observing program behavior. when something unexpected happens you should devise test to see what causes the problem. step through code, add buffer to save copy of values, swap the order of elements etc. it is NOT the timer that has "jumpy value", it is the char array that was not cleared. if you tried one of mentioned things you would see that right away.

    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

  • to clear string you can use function StrClear(), or use loop to reset each character.

    one form of workaround could also be to use fixed width output (your string length changed because of minus sign once it disappeared when value became positive). advantage here is that output is easier to read (by humans) but file will be larger.


    ... or simply add several space characters at the end of the format string. this will just make the output file larger without but columns would continue to shift based on sign. this is probably why you put timer in the last column.

    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

  • hmmm... looks suspiciously similar to many of my functions... 8)


    even names, order of parameter etc are quite close.

    i was rather surprised to see string to/from I/O, i was pretty sure that nobody else would go for it but i guess i was wrong. mine has optional limit so one can make sure that too long strings do not read/write to something out of range.

    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

  • hmmm... looks suspiciously similar to many of my functions... 8)

    Great minds think alike? :pfeif:


    At this remove, it's hard to remember which functions I created, and which I collected from various sources. Pretty sure the random-number generator, for one, is based heavily on your example.


    Yeah, the string-over-IO function only got developed to a certain point, then stopped, b/c we ended up needing to move so much string data that it would take a couple minutes, even using ridiculous amounts of I/O and assuming 24ms for each block transfer. That's when we switched to using EKI, which was more difficult to set up, but worked much better once it was (aside from causing a SYS 14 fault and hard-killing the robot until KUKA eventually fixed that bug in the EKI error counter).

  • Thanks for the advice guys. Including the strclear() within the loop worked perfectly. I've also removed the issue of duplicates. It was when moving into negative numbers it was adding 1 to 6 characters to the array through the '-' character that I wasn't accounting for.


    Python being the language I'm probably most comfortable in, shifting to KRL is always a bit of a shock to the system.


    And thanks for the functions, I'll go over them in detail.

  • Great minds think alike? :pfeif:


    At this remove, it's hard to remember which functions I created, and which I collected from various sources. Pretty sure the random-number generator, for one, is based heavily on your example.


    Yeah, the string-over-IO function only got developed to a certain point, then stopped, b/c we ended up needing to move so much string data that it would take a couple minutes, even using ridiculous amounts of I/O and assuming 24ms for each block transfer. That's when we switched to using EKI, which was more difficult to set up, but worked much better once it was (aside from causing a SYS 14 fault and hard-killing the robot until KUKA eventually fixed that bug in the EKI error counter).

    Interestingly, I started with EKI for this project. The data points were 200ms apart, which was too lo-fidelity, so switched to recording locally on the control pc. Pretty sure it wasn't a networking issue, but that I was using the sps.sub to communicate with EKI, but by that stage I was using cwrite.

  • I'm surprised I can't write $PRO_NAME[] to a line via swrite? I know the variable is write protected, but does that mean I am unable to read it within the submit interpreter.. ?


    Code
    SWRITE(FILEINFO[], S, OFS, "%c, %i", $PRO_NAME[], $ACT_BASE)

    This line with $pro_name included throws the KSS01422 error that fileinfo[] value invalid. So I attempted to create another CHAR array name[] = $pro_name - still no luck. Is this futile?


    edit: I also attempted strcopy..

    Edited once, last by singline ().

  • I'm surprised I can't write $PRO_NAME[] to a line via swrite? I know the variable is write protected, but does that mean I am unable to read it within the submit interpreter.. ?


    Code
    SWRITE(FILEINFO[], S, OFS, "%c, %i", $PRO_NAME[], $ACT_BASE)

    This line with $pro_name included throws the KSS01422 error that fileinfo[] value invalid. So I attempted to create another CHAR array name[] = $pro_name - still no luck. Is this futile?


    edit: I also attempted strcopy..


    I'm using it all the time in the sps for reading...

    Did you tried also $pro_name1[]?

    only $PRO_NAME[] depends on setting in $INTERPRETER

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