This example models a home climate control system by using a Truth Table block. Homes rarely maintain a constant climate without a climate control system in place, and occupants usually rely on automated systems to maintain a desired climate. Because temperature and humidity are dynamic, maintaining desired conditions requires consistent monitoring and adjusting. To model how a home activates different subsystems that maintain a desired climate, this model uses a Truth Table block to manage logical decision making.
In this example, the Truth Table block labeled
ClimateController controls all of the physical subsystem outputs. The block uses four inputs: the desired temperature
T_thresh, the actual home temperature
t, the desired humidity
H_thresh, and the actual home humidity
h. Double-click the block to see how the block uses the inputs to produce the outputs. The
ClimateController block includes two tables: the Condition Table and the Action Table.
The Condition Table shows how the inputs are logically evaluated, and illustrates the two comparisons made by the block and the four actions that can be taken. To execute the first action, the two conditions must be
True. If either condition is not
True, the block tests the conditions outlined in the next decision column, which requires only the first condition to be
True. This evaluation continues from left to right until a decision is made or the last decision column is reached, which then executes. In this example, the
- entries function like
False conditions. As a result, the block would behave the same way if the
- conditions were explicitly defined as
False. However, automatically generated code using only
False conditions may produce suboptimal code coverage. To avoid that issue, this example uses
In the first row, the block compares the home temperature to the desired temperature, and the home cooler and heater are controlled using the
HeatOn actions, respectively. When
t > T_thresh, the block activates the
CoolOn action. If this condition is not
True, the block activates the
HeatOn action. In the second row, the block compares the home humidity to the desired humidity, and the humidifier is controlled using the
HumidOn action. When
h < H_thresh, the block activates the
The Action Table defines the block outputs associated with each logical action. In the first row,
CoolOn sets the value of
1 and the value of
0. In the second row,
HeatOn sets the value of
1 and the value of
0. By default, the humidifier is
0 unless the block enables
In the model, the green blocks labeled
Heater represent the physical subsystems that regulate the climate of the home. The
Humidifier subsystem includes a Switch block that engages from the output of the
ClimateController block. If the input to the
Humidifier subsystem is
1, the subsystem outputs
1.5. Otherwise, the subsystem outputs a value of
Cooler subsystems work on similar principles. They each include two Switch blocks. One Switch block outputs a value that affects the temperature, which is the output at the dt and dt1 ports for the
Heater, respectively. The other Switch block outputs a value that affects the humidity, which is output at the dh and dh1 ports for the
Heater, respectively. If
cooler = 1, the
Cooler subsystem activates, and if
heater = 1, the
Heater subsystem activates. When engaged, the
Heater subsystem outputs
1 at dt1, and the
-1 at dt. Both subsystems output
-0.5 at dh and dh1 when engaged.
Due to how the
ClimateController block is configured, the
Heater subsystems will not activate at the same time.
External heat and humidity also affect the climate of the home. The model represents the effect of these conditions as heat and humidity flow. The
externalHeatFlow subsystem models external heat flow, and the
externalHumidityFlow subsystem models external humidity flow. The
externalHeatFlow subsystem takes the difference between the external and internal temperatures and multiplies the difference by a coefficient.
Higher values of the coefficient represent larger heat flows, which occur in less insulated homes. Although the
externalHumidityFlow subsystem represents a different physical behavior than
externalHumidityFlow subsystem uses the same arrangement of blocks and connections. The
externalHumidityFlow subsystem takes the difference between between the external and internal humidities and multiplies the difference by a coefficient.
Running the model populates the two Floating Scope blocks. The Scope block labeled
temperatureScope displays the external temperature (
ET) and the home temperature (
The Scope block labeled
humidityScope plots the external humidity (
EH) and the home humidity (
The simulation is configured to run indefinitely. To stop the simulation, you can stop it manually by pressing the Stop button or by adjusting the stop time before running the simulation.
You can adjust the external temperature by using a different external temperature signal or by modifying the signal amplitude. Try adjusting the amplitude of the Sine Wave blocks, externalTemp and externalHumid, and observe how the model responds.
Other homes may not be as insulated or might have more effective climate control subsystems. These physical differences affect the outputs of the subsystems. Try adjusting the
Cooler subsystem outputs by changing the Constant block values.