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

Analog Input Value from SPS loop

  • RoboMan3000
  • March 18, 2025 at 11:31 PM
  • Thread is Resolved
  • RoboMan3000
    Reactions Received
    2
    Trophies
    1
    Posts
    59
    • March 18, 2025 at 11:31 PM
    • #1

    Hey there,


    KRC4, KSS 8.6


    Looking for a way to have an analog input value always available to be logged during motion without interrupting the motion.

    Basically, have narrowed down that I'll need to associate it to a variable in the submit interpreter loop.


    So, I make a "module" where the DAT file is public and declare a global variable with the same name as declared in the sps file.

    Workvisual acknowledges the variable in my DAT file will be masked with the value from the sps loop.


    The problem is, when my robot moves to the first logging point, and attempts to store the data, I get the error:
    KSS01422
    Variable value invalid

    Is there something simple I'm missing?
    To reiterate - all the variables are declared as REAL, and besides the declaration, I can assign my variable a constant value (like 1) and it will still throw this error when I run my program.

    :SOS_button:

  • Go to Best Answer
  • RoboMan3000
    Reactions Received
    2
    Trophies
    1
    Posts
    59
    • March 19, 2025 at 1:53 AM
    • #2

    Update:
    I'm attempting to have the signal always available, to store in a matrix...
    Turns out even storing to a matrix in line with motion commands interrupts interpolation.

    Was able to get past the Variable Value Invalid by declaring the $ANIN as a signal, in the SPS and as a GLOBAL SIGNAL in the DAT file. So that's not the problem I'm facing anymore.

    Not sure if reading from a matrix will also interrupt interpolation. I plan on using data from the logging to apply to a $VEL.CP = BASE_SPD * MOD[i] later in the program...

    Just trying to read / write from a sensor without interrupting the robot motion. If there is something silly I'm missing, please let me know!

  • Leon
    Reactions Received
    35
    Trophies
    5
    Posts
    471
    • March 19, 2025 at 12:43 PM
    • #3

    can you show your actual code? it makes it a lot easier to debug what is going on.

    For example i have my linear velocity linked to outputs so i can read it in an external PLC:

    Code
    ;variable declaration (in my case in #config.dat)
    SIGNAL Vel_lin_current $out[49]  TO $out[64]
    
    ;writing a value to it: (in the sps.sub)
    vel_lin_current = $vel_act * 1000

    In my case writing is performed in the SPS, so this has no influence on motion. So if you are writing values between motion command and your seeing an interpolation stop, then it has to be something in your code. It is only impossible to know without seeing the actual code.

    Every problem has a solution, that isn't the problem. The problem is the solution.

  • Online
    panic mode
    Reactions Received
    1,280
    Trophies
    11
    Posts
    13,085
    • March 19, 2025 at 5:43 PM
    • #4

    I am inclined to do such thing using an interrupt and timer...

    Back to your question. You did not identify what triggers the message. the variable name is 'value' which is most likely one of runtime variables used by KUKA libraries. That would suggest the problem in how you use such routine. Post your code. If possible shrink it to a smallest routine that still exhibits the problem.

    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
    • March 19, 2025 at 6:09 PM
    • #5
    Quote from RoboMan3000

    Was able to get past the Variable Value Invalid by declaring the $ANIN as a signal, in the SPS and as a GLOBAL SIGNAL in the DAT file. So that's not the problem I'm facing anymore.

    That should not be necessary. $ANIN, like $IN and $OUT and $ANOUT, are System variables, and thus inherently Global. Any module should be able to access it directly, no declarations necessary.

  • RoboMan3000
    Reactions Received
    2
    Trophies
    1
    Posts
    59
    • March 19, 2025 at 6:27 PM
    • #6

    Thanks guys. Love the energy on this forum!
    Here's a snippet of the code panic mode  Leon : (No variables are not using common names, apologies for the confusion there)

    DEF TestFile_1 ( )

    LIN {X 30, Y 30, Z 0, A 0, B 90, C 0, E1 0, E2 0, E3 0, E4 0} C_DIS

    WAIT SEC 1

    L1_ScDat [1] = SDIST

    LIN {X 33.5, Y 30, Z 0, A 0, B 90, C 0, E1 0, E2 0, E3 0, E4 0} C_DIS

    L1_ScDat [2] = SDIST

    LIN {X 37, Y 30, Z 0, A 0, B 90, C 0, E1 0, E2 0, E3 0, E4 0} C_DIS

    L1_ScDat [3] = SDIST
    .....
    ..... And so on, the code sets an array variable equal to an analog input. Here's how SDIST is set in the submit interpreter:

    ;FOLD USER PLC
    ;Make your modifications here
    SDIST = ($ANIN[1]*(240/8))-140
    ;ENDFOLD (USER PLC)

    So SkyeFire while $ANIN[1] is global, I adjust the value as necessary here to log a usable number. Even with just SDIST = $ANIN[1], it interrupts the robot motion to log data in the array as shown above.

    I'm thinking I'll just have to make a more complex submit interpreter loop that logs the data into arrays on its own. Probably using a case switch approach because there are a set number of conditions to iterate through in this process...

  • Online
    SkyeFire
    Reactions Received
    1,052
    Trophies
    12
    Posts
    9,429
    • March 19, 2025 at 7:21 PM
    • #7
    Quote from RoboMan3000

    LIN {X 33.5, Y 30, Z 0, A 0, B 90, C 0, E1 0, E2 0, E3 0, E4 0} C_DIS

    L1_ScDat [2] = SDIST

    LIN {X 37, Y 30, Z 0, A 0, B 90, C 0, E1 0, E2 0, E3 0, E4 0} C_DIS

    L1_ScDat [3] = SDIST

    I thought you were just logging the values of the $ANIN in the SPS. This seems like you're doing the logging as part of the motion program. What exactly are you trying to do?

    If the L1_ScDat[] array is a global variable, then this code should not be causing any errors or motion pauses. However, given the way the Advance Run Pointer works, you'll probably get inaccurate values in the array because the assignment will happen several moves ahead of the actual motion. You would be better served to use TRIGGER commands.

    Quote from RoboMan3000

    So SkyeFire while $ANIN[1] is global, I adjust the value as necessary here to log a usable number. Even with just SDIST = $ANIN[1], it interrupts the robot motion to log data in the array as shown above.

    Something's not right here. If the SPS module is the only program accessing the $ANIN value directly, then there should be no effect on the motions. What value is $ADVANCE when this happens? Have you tested using $STOP_NOAPPROX?

  • RoboMan3000
    Reactions Received
    2
    Trophies
    1
    Posts
    59
    • March 19, 2025 at 9:21 PM
    • #8
    Quote from SkyeFire

    I thought you were just logging the values of the $ANIN in the SPS. This seems like you're doing the logging as part of the motion program. What exactly are you trying to do?

    Hey SkyeFire. I'm trying to use a distance sensor to log its value in a matrix.
    I haven't gotten the SPS logging system in place yet because I have a variety of arrays I am to log data to. I was just trying to make a calculated variable always available based on that input signal.


    The arrays are global variables declared in my public DAT file.

    Quote from SkyeFire

    However, given the way the Advance Run Pointer works, you'll probably get inaccurate values in the array because the assignment will happen several moves ahead of the actual motion. You would be better served to use TRIGGER commands.

    Ahh I was worried about this. Was trying to work with MxAutomation for a bit and it kept doing that, logging the ANIN value as soon as it entered the interpolation buffer. Yes I can't have that happening. I keep the advance set to 3 because our robot needs to have smooth motion.

    I don't think $STOP_NOAPPROX would help here, my goal is to have the logging in sync with the waypoints being reached.


    SkyeFire do you know if the ADVANCE will also pass flags? If I have a flag after every point, will they be flipped as soon as they enter the interpolation buffer? If that's the case, I probably will have to use some kind of trigger....

  • Online
    SkyeFire
    Reactions Received
    1,052
    Trophies
    12
    Posts
    9,429
    • March 19, 2025 at 9:43 PM
    • #9
    Quote from RoboMan3000

    I don't think $STOP_NOAPPROX would help here, my goal is to have the logging in sync with the waypoints being reached.

    If you're having issues with interrupted motion (i.e., the robot stopping briefly at every point), you have an issue with breaking the ARP and $STOP_NOAPPROX would be part of the troubleshooting process.

    Quote from RoboMan3000

    SkyeFire do you know if the ADVANCE will also pass flags? If I have a flag after every point, will they be flipped as soon as they enter the interpolation buffer? If that's the case, I probably will have to use some kind of trigger....

    The ARP basically means that every non-motion command between the ARP and the Main Run Pointer gets executed in advance. So if you have something like:

    Code
    PTP xP1 C_PTP
    PTP xP2 C_PTP
    For _nIndex = 1 to 1000
      MyArray[_nIndex] = _nIndex
    ENDFOR
    PTP xP3

    Then, assuming $ADVANCE is defaulted to 3, that entire FOR loop will execute as the robot leaves xP1 headed for xP2.

    Setting $OUTs or WAITing for $INs won't work quite the same, because they "break" the ARP. But if anything inside that FOR loop broke the ARP, then the robot would come to a complete halt briefly at xP2 instead of approximating past it to reach xP3.

    So, setting a $FLAG should not break the ARP, but will instead get executed several motions ahead.

  • RoboMan3000
    Reactions Received
    2
    Trophies
    1
    Posts
    59
    • March 19, 2025 at 10:04 PM
    • #10
    Quote from SkyeFire

    The ARP basically means that every non-motion command between the ARP and the Main Run Pointer gets executed in advance. So if you have something like:

    ....

    So, setting a $FLAG should not break the ARP, but will instead get executed several motions ahead.

    SkyeFire ahhhhh. I've read up in the programming and operations manual a bit more about the ARP.

    This seems to be a deeper problem I have here. I will not be able to use in-line commands for this use case, while maintaining the interpolation, huh? This is because keeping data synchronized to the TCP's intended position is my goal...

    Do you have any thoughts on how this process could be done?

  • RoboMan3000
    Reactions Received
    2
    Trophies
    1
    Posts
    59
    • March 20, 2025 at 12:48 AM
    • #11

    Update:
    Using TRIGGER allows me to associate the raw $ANIN value to my arrays without pausing motion and should theoretically synchronize the data collection with position.

    Now, when I get the raw $ANIN values from the array and attempt to convert them to an actual distance from the voltage data, I get the <array item> value invalid error...
    All I do for this is multiply it by a constant, then subtract a constant.

  • Online
    panic mode
    Reactions Received
    1,280
    Trophies
    11
    Posts
    13,085
    • March 20, 2025 at 4:32 AM
    • #12

    i would like to say that there are couple of things that are not done correctly (for me).

    when i ask for program example, i mean really a program module that i can put on a robot or OL and test. what was shared in #6 is not even close to that. it is some sort of pseudo code that was abbreviated and the important parts are missing - including array declaration.


    i do not like to rely on data from SPS for anything that is happening in real time in robot task. since SPS runs in the background and asynchronously from robot program. submit is a low priority task and it execution is all but reliable since it can be influenced by many factors such as code length, allocated CPU quota, and overall performance. so it can be sacrificed if performance hits some threshold... maybe the code in Submit is executed 1000 times during one quota,... or maybe it takes 1000 quotas to run it once.

    and i would like to point out that this is the same kind of problem with trying to use SPS to send XYZ position values to PLC while robot program is running. without on error proceed this WILL fail... because program can choose another tool and base and at the moment that SPS is trying to read Cartesian position, it could be the wrong moment (there may not be a valid tool and valid base). what you have is a similar thing but in reverse. the value you are trying to record, may not exist... which would explain the message you are trying to deal with.

    so why not put all you want into a subroutine and call it by an interrupt or trigger from the robot program?

    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

  • RoboMan3000
    Reactions Received
    2
    Trophies
    1
    Posts
    59
    • March 21, 2025 at 6:11 PM
    • #13

    panic mode
    Thank you always for sharing your wisdom.
    In reality I didn't consider triggers (what I'm using now and works great!) because I didn't know they existed... Lol.

    As for an interrupt, not sure how that would be triggered a manner similar to the trigger function. I will read on that, so thank you for the direction.


    Your opinion makes complete sense about the sps loop. I agree that makes it much less favorable to use, and I am now using a global signal for the ANIN in my DAT file.


    The value invalid error I was recieving was for something much sillier than what you proposed.
    Simply an unassigned variable in my list.. Value[i] = "" :upside_down_face:

    Thank you all for the help.

  • Online
    panic mode
    Reactions Received
    1,280
    Trophies
    11
    Posts
    13,085
    • March 21, 2025 at 6:49 PM
    • #14

    so how is your plan of logging supposed to work?

    are you storing values at specific points (move ends or mid point of interpolation)? since motions tend to be different length, logged data would not be evenly distributed. this also means that logging would require inserting statements into each program you need.

    if you are logging data periodically (after some time interval or after some distance traveled) then you could get more uniform data set. this can be done without modifying of existing programs.

    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

  • RoboMan3000
    Reactions Received
    2
    Trophies
    1
    Posts
    59
    • March 21, 2025 at 7:20 PM
    • #15
    Quote from panic mode

    so how is your plan of logging supposed to work?

    My plan here is to write all of the list data to a text file when my master script reaches the end of the child programs.

    Quote from panic mode

    are you storing values at specific points (move ends or mid point of interpolation)? since motions tend to be different length, logged data would not be evenly distributed. this also means that logging would require inserting statements into each program you need.

    Oddly enough, all my points are evenly spaced. But I use this trigger setup here:
    TRIGGER WHEN PATH=0 ONSTART DELAY=0 DO Ln_ScDat [n] = SDIST

    since my tool path is all LIN moves, it grabs the input data at all the start points, and I have two triggers in the last move which grab both the start point and the end point for completion.

    I generate my scripts on the computer, so inserting triggers between every line is no big deal, except for the extra burden of doubling my program size... And doubling the rate of needing to do the ol' delete and replace programs to stay below the 40MB memory limit.


    Frustratingly, the examples I've found in the CWRITE manual are pretty sparse for file generation / population. When I get to the CWRITE portion, it simply executes, no files are created and my error detection system doesn't give me much insight.
    Here's what I've come up with so far:

    DEF writeScanDataToFile()
    ; Declarations
    DECL INT HANDLE ; File handle
    DECL STATE_T STAT ; Status variable for CWRITE
    DECL MODUS_T MODE ; Mode for synchronous operation
    DECL INT i ; Loop counter
       
    ; Initialize mode to synchronous
    MODE = #SYNC
    HANDLE = 0
       
    ; Open the file on D: drive in write mode ("w")
    CWRITE($FCT_CALL, STAT, MODE, "krl_fopen", "D:\NETWORK_DRIVE\Ln_Scandata.txt", "w", HANDLE)
       
    ; Check if file opened successfully
    IF (STAT == #OK) THEN
    ; Loop through the array and write each element
    FOR i = 1 TO N
    ; Write the element with a newline (CRLF = 'H0D''H0A')
    CWRITE($FCT_CALL, STAT, MODE, "krl_fputc", HANDLE, "%f'H0D''H0A'", Ln_ScDat [i])
    ENDFOR
           
    ; Close the file
    CWRITE($FCT_CALL, STAT, MODE, "krl_fclose", HANDLE)
    ELSE
    ; Handle file open error
    $OUT[1] = TRUE ; Set output 1 to indicate error
    ENDIF
    END
  • hermann
    Reactions Received
    407
    Trophies
    9
    Posts
    2,612
    • March 22, 2025 at 8:43 AM
    • #16

    Leave out the path in filename, the file will be created in subfolder /user. Iirc you can't specify a path.

  • Online
    SkyeFire
    Reactions Received
    1,052
    Trophies
    12
    Posts
    9,429
    • March 24, 2025 at 1:48 PM
    • #17
    Quote from RoboMan3000

    Frustratingly, the examples I've found in the CWRITE manual are pretty sparse for file generation / population. When I get to the CWRITE portion, it simply executes, no files are created and my error detection system doesn't give me much insight.

    I've attached an old library module of mine that works pretty well. The Log routines (Open, Append, Close, etc) have been used in production and beaten into fairly solid shape. You might be able to make use of them. The module has internal dependencies, though, so you'll probably want to import the whole thing.

    Files

    krlfunctions.zip 21.69 kB – 8 Downloads
  • RoboMan3000
    Reactions Received
    2
    Trophies
    1
    Posts
    59
    • March 24, 2025 at 7:19 PM
    • #18
    Quote from hermann

    Leave out the path in filename, the file will be created in subfolder /user. Iirc you can't specify a path.

    Ah. My life would be so much easier if I could simply write the file somewhere my computer could pull from. Is the only way to do that with EKI or with the krl_mount?


    Thank you SkyeFire!!

  • Online
    panic mode
    Reactions Received
    1,280
    Trophies
    11
    Posts
    13,085
    • March 24, 2025 at 8:08 PM
    • #19

    it is not the only way but this is an important first step (if using CWRITE).
    then you could share that folder with other PCs, or use krl_mount to place in a different folder.

    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
    panic mode
    Reactions Received
    1,280
    Trophies
    11
    Posts
    13,085
    • March 24, 2025 at 9:22 PM
    • #20

    btw how many points you need to record?

    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

Similar Threads

  • sps.sub user PLC section

    • robot-cnc
    • December 29, 2022 at 1:54 PM
    • KUKA Robot Forum

Tags

  • IO
  • sps
  • KSS8.6
  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