These squares represent the trolleys with the material loaded on them.
Each trolley has a number representing the material type on the trolley.
Point is that trolleys must be loaded in such a way that the material with the same number must be together (at least two trolleys with the same number must be together, but there can also be 3 or 4).
So, in order to easily differentiate the groups of the same numbers (materials), I need to color the squares. The two colors in the picture are only examples.
The numbers are coming from PLC... so I have 10 tags with 10 numbers (integers).
The PLC is responsible for moving numbers from one position to another (like FIFO).
The size of the number doesn't matter. It can be 3 or 4 or 5 or 6 digits...
Also, the range of the numbers is not in sequence...
The numbers (trolleys) are always moving from left to right.
When the material on a trolley on position 10 is unloaded, the number disappears and the empty trolley is moved out.
Then the trolley from position 9 is moved to position 10, the trolley from position 8 to 9, 7 to 8, and so on.
When position 1 is empty, a new trolley with new material (number) is brought to position 1.
However, it is not necessary that all 10 trolleys are in a row. Sometimes there can be only one trolley somewhere in the middle, 3 trolleys at the end of the line, or 5 trolleys at the beginning...
To be honest, I don't have any good ideas on how to approach this 'problem'.
What all needs to be developed here? Is it a simple matter of developing an algorithm for differential colors? ...or is there still the logistical problem of moving the numbers around that needs to be solved as well?
I'd likey put the materials and colors into a dataset tag. as a new material comes in, assign a color and and add it to the dataset. You can then use a lookup function to set the box color.
incoming material and incoming trigger are tags to shift values into the trolleys.
ColorPalette is a dataset tag holding the colors to use
*lookupData is a document tag holding the material to color values
The project has one window and one gateway tag change script. The script checks for a new incoming value and assigns a color if needed. materials are out of the queue, it will be removed from lookupData.
tagList = ['[Test]JC_Trolley/trolley1',
'[Test]JC_Trolley/trolley2',
'[Test]JC_Trolley/trolley3',
'[Test]JC_Trolley/trolley4',
'[Test]JC_Trolley/trolley5',
'[Test]JC_Trolley/trolley6',
'[Test]JC_Trolley/trolley7',
'[Test]JC_Trolley/trolley8',
'[Test]JC_Trolley/trolley9',
'[Test]JC_Trolley/trolley10',
'[Test]JC_Trolley/ColorPalette',
'[Test]JC_Trolley/Palette Pointer',
'[Test]JC_Trolley/lookupData'
]
valuesIn = [tag.value for tag in system.tag.readBlocking(tagList)]
# Get trolley values
trolley = valuesIn[:9]
# Create a set of unique materials in the trolleys
materials = set(str(item) for item in trolley if item > 0)
# Get the color palette and pointer value
palette = valuesIn[10].getColumnAsList(1)
pointer = valuesIn[11]
# get the lookup document
lookupDict = valuesIn[12]
# If the tag is null, create an empty dict, else convert to dict
if lookupDict is None:
lookupDict = {}
else:
lookupDict = lookupDict.toDict()
# Get the first trolley. If it's non-zero, and doesn't exist in the lookup
# assign the next color in the palette
trolleyIn = trolley[0]
if trolleyIn > 0:
if trolleyIn not in lookupDict.keys():
lookupDict[str(trolleyIn)] = palette[pointer]
pointer += 1
if pointer >= 10:
pointer = 0
# remove old items from the lookup dict
items_to_remove = set(lookupDict.keys()) - materials
print materials, lookupDict.keys(), items_to_remove
for item in items_to_remove:
del lookupDict[item]
# Write updated pointer and lookuip data back to tags.
tagsOut = ['[Test]JC_Trolley/Palette Pointer',
'[Test]JC_Trolley/lookupData'
]
system.tag.writeBlocking(tagsOut, [pointer, system.util.jsonEncode(lookupDict)])