Tutorial 1:
Create a component
In this first tutorial, we will show you some key ideas of VIGO6 that will help you build your first control component.
The tutorial switch between theory and hands-on exercises with "how-to" videos as a help.
Now let's start with VIGO6
What you need to build - THE Control logic
1. You need to build the light green component in the picture to the left. You specify a setpoint. When the temperature is below the setpoint, the component should turn on an output connected to a heating element. But, when the temperature is above the setpoint, the output should turn off.
2. You "measure" the temperature with a 4-20 mA temperature transmitter.
3. The regulation is a simple on/off controller with a temperature hysteresis. You control the regulating interval with a timer.
What you need to build - THE View
You need to be able to view both the setpoint and the current temperature and change the setpoint.
NB: A note on names. When you need to name a new type, we will present the name like this "XX_Temperature_regulator_simple".
Please use two letters that make sense to you – like your initials – and use them instead of "XX".
SEE THE INTRO
Step 1 - Create a temperature regulator component
1. Open the component
a. Click on the "open type"-icon (or press "CTRL-O").
b. Then select "COMPONENTS>>".
c. You can now type any part of the name or GUID.
Find "PD_7664 Process_component" – and double-click to open it.
The GUID is a unique identifier for each type in VIGO6, including a version-number.
By creating a descendent of a component, this new component has the same features as the component it was "created from", and in this new component, it is possible to implement new features/functionality, add functionality to features already implemented in the ancestor component.
The Processcomponent (PD_7664), used as ancestor, features error handling, manual/auto etc., ready to use in the descendent.
2. Create a new type
a. Right-click on the component name
b. Select “Create new descendant of type”.
A new tab will open with the new type, where you are the writer.
The component is inherited from PD_7664.
c. Change the name. Double-click on the name of your component and change it to "XX_Temperature_regulator_simple".
NB: When you press space, you make an underscore!
SEE HOW IT WORKS
Step 2 - Create variables and constants in your component
1. Add an instance constant
a. Right-click on the section "INSTANCE CONSTANTS".
b. Click on "Add constant".
c. Choose PD_2003 Float32.
d. Change the name to Regulating_interval.
e. Right-click on the variable and press "Quantity type".
Choose TimeDifference.
It defines how often the regulator runs.
3. Add a non-volatile variable
a. Right-click on the section "NON-VOLATILE VARIABLES"
b. Click on "Add variable".
c. Choose PD_2003 Float32.
d. Change the name to Setpoint_value.
e. Right-click on the variable and press "Quantity type".
Choose AbsoluteTemperature.
f. Set the default value to 25 [degrees celcius].
It holds the set-point for the regulator.
SEE HOW IT WORKS
Step 3 - Add subcomponents - registers and timer
We want to make the variables Setpoint_value and Actual_temperature_value visible outside of the
control component – for example for the view or for other components.
Any component must have an interface, so other components and visualizations, can read and write data to/from the component.
Here the Register subcomponent may be used. The interface also include methods with external access and Get/Set methods.
Add registers
1. Add a register
a. Right-click on the subcomponent section of your component and select:
b. Add>>, Register>> click on PD_4050 Register.
2. Change the name of the new register to "Setpoint"
3. Assign data to the register
a. Right-click on the register and click: "Assign data field to the register subcomponent".
b. Select "Setpoint_value" as the register variable.b. Make sure that you enable "get" and "set" for all user types. To clarify, it tells the view that the variable is to read and write.
c. Press "define value range". Set the maximum value to 40 and minimum value to 20. Do the same for alarm limit high and alarm limit low.
4. Add the next register
a. Then create a register with the name Actual_temperature for the variable Actual_temperature_value in the same way.
b. Enable "get" and disable "set" for all user types. This tells the view that this variable is read-only, and nobody car write the data from a visualization.
c. Press "define value range". Set the maximum value to 100 and the minimum value to 0. Do the same for alarm limit high and alarm limit low.
Add a timer
1. Add a timer, so you can repeat your regulation at defined intervals:
a. Add PD_4404 Timer_subcomponent to the Subcomponent section.
b. Change the name to Timer.
c. Click on the timer.
Read the usage for a Timer_subcomponent, by selecting the methods and reading the documentation to the right of the VIGO6 navigation tree.
SEE HOW IT WORKS
Step 4 - Add connectors - CONNECTION TO OTHER COMPONENTS
Your temperature regulator component will need to interface to the orange temperature input component and to the blue digital output component.
Therefore in this case two connectors are needed.
One for the temperature and one for the output.
For enabling components to communicate with each other VIGO6 uses connectors.
A connector is specializing a specific "interface", which can be a data-type, or a component type. Via this connector, the (external) interface can be accessed.
Create a connection to the output component
1. Under the section "Connection to external components" in your component:
Add Connector to component of type: Digital output base PD 2824, which is a basis for more output types.
2. Rename it to Output.
3. Create a connection to a temperature component:Add Connector to component of type: Temperature Input Base PD 2854.
4. Rename it to Temperature.
SEE HOW IT WORKS
Step 5 - Add a method and write your control code
Now you need to write the actual piece of code that will enable your component to make the wanted regulation.
Create a new method:
1. Right-click on the method section and select "Add Method".
Name it Regulate
Write code for your temperature control:
You can right-click and use "select identifier" and "code templates" instead of writing all the code yourself.
2. Read the temperature from the input component into the register "Actual_temperature" in the control component
4. If the temperature is lower than the setpoint, then open the output
5. In all other cases close the output.
SEE HOW IT WORKS
Here is what your code should look like:
Step 6 - Repeat the regulation
A method gained from an ancestor can be “Overridden” meaning you can add onto the method with your own code.
Once a method is “Overridden” the method will contain a keyword “INHERITED”.
INHERITED covers all the code that is implemented in the ancestor.
Meaning that if in the ancestor this code is written:
a := 1
b := 2
c := a + b
Then calling INHERITED in the overridden method, will also assign 1 to a, 2 to b and assign the sum of a and b to c.
Hereafter you could have written c := c + 1
Like this:
IHERITED
c := c + 1
And now c is equal to 4
INHERITED is all the funktionality of this method that you have “Gained” by creating a decendant of a type.
In this case a method is already implemented with some functionality.
This functionality is executed by calling INHERITED as per the following example:
INHERITED
In the above example, the functionality gained is performed first, then your own functionality is performed. It is also possible to have your own functionality be performed before the “Gained” functionality, as seen by the following example:
My code added onto method…
INHERITED
You need to make sure that your regulation keeps running at specific intervals, and for this, you use the timer subcomponent that you added earlier.
1. Where to insert your program
a. Fold out the Timer subcomponent in your component and select the method "Timermethod".
b. Right-click to ‘Override’ and open "Program".
In the first line of the program, it says INHERITED. This shows that the method of the ancestor will run. Don’t delete the INHERITED, unless you know what happens in the code from the whole ancestor chain.
a. Calls the Regulate method
b. Runs the Timer again – in the time you have set in your constant Regulating_interval.
What your code should look like
SEE HOW IT WORKS
Step 7 - Handle the startup in Init
What your code should look like:
A component or sub-component here after just named by component, have two different methods called during / just after power-up.
The method Init() is called during start-up, and cannot perform any kind of communication with other components. Override this method for initializing data, or presetting data.
The method After_init(), is executed when the primary start-up is done for all components in the device, and will execute ‘just after’ Init() as soon as possible.
This method may communicate externally (via a connector). Override this method to set for instance an output in a specific state.
SEE HOW IT WORKS
Visualization
In VIGO6 you decide at the component level what parts of the component to make available in a view. If you need to see or edit data outside of your component – you need a register.
You did the same for setpoint and actual temperature.
You can create your own views or use and build upon views that others have made.
Let us make a simple view of our temperature regulator component.
When creating a visualization, it is created on base of an already existing visualization (here Comp_view).
So in the same way as for the component inheritance, one ‘gets the already implemented features’
Inheritance has the great advantage that an error in the ancestor, only needs to be corrected once, and the descendents just need updating to this new ancestor version
A view always has a “For-type” meaning it has a relation to some GUID, in this case it has a for type to that of a component. This for type can be overridden to being a for-type of any type that descends from the same as the current fot-type.
Ja det er mega kringlet men jeg ved ikke hvordan jeg ellers skal beskrive dette.
Step 8 - Create a view of
the temperature regulator component
Your component should be able to view and change the set-point and to view the current temperature.
1. Open your control component “XX_Temperature_regulator_simple”.
2. Right-click and pick “create new view for this type based on” PD_11813 – Comp_view”.
3. Rename the view to “Window_for_XX_temperature_regulator_simple”.
4. Choose type constants, view_region, bottomRight and set y to 50[mm] and x to 100[mm].
5. Save your view.
6. Open your graphical editor by pressing the “Show view”-icon seen to the right. It is just above the VIGO6-navigation tree and looks like a play button.
You now see your empty view.
6a. Instead of adjusting the size in 4., it is also possible to adjust the size, by right-click on the shown view, and adjust the size here.
7. Add the values to show
a. Right-click on the view list and pick “add”- “view for control instance”.
b. Click on the plus sign next to ” XX_temperature_regulator_simple”.
c. Pick register “Setpoint”.
d. Select view PD_2159 – Number_name_value_unit.
8. On your view, you now see the element and you can drag it where you want on the screen.
9. Add a similar view for register “Actual temperature”.
Your view should look like this:
SEE HOW IT WORKS
Congratulations
Finally, you have created your control component with control logic and a view. You can use it again and again.
Now let us move to the next tutorial where you learn how to create assemblies, main assemblies, and projects.
And you will set up your testbed and load your components into a hardware module.