Could you tell me the difference between a UDT and a AOI , and why would they be used ?
While it is tempting to just point toward a bunch of Rockwell manuals, which explain these topics in great detail, that would be someplace to go when it is time to put these tools into practice.
Instead, I will take the approach of pointing out what is common: both the User Defined Type (UDT) and Add-On Instruction (AOI) allow the programmer to extend basic building blocks in the Logix environment into more complex elements that can be easily dropped into your programs.
In the case of a UDT, you are taking the basic data types -- integers, reals, booleans -- and combining them to create a new, more complex data type. Then you can create a Tag using the UDT just like you create tags of native types like DINT, REAL, BOOL, etc.
The STRING data type is an example of a UDT, though it is supplied with the Logix programming environment. Nevertheless, it is UDT-like because it consists of an array of short integers to hold the characters, and a separate integer to hold the length of the string. So when you create a STRING tag, you are actually getting an 80-element array of SINTs and a DINT tag to store the string's actual length.
A primary reason to bother with UDT-based tags is that it allows you to collect related data in one unit. You can then pass that collection as a single tag to subroutines, other processors, and instructions, including AOIs. Even if not used for sharing data, the UDT is a method to make programs more readable by keeping closely related data items together.
Similarly, with the AOI you are extending the Logix environment, but from an instruction/logic standpoint rather than data type/collection. The AOI is basically a collection of logic -- like a subroutine -- that performs a specific task common to your application. Unlike a subroutine, Logix allows you to package AOI logic in a such a way that you can drop into a program just like it was a native instruction that came with Logix. It will typically have input parameters, output parameters, and maybe status bits.
I am glossing over many details, especially related to subroutines and AOIs. These are well covered in the Rockwell manuals, as wells as threads in this forum. The general idea is that the AOI should do specific task, is well-tested, and not subject to frequent change. It can then be reliably used in multiple places in your application environment, as well as shared with others.
I hope this attempt to "scratch the itch" of UDT versus AOI was helpful. I'm sure there will be other perspectives toward understanding these topics.