1. Home
    1. Dashboard
    2. Search
  2. Forum
    1. Unresolved Threads
    2. Members
      1. Recent Activities
      2. Users Online
      3. Team Members
      4. Search Members
      5. Trophys
  3. Articles
  4. Blog
  5. Videos
  6. Jobs
  7. Shop
    1. Orders
  • Login or register
  • Search
This Thread
  • Everywhere
  • This Thread
  • This Forum
  • Articles
  • Pages
  • Forum
  • Blog Articles
  • Products
  • More Options
  1. Robotforum - Support and discussion community for industrial robots and cobots
  2. Forum
  3. Industrial Robot Support and Discussion Center
  4. KUKA Robot Forum
Your browser does not support videos RoboDK Software for simulation and programming
Visit our Mainsponsor
IRBCAM
Robotics Channel
Robotics Training
Advertise in robotics
Sponsored Ads

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

  • kiiwa
  • May 11, 2017 at 6:16 PM
  • Thread is Resolved
  • kiiwa
    Reactions Received
    9
    Trophies
    4
    Posts
    369
    • May 11, 2017 at 6:16 PM
    • #1

    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

  • panic mode
    Reactions Received
    1,262
    Trophies
    11
    Posts
    13,027
    • May 11, 2017 at 6:58 PM
    • #2

    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

  • panic mode
    Reactions Received
    1,262
    Trophies
    11
    Posts
    13,027
    • May 11, 2017 at 7:05 PM
    • #3

    here is some code to read, writing is very much the same...
    https://www.robot-forum.com/robotforum/kuk…88863/#msg88863

    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

  • kiiwa
    Reactions Received
    9
    Trophies
    4
    Posts
    369
    • May 12, 2017 at 9:33 AM
    • #4

    Thanks a lot, man! That's what I needed, just a place to start digging. I found the document also, the one you shared on mrplc forums, for KSS 8.3.

  • Online
    SkyeFire
    Reactions Received
    1,038
    Trophies
    12
    Posts
    9,371
    • May 12, 2017 at 4:39 PM
    • #5

    There's been a few forum threads discussing this as well -- use the Search function and look for 'fopen', 'fread', 'fwrite', etc.

  • kiiwa
    Reactions Received
    9
    Trophies
    4
    Posts
    369
    • May 15, 2017 at 4:00 PM
    • #6

    Thanks guys, I've been following panic mode's answer on this thread:
    https://www.robot-forum.com/robotforum/kuk…te-krl_fprintf/
    and it helped a lot. I'm tuning it for my needs.

  • panic mode
    Reactions Received
    1,262
    Trophies
    11
    Posts
    13,027
    • May 15, 2017 at 4:28 PM
    • #7

    no problem, glad I could help... :beerchug:

    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

  • kiiwa
    Reactions Received
    9
    Trophies
    4
    Posts
    369
    • May 15, 2017 at 7:02 PM
    • #8

    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.
    https://www.robot-forum.com/robotforum/kuk…-date-and-hour/
    Here's a snippet of my code:

    Code
    &ACCESS RVP1
    &REL 1
    &PARAM EDITMASK = *
    &PARAM TEMPLATE = C:\KRC\Roboter\Template\vorgabe
    DEF logPointTime(x1:in)
    decl int x1
    int handle
    decl state_t s
    decl modus_t m
    decl char myData[200]
    decl int ofs 
    ofs=0
    
    
    ; put everything into one string....  
    swrite(myData[],s,ofs,"point %d at %d%s%d%s%d%s%d'H0D''H0A'",x1, $DATE.HOUR, ":", $DATE.MIN, ":", $DATE.SEC, ".", $DATE.CSEC)
    ; ... and then write entire string to a file (at once!)
    m=#sync
    handle=$date.sec
    
    
    ; open file
    CWRITE($FCT_CALL,s,m,"krl_fopen","robot_log.txt","a",handle)
    
    
    ; write data
    CWRITE($FCT_CALL,s,m,"krl_fprintf",handle,"%s",myData[])
    
    
    ; close file
    cwrite($FCT_CALL, s,m,"krl_fclose",handle)
    
    
    END
    Display More
    Code
    for i = 1 to 100
    logPointTime(i)
    ;wait sec 1
    endfor


    The result looks like this:

    Code
    point 1 at 17:44:27.0
    point 2 at 17:44:28.0
    point 3 at 17:44:28.0
    point 4 at 17:44:29.0
    point 5 at 17:44:30.0
    point 1 at 17:49:50.0
    point 2 at 17:49:50.0
    point 3 at 17:49:50.0
    point 4 at 17:49:50.0
    point 5 at 17:49:50.0
    point 6 at 17:49:50.0
    point 7 at 17:49:50.0
    point 8 at 17:49:50.0
    point 9 at 17:49:50.0
    point 10 at 17:49:50.0
    Display More
  • panic mode
    Reactions Received
    1,262
    Trophies
    11
    Posts
    13,027
    • May 15, 2017 at 11:06 PM
    • #9

    just start timer and use ms from it.

    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

  • singline
    Reactions Received
    2
    Trophies
    3
    Posts
    23
    • May 27, 2021 at 2:56 PM
    • #10

    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:

    Code
    DECL CHAR CURRENT[200]
    DECL STATE_T S
    DECL MODUS_T M
    DECL IN OFS
    decl bool ran
    decl int handle
    ;ENDFOLD (USER DECL)
    ;ENDFOLD (DECLARATIONS)
    ;FOLD INI
    ;FOLD USER INIT
    ; Please insert user defined initialization commands
    OFS = 0
    ran = false
    handle = 0
    
    
    ; open file
    CWRITE($FCT_CALL,s,m,"krl_fopen","spline_log.txt","a", handle)
    
    
    ;ENDFOLD (USER INIT)
    ;ENDFOLD (INI)
    
    
    
    
    LOOP
    ;FOLD USER PLC
    ;Make your modifications here
    ;IF ($TIMER[63] > UPDATETIME) THEN
    
    
    IF RECORD THEN
    ran = true
    ofs = 0
    SWRITE(CURRENT[], S, OFS, "%.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %i", $POS_ACT.X, $POS_ACT.Y, $POS_ACT.Z, $POS_ACT.A, $POS_ACT.B, $POS_ACT.C, $TIMER[8])
    M = #SYNC
    ; write data
    CWRITE($FCT_CALL,s,m,"krl_fwriteln", handle, CURRENT[])
    
    
    ENDIF
    
    
    IF NOT RECORD AND RAN THEN
    ; close file
    CWRITE($FCT_CALL, s,m,"krl_fclose", handle)
    wait sec 0
    ran = false
    ENDIF
    
    
    ;ENDFOLD (USER PLC)
    ENDLOOP
    
    
    ;FOLD ;%{H};
    END
    ;ENDFOLD
    ;FOLD USER SUBROUTINE
    ;Integrate your user defined subroutines
    
    
    ;ENDFOLD (USER SUBROUTINE)
    Display More


    the KRL is very simple:

    Code
    ;FOLD LIN SPEED IS 0.25 m/sec, INTERPOLATION SETTINGS IN FOLD
    $VEL.CP=0.25
    $ADVANCE=3
    ;ENDFOLD
    
    
    PTP {X 10, Y -10, Z 0, A 0, B 90, C 0, E1 0, E2 0, E3 0, E4 0, S 'B 110'} C_PTP
    LIN {X 10, Y -10, Z 0, A 0, B 90, C 0, E1 0, E2 0, E3 0, E4 0} C_DIS
    SPLINE
    SPL {X 290, Y -110, Z 0, A 0, B 90, C 0, E1 0, E2 0, E3 0, E4 0} WITH $ORI_TYPE = #VAR
    SPL {X 10, Y -210, Z 0, A 0, B 90, C 0, E1 0, E2 0, E3 0, E4 0} WITH $ORI_TYPE = #VAR
    SPL {X 290, Y -310, Z 0, A 0, B 90, C 0, E1 0, E2 0, E3 0, E4 0} WITH $ORI_TYPE = #VAR
    SPL {X 10, Y -410, Z 0, A 0, B 90, C 0, E1 0, E2 0, E3 0, E4 0} WITH $ORI_TYPE = #VAR
    ENDSPLINE
    PTP {A1 5, A2 -90, A3 100, A4 5, A5 10, A6 -5, E1 0, E2 0, E3 0, E4 0} C_PTP
    
    
    END
    Display More

    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..?

  • panic mode
    Reactions Received
    1,262
    Trophies
    11
    Posts
    13,027
    • May 27, 2021 at 3:22 PM
    • #11

    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

  • panic mode
    Reactions Received
    1,262
    Trophies
    11
    Posts
    13,027
    • May 27, 2021 at 3:28 PM
    • #12

    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

  • Online
    SkyeFire
    Reactions Received
    1,038
    Trophies
    12
    Posts
    9,371
    • May 27, 2021 at 7:20 PM
    • #13

    The various Logxxxx functions in this module may be a useful example.

    Files

    krlfunctions.zip 21.69 kB – 93 Downloads
  • panic mode
    Reactions Received
    1,262
    Trophies
    11
    Posts
    13,027
    • May 28, 2021 at 12:23 AM
    • #14

    hmmm... looks suspiciously similar to many of my functions... :smiling_face_with_sunglasses:

    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

  • Online
    SkyeFire
    Reactions Received
    1,038
    Trophies
    12
    Posts
    9,371
    • May 28, 2021 at 3:43 PM
    • #15
    Quote from panic mode

    hmmm... looks suspiciously similar to many of my functions... :smiling_face_with_sunglasses:

    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).

  • singline
    Reactions Received
    2
    Trophies
    3
    Posts
    23
    • May 28, 2021 at 5:54 PM
    • #16

    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.

  • Online
    SkyeFire
    Reactions Received
    1,038
    Trophies
    12
    Posts
    9,371
    • May 28, 2021 at 10:09 PM
    • #17

    I also found it useful to set every value to a fixed number of characters, and always include the +/- symbol. So lists like:

    +0001.10

    -0022.02

    +9999.99

    And so on.

  • singline
    Reactions Received
    2
    Trophies
    3
    Posts
    23
    • May 29, 2021 at 9:04 AM
    • #18
    Quote from SkyeFire

    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.

  • singline
    Reactions Received
    2
    Trophies
    3
    Posts
    23
    • May 29, 2021 at 2:34 PM
    • #19

    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 (May 29, 2021 at 2:56 PM).

  • DannyDJ
    Reactions Received
    62
    Trophies
    6
    Posts
    493
    • May 31, 2021 at 9:24 AM
    • #20
    Quote from 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

