Value Error: Attempted to use an uninitialized variable - which is initialized

I am using some script in my ur robots to offset the position of a placement position. Only in X and Y reference to base. These offsets are done within a subprogram which is called by the main program.

Every now and then one of the robots decides that the variable I am using is no longer initialized and it will not run, the only way round it is disabling that line and restarting. Then later on clearing the subprogram and reloading it.

Has anyone experienced anything like it? It’s happened twice this week on programs that previously ran fine and no alterations have been made. The only thing I think is different between the two robots is the other robot that hasn’t shown this issue doesn’t have a subprogram, this one does because its actions are more complicated, and its within the subprogram where I am doing this offset.

See photos of error, lines of code and variables.

Your variable PLC_1_150_150 must not be retaining its value, since you can see the lines immediately preceeding the error line properly assign the other variables values. Determine when that variable is SUPPOSED to get a value and make sure that’s happening prior to the subprogram getting called. This may be as simple as storing it as an installation variable so its retained, or else pushing this initial value from the PLC in the Before Start routine.

In general, sub programs are bad on the UR. I wish they weren’t, and I wish I could be more descriptive than that, but its just my personal experience that they often cause more problems than they solve.