Using interrupt to store values

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


  • Place your Ad here!
  • 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

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

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

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

    • Helpful

    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

  • 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

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

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

  • 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

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


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

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

  • 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


    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

  • 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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account
Sign up for a new account in our community. It's easy!
Register a new account
Sign in
Already have an account? Sign in here.
Sign in Now

Advertising from our partners