Exercise 6: Control and Simulation in LabVIEW (Solutions)
Transcript of Exercise 6: Control and Simulation in LabVIEW (Solutions)
EE4107 -‐ Cybernetics Advanced
Faculty of Technology, Postboks 203, Kjølnes ring 56, N-3901 Porsgrunn, Norway. Tel: +47 35 57 50 00 Fax: +47 35 57 54 01
Exercise 6: Control and Simulation in LabVIEW (Solutions) In this task you will learn how to use the Simulation palette in LabVIEW.
You need the “LabVIEW Control Design and Simulation Module” for this Task.
Below we see the Simulation palette in LabVIEW:
It is recommended that you watch the video “Simulation Palette Overview” (about 15 minutes) by Finn Haugen before you start with the exercises.
Task 1: Bacteria Simulation
In this task we will use LabVIEW and the LabVIEW Control Design and Simulation Module to simulate a simple model of a bacteria population in a jar.
The model is as follows:
birth rate=bx
death rate = px2
2
EE4107 -‐ Cybernetics Advanced
Then the total rate of change of bacteria population is:
𝒙 = 𝒃𝒙 − 𝒑𝒙𝟐
Set b=1/hour and p=0.5 bacteria-‐hour
We will simulate the number of bacteria in the jar after 1 hour, assuming that initially there are 100 bacteria present.
Task 1.1
Draw Block Diagram for the system using “pen and paper”.
Solution:
Block diagram for the system:
Task 1.2
Simulate the system in LabVIEW, where you follow these steps:
1. Start LabVIEW and use the Control and Simulation Loop from Control Design and Simulation Palette in LabVIEW
2. Drag in the necessary Blocks from the palette (including the plot). 3. Use the “Connection Wire” from the Tools palette and draw the necessary wires. 4. Configure Simulation Parameters (right-‐click on the Control and Simulation Loop border) 5. Start the Simulation. The Simulation result should be present in a plot.
3
EE4107 -‐ Cybernetics Advanced
Solution:
Below you see the “Control and Simulation Loop” and different blocks that may be used in this simulation:
We can may also use the “Multiplication” blocks instead of the “Gain” blocks:
The simulation results should look like this:
4
EE4107 -‐ Cybernetics Advanced
The Simulation parameters are used:
Task 2: Spring-‐mass damper system
Use “LabVIEW Control Design and Simulation Module” and the “Control and Simulation Loop” in order to create a simulation of a spring-‐mass damper system.
The differential equation for the system is as follows:
𝑥 =1𝑚(𝐹 − 𝑐𝑥 − 𝑘𝑥)
Where.
𝐹 is an external force applied to the system
5
EE4107 -‐ Cybernetics Advanced
𝑐 is the damping constant of the spring
𝑘 is the stiffness of the spring
𝑚 is a mass
𝑥 is the position of the mass
𝑥 is the first derivative of the position, which equals the velocity of the mass
𝑥 is the second derivative of the position, which equals the acceleration of the mass
Task 2.1
Draw Block Diagram for the system using “pen and paper”.
Solution:
Block Diagram:
Note! 𝑐 = 𝑑 = damping constant of the spring in the figures.
You may also use this notation:
6
EE4107 -‐ Cybernetics Advanced
Task 2.2
Implement and simulate the system in LabVIEW.
Simulate and plot the position (𝑥), the velocity (𝑥), and the acceleration (𝑥) in 3 different plots.
In the simulations you may set 𝐹 = −9.8,𝑚 = 1, 𝑐 = 1 𝑎𝑛𝑑 𝑘 = 100
Then try to set 𝑚 = 10𝑘𝑔 and see the difference. Try also different values for 𝑐 and 𝑘 and see what happens. Try to explain the results.
Solution:
Block Diagram:
The Simulation Parameters are used:
7
EE4107 -‐ Cybernetics Advanced
Front Panel and Simulation results:
𝑚 = 1𝑘𝑔:
𝑚 = 10𝑘𝑔:
Task 3: PID Control
In this task you will use the example “General PID Simulator.vi” as a base for your simulation. Use the “NI Example Finder” (Help → Find Examples… in the LabVIEW menu) in order to find the VI in LabVIEW.
Task 3.1
Run the example and see how it is implemented and how it works.
8
EE4107 -‐ Cybernetics Advanced
Task 3.2
Replace the function “PID.vi” with the more advanced function “PID Advance.vi” instead.
Note! Make sure to save it with another name!
Task 3.3
Change 𝑇! and 𝑇! so the unit is seconds instead of minutes on your Front Panel (User Interface).
The functions “PID.vi” and “PID Advanced.vi” requires that 𝑇! and 𝑇! is in minutes, while it’s normal to use seconds as the unit for these parameters. You can use the following piece of code in order to transform them:
Run simulations and find proper values for 𝐾! 𝑇! and 𝑇!.
Solutions:
Front Panel:
9
EE4107 -‐ Cybernetics Advanced
Block Diagram:
The following PI(D) parameters are used in the simulations:
𝐾! = 20
𝑇! = 0.48𝑠
𝑇! = 0𝑠
Additional Resources
Basic LabVIEW programming:
• Tutorial: Introduction to LabVIEW: http://home.hit.no/~hansha/?tutorial=labview • LabVIEW Starter: http://home.hit.no/~hansha/training/labview/starter
Control and Simulation:
• http://home.hit.no/~hansha/?lab=control_simulation
Here you will find additional tasks, tutorials and other resources.
Videos:
• Simulation Palette Overview (about 15 minutes) by Finn Haugen.