using arrays and for loops

Afternoon,

I am familiarising myself with Arrays for the first time and was wondering if anyone had a tidy way to solve the following issue; 

I am populating an array with robtargets so that the robot can plot a path back to a home position. However depending on the position the robots has to navigate home from the array is not always entirely populated. 

when I run my final bit of code:

    FOR i FROM 1 TO DIM(aHomePath,1) DO 
        MoveL aHomePath{i},v100,fine,tool0;
        WaitUntil\InPos, TRUE;
    ENDFOR   

Obviously I get an error when the array is not entirely populated. 

Is there a function to either ignore items in an array without any value? or failing this, rather than declaring my array as: 

    VAR Robtarget HomePath{10};

Could could i make the declaration of how many items are in the list variable so there is only ever the amount of items in the Array that the robot needs to navigate home? 

Thanks in advance :) 

Tagged:

Answers

  • This could work:
        FOR i FROM 1 TO DIM(aHomePath,1) DO 
            IF aHomePath{i}.trans <> [0,0,0] THEN
                MoveL aHomePath{i},v100,fine,tool0;
                WaitUntil\InPos, TRUE;
            ENDIF
        ENDFOR
    If the robtarget is empty, it will be ignored.
    Make the array the maximum size you will need, you can't edit array sizes during runtime. 

    Systemintegrator - Web / C# / Rapid / Robotstudio

    If I helped, please press Vote Up  :smile:
  • Thanks for your time and appreciate the advice :) 

    I had thought of something similar, I was just interested to see if their was a more efficient way. 

    Not that it matters as this is a working solution, but if the array was declared as size {20} and only 2 positions were required to safely navigate home this causes a small delay whilst in the FOR loop. 
  • You can put the forloop in a separate proc and return when you find the first empty robtarget. 
    Systemintegrator - Web / C# / Rapid / Robotstudio

    If I helped, please press Vote Up  :smile:
  • I've had the same thing before with storing information about unknown quantities, I usually store the index of the last item in the array so I know when I hit that index it will finish. I also find that useful because I can view that value in program data or remotely and see what the current index is and the final index as opposed to having to look at the array and figure out how many iterations are left. This is for dealing with large fillet welds up to ~90 passes, it might not be useful in your application to see that.

    Good Luck.