Searching a UDT array

Join Date
Nov 2006
Location
CHICAGO
Posts
12
I am using a UDT that has tool data. I need to query based on three values within an array of 43. ex. ToolData[43] DataType - udt_tool

I have three tags
1) ToolID
2) ToolPresent
3)ToolBroken

I need to search through the array and find a ToolID that matches, has a ToolPresent value of 1 and a ToolBroken value of 0. Can only be done using laddder logic. šŸ™ƒ
 
Last edited:
Welcome to the forum.

Yes. This can be done in ladder.

There is an FSC (file search compare) instruction although I haven't ever used it on an array of a UDT. I'd set up a For/Next loop and just index through the array until it finds a condition match.
Code:
OTU ToolFound CLR Index
LBL Loop EQU ToolData[Index].ToolID Source XIC ToolData[Index].ToolPresent XIO ToolData[Index].ToolBroken OTL ToolFound
XIO ToolFound ADD Index 1 Index
XIO ToolFound LES Index 43 JMP Loop
 
Last edited:
I tried the FSC instruction, works well with a 1 to 1 comparison. But if I want to compare one field (ToolID) and evaluate two other fields there is no way to do it with this instruction. Using logix 5000 ver 21. No Next instruction. Easier with structured text I am sure but I do not have that capability with the stripped down version of logix I am using. Ladder logic only.

Errors out when trying to compare an INT to a UDT. Seems to only want a UDT to UDT comparison.
 
Try the ladder code in my previous post. It implements a for/next loop using LBL/JMP pairs.
If you are unfamiliar with the ladder mnemonics then in RSLogix5000 on a blank rung double click the rung number. A mnemonic editor line will open at the top of the ladder file. Paste the lines of code one at a time, each one on a blank rung. Logix5000 will show you the ladder.
 
Appears to keep faulting the PLC. Assuming if it runs and doesn't find it it errors out. Need to control this situation so I will try adding more code.



(Type 04) Program Fault (can be trapped by a fault routine)
(Code 20) Array subscript too large, or CONTROL data type POS or LEN invalid.
 
Last edited:
Make sure you are not indexing past the end of your array. You will need to add logic to handle not found conditions. The value of Index is the array position where a match was found only if ToolFound is true and if index is between 0 and 42, otherwise Index will be past the end of your array.
 
This is what I have written so far, not working.

EQU(RobotRequestedToolID,ActiveToolData.ToolD_Output)XIC(RobotToolLoaded)OTE(ToolLoadedCurrent); NEQ(RobotRequestedToolID,ActiveToolData.ToolD_Output)XIC(RobotToolLoaded)JMP(Loop); OTU(ToolFound)COP(Index,ToolFoundLocation,1)CLR(Index); LBL(Loop)EQU(ToolHolderData[Index].ToolD_Output,RobotRequestedToolID)XIC(ToolHolderData[Index].ToolPresent)XIO(ToolHolderData[Index].ToolBroken)OTL(ToolFound); XIO(ToolFound)ADD(Index,1,Index); EQU(Index,42)[OTE(ToolNotFound_Error),OTU(ToolFound),CLR(Index)]; XIO(ToolFound)LES(Index,43)JMP(Loop);

(Type 06) Watchdog Fault
(Code 01) Task watchdog expired. May have been caused by an infinite loop, a complex program, or a higher priority task.
 
Last edited:
This area:

EQU(Index,42)
[OTE(ToolNotFound_Error),
OTU(ToolFound),CLR(Index)];

says if the index = 42, unlatch ToolFound & reset the Index

then, your last line says
XIO(ToolFound)
LES(Index,43)
JMP(Loop);

Which, if it has not found the tool, and Index < 43 (which it will be if not found) then JMP o Loop. This area is causing your watchdog to fault...
Maybe an additional check for 'ToolNotFound_Error' can break you out of the loop when not finding the Tool.
 
I will have to test the new BRK statement I added on Monday. Thanks for pointing that out.

EQU(RobotRequestedToolID,ActiveToolData.ToolD_Output)XIC(RobotToolLoaded)OTE(ToolLoadedCurrent); NEQ(RobotRequestedToolID,ActiveToolData.ToolD_Output)[XIC(RobotToolLoaded),XIO(RobotToolLoaded)]JMP(Loop); OTU(ToolFound)CLR(Index); LBL(Loop)EQU(ToolHolderData[Index].ToolD_Output,RobotRequestedToolID)XIC(ToolHolderData[Index].ToolPresent)XIO(ToolHolderData[Index].ToolBroken)[OTL(ToolFound),COP(ToolHolderData[Index],ActiveToolData,1)]; XIO(ToolFound)ADD(Index,1,Index); XIO(ToolFound)LES(Index,43)JMP(Loop); EQU(Index,43)[OTE(ToolNotFound_Error),OTU(ToolFound),CLR(Index),BRK()];
 
