... most of all our parents which gave us the opportunity to study at the KHLim and
to do an Erasmus stage. ...... GOFFIN W. Regeltechniek, KHLim. AUTODESK ...
Simulation program for domotics Promoters :
M. C. Crincket M. W. Claes
Aerts Thomas Leroy Stijn 2006-2007
Preface This final project is the result of a lot of research and a lot of work. Without the help of certain persons, it’s for sure without them the realisation of this project was a lot more difficult. That’s why we want to thank the persons who contributed to the realisation of this project. First of all we’d like to thank Mr. C. Crincket our stage director, for his advice and suggestions. We also would like to thank Mr. W. Claes, our promoter for his advice and motivation. Great thanks also go out to German Gutierrez Zubizarreta, for his help with AutoCAD and the drawings We also would like to thank the other students for their moral support, but most of all our parents which gave us the opportunity to study at the KHLim and to do an Erasmus stage.
2
Preface ...................................................................................................................................2 1
Introduction ....................................................................................................................6
2
Autocad ..........................................................................................................................7 2.1 Introduction ............................................................................................................7 2.2 Layers .....................................................................................................................7 2.3 Blocks ...................................................................................................................10 2.4 Views....................................................................................................................12
3
Visual Basic..................................................................................................................17 3.1 Used elements .......................................................................................................17 3.1.1 Label .............................................................................................................17 3.1.2 Command button ...........................................................................................17 3.1.3 Scroll-bar ......................................................................................................17 3.1.4 Frame with options ........................................................................................17 3.1.5 TextBox ........................................................................................................17 3.1.6 PictureBox ....................................................................................................18 3.1.7 Image ............................................................................................................18 3.2 The program .........................................................................................................19 3.2.1 The language form ........................................................................................20 3.2.2 Actual program: ............................................................................................22 3.2.3 Change the setpoint .......................................................................................25 3.2.4 Exit button.....................................................................................................27 3.2.5 Choose the force of the wind .........................................................................27 3.2.6 The option day ..............................................................................................28 3.2.7 Choice of the controller .................................................................................30 3.2.8 The Timer .....................................................................................................32 3.2.9 The PID regulator ..........................................................................................34 3.2.10 The On/Off regulator .....................................................................................35 3.2.11 Module with variables ...................................................................................37
4
Controllers ....................................................................................................................39 4.1 On/Off controller with hysteresis...........................................................................39 4.2 PID controller .......................................................................................................41 4.2.1 Proportional action ........................................................................................41 4.2.2 Integrating action...........................................................................................49 4.2.3 Differential action .........................................................................................49 4.2.4 Combination: PID .........................................................................................49
5
Bibliography .................................................................................................................51
6
Appendix 1: The program .............................................................................................52
3
Figure 1: make a new layer .....................................................................................................7 Figure 2: properties of a layer .................................................................................................7 Figure 3: color of the layer .....................................................................................................8 Figure 4: linetype ...................................................................................................................8 Figure 5: thickness of line .......................................................................................................9 Figure 6: list of used layers .....................................................................................................9 Figure 7: insert a block .........................................................................................................10 Figure 8: use an existing block..............................................................................................10 Figure 9: the chosen block ....................................................................................................11 Figure 10: the house in 3D ....................................................................................................12 Figure 11: front of the house .................................................................................................12 Figure 12: back of the house .................................................................................................13 Figure 13: right side of the house ..........................................................................................13 Figure 14: Left side of the house...........................................................................................13 Figure 15: top view...............................................................................................................14 Figure 16: house with ligth ...................................................................................................15 Figure 17: house with the blinds ...........................................................................................15 Figure 18: house with lights and blinds .................................................................................16 Figure 19: a label ..................................................................................................................17 Figure 20: a command button ...............................................................................................17 Figure 21: a scroll-bar...........................................................................................................17 Figure 22: frame with options ...............................................................................................17 Figure 23: TextBox ..............................................................................................................18 Figure 24: PictureBox...........................................................................................................18 Figure 25: Image ..................................................................................................................18 Figure 26: choose a form ......................................................................................................19 Figure 27: Form: frmTaal .....................................................................................................20 Figure 28: Form: frmProject .................................................................................................22 Figure 29: the button +5 .......................................................................................................25 Figure 30: The button -5 .......................................................................................................25 Figure 31: scroll-bar for the temperature ...............................................................................26 Figure 32: the exit button ......................................................................................................27 Figure 33: scroll-bar for the force of the wind .......................................................................27 Figure 34: the option day ......................................................................................................28 Figure 35: choose option Dark ..............................................................................................29 Figure 36: choose the PID ....................................................................................................30 Figure 37: variables of the PID .............................................................................................30 Figure 38: when we choose On/Off ......................................................................................30 Figure 39: hysteresis .............................................................................................................31 Figure 40 : Graph of the On/Off controller............................................................................39 Figure 41: PID controller ......................................................................................................41 Figure 42: Control loop ........................................................................................................41 Figure 43: step response of the P controller ..........................................................................42 Figure 44: root-locus of a stable system ................................................................................42 Figure 45: step response of a stable system ...........................................................................43 Figure 46: loot-locus of an instable proces ............................................................................44 Figure 47: step response of an instable system ......................................................................44 Figure 48: root-locus with critical gain .................................................................................48 Figure 49: step response with critical gain ............................................................................48 Figure 50: step response for an I controller ...........................................................................49
4
Figure 51: step response for a PD controller .........................................................................49 Figure 52: theoretical step response of a PID controller ........................................................50 Figure 53: practical step response of a controller ..................................................................50
5
1 Introduction Our assignment was the simulation of an automated house. We have drawn the house in AutoCAD and wrote the simulation program in Visual Basic. In the first part, the construction of the house is explained and a brief introduction to AutoCAD is given. After that we’ve explained the program along with an introduction to Visual Basic with an explanation for the most common used controls and commands. In the end the controllers are explained. Our intention was to create a simulation program to show the difference between a conventional controller and like a thermostat and a PID controller, the type of controller most used in industrial environment We’ve chosen for this project because of our interest in automation technology and controllers, but also because of the challenge to create a program. Another reason was the show that the conventional controller aren’t always the best.
6
2
AutoCAD
2.1 Introduction AutoCAD is a CAD program for 2- and 3- dimensions designing. It’s a program that uses vectors for making designs. It uses primitive elements, like lines, circles, arcs and text for making complex objects.
2.2 Layers Layers are a big help to organize the properties of a drawing. With the layers, it’s possible for separate the functions of a design. It’s possible to change all the properties of a layers, like the color, type of line, line thickness, and if the layer got to be printed or not. Make a new layer in AutoCad . We select the function Layer in the menu Format.
Figure 1: make a new layer
Then we chose the button New.
Figure 2: properties of a layer
We choose a name for the new layer and the properties, like the color. 7
Figure 3: color of the layer
It’s also possible to change the Linetype. We clique on Continuous. In the new window we choose the button Load and then it’s possible to choose out of some standard lines.
Figure 4: linetype
For change the thickness of the line, we click on lineweight.
8
Figure 5: thickness of line
You can use for every element another layer; the next picture shows the layers we used.
Figure 6: list of used layers
vloer raster ramen pilaar muren licht punten gras deuren dak
floor fence windows pillar
We’ve chosen for these layers to facilitate the drawing, we made different layers for the walls, the roof, etc. Because they all have different properties. That’s why we decided to divide the drawing in basic pieces, a layer for the windows, another for the floor, etc.
wall source of light grass doors roof
9
2.3 Blocks You can save a lot of time by using blocks. Because you can use an existing part and don’t have to create a new one. In our project we insert a tree as a block. For inserting a block, you choose in the menu Insert, and choose Block.
Figure 7: insert a block
In the next window we click Browse and we choose an existing block.
Figure 8: use an existing block
10
For example the next block.
Figure 9: the chosen block
We place the block on the drawing where we want.
11
2.4 Views In three-dimensional
Figure 10: the house in 3D
Front view
Figure 11: front of the house
Back view
12
Figure 12: back of the house
Right view
Figure 13: right side of the house
Left view
Figure 14: Left side of the house
Top view
13
Figure 15: top view
14
With the lights
Figure 16: house with ligth
With the blinds
Figure 17: house with the blinds
15
With the blinds and the light
Figure 18: house with lights and blinds
We’ve chosen the draw the house like this because we needed visible windows to visualize the shutter. And we were also in need of a simple garden to place outside lights the simulate when the lights have to go on.
16
3 Visual Basic Visual basic is an evolution of Basic from Microsoft; it’s used for creating applications and programs in Windows. It’s possible to create programs relative fast, because of the simplicity. We just have to manipulate the visual elements and write the proper code with the elements.
3.1 Used elements 3.1.1 Label A « label » is used for changing the text, but not by the user.
Figure 19: a label
3.1.2 Command button The « command button » will execute an action when the user clicks the button.
Figure 20: a command button
3.1.3 Scroll-bar With a « scroll-bar » you can change a value.
Figure 21: a scroll-bar
3.1.4 Frame with options A « Frame » is used to group commands, like options in this case.
Figure 22: frame with options
3.1.5 TextBox A « TextBox » is used so the user can give information to the program.
17
Figure 23: TextBox
3.1.6 PictureBox In a « PictureBox » you can place bitmaps, icons, Windows metafiles. But it also can be used to place text or a group of commands. We use it to program a graph.
Figure 24: PictureBox
3.1.7 Image With « image » we can place bitmaps, icons and windows metafiles. We can also use an « image » as a « command button ».
Figure 25: Image
18
3.2 The program Because we have two formuliers, we got to choose wich has to start up first.
Figure 26: choose a form
19
3.2.1 The language form When we work with the program we get the first screen. Here you can choose the langue you prefer, English, French, Dutch or German.
Figure 27: Form: frmTaal
The next is the code from the form: Private Sub formLoad() 'with formload() we can set the things which have to happen, 'when the form will load. 'With .Hide you hide a object, in this case it’s the form "frmProject" 'With .Show you let see a object, in this case it’s the form "frmTaal" frmProject.Hide frmTaal.Show End Sub ___________________________________________________________________ Private Sub cmdDuits_Click() 'with _Click() we program the action which has to occur when we click the object 'The value of "intTaal" is an indication for the chosen langue. 'intTaal=1 -> english 'intTaal=2 -> french 'intTaal=3 -> dutch 'intTaal=4 -> german intTaal = 4 frmTaal.Hide frmProject.Show
20
End Sub ___________________________________________________________________ Private Sub cmdEngels_Click() intTaal = 1 frmTaal.Hide frmProject.Show End Sub ___________________________________________________________________ Private Sub cmdFrans_Click() intTaal = 2 frmTaal.Hide frmProject.Show End Sub ___________________________________________________________________ Private Sub cmdNederlands_Click() intTaal = 3 frmTaal.Hide frmProject.Show End Sub
21
3.2.2 Actual program:
Figure 28: Form: frmProject
When we work with the program, the first first thing that will happen is execute the « Form_load() » Private Sub Form_load() ' with formload() we can decide what has to happen when the form loads. ' For centering the form: frmProject.Left = (Screen.Width / 2) - (frmProject.Width / 2) frmProject.Top = (Screen.Height / 2) - (frmProject.Height / 2) ' For loading the standard pictures (LoadPicture): imgDoorsnede.Picture = LoadPicture(App.Path & "\verwarming_aan_licht_uit.bmp") img3d.Picture = LoadPicture(App.Path & "\standaard.bmp") ' With the variable "intTaal" from the form "frmTaal" we choose the language of the ' program ' With .Caption we can change the text from the "labels" ' The structure of the case is like this "Select Case - End Select": ' Select Case ' Case ' ' Case ' ' ... ' End Select 22
Select Case intTaal Case 1 lblWind.Caption = "Wind" lblSetpoint.Caption = "Desired temperature:" fraLicht.Caption = "Light:" optDuister.Caption = "Dark" optLicht.Caption = "Light" fraRegelaar.Caption = "Regulator:" lblTemp.Caption = "Current temperature:" Case 2 lblWind.Caption = "Vent" lblSetpoint.Caption = "Température désirée:" fraLicht.Caption = "Clarté:" optDuister.Caption = "Nuit" optLicht.Caption = "Jour" fraRegelaar.Caption = "Régulateur:" lblTemp.Caption = "Température présente:" Case 3 lblWind.Caption = "Wind" lblSetpoint.Caption = "Gewenste temperatuur:" fraLicht.Caption = "Lichtsterkte:" optDuister.Caption = "Donker" optLicht.Caption = "Licht" fraRegelaar.Caption = "Regelaar:" lblTemp.Caption = "Huidige temperatuur:" Case 4 lblWind.Caption = "Wind" lblSetpoint.Caption = "Gewünschte Temperatur:" fraLicht.Caption = "Licht:" optDuister.Caption = "Dunkel" optLicht.Caption = "Licht" fraRegelaar.Caption = "Regler" lblTemp.Caption = "Heutige Temperatur:" End Select ' Now we’ve set a standard variable: ' With .Value we can change the value of the object hscSetpoint.Value = 23 ' Here we dedicate the value of the scroll-bar to the variable “intSetpoint” intSetpoint = hscSetpoint.Value lblPv.Caption = CInt(dblProceswaarde) & "°C" intWaarde = 2000 intToevoer = (10 * (intWaarde / 100)) / 6
23
optPid.Value = True optLicht.Value = True ' For inserting and remembering the values of the variables from the controller: ' The "TextBox" .Text is used, so the user can give a value for the variable, ' because its after the equality sign, so the first variable gets the value of the second ' one dblKr = txtKr.Text dblTi = txtTi.Text dblTd = txtTd.Text ' The standard option for the controller is the PID controller, ' With .Visible we can make a object visible or invisible, depending on the ' value of the expression: "True" or "False" If optPid.Value = True Then lblTd.Visible = True txtTd.Visible = True lblTi.Visible = True txtTi.Visible = True lblKr.Visible = True txtKr.Visible = True lblHysteresis.Visible = False txtHysteresis.Visible = False End If ' settings of the properties of the "PictureBox" for drawing a graph pctGrafiek.Cls pctGrafiek.ScaleMode = 3 pctGrafiek.ScaleHeight = 110 pctGrafiek.ScaleWidth = 100 pctGrafiek.AutoRedraw = True pctGrafiek.ForeColor = vbCyan pctGrafiek.DrawStyle = 0 pctGrafiek.DrawWidth = 1 End Sub
24
3.2.3 Change the setpoint There are three ways to change the value : 1. With the button « +5 » 2. With the button « -5 » 3. With the slidebar With the +5 and -5 buttons we’re able to give a immediate change which is clearly visible. With these buttons we’re able to simulate a step response to see how the process would react on a change.
The button « +5 » :
Figure 29: the button +5
The code : Private Sub cmdPlus5_Click() ' When we click the button, the value of the setpoint will be increased by 5 intSetpoint = intSetpoint + 5 ' The loop "If - End If": ' If Then ' ' End If ' We set the max limit of the setpoint at 40°C: If intSetpoint > 40 Then intSetpoint = 40 End If hscSetpoint.Value = intSetpoint End Sub
The button « -5 » :
Figure 30: The button -5
25
The code : Private Sub cmdPlus5_Click() ' When we click the button, the value of the setpoint will be decreased by 5 intSetpoint = intSetpoint – 5 ' We set the min limit of the setpoint at -10°C: If intSetpoint > -10 Then intSetpoint = -10 End If hscSetpoint.Value = intSetpoint End Sub
The scroll-bar:
Figure 31: scroll-bar for the temperature
The code: Private Sub hscSetpoint_Change() ' When we change the setpoint with the scroll-bar, the routine _Change() takes place ' When the temperature is positive, the text will be red if negative the text will be ' blue: If hscSetpoint.Value > 0 Then lblSetpoint2.ForeColor = &HFF& Else lblSetpoint2.ForeColor = &HC00000 End If intSetpoint = hscSetpoint.Value lblSetpoint2.Caption = hscSetpoint.Value & "°C" End Sub
26
3.2.4 Exit button
Figure 32: the exit button
the code: Private Sub cmdSluiten_Click() ' Click this button and the program closes End End Sub
3.2.5 Choose the force of the wind
Figure 33: scroll-bar for the force of the wind
The code : Private Sub hscWind_Change() ' With the "Case" structure, the beaufort scale will be decided Select Case hscWind.Value Case Is 117 strBeaufort = "12-14" Case Else End Select lblWindtext.Caption = hscWind.Value & " km/h " & "- Beaufort: " & strBeaufort If optDuister.Value = True Then ' When it’s night the blinds got to go down if the force of the wind is not to high ' the outside lights are on If hscWind.Value > 70 Then ' If the force of the wind is higher than 70 km/h, the blinds got to stay open, ' the outside lights are on img3d.Picture = LoadPicture(App.Path & "\licht_op.bmp") Else 'Le force du vent est moins que 70 km/h, les stores peuvent descendre img3d.Picture = LoadPicture(App.Path & "\licht_af.bmp") End If Else ' When its day, the blinds got to be open ' the outside lights are off img3d.Picture = LoadPicture(App.Path & "\standaard.bmp") End If End Sub
3.2.6 The option day When we choose “Light”, the lighs are off.
Figure 34: the option day
The code :
Private Sub optLicht_Click() ' When we choose the option "Light", the lights are off. img3d.Picture = LoadPicture(App.Path & "\standaard.bmp")
28
End Sub
When we choose for “Dark”, the lights are on and the stores are open or closed, depending on the force of the wind.
Figure 35: choose option Dark
The code: Private Sub optDuister_Click() ' When we choose "Dark", the outside lights are on ' and the stores are open or closed, depending on the force of the wind If hscWind.Value > 70 Then ' Blinds are open: Force of the wind > 70km/u) img3d.Picture = LoadPicture(App.Path & "\licht_op.bmp") Else ' Blinds are closed: Force of the wind < 70km/u) img3d.Picture = LoadPicture(App.Path & "\licht_af.bmp") End If End Sub
29
3.2.7 Choice of the controller When we choose the PID regulator,
Figure 36: choose the PID
The options of the PID regulator will become visible.
Figure 37: variables of the PID
The code: Private Sub optPid_Click() ' When we choose for the PID regulator, ' the program makes the "TextBox" for the variables visible. ' it works with the option .Visible lblTd.Visible = True txtTd.Visible = True lblTi.Visible = True txtTi.Visible = True lblKr.Visible = True txtKr.Visible = True lblHysteresis.Visible = False txtHysteresis.Visible = False End Sub
When we choose the regulator On/Off,
Figure 38: when we choose On/Off
The program makes the “TextBox” visible to adjust the hysteresis.
30
Figure 39: hysteresis
the code : Private Sub optOnOff_Click() ' When we choose for the regulator On/Off, ' the program makes the "TextBox" visible for adapt the hysteresis. ' you make the options visible with the command .Visible lblTd.Visible = False txtTd.Visible = False lblTi.Visible = False txtTi.Visible = False lblKr.Visible = False txtKr.Visible = False lblHysteresis.Visible = True txtHysteresis.Visible = True End Sub
31
3.2.8 The Timer We need a « Timer » because the program got to work in a loop until it gets closed. Private Sub Timer1_Timer() ' define the variable "intVerandering" intVerandering = (intVerandering * 30) / 60 On Error Resume Next ' When the value txtKr, txtTi, or txtTd are more than 100, ' they will be 100 and when they are less 0, ' they will be 0. The hysteresis is also limited. ' between 1 and 7. If txtKr < 0 Then txtKr = 0 End If If txtKr > 100 Then txtKr = 100 End If dblKr = Val(txtKr) If txtTi < 0 Then txtTi = 0 End If If txtTi > 100 Then txtTi = 100 End If dblTi = Val(txtTi) If txtTd < 0 Then txtTd = 0 End If If txtTd > 100 Then txtTd = 100 End If dblTd = Val(txtTd) If txtHysteresis < 1 Then txtHysteresis = 1 End If If txtHysteresis > 7 Then txtHysteresis = 7 End If '----------------------------------------------------' Calculate the error, the difference between the setpoint and the procesvalue. lblPv.Caption = CInt(dblProceswaarde) & "°C" dblError = intSetpoint - dblProceswaarde lblError.Caption = CInt(dblError)
32
' Code for load the loop of the PID regulator If optPid.Value = True Then ' Code for visualize the temperature if its out of the graph. If dblProceswaarde < 50 Then dblProceswaarde = dblProceswaarde + intToevoer End If If dblProceswaarde > -10 Then dblProceswaarde = dblProceswaarde - intVerandering End If pid End If ' Code for load the loop of the On/Off regulator If optOnOff.Value = True Then aan_uit End If ' Code for the graph and to showing the temperature pctGrafiek.Cls intPvgrafiek(100) = dblProceswaarde For intX = 0 To 99 intPvgrafiek(intX) = intPvgrafiek(intX + 1) pctGrafiek.PSet (intX, 70 - (intPvgrafiek(intX))) Next intX ' Code to show the setpoint in the graphic ' With .Line we draw a line (in yellow -> vbYellow) pctGrafiek.Line (0, 70 - intSetpoint)-(100, 70 - intSetpoint), vbYellow End Sub
33
3.2.9 The PID regulator The code for the PID regulator: Private Sub pid() ' We use a filter to limite the D action intFilter = 10 ' The input of the regulator is the actual temperature multiplied with the difference from ' the last temperature ' the variable Td dblInputD = dblProceswaarde + (dblVorige - dblProceswaarde) * (dblTd / 60) ' to remember the last measure of the temperature dblVorige = dblProceswaarde dblInputDF = dblInputDF + (dblInputD - dblInputDF) * intFilter / 60 dblOutput = (intSetpoint - dblInputDF) * (dblKr / 100) + dblFeedback ' To clamp the output between 0 and 100% If dblOutput > 100 Then dblOutput = 100 End If If dblOutput < 0 Then dblOutput = 0 End If ' Give the changes intVerandering = 100 - dblOutput dblFeedback = dblFeedback - (dblFeedback - dblOutput) * dblTi / 60 '--------------------------------------------------------------------------------' To show the correct images, we made the program in two parts: ' One part when it’s dark, and the other part when its light ' When its dark (optDuister.Value=true): If optDuister.Value = True Then If dblProceswaarde > intSetpoint Then ' the actual temperature is higher than the setpoint imgDoorsnede.Picture = LoadPicture(App.Path & "\verwarming_min_licht_aan.bmp") End If If dblProceswaarde < intSetpoint Then ' the actual temperatuur is lower than the setpoint imgDoorsnede.Picture = LoadPicture(App.Path & "\verwarming_veel_licht_aan.bmp") End If If dblProceswaarde = intSetpoint Then ' the actual temperatuur and the setpoint are equal imgDoorsnede.Picture = LoadPicture(App.Path & "\verwarming_aan_licht_aan.bmp") End If End If '----------------------------------------------------------------------------------
34
' When it’s light (optLicht.Value=true): If optLicht.Value = True Then If dblProceswaarde > intSetpoint Then ' the actual temperature is higher than the setpoint imgDoorsnede.Picture = LoadPicture(App.Path & "\verwarming_min_licht_uit.bmp") End If If dblProceswaarde < intSetpoint Then ' the actual temperature is lower than the setpoint imgDoorsnede.Picture = LoadPicture(App.Path & "\verwarming_veel_licht_uit.bmp") End If If dblProceswaarde = intSetpoint Then ' the actual temperatuur and the setpoint are equal imgDoorsnede.Picture = LoadPicture(App.Path & "\verwarming_aan_licht_uit.bmp") End If End If End Sub
3.2.10
The On/Off regulator
The code of the On/Off regulator: Private Sub aan_uit() intSetpoint = hscSetpoint.Value intHysteresis = Val(txtHysteresis) ' There is a min and max limit for the band of the hysteresis ' "intOnder" is the lower limit ' "intBoven" is the upper limit intOnder = intSetpoint - intHysteresis intBoven = intHysteresis + intSetpoint ' To show the correct images, we made the program in two parts: ' One part when it’s dark, and the other when it’s light ' When it’s day (optLicht.Value=true): If optLicht.Value = True Then If (dblProceswaarde < intOnder) Or (dblProceswaarde > intBoven) Then ' When the actual temperature is lower than the lower limit or higher than the upper limit. If dblProceswaarde >= intBoven Then ' When the actual temperature is higher or equal than the upper limit, ' the output has to decrease dblProceswaarde = dblProceswaarde - 1 imgDoorsnede.Picture = LoadPicture(App.Path & "\verwarming_uit_licht_aan.bmp") End If
35
If dblProceswaarde = intBoven Then ' When the actual temperature is higher or equal than the upper limit, ' the output has to decrease dblProceswaarde = dblProceswaarde - 1 imgDoorsnede.Picture = LoadPicture(App.Path & "\verwarming_uit_licht_aan.bmp") End If If dblProceswaarde 40 Then intSetpoint = 40 52
End If hscSetpoint.Value = intSetpoint End Sub ____________________________________ Private Sub cmdSluiten_Click() End End Sub ____________________________________ Private Sub Form_load() frmProject.Left = (Screen.Width / 2) - (frmProject.Width / 2) frmProject.Top = (Screen.Height / 2) - (frmProject.Height / 2) imgDoorsnede.Picture = LoadPicture(App.Path & "\verwarming_aan_licht_uit.bmp") img3d.Picture = LoadPicture(App.Path & "\standaard.bmp") Select Case intTaal Case 1 lblWind.Caption = "Wind" lblSetpoint.Caption = "Desired temperature:" fraLicht.Caption = "Light:" optDuister.Caption = "Dark" optLicht.Caption = "Light" fraRegelaar.Caption = "Regulator:" lblTemp.Caption = "Current temperature:" Case 2 lblWind.Caption = "Vent" lblSetpoint.Caption = "Température désirée:" fraLicht.Caption = "Clarté:" optDuister.Caption = "Nuit" optLicht.Caption = "Jour" fraRegelaar.Caption = "Régulateur:" lblTemp.Caption = "Température présente:" Case 3 lblWind.Caption = "Wind" lblSetpoint.Caption = "Gewenste temperatuur:" fraLicht.Caption = "Lichtsterkte:" optDuister.Caption = "Donker" optLicht.Caption = "Licht" fraRegelaar.Caption = "Regelaar:" lblTemp.Caption = "Huidige temperatuur:" Case 4 lblWind.Caption = "Wind" lblSetpoint.Caption = "Gewünschte Temperatur:" fraLicht.Caption = "Licht:" optDuister.Caption = "Dunkel" optLicht.Caption = "Licht" fraRegelaar.Caption = "Regler"
53
lblTemp.Caption = "Heutige Temperatur:" End Select hscSetpoint.Value = 23 intSetpoint = hscSetpoint.Value lblPv.Caption = CInt(dblProceswaarde) & "°C" intWaarde = 2000 intToevoer = (10 * (intWaarde / 100)) / 6 optPid.Value = True optLicht.Value = True dblKr = txtKr.Text dblTi = txtTi.Text dblTd = txtTd.Text If optPid.Value = True Then lblTd.Visible = True txtTd.Visible = True lblTi.Visible = True txtTi.Visible = True lblKr.Visible = True txtKr.Visible = True lblHysteresis.Visible = False txtHysteresis.Visible = False End If pctGrafiek.Cls pctGrafiek.ScaleMode = 3 pctGrafiek.ScaleHeight = 110 pctGrafiek.ScaleWidth = 100 pctGrafiek.AutoRedraw = True pctGrafiek.ForeColor = vbCyan pctGrafiek.DrawStyle = 0 pctGrafiek.DrawWidth = 1 End Sub ____________________________________ Private Sub hscWind_Change() Select Case hscWind.Value Case Is 117 strBeaufort = "12-14" Case Else End Select lblWindtext.Caption = hscWind.Value & " km/h " & "- Beaufort: " & strBeaufort If optDuister.Value = True Then If hscWind.Value > 70 Then img3d.Picture = LoadPicture(App.Path & "\licht_op.bmp") Else img3d.Picture = LoadPicture(App.Path & "\licht_af.bmp") End If Else img3d.Picture = LoadPicture(App.Path & "\standaard.bmp") End If End Sub Private Sub optDuister_Click() If hscWind.Value > 70 Then img3d.Picture = LoadPicture(App.Path & "\licht_op.bmp") Else img3d.Picture = LoadPicture(App.Path & "\licht_af.bmp") End If End Sub ____________________________________ Private Sub optLicht_Click() img3d.Picture = LoadPicture(App.Path & "\standaard.bmp") End Sub ____________________________________ Private Sub optOnOff_Click() lblTd.Visible = False
55
txtTd.Visible = False lblTi.Visible = False txtTi.Visible = False lblKr.Visible = False txtKr.Visible = False lblHysteresis.Visible = True txtHysteresis.Visible = True End Sub ____________________________________ Private Sub optPid_Click() lblTd.Visible = True txtTd.Visible = True lblTi.Visible = True txtTi.Visible = True lblKr.Visible = True txtKr.Visible = True lblHysteresis.Visible = False txtHysteresis.Visible = False End Sub ____________________________________ Private Sub Timer1_Timer() intVerandering = (intVerandering * 30) / 60 On Error Resume Next If txtKr < 0 Then txtKr = 0 End If If txtKr > 100 Then txtKr = 100 End If dblKr = Val(txtKr) If txtTi < 0 Then txtTi = 0 End If If txtTi > 100 Then txtTi = 100 End If dblTi = Val(txtTi) If txtTd < 0 Then txtTd = 0 End If If txtTd > 100 Then txtTd = 100 End If dblTd = Val(txtTd) If txtHysteresis < 1 Then
56
txtHysteresis = 1 End If If txtHysteresis > 7 Then txtHysteresis = 7 End If lblPv.Caption = CInt(dblProceswaarde) & "°C" dblError = intSetpoint - dblProceswaarde lblError.Caption = CInt(dblError) If optPid.Value = True Then If dblProceswaarde < 50 Then dblProceswaarde = dblProceswaarde + intToevoer End If If dblProceswaarde > -10 Then dblProceswaarde = dblProceswaarde - intVerandering End If pid End If If optOnOff.Value = True Then aan_uit End If pctGrafiek.Cls intPvgrafiek(100) = dblProceswaarde For intX = 0 To 99 intPvgrafiek(intX) = intPvgrafiek(intX + 1) pctGrafiek.PSet (intX, 70 - (intPvgrafiek(intX))) Next intX pctGrafiek.Line (0, 70 - intSetpoint)-(100, 70 - intSetpoint), vbYellow End Sub ____________________________________ Private Sub hscSetpoint_Change() If hscSetpoint.Value > 0 Then lblSetpoint2.ForeColor = &HFF& Else lblSetpoint2.ForeColor = &HC00000 End If intSetpoint = hscSetpoint.Value lblSetpoint2.Caption = hscSetpoint.Value & "°C" End Sub ____________________________________ Private Sub pid() intFilter = 10 dblInputD = dblProceswaarde + (dblVorige - dblProceswaarde) * (dblTd / 60) dblVorige = dblProceswaarde dblInputDF = dblInputDF + (dblInputD - dblInputDF) * intFilter / 60
57
dblOutput = (intSetpoint - dblInputDF) * (dblKr / 100) + dblFeedback If dblOutput > 100 Then dblOutput = 100 End If If dblOutput < 0 Then dblOutput = 0 End If intVerandering = 100 - dblOutput dblFeedback = dblFeedback - (dblFeedback - dblOutput) * dblTi / 60 If optDuister.Value = True Then If dblProceswaarde > intSetpoint Then imgDoorsnede.Picture = LoadPicture(App.Path & "\verwarming_min_licht_aan.bmp") End If If dblProceswaarde < intSetpoint Then imgDoorsnede.Picture = LoadPicture(App.Path & "\verwarming_veel_licht_aan.bmp") End If If dblProceswaarde = intSetpoint Then imgDoorsnede.Picture = LoadPicture(App.Path & "\verwarming_aan_licht_aan.bmp") End If End If If optLicht.Value = True Then If dblProceswaarde > intSetpoint Then imgDoorsnede.Picture = LoadPicture(App.Path & "\verwarming_min_licht_uit.bmp") End If If dblProceswaarde < intSetpoint Then imgDoorsnede.Picture = LoadPicture(App.Path & "\verwarming_veel_licht_uit.bmp") End If If dblProceswaarde = intSetpoint Then imgDoorsnede.Picture = LoadPicture(App.Path & "\verwarming_aan_licht_uit.bmp") End If End If End Sub ____________________________________ Private Sub aan_uit() intSetpoint = hscSetpoint.Value intHysteresis = Val(txtHysteresis) intOnder = intSetpoint - intHysteresis intBoven = intHysteresis + intSetpoint If optLicht.Value = True Then
58
If (dblProceswaarde < intOnder) Or (dblProceswaarde > intBoven) Then If dblProceswaarde >= intBoven Then dblProceswaarde = dblProceswaarde - 1 imgDoorsnede.Picture = LoadPicture(App.Path & "\verwarming_uit_licht_aan.bmp") End If If dblProceswaarde intBoven) Then If dblProceswaarde >= intBoven Then dblProceswaarde = dblProceswaarde - 1 imgDoorsnede.Picture = LoadPicture(App.Path & "\verwarming_uit_licht_aan.bmp") End If If dblProceswaarde