Advertising from our partners

IRBCAM
Robotics Channel
Robotics Training
Advertise in robotics
Advertise in Robotics
Advertise in Robotics

Job Postings

  • Anyware Robotics is hiring!

    yzhou377 February 23, 2025 at 4:54 AM
  • How to see your Job Posting (search or recruit) here in Robot-Forum.com

    Werner Hampel November 18, 2021 at 3:44 PM
Your browser does not support videos RoboDK Software for simulation and programming

Tag Cloud

  • abb
  • Backup
  • calibration
  • Communication
  • CRX
  • DCS
  • dx100
  • dx200
  • error
  • Ethernet
  • Ethernet IP
  • external axis
  • Fanuc
  • help
  • hmi
  • I/O
  • irc5
  • IRVIsion
  • karel
  • kawasaki
  • KRC2
  • KRC4
  • KRC 4
  • KRL
  • KUKA
  • motoman
  • Offset
  • PLC
  • PROFINET
  • Program
  • Programming
  • RAPID
  • robodk
  • roboguide
  • robot
  • robotstudio
  • RSI
  • safety
  • Siemens
  • simulation
  • SPEED
  • staubli
  • tcp
  • TCP/IP
  • teach pendant
  • vision
  • Welding
  • workvisual
  • yaskawa
  • YRC1000

