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

Help with Modular Trajectory Execution in KUKA KRL [KUKA KR210 R2700-2 / KRC5 - KSS 8.7]

  • Asreborn
  • June 10, 2025 at 9:14 AM
  • Thread is Resolved
  • Asreborn
    Reactions Received
    2
    Posts
    2
    • June 10, 2025 at 9:14 AM
    • New
    • #1

    Hello everyone,

    I’m currently working on a KUKA robot control system, and I’m looking for some guidance on managing and executing robot trajectories dynamically. Specifically, I want to modularize the handling of waypoints (1 to 100 waypoints per trajectory) and allow the PLC to execute these trajectories when needed.

    Current Setup:

    • The trajectory planner computes robot movement paths and sends the data to the robot. These paths consist of waypoints (A1 to A6), and each trajectory has a fixed number of waypoints (currently 10 waypoints).
    • The robot stores these trajectories in its memory, and the PLC can later trigger the execution by specifying the program number (progNum), which determines which trajectory to execute.

    Goal:

    • I would like to modularize the number of waypoints in a trajectory so that the number of waypoints can vary dynamically, rather than being fixed at 10 waypoints. Ideally, I want the system to support 1 to 100 waypoints per trajectory.
    • The planner will compute and send the waypoints, and the PLC will simply execute the trajectory by calling the progNum without worrying about the number of waypoints.
    • Receive something like this where wp_list it's a list of joint (A1 to A6), num_of_wp (1 to 100) is the number of wp in the trajectory and traj_number it's the number of the trajectory.

      RET = EKI_GetRealArray("planner", "Robot/wp_list", wp_list[])

      RET = EKI_GetInt("planner", "Robot/num_of_wp", num_of_wp)

      RET = EKI_GetInt("planner", "Robot/traj_number", traj_number)

      Code
      <Robot>
        <wp_list>134.2</wp_list>
        <wp_list>-89.7</wp_list>
        <wp_list>120.5</wp_list>
        <wp_list>-45.2</wp_list>
        <wp_list>80.4</wp_list>
        <wp_list>190.8</wp_list>
      
        <wp_list>-30.9</wp_list>
        <wp_list>-12.3</wp_list>
        <wp_list>55.0</wp_list>
        <wp_list>132.7</wp_list>
        <wp_list>-24.6</wp_list>
        <wp_list>-310.5</wp_list>
      
        ...
          
      </Robot>
      
      <Robot>
        <num_of_wp>2</num_of_wp>
      </Robot>
      
      <Robot>
        <traj_number>1</traj_number>
      </Robot>
      Display More

    Key Challenges:

    1. Dynamic Waypoint Length:
      • Currently, the system is hardcoded for 10 waypoints. I want to change this so that the number of waypoints can vary from 1 to 100, without requiring any changes to the program code for each new trajectory length.
    2. Executing Trajectories by progNum (traj_number) :
      • The PLC should not need to manage the waypoints directly. It should only provide the progNum to the robot to execute the corresponding trajectory stored in memory.
    3. Efficient Access and Execution of Trajectories:
      • I need a clean and flexible way to store trajectories and execute them dynamically based on the progNum.

    Current Approach:

    Here is the current logic for executing the trajectory based on progNum:

    Code
    ;FOLD poses definition
    iProgNum_move = iProgNum_move - 1000
    WAIT FOR ((program[iProgNum_move].position10.speed) <> 0)
    ;FOLD position 1          
    BAS(#VEL_PTP, program[iProgNum_move].position1.speed)
    BAS(#ACC_PTP, 100)
    pose1.A1 = program[iProgNum_move].position1.A1
    pose1.A2 = program[iProgNum_move].position1.A2
    pose1.A3 = program[iProgNum_move].position1.A3
    pose1.A4 = program[iProgNum_move].position1.A4
    pose1.A5 = program[iProgNum_move].position1.A5
    pose1.A6 = program[iProgNum_move].position1.A6
    ;ENDFOLD
    
    ... (repeated for positions 2 to 10)
    
    LINCORRECTION:
    IF NOT lin_correction THEN
        ;FOLD PTP (plan trajectory)
        SPTP pose1 C_DIS
        SPTP pose2 C_DIS
        SPTP pose3 C_DIS
        SPTP pose4 C_DIS
        SPTP pose5 C_DIS
        SPTP pose6 C_DIS
        SPTP pose7 C_DIS
        SPTP pose8 C_DIS
        SPTP pose9 C_DIS
        SPTP pose10
        ;ENDFOLD
    ELSE
        ; Handle linear correction if needed
        ...
    ENDIF
    Display More

    This approach works well for 10 fixed waypoints, but I would like to extend it to handle a variable number of waypoints, from 1 to 100 waypoints.

    What I’ve done:

    I did this outside of my main code. But I am missing the part where the points are linked to a trajectory number.

    Code
       ; Initialize flags and buffer
       FOR i = 1 TO 9999
          wp_list[i] = 0
       ENDFOR
       num_of_points = 0
    
       ; Initialize EKI communication
       RET = EKI_Init("planner")
    
       RET = EKI_Open("planner")
    
       ; Move robot to home position first
       PTP XHOME
       BAS(#VEL_PTP, 100)
       BAS(#ACC_PTP, 100)
       $ADVANCE = 5
    
       LOOP
          ; Wait for new trajectory data from ethernet interface
          WAIT FOR $FLAG[199] ; Flag signals trajectory_list data ready
          RET = EKI_GetRealArray("planner", "Robot/wp_list", wp_list[])
          $FLAG[199] = FALSE
    
          WAIT FOR $FLAG[197] ; Flag signals num_of_traj ready
          RET = EKI_GetInt("planner", "Robot/num_of_wp", num_of_wpoints)
          $FLAG[197] = FALSE
    
          ; Validate number of points
          IF (num_of_wpoints < 1) OR (num_of_wpoints > 100) THEN
             HALT ; invalid number of points
          ENDIF
    
          ; Parse trajectory_list[] into traj_buffer E6AXIS array
          FOR i = 1 TO num_of_points
             traj_buffer[i].A1 = wp_list[(i-1)*6 + 1]
             ax1 = traj_buffer[i].A1
             traj_buffer[i].A2 = wp_list[(i-1)*6 + 2]
             ax2 = traj_buffer[i].A2
             traj_buffer[i].A3 = wp_list[(i-1)*6 + 3]
             ax3 = traj_buffer[i].A3
             traj_buffer[i].A4 = wp_list[(i-1)*6 + 4]
             ax4 = traj_buffer[i].A4
             traj_buffer[i].A5 = wp_list[(i-1)*6 + 5]
             ax5 = traj_buffer[i].A5
             traj_buffer[i].A6 = wp_list[(i-1)*6 + 6]
             ax6 = traj_buffer[i].A6
          ENDFOR
    
          ; Move through spline trajectory with blending
          $APO.CDIS = 150  ; blending zone [mm] adjust for smoothness
    
          FOR i = 1 TO num_of_points
             IF i <> num_of_wpoints THEN
                SPTP traj_buffer[i] C_DIS
             ELSE
                SPTP traj_buffer[i]
             ENDIF
          ENDFOR
    
    
          ; Ready for next trajectory
       ENDLOOP
    
    END
    Display More

    In the end it would be to have a trajectory list which have inside the number of the trajectory, the number of wp and the list of wp.

    Example : traj n°1, 24 waypoints, list of wp [A1 … A6]*24


    I might have taken the wrong way to do it, so I am happy to receive any suggestions as it's currently blocking my development ! :smiling_face:

    Thanks!

  • Fubini June 10, 2025 at 9:19 AM

    Approved the thread.
  • kovaley
    Trophies
    2
    Posts
    14
    • June 10, 2025 at 7:54 PM
    • New
    • #2

    If I'm not mistaken, there is no way to set array size dynamically in KRL. That being said, you can set your array dimensions large enough for your needs and not use some of it...

    Have you tried adding another dimension to your array traj_buffer? You could have one dimension for the trajectory number and one for your waypoints and it would not change your current architecture too much. You could have an array like

    Code
    E6Axis traj_buffer[100,100]

    And when the plc calls program 1, then you loop through

    Code
    FOR i=1 TO num_of_points
    	PTP traj_buffer[1,i]
    ENDFOR

    This is not the solution I would use, but I think it could work even if it's not the most efficient use of memory... I also don't know how the motion planner handles the advance and the spline motions when the points are not hardcoded and read from an array, it might not work the way you want it to depending on your application.

    I have a somehow similar application, where I have to change program on the fly just before executing them. I generate my programs offline and then transfer them to the robot using the option package DirectoryLoader. You could do something in the same vein and add your new program and modify the calling module to link it at the same time.

    Edited once, last by kovaley (June 10, 2025 at 8:00 PM).

  • panic mode
    Reactions Received
    1,280
    Trophies
    11
    Posts
    13,086
    • June 11, 2025 at 3:04 PM
    • New
    • #3

    correct, KRL does not support dynamic arrays so using arrays large enough is a way to go. and since TS is not showing use of any external axes, it would be more efficient to declare it as AXIS instead of E6AXIS type. also less data is easier to monitor.

    in terms of organizing things for EKI transfer, i like to put anything permanent at the begin, and bulk that changes dynamically at the end of the message. i would hate to scroll through pages of data in search of how many points are in the data that one is sifting through.

    also since AXIS has 6 elements and up to 100 way points are used, that means 6*100=600 REALs. so looping through an array with 9999 elements is excessive.

    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,052
    Trophies
    12
    Posts
    9,429
    • June 11, 2025 at 10:48 PM
    • New
    • #4
    Quote from panic mode

    also since AXIS has 6 elements and up to 100 way points are used, that means 6*100=600 REALs. so looping through an array with 9999 elements is excessive.

    In the past, for situations where the DECL'd size of the array had to be excessively large, I got into the habit of "initializing" the array with a specific nonsense value (like, 99999), before filling in just the elements the next run would use. Then, during the run, the program would bail if the next element read from the array was the nonsense value.

  • Hes
    Reactions Received
    42
    Trophies
    2
    Posts
    243
    • June 15, 2025 at 9:34 PM
    • New
    • #5
    Quote from SkyeFire

    In the past, for situations where the DECL'd size of the array had to be excessively large, I got into the habit of "initializing" the array with a specific nonsense value (like, 99999), before filling in just the elements the next run would use. Then, during the run, the program would bail if the next element read from the array was the nonsense value.

    A nonsense value like 99999 is really good as you will get a workspace error in case one of those get thru and is trying to be used. Whereas values like 0 are usually reachable and can result in more or less carnage :kissing_face:

  • Asreborn
    Reactions Received
    2
    Posts
    2
    • June 17, 2025 at 11:19 AM
    • New
    • #6

    ✅ First Draft Working — Dynamic Trajectory Execution via EKI

    Thanks, everyone!
    I now have my first draft up and running exactly as intended. The robot is now capable of receiving and executing dynamic-length trajectories over EKI, with the number of waypoints determined at runtime.


    🧠 Main KRL Program

    TrajExecutor.dat

    Code
    DEFDAT TrajExecutor public
       DECL GLOBAL AXIS traj_buffer[100,100]
       DECL GLOBAL INT traj_length[100]
       DECL GLOBAL INT traj_to_execute
    ENDDAT

    TrajExecutor.src

    Code
    DEF TrajExecutor( )
       DECL INT i, exec_traj_num
    
       ; Init
       BAS (#INITMOV,0 )
       BAS(#VEL_PTP, 100)
       BAS(#ACC_PTP, 100)
       $ADVANCE = 5
    
       PTP $POS_ACT
    
       LOOP
          ; Wait for PLC to trigger execution
          WAIT FOR bStart
          exec_traj_num = traj_to_execute ;set by plc
    
          ; Validate trajectory
          IF traj_length[exec_traj_num] <= 0 THEN
             HALT
          ENDIF
    
          ; Execute
          FOR i = 1 TO traj_length[exec_traj_num]
             IF i <> traj_length[exec_traj_num] THEN
                SPTP traj_buffer[exec_traj_num, i] C_DIS
             ELSE
                SPTP traj_buffer[exec_traj_num, i]
             ENDIF
          ENDFOR
    
          ; Return to home
          PTP XHOME
       ENDLOOP
    END
    Display More

    🔄 Subprogram – Data Reception

    TrajHandler.sub

    Code
    DEF TrajHandler( )
       ; Receives and parses trajectory data via EKI
    
       DECL INT i, num_of_wp, traj_number
       DECL REAL wp_list[600]
       DECL AXIS temp_axis
       DECL EKI_Status RET_traj
    
       ; Initialize connection
       RET_traj = EKI_Init("traj_test")
       RET_traj = EKI_Open("traj_test")
    
       ; Defaults
       num_of_wp = 0
       traj_number = 0
       FOR i = 1 TO 600
          wp_list[i] = 999
       ENDFOR
    
       WHILE TRUE
          IF $FLAG[101] THEN
             IF $FLAG[601] THEN
                ; Receive data
                RET_traj = EKI_GetInt("traj_test", "Robot/num_of_wp", num_of_wp)
                RET_traj = EKI_GetRealArray("traj_test", "Robot/wp_list", wp_list[])
                RET_traj = EKI_GetInt("traj_test", "Robot/traj_number", traj_number)
                $FLAG[601] = FALSE
    
                ; Validate and buffer
                IF (num_of_wp < 1) OR (num_of_wp > 100) THEN
                   HALT
                ENDIF
    
                traj_length[traj_number] = num_of_wp
    
                FOR i = 1 TO num_of_wp
                   temp_axis.A1 = wp_list[(i-1)*6 + 1]
                   temp_axis.A2 = wp_list[(i-1)*6 + 2]
                   temp_axis.A3 = wp_list[(i-1)*6 + 3]
                   temp_axis.A4 = wp_list[(i-1)*6 + 4]
                   temp_axis.A5 = wp_list[(i-1)*6 + 5]
                   temp_axis.A6 = wp_list[(i-1)*6 + 6]
    
                   traj_buffer[traj_number, i] = temp_axis
                ENDFOR
             ENDIF
          ELSE
             ; Reset and reconnect
             RET_traj = EKI_Close("traj_test")
             RET_traj = EKI_Clear("traj_test")
             RET_traj = EKI_Init("traj_test")
             RET_traj = EKI_Open("traj_test")
             WAIT SEC 5.0
          ENDIF
       ENDWHILE
    END
    Display More

    📄 EKI XML Configuration

    Code
    <ETHERNETKRL>
    	<CONFIGURATION>
    		<EXTERNAL>
    			<TYPE>Client</TYPE>
    		</EXTERNAL>
    		<INTERNAL>
    			<ENVIRONMENT>Program</ENVIRONMENT>
    			<BUFFERING Mode="FIFO" Limit="512"/>
    			<IP>x.x.x.x</IP>
    			<PORT>54608</PORT>
    			<ALIVE Set_Flag="101" Ping="10"/>
    		</INTERNAL>
    	</CONFIGURATION>
    
    	<RECEIVE>
    		<XML>
    			<ELEMENT Tag="Robot/num_of_wp" Type="INT"/>
    			<ELEMENT Tag="Robot/wp_list" Type="REAL" Array="600"/>
    			<ELEMENT Tag="Robot/traj_number" Type="INT" Set_Flag="601"/>
    		</XML>
    	</RECEIVE>
    
    	<SEND>
    		<XML>
    			<ELEMENT Tag="Robot/Ack/@status"/>
    		</XML>
    	</SEND>
    </ETHERNETKRL>
    Display More

    🐍 Python Example – Sending Trajectory

    Code
    <Robot>
        <num_of_wp>23</num_of_wp>
        
        <wp_list>-148.9</wp_list>
        <wp_list>-89.8</wp_list>
        <wp_list>34.6</wp_list>
        ...
        <wp_list>91.7</wp_list>
        
        <traj_number>1</traj_number>
    </Robot>
    Display More

    📝 Each waypoint consists of 6 joint angles (A1–A6), sent as a flat list.
    ➡️ For 23 waypoints → 138 values (23 × 6).


    This setup achieves exactly what I needed:

    • Trajectory length is dynamic (1–100 waypoints)
    • The PLC only references the trajectory number
    • Storage and execution are cleanly separated and modular

    Happy to receive any suggestions for improving my code if you spot any mistakes.

    Thanks again for the support !

  • panic mode
    Reactions Received
    1,280
    Trophies
    11
    Posts
    13,086
    • June 17, 2025 at 5:23 PM
    • New
    • #7

    nice contribution.

    for those that like to see in the archive what the data was, for example if something unexpected happened, buffer values would need to be initialized.

    Files

    TrajExecutor.DAT.txt 298.55 kB – 1 Download

    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

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

  • KUKA
  • data
  • structure
  • Trajectory planning
  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