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

Issues reading a writing positions to text file for homing

  • emerald_geni
  • June 2, 2022 at 3:51 AM
  • Thread is Unresolved
  • emerald_geni
    Trophies
    2
    Posts
    25
    • June 2, 2022 at 3:51 AM
    • #1

    Hi guys,

    I am using KSS 8.6 END V6

    I am trying to create a homing sequence by filling up a text file then rereading it backwards to get back to home.

    Have created a block of code to record positions and an interrupt to call READCSV.src to read back the positions and send it back for execution in reverse.

    After reversing the file will be deleted and an empty text file( CREATECSV.src) is called to create an empty text file for the next homing call.

    I have found the post below to be suitable.

    Post

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

    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, 34 lines)

    (Code, 4 lines)



    The result looks like this:

    (Code, 15 lines)

    kiiwa
    May 15, 2017 at 7:02 PM

    I am able to Open a file, Start populating positions and close it.


    The issue i am facing is that the positions are recorded at cycle time rate thus too many positions. so i added a timer to lengthen the sample rate. This does not seem to work.

    The robot moves in reverses smoothly for awhile and starts to jerk after.

    Any assistance would be greatly appreciated.


    Code: SPS.SUB
    &ACCESS  RVO
    &COMMENT PLC on control
    DEF  SPS ( )
      ;FOLD DECLARATIONS
      ;FOLD BASISTECH DECL
      ;Automatik extern
      DECL CHAR CURRENT[200]
      DECL STATE_T STAT
      DECL MODUS_T MODE
      DECL INT OFS
      DECL INT UPDATETIME
      DECL BOOL ran
      ;DECL INT global_handle
      DECL BOOL RECORD
      DECL BOOL rob_stopped
      DECL BOOL peri_rdy
      ;DECL BOOL timer1_Q
      ;ENDFOLD (BASISTECH DECL)
      ;FOLD USER DECL
      ; Please insert user defined declarations
    
      ;ENDFOLD (USER DECL)
      ;ENDFOLD (DECLARATIONS)
      ;FOLD INI
      ;FOLD AUTOEXT INIT
      INTERRUPT DECL 91 WHEN $PRO_STATE1==#P_FREE DO RESET_OUT ()
      INTERRUPT ON 91
      INTERRUPT DECL 92 WHEN $PRO_MOVE==TRUE DO RESET_LINESEL()
      INTERRUPT ON 92
      $LOOP_MSG[]="                                                            "
      MODE=#SYNC
      $H_POS=$H_POS
      ;Automatic extern
      IF $MODE_OP==#EX THEN
        CWRITE($CMD,STAT,MODE,"RUN/R1/CELL()")
      ENDIF
      ;ENDFOLD (AUTOEXT INIT)
      ;FOLD BACKUPMANAGER PLC INIT
      BM_ENABLED = FALSE
      BM_OUTPUTVALUE = 0
      ;ENDFOLD (BACKUPMANAGER PLC INIT)
      ;FOLD USER INIT
      ; Please insert user defined initialization commands
       OFS = 0
       ran = false
       ;global_handle = 0
       RECORD = FALSE
       ; open file
       CWRITE($FCT_CALL,STAT,MODE,"krl_fopen","position_log.txt","a", global_handle)
      ;ENDFOLD (USER INIT)
      ;ENDFOLD (INI)
      
    
    
    ;timer1_Q=$timer_flag[1]
    ;UPDATETIME=-30
    
      LOOP
        WAIT FOR NOT($POWER_FAIL)
              ;FOLD BASISTECH PLC
                 BasisTech_PLC_LOOP()
              ;ENDFOLD (BASISTECH PLC)
              ;FOLD BACKUPMANAGER PLC
              IF BM_ENABLED THEN
                BM_OUTPUTSIGNAL = BM_OUTPUTVALUE
              ENDIF
              ;ENDFOLD (BACKUPMANAGER PLC)
              ;FOLD USER PLC
              ;Make your modifications here
              
             rob_stopped = $ROB_STOPPED
             peri_rdy    = $PERI_RDY  
               
           ; $TIMER[1]      = -500 ;set timer duration
           ; $TIMER_STOP[1] = false;  start timer
             
             IF NOT rob_stopped THEN
                RECORD = TRUE
                $TIMER_STOP[1] = FALSE
                ELSE 
                RECORD = FALSE
                $TIMER_STOP[1] = TRUE
                
             ENDIF
             
             ;AND ($timer[1] >=-1000)
             IF RECORD==TRUE  AND ($timer[1] >=-2000) THEN
                
                ran = true
                OFS = 0
                SWRITE(CURRENT[], STAT, OFS, "%.3f, %.3f, %.3f, %.3f, %.3f, %.3f", $POS_ACT.X, $POS_ACT.Y, $POS_ACT.Z, $POS_ACT.A, $POS_ACT.B, $POS_ACT.C)
                MODE = #SYNC
                ; write data
                CWRITE($FCT_CALL,STAT,MODE,"krl_fwriteln", global_handle, CURRENT[])
         
               IF  (NOT STRCLEAR(CURRENT[])) THEN
                   halt
               ENDIF
                ;$TIMER_STOP[1] = TRUE ; 
                
             ENDIF
             
             IF $TIMER[1] >=-500 then
                
                $TIMER_STOP[1] = TRUE
                $TIMER[1]      = -2000
                $TIMER_STOP[1] = false
             
             ENDIF
             
             ; close file
             IF  NOT RECORD AND ran AND NOT peri_rdy THEN
                
                
                CWRITE($FCT_CALL, STAT,MODE,"krl_fclose", global_handle)
                ran = false
                
             ENDIF
             
    
    
             ;Set speed limits 
                IF $MODE_OP == #EX THEN
                   
                    IF $OV_PRO >10 THEN
                      $OV_PRO =10
                    ENDIF                
                ENDIF 
                    
                IF $MODE_OP == #AUT THEN
                   
                    IF $OV_PRO >10 THEN
                      $OV_PRO =10
                      
                    ENDIF
                ENDIF
                
                IF $MODE_OP == #T1 THEN
                   
                    IF $OV_PRO >49 THEN
                      $OV_PRO =30
                    ENDIF
                ENDIF
        
        ;ENDFOLD (USER PLC)
        
      ENDLOOP
      ;FOLD ;%{H}
      ;FOLD
    END
      ;ENDFOLD
    
    
    DEF  RESET_OUT ( )
      INT N
      MsgLoop(" ")
      IF REFLECT_PROG_NR == 1 THEN   
        FOR N = 0 TO PGNO_LENGTH - 1       
          $OUT[PGNO_FBIT_REFL + N] = FALSE
        ENDFOR
      ENDIF
      IF (PGNO_REQ >0) THEN   
        $OUT[PGNO_REQ]=FALSE
      ELSE
        IF (PGNO_REQ <0) THEN
          $OUT[-PGNO_REQ]=TRUE
        ENDIF
      ENDIF
    END
    
    DEF RESET_LINESEL()
      $LINE_SEL_OK=FALSE
    END
    ;FOLD USER SUBROUTINE
    ; Integrate your user defined subroutines
    
    ;ENDFOLD (USER SUBROUTINE)
    ;ENDFOLD
    Display More
    Code: Read_CSV
    DEF  read_csv ( )
    DECL state_t S
    DECL modus_t M
    DECL int handle,read,n,i
    DECL char Buff[256], fmt[64], tmp[10]
    DECL BOOL debug
    
    
    ;FOLD INI;%{PE}
      ;FOLD BASISTECH INI
        GLOBAL INTERRUPT DECL 3 WHEN $STOPMESS==TRUE DO IR_STOPM ( )
        INTERRUPT ON 3 
        BAS (#INITMOV,0 )
      ;ENDFOLD (BASISTECH INI)
      ;FOLD USER INI
        ;Make your modifications here
       $TOOL = TOOL_DATA[2]
       $BASE = BASE_DATA[2]
      ;ENDFOLD (USER INI)
    ;ENDFOLD (INI)
    
    
    debug = false
    
    ; initialize buffer, it cannot be empty
    for n=1 to 256
      Buff[n]=32 ; 0x20 is a space character
    endfor
    
    for n=1 to 1000
      P[n]={X 0,Y 0,Z 0,A 0,B 0,C 0}
    endfor
    
    fmt[] = "%f, %f, %f, %f, %f, %f" ; line format
    handle=0      ; pick file handle 
    read=0   ; number of characters read from file  
    
    
    ;-------> step 1 - open file <------------
    ; note: file is stored in C:\KRC\ROBOTER\USERFILE
    if debug then
      cwrite($FCT_CALL,S,M,"krl_fclose_all",-99)
      halt
    endif
    
    cwrite($FCT_CALL,S,M,"krl_fopen","position_log.txt","r",handle)
    wait for S.ret1==#data_ok ; confirm action 
    
    ;-------> step 2 - read from file <-------
    n=0
    repeat
    
      if debug then
        halt
      endif
    
      n=n+1
      MsgNotify("Trying to read line %1",,n)
      tmp[]="          "
    
      cwrite($FCT_CALL,S,M,"krl_fscanf",handle,fmt[],P[n].X,P[n].Y,P[n].Z,P[n].A,P[n].B,P[n].C)
    
    ;or (n>=100) , (S.msg_no== -4))
    
    until ((S.ret1<>#data_ok) or (n>=1000))
    
     if S.msg_no== -4 then
       msgnotify("end of file")
     endif
     
    ;-------> step 3 - close file  <----------
    cwrite($FCT_CALL,S,M,"krl_fclose",handle)
    wait for S.ret1==#data_ok
    
    
     SPTP $AXIS_ACT
     
    i = n
    
    REPEAT
       
       $TOOL = TOOL_DATA[2]
       $BASE = BASE_DATA[2]
       
    
       SLIN P[i]
       i= i-1
    
    UNTIL (i == 1)
    
    ; delete file
    cwrite($FCT_CALL,S,M,"krl_remove","position_log.txt")
    
    WAIT SEC 3
    
    Create_CSV();
    
    END
    Display More
  • hermann
    Reactions Received
    407
    Trophies
    9
    Posts
    2,612
    • June 2, 2022 at 6:29 AM
    • #2

    1. You really programmed a 'halt' in sps.sub? Shouldn't be executed (only if something is going wrong, but anyway a fail.

    2. Your idea only works when your program always uses the same tcp. And no PTP movent is used.

    3. Your timer handling is a bit strange. You set the timer to -2000 if he is higher than - 500, but you write a position when the timer is higher than -2000, so you write positions as fast as possible.

    You should work with $timer_flag.

    Set timer to -1500 (or whatever, 1.5 seconds are very slow, if robot moves with 2 m/s!)

    and then save position when $timer_flag is true.

  • Online
    panic mode
    Reactions Received
    1,280
    Trophies
    11
    Posts
    13,083
    • June 2, 2022 at 2:07 PM
    • #3

    and to continue with few more tips....

    4. do NOT write code in SPS. create separate SRC/DAT file, debug it in robot interpreter and when all is said and done, then just link it to SPS.

    5. do not try to use Cartesian position like that. your program is continuously reading $POS_ACT and it will crash. you need to check if the tool and base are set or use OBN_ERROR_PROCEED

    6. your RECORD strategy is flawed. it will crash the submit, for example RECORD can be set/reset multiple times. when it is reset, attempt is made to close the currently open file. but next time RECORD is true, attempts are made to write to a file without having new handle or file open.

    7. STAT value is never evaluated. in a robust program this need to be handled.

    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

  • emerald_geni
    Trophies
    2
    Posts
    25
    • June 5, 2022 at 2:56 PM
    • #4
    Quote from hermann

    1. You really programmed a 'halt' in sps.sub? Shouldn't be executed (only if something is going wrong, but anyway a fail.

    2. Your idea only works when your program always uses the same tcp. And no PTP movent is used.

    3. Your timer handling is a bit strange. You set the timer to -2000 if he is higher than - 500, but you write a position when the timer is higher than -2000, so you write positions as fast as possible.

    You should work with $timer_flag.

    Set timer to -1500 (or whatever, 1.5 seconds are very slow, if robot moves with 2 m/s!)

    and then save position when $timer_flag is true.

    Display More

    Thanks for your input hermann.i have sorted points 1and 3. could you elaborate point 2;what do you mean by no PTP movement used.

  • emerald_geni
    Trophies
    2
    Posts
    25
    • June 5, 2022 at 3:07 PM
    • #5
    Quote from panic mode

    and to continue with few more tips....

    4. do NOT write code in SPS. create separate SRC/DAT file, debug it in robot interpreter and when all is said and done, then just link it to SPS.

    5. do not try to use Cartesian position like that. your program is continuously reading $POS_ACT and it will crash. you need to check if the tool and base are set or use OBN_ERROR_PROCEED

    6. your RECORD strategy is flawed. it will crash the submit, for example RECORD can be set/reset multiple times. when it is reset, attempt is made to close the currently open file. but next time RECORD is true, attempts are made to write to a file without having new handle or file open.

    7. STAT value is never evaluated. in a robust program this need to be handled.

    Thank your for your reply Panic Mode.

    have taken note of points 4 and 7 and made changes accordingly. i am still testing if this method is feasible. for point 6 i have a separate SRC file called CREATECSV to create a new file after the first one is closed.

    do you have any other advice to address this issue or a solution more suitable? This is my first robot and still learning the ropes.

  • Online
    panic mode
    Reactions Received
    1,280
    Trophies
    11
    Posts
    13,083
    • June 5, 2022 at 3:58 PM
    • #6

    point 6 refers to your SPS code shared in first post. it simply cannot work like that. you have arranged it so that

    a) file can only be open BEFORE loop (in other words this is a one time thing!!!)

    b) file can be closed INSIDE loop (so this could happen many times - every time RECORD is false)

    c) inside the loop you access file based on flag RECORD and that flag is set/reset many times

    every time one access file (read or write), file must be open. but there is nothing in your example that will reopen it or even check if it is open.

    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

  • hermann
    Reactions Received
    407
    Trophies
    9
    Posts
    2,612
    • June 5, 2022 at 5:55 PM
    • #7

    For the ptp thing:

    You use SLIN in your homing routine, if you are using SPTP, PTP or LIN in your main program, this can lead to collisions, depending on your record intervall.

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

Tags

  • Homing
  • text_file
  • CWRITE
  • SWRITE
  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