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

Using interrupt to store values

  • chis
  • February 25, 2020 at 11:10 PM
  • Thread is Unresolved
  • chis
    Trophies
    3
    Posts
    7
    • February 25, 2020 at 11:10 PM
    • #1

    Hi, I am programming for the Kuka and trying to store the external probe values in an array.

    I am facing 2 problems.

    1. The program which i have mentioned below is getting stuck at Resume and its not coming back to main programming. If I am not giving interrupt then its working fine but once I gave some external interrupt then it get stuck at Resume.

    2. The points in the interrupt that is the $POS_INT values need to store in an array which is accessible outside the interrupt program.

    Code
    INTERRUPT DECL 10 WHEN $IN[1]==TRUE DO STOREOFFSET()
    
    LIN{Y 0}
    STARTPOINT = $POS_ACT
    SEARCH($POS_ACT)
    LIN STARTPOINT
    
    LIN {Y 50}
    STARTPOINT = $POS_ACT
    SEARCH($POS_ACT)
    LIN STARTPOINT
    
    ;----------------------------------------------------------------
    DEF SEARCH(STARTPROBE:IN)
    E6POS STARTPROBE
    ;Enable the Interrupt
    INTERRUPT ON 10
    
    ;Calculate Max Probe loc, ":" is geometric operator
    ENDPROBE = STARTPROBE : {X 0, Y 0, Z -100, A 0, B 0, C 0}
    
    ;Move to max probe location
    LIN ENDPROBE
    
    ;Return to start
    INTERRUPT OFF 10
    END
    
    
    ;------------------------------------------------------
    
    DEF STOREOFFSET()
    E6POS PROBEPTS
    
    ;Disable the the interrupt so it doesn't get stuck in loop
    INTERRUPT OFF 10
    PROBEPTS = $Pos_INT
    
    ;Stop the robot
    BRAKE 
    
    ;Resume the main program after being interrupted
    RESUME
    
    END
    Display More
  • Go to Best Answer
  • panic mode
    Reactions Received
    1,263
    Trophies
    11
    Posts
    13,030
    • February 25, 2020 at 11:44 PM
    • #2

    1. of course... you are not managing advance run

    2. i see no array declaration, or array index variable declaration. and you are saving $POS_INT to a runtime variable not visible to rest of the program

    all of those are basics one need to master before getting to interrupts

    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

  • Simon_3541534
    Reactions Received
    1
    Trophies
    3
    Posts
    1
    • February 26, 2020 at 9:25 AM
    • #3
    Quote from chis

    LIN ENDPROBE

    ;Return to start
    INTERRUPT OFF 10

    Ersetze durch:

    Quote

    LIN ENDPROBE

    WAIT SEC 0


    ;Return to start
    INTERRUPT OFF 10

    Der Vorlaufzeiger muss im Unterprogramm sein, wenn der Interrupt zieht. Das wird durch Vorlaufstopp via "WAIT SEC 0" erreicht.

    Wenn der Vorlaufzeiger auf der Ebene der Interruptdeklaration ist, dann kann der Interrupt nicht aufgerufen werden. (Siehe Systemintegrator-Doku zu Interrupts)

  • Online
    SkyeFire
    Reactions Received
    1,038
    Trophies
    12
    Posts
    9,373
    • February 26, 2020 at 2:45 PM
    • #4

    Add a WAIT SEC 0 at the end of the SEARCH program to break the Advance Run Pointer.

    You can declare an array in the DAT file of the module, and an integer variable to keep track of the index. DECL it as GLOBAL to make it universally available. To retain the memory, give the DECLs initial values.

  • chis
    Trophies
    3
    Posts
    7
    • February 26, 2020 at 9:09 PM
    • #5

    Hi SkyeFire I got my interrupt working by adding WAIT SEC 0 . Thanks!!

    That was very helpful.

    Is there any way by which I can define an array in the program and not in the dat file and populate the values in the array and can use in the program if needed.

  • panic mode
    Reactions Received
    1,263
    Trophies
    11
    Posts
    13,030
    • February 27, 2020 at 1:28 AM
    • Best Answer
    • #6

    impossible... your program is not working and you cannot use saved value. you just got part "1" resolved, though you don't understand how and why.

    you are jumping the gun. using RESUME also involves some safety concerns and you are pushing forward without mastering basics.

    so be warned and ... just be careful... and go back and re-evaluate all feedback you got... you skipped some important info.


    Here is small part of it:

    declaration syntax may look the same BUT .... it is not. and not all declarations are equal. depending on WHERE and HOW variable is declared and initialized will affect many things. for example how and when it can be accessed, how and when it can be monitored, if and how long value is retained etc.

    each place of declaration has very specific limitations.

    if variable is not declared in a DAT file, it is a RUNTIME variable and it is just not suitable for what you are trying to do.

    runtime means that random block of memory is reserved for the variable when the program is started, and it is lost immediately when program ends. if this declaration is in some subprogram, there is a good chance that every time subprogram is called, assigned memory is a different RAM location. further more, such variables are ONLY usable within ONE routine where they are defined - that's it. which makes it great for temporary variables so you are not constantly tying up memory. you take it, use it and give it back. very economical.... but at a cost of life and scope and ability to monitor when debugging - to monitor it program must be selected, started and PAUSED.

    so.... you may pause program when in ISR and see that value is copied from $POS_INT to your variable but this is completely and utterly useless - as soon as the ISR is done, that memory location is lost and you no longer have saved value. and no other routine could access it anyway because it is a runtime variable.


    variable declared in a DAT file is STATIC. it means as soon as DAT file is linked (used) first time, memory location is reserved to the variable. you may still not monitor it all the time (access is blocked if program is deselected) but same memory is used and it STILL retains value... even if you cancel program and select it again.... and see the previous value. memory is reserved until power down.

    guess what happens if you have many programs with DAT files if you keep selecting one after another (does not matter if they run, as long as they got selected or - linked). yup, each time you select one program module, all variables in corresponding DAT file get PERMANENT hold of memory - even if you never run the program. and if you keep selecting more and more programs, more and more memory gets allocated - PERMANENTLY (well, until reboot). so you get less and less free RAM every time you select program that was not selected before. this is one of the reasons why programs exported from CAD/CAM are only SRC files.

    to make STATIC variable RETENTIVE, it need to be both declared and initialized in a DAT file. then as soon as variable is changed SOMEHOW, it's declaration is also updated and DAT file is saved. this means that variable will have value to be initialized with after reboot.

    to make STATIC variable GLOBAL, it need to be declared either in $CONFIG.DAT.

    alternatively it can also be declared in some DAT file if that file is PUBLIC and particular declaration contains keyword GLOBAL.

    also note that local STATIC variables (declared in local DAT file), can be accessed by all local routines (SRC file with same name as the DAT file).

    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

  • Davis
    Reactions Received
    1
    Trophies
    3
    Posts
    1
    • February 28, 2020 at 2:24 AM
    • #7

    Hello, guys,the method of storing values is as follows :

    DEF StoreInArray( )
    DECL CHAR POS_INT1[256]
    ;DECL CHAR POS_INT[256]
    DECL INT OFFSET,LEN
    DECL STATE_T STATE
    OFFSET=0
    SWRITE(POS_INT[],STATE,OFFSET,"%S%F%S%F%S%F","{X",PROBEPTS.X,"Y",PROBEPTS.Y,"Z",PROBEPTS.Z)
    OFFSET=0
    SWRITE(POS_INT1[],STATE,OFFSET,"%S%F%S%F%S%F%%S","A",PROBEPTS.A,"B",PROBEPTS.B,"C",PROBEPTS.C,"}")
    LEN=STRADD(POS_INT[],POS_INT1[])
    END

  • chis
    Trophies
    3
    Posts
    7
    • February 28, 2020 at 7:06 PM
    • #8
    Quote from panic mode

    impossible... your program is not working and you cannot use saved value. you just got part "1" resolved, though you don't understand how and why.

    you are jumping the gun. using RESUME also involves some safety concerns and you are pushing forward without mastering basics.

    so be warned and ... just be careful... and go back and re-evaluate all feedback you got... you skipped some important info.


    Here is small part of it:

    declaration syntax may look the same BUT .... it is not. and not all declarations are equal. depending on WHERE and HOW variable is declared and initialized will affect many things. for example how and when it can be accessed, how and when it can be monitored, if and how long value is retained etc.

    each place of declaration has very specific limitations.

    if variable is not declared in a DAT file, it is a RUNTIME variable and it is just not suitable for what you are trying to do.

    runtime means that random block of memory is reserved for the variable when the program is started, and it is lost immediately when program ends. if this declaration is in some subprogram, there is a good chance that every time subprogram is called, assigned memory is a different RAM location. further more, such variables are ONLY usable within ONE routine where they are defined - that's it. which makes it great for temporary variables so you are not constantly tying up memory. you take it, use it and give it back. very economical.... but at a cost of life and scope and ability to monitor when debugging - to monitor it program must be selected, started and PAUSED.

    so.... you may pause program when in ISR and see that value is copied from $POS_INT to your variable but this is completely and utterly useless - as soon as the ISR is done, that memory location is lost and you no longer have saved value. and no other routine could access it anyway because it is a runtime variable.


    variable declared in a DAT file is STATIC. it means as soon as DAT file is linked (used) first time, memory location is reserved to the variable. you may still not monitor it all the time (access is blocked if program is deselected) but same memory is used and it STILL retains value... even if you cancel program and select it again.... and see the previous value. memory is reserved until power down.

    guess what happens if you have many programs with DAT files if you keep selecting one after another (does not matter if they run, as long as they got selected or - linked). yup, each time you select one program module, all variables in corresponding DAT file get PERMANENT hold of memory - even if you never run the program. and if you keep selecting more and more programs, more and more memory gets allocated - PERMANENTLY (well, until reboot). so you get less and less free RAM every time you select program that was not selected before. this is one of the reasons why programs exported from CAD/CAM are only SRC files.

    to make STATIC variable RETENTIVE, it need to be both declared and initialized in a DAT file. then as soon as variable is changed SOMEHOW, it's declaration is also updated and DAT file is saved. this means that variable will have value to be initialized with after reboot.

    to make STATIC variable GLOBAL, it need to be declared either in $CONFIG.DAT.

    alternatively it can also be declared in some DAT file if that file is PUBLIC and particular declaration contains keyword GLOBAL.

    also note that local STATIC variables (declared in local DAT file), can be accessed by all local routines (SRC file with same name as the DAT file).

    Display More

    Hi Panic mode,

    Thanks for all your help. I really appreciate you took time and you want me to learn the basics first.

    Actually I read the KUKA document and there I didn't get much understanding on Advance run thing.

    So I tried without that.

    Regarding the Array saving thing, I want the array data in this program only and I don't want to use it later. I saw this one code in documentation and tried it but its not working, I know it should not work as I have not defined the array. But how it's working on the document. Can you help me with this.

  • panic mode
    Reactions Received
    1,263
    Trophies
    11
    Posts
    13,030
    • February 28, 2020 at 10:42 PM
    • #9

    "I didn't get much understanding on Advance run thing. So I tried without that."

    well, that is a pretty good way to kill or maim someone or the robot. would you give instructions to someone wanting to drive through crowded street without understanding vehicle controls or traffic rules? or someone trying to work as a pilot, electrician or surgeon without proper training? you know all of these are regulated for a reason.

    i could write very very long study of code example like this. just don't have time or interest.

    so... what exactly is tripping you? can you be specific....

    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,263
    Trophies
    11
    Posts
    13,030
    • February 28, 2020 at 10:58 PM
    • #10

    ok i just threw an example together, this should work on just about any KUKA robot and should be safe to run as is on most systems. it only moves +/- 200mm from home.

    array has 10 elements so it can store up to 10 positions but you can limit how many you really want (default is set to 7, with "MaxPosition = 7"). Once specified limit is reached, search is aborted (even before reaching end point). And then it should move robot to each of saved positions.

    good luck

    Files

    SEARCH_DEMO.zip 1.53 kB – 54 Downloads

    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

  • chis
    Trophies
    3
    Posts
    7
    • March 2, 2020 at 8:41 PM
    • #11

    Hey panic mode,

    Thanks for all your help!

    Actually I try to make multiple codes as I am in school and I get the KUKA just 2 times a week to test the code. I have used you code and tried to modify the code as per my requirement.

    I have make one more code using the code given in document as well. I tested that but it's not working as per expectation. Can you let me know how can I make that work as well. I know the problem is in the interrupt where the value is runtime variable and it's not coming out of interrupt.

    In the code attached when I am doing LIN {TestArray[1]}, LIN{TestArray[2]}

    The values getting stored in the test array are ENDPROBE values from the search function and not from interrupt. I want if the interrupt is not called then it should save the ENDPROBE value from the search function and if the interrupt is called it should save value from the interrupt function's $POS_INT value.

    Code
    E6POS ENDPROBE
    E6POS STARTPROBE
    INT NProbe
    E6POS TestArray[10]
    
    NProbe = 0
    
    INTERRUPT DECL 10 WHEN $IN[1]==TRUE DO STOREOFFSET()
    
    LIN{Y 0}
    STARTPOINT = $POS_ACT
    SEARCH($POS_ACT, ENDPROBE, NProbe)
    TestArray[NProbe] = ENDPROBE
    LIN STARTPOINT
    
    LIN {Y 50}
    STARTPOINT = $POS_ACT
    SEARCH($POS_ACT, ENDPROBE, NProbe)
    TestArray[NProbe] = ENDPROBE
    LIN STARTPOINT
    
    LIN{TESTARRAY[1]}
    LIN{TESTARRAY[2]}
    
    END
    ;----------------------------------------------------------------
    DEF SEARCH(STARTPROBE:IN, ENDPROBE:OUT, NProbe:OUT)
    E6POS STARTPROBE
    E6POS ENDPROBE
    INT NProbe
    
    NProbe = NProbe+1
    ;Enable the Interrupt
    INTERRUPT ON 10
    
    ;Calculate Max Probe loc, ":" is geometric operator
    ENDPROBE = STARTPROBE : {X 0, Y 0, Z -100, A 0, B 0, C 0}
    
    ;Move to max probe location
    LIN ENDPROBE
    WAIT SEC 0
    
    ;Return to start
    INTERRUPT OFF 10
    END
    ;------------------------------------------------------
    
    DEF STOREOFFSET(ENDPROBE:OUT)
    E6POS ENDPROBE
    
    ;Disable the the interrupt so it doesn't get stuck in loop
    INTERRUPT OFF 10
    
    ENDPROBE = $Pos_INT
    
    ;Stop the robot
    BRAKE 
    
    ;Resume the main program after being interrupted
    RESUME
    END
    Display More
  • panic mode
    Reactions Received
    1,263
    Trophies
    11
    Posts
    13,030
    • March 2, 2020 at 9:30 PM
    • #12

    "I know the problem is in the interrupt where the value is runtime variable and it's not coming out of interrupt."

    exactly... you cannot do that. read the manual and get back to drawing board.

    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

  • chis
    Trophies
    3
    Posts
    7
    • March 2, 2020 at 10:46 PM
    • #13

    But how the example in book is working?

    I got one more thing which says that I should define the TestArray or any value which I am saving in interrupt in Cofig file.

    I have saved both my TestArray and ENDPROBE in Config file. Then also I am not able to get the value out of interrupt.

    Edited once, last by chis (March 2, 2020 at 11:02 PM).

  • panic mode
    Reactions Received
    1,263
    Trophies
    11
    Posts
    13,030
    • March 3, 2020 at 12:35 AM
    • #14

    those are all different questions...

    "But how the example in book is working?"

    >> not the same things as your code. they commented out INTERRUPT OFF inside ISR

    "I should define the TestArray or any value which I am saving in interrupt in Cofig file."

    >>Not sure about that file, you probably meant $config.dat. yes you can do that and this would make those variables global. then they can be used with interrupts.

    "I have saved both my TestArray and ENDPROBE in Config file. Then also I am not able to get the value out of interrupt."

    >> of course not. YOUR example is using RUNTIME variables. this is double declaration but robot will still let it slide (names are duplicate but scope is not). and this means your ISR still uses your runtime variable instead of global one.

    you see computers are built by humans.... and like with everything else humans did, that means everything about them is always tailored to mimic or replicate human interactions and experiences as much as possible.

    lets have an example:

    imagine you live in a village or street with 2000 people.

    lets say each house has one or more residents.

    lets say variable name is first name of each resident.

    and lets say there is at least one male resident in each house and they get names like Mike, Peter, George, Donald, Robert, Steve etc.

    there is a good chance that same name can be assigned to several of the residents.

    if there is no house with residents with duplicate names, it is not a problem. when one wife screams "PETER", it is exactly one Peter that freezes and wonders "what now?", even though several neighbours (and maybe other Peters) could hear her. This is because he is a LOCAL variable/resident in THAT house.

    if you yell same name in another house, either another Peter will think WTF is going on now (if Peter was found) or everyone in house will say there is no Peter here. Well you always extend the scope and look further - fist start looking nearby (local place, program or house) and if variable is NOT found, you may start looking for that name/variable elsewhere by knocking on doors of other houses until you check them all.

    this is exactly how computers try to find variable... first look closer (local, runtime variable declared in SRC) then a bit further (local, static declared in DAT), then a bit further (global static) and if not found - well it is not found and you get an error. but if you do find one, you use FIRST ONE YOU FIND (local runtime in your case).

    if two or more residents in same house have same name, that is confusing (even for humans). in computer science this is just not allowed (same name and same scope, in this example house is local scope, village was global scope).

    scope and life of variable is very important. this is one of fundamentals that need to be understood before moving onto more complex concepts.


    imagine this example

    Code
    DEF HOMEY()
      BAS(#INITMOV,0)
    
      PTP xHOME ; motion #1
      Modify_Home()
      PTP xHOME ; motion #3 (did this position change? is it same as motion#1 or motion#2?)
    END
    
    DEF MODIFY_HOME()
      DECL E6AXIS xHOME  
      xHOME = $AXIS_ACT
      xHOME.A1 = xHOME.A1 + 10
      PTP xHOME ; motion #2, we move to modified HOME position
    END
     
    Display More

    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,263
    Trophies
    11
    Posts
    13,030
    • March 3, 2020 at 2:03 AM
    • #15

    1. missing initialization of motion parameters

    2. first motion must be PTP for BCO

    3. variable declarations need to be in the DAT file (local DAT file is fine)

    4. STOREOFFSET() has no parameter in interrupt declaration, but it does in ISR

    5. cannot use variable names inside curly braces, only literals are allowed : LIN {TESTARRAY[1]}

    6 deactivating interrupt only inside disposable sub. in other words, when interrupt is triggered, RESUME will cancel this sub and INTERRUPT OFF will not be executed, next trigger with crash program.

    7. STOREOFFSET() attempts to use parameter (a runtime variable).

    8. ENDPROBE declared in main and ISR are two different memory locations

    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

  • chis
    Trophies
    3
    Posts
    7
    • March 6, 2020 at 9:07 PM
    • #16

    Hi panic mode,

    Thanks for all your help. I really appreciate the way you tried to explain the concepts and now the code is working for me as expected.

    Thanks once again!!

  • panic mode
    Reactions Received
    1,263
    Trophies
    11
    Posts
    13,030
    • March 6, 2020 at 9:22 PM
    • #17

    very well...

    and good luck with the next challenge.

    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

  • interrupt
  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