Modeling with Objects and Variables
Just to recap, Variables ore one of the possibilities to deliver the values, Objects are used for structure and semantics. This post will further explain Objects and Variables and how they are used in an example. For a general overview about the OPC UA Node Classes and the node tree, please refer to OPC UA Fundamentals – 1.
Objects
Each Object has an ObjectType. The different ObjectTypes are organized in a type hierarchy, inheriting from each other. On top of the pyramid there is the BaseObjectType being the root of all ObjectTypes. An Object node itself has no data value, just a name. The OPC UA standard predefines a lot of ObjectTypes.
Practically Objects are used in two manners. First there are simple Objects that define just the Object node themself. They can be used like folders in a file system, helping to organize all the files and make it more easy to explore. In that case, just the BaseObjectType can be used. Secondly Objects can define a whole structure of nodes. The corresponding ObjectType defines the template. This is useful if those structures appear several times in the node tree, for modeling purposes, for defining standards and to make these structures easily discoverable for Clients.
Simple Object | BaseObjectType |
Object with node structure | derived types like StateMachineType |
Variables
Variable nodes are one way to provide the precious data. They have a Value attribute with a defined data type. For beginners, one of the most confusing concepts of OCP UA is the introduction of the VariableType. It is not to be confused with the DataType. The DataType defines the structure and type of the value. However the VariableType enables further possibilities through defining additional subvariables or limitations to attributes. Usage of a VariableType will be shown later in the concrete example. The OPC UA standard predefines a lot of VariableTypes
Like the ObjectTypes, the VariableTypes are organized in a type hierarchy. On top of the pyramid there is the BaseVariableType. A simple Variable node which just provides a value (also called “Property”), can be of BaseVariableType or PropertyType. The PropertyType is the same as the BaseVariableType, just with another name exactly for that purpose.
Simple Variable | BaseVariableType or PropertyType |
Variable with subvariables | derived types like AnalogItemType |
Modeling a coffee machine
Let’s suppose we are creating an OPC UA server for a coffee machine. The first thoughts go into which values we want to provide (e.g. via Variables) and which commands for remote control shall be possible (e.g. via Methods). Let’s make a table to collect the ideas.
Selector | DataType: Integer | Defines the kind of coffee, like Espresso. |
Counter | DataType: Integer | Counts the served cups. |
Temp | DataType: Integer | Current temperature of the brewing group. |
CupDetected | DataType: Bool | Is a cup detected. |
IsDetected | DataType: Bool | Is the water tank inserted. |
FillingLevel | DataType: Double | Filling level of the water tank. |
Start | Method | Start producing a cup of coffee. |
Stop | Method | Stop or interrupt producing a cup. |
Now it would be possible to provide all those values as a flat list of nodes. But there are many advantages in creating more structure and semantics. One possible first iteration of a node tree is shown in the next diagram. It introduces Objects for the control unit, the brewing group and the water tank. The simplest way is to just use the BaseObjectType for all Objects and the PropertyType for all Variables.
To really leverage the advantages of the ObjectType system, like in defining a standard for coffee machine manufacturers, we introduce further types. We create a new type “ControlType” which defines the whole node structure of the ControlUnit. Also we want to deliver the filling level of the water tank including a unit and the allowed value range. Therefore we can use the OPC UA predefined VariableType “AnalogItemType“.
Finally we could define an ObjectType “CoffeeMachineType” for the entire coffee machine. So each coffee machine instance object would need to have exactly that predefined node structure. Most of the, time when creating such new ObjectTypes, they derive from BaseObjectType.
Further exploration of Objects and Variables
A great way to further explore predefined types, custom made types and node trees is to use a generic OPC UA client like the UaExpert of UnifiedAutomation. Just connect to a sample OPC UA server and have a look at the node tree and the type hierarchies. Since each OPC UA server includes all the predefined types, that can be a more interesting way. Reading just the documentation can be boring. After creating an account, UaExpert can be downloaded from the website of UnifiedAutomation. The next Screenshots show the experience. Within the folder “Types” you can explore the complete OPC UA type space.
Another important source of information are the official OPC UA specifications and the Companion Specifications. There is a html version and a pdf version on the site of the OPCFoundation. Create a free account and get the pdf documents.
- Specifications – html version
- OPC UA specifications – pdf versions
- Companion specifications – pdf versions
OPC UA specification Part5: Information Model contains all the predefined ObjectTypes and VariableTypes.
The newer companion specifications also contain a introduction to OPC UA, focusing on Objects and Variables.
Finally you can find all standardized and predefined types in the UA-Nodeset Github Repository of the OPCFoundation. That is for programmatic usage.