Logic doesnt seem to execute, even though the number i am requesting matches a number in the array. What happens is it cannot find it, then zeroes out the index. Help!

OTU(ToolFound)CLR(Index); LBL(Loop)EQU(ToolHolderData[Index].ToolID_Output,robot.FromInt.iReqToolID)XIC(ToolHolderData[Index].ToolPresent)XIO(ToolHolderData[Index].ToolBroken)[OTL(ToolFound),COP(ToolHolderData[Index],ActiveToolData,1),COP(Index,ToolFoundLocation,1),MOV(ToolFoundLocation,robot.ToInt.iRequestedToolPos),MOV(1,ToolHolderData[Index].ToolActive),CLR(Index)BRK()]; XIO(ToolFound)LES(Index,43)ADD(Index,1,Index); XIO(ToolFound)LES(Index,43)JMP(Loop); [XIC(ToolFound),EQU(Index,43)][BRK(),CLR(Index),OTU(ToolFound),OTE(ToolNotFound_Error)];
 
I think you should replace the BRK's with EXIT, but I don't think that's necessary either - if you don't find the JMP rung true then it will just fall out of the loop.

Help file says the BRK is to break from a FOR loop, but then there are some references to BRK in the JMP help area too so I don't know if it's ONLY for the FOR loop construct.
The 5th rung of your logic says:
- If ToolFound OR Index=43 then
- CLR Index (there's your zeroing of the Index)
- Unlatch ToolFound (there is why it appears to not find it)
- turn on ToolNotFound_Error (this will only last one scan since you clear the rung's conditions)

I think for testing purposes I would eliminate ToolBroken then add it back after you get it all working - it's just another variable in the equation right now.

You may also want to latch a ToolNotFound bit so's you can actually see that it failed. They way you're clearing things, I'm not sure you can even detect that it was found. Right now, you're clearing the things that would indicate you found a match...
 
I tried the FSC instruction, works well with a 1 to 1 comparison. But if I want to compare one field (ToolID) and evaluate two other fields there is no way to do it with this instruction. Using logix 5000 ver 21. No Next instruction. Easier with structured text I am sure but I do not have that capability with the stripped down version of logix I am using. Ladder logic only.

Errors out when trying to compare an INT to a UDT. Seems to only want a UDT to UDT comparison.

This is not true. Attached is a simple program using the FSC to Find your Data And it will report what position it was found. I used a simple Tool ID of 1 and 2. You can change the Tool Present And Tool Broken to see the position change.

Enter 1 for good result
Enter 2 for Tool Not Found

Program is Version 18
 
Last edited:
I have not tested or look closely at your current routine. I only tested the FSC. I made a UDT of your 3 requirements. ID. Present and Broken. I then created a Tag Called Tool_Info of the UDT data type I called Tool_Data. I set the first 10 ID's to 1 and next few to 2. Then set the present and broken to 1 or 0. to test and see position change. The only trick I used was indirect addressing to confirm the Tool present and broken requirement of the found position. Then,if Not true reset inhibit bit to continue search. If true then Tool_Good and move position to Found register. If the FSC instruction gets done and Not Tool_Good then No_Tool_Found.
 
You are clearing the Index and the ToolFound on entry to the program, so there's no need to clear them at the end of the routine. So, stop doing that clearing on your last rung and you may be able to see the results.
 

Similar Topics

Hi Guys, Is there an instruction suitable for searching an array of UDTs for lowest value? I can achive using a loop but figure theres an...
Replies
1
Views
2,557
Is it possible to find the locations of a UDT member inside AOIs in RSLogix? I have a project with several UDTs that are InOut parameters for...
Replies
1
Views
2,835
is it just me, or has something happened with the google search when using chrome? looks likes safari on mac is ok, but edge/chrome on windoze has...
Replies
10
Views
837
Besides using BootP in the past, I am relatively new to having to look for privately addressed devices in many control networks. All of the...
Replies
23
Views
3,948
Good morning, could anyone recommend a 24VDC pulse counter which counts up or down to a preset #? Once it reaches this number, send a 24VDC back...
Replies
3
Views
1,647
Back
Top Bottom