Thread Tag Cloud

  • abb
  • Backup
  • calibration
  • Communication
  • CRX
  • DCS
  • dx100
  • dx200
  • error
  • Ethernet
  • Ethernet IP
  • external axis
  • Fanuc
  • help
  • hmi
  • I/O
  • irc5
  • IRVIsion
  • karel
  • kawasaki
  • KRC2
  • KRC4
  • KRC 4
  • KRL
  • KUKA
  • motoman
  • Offset
  • PLC
  • PROFINET
  • Program
  • Programming
  • RAPID
  • robodk
  • roboguide
  • robot
  • robotstudio
  • RSI
  • safety
  • Siemens
  • simulation
  • SPEED
  • staubli
  • tcp
  • TCP/IP
  • teach pendant
  • vision
  • Welding
  • workvisual
  • yaskawa
  • YRC1000
  1. Privacy Policy
  2. Legal Notice
Powered by WoltLab Suite™
As a registered Member:
* You will see no Google advertising
* You can translate posts into your local language
* You can ask questions or help the community with your knowledge
* You can thank the authors for their help
* You can receive notifications of replies or new topics on request
* We do not sell your data - we promise

JOIN OUR GREAT ROBOTICS COMMUNITY.
Don’t have an account yet? Register yourself now and be a part of our community!
Register Yourself Lost Password
Robotforum - Support and discussion community for industrial robots and cobots in the WSC-Connect App on Google Play
Robotforum - Support and discussion community for industrial robots and cobots in the WSC-Connect App on the App Store
Download