This demonstration of Fuzzy Logic has been created using the FuzzyJ Toolkit for the Java(tm) platform that was created at the National Research Council of Canada. The code for this demo is a hybrid of Java(tm) code and the rule based expert system Jess from Sandia National Laboratories. Another version is written entirely in Java. Although the Java version is smaller (since it does not include) all of the required Jess system, it is less flexible from the standpoint of creating expert systems. The Jess rules are easier to read, understand and maintain than the equivalent Fuzzy rules in Java. Also the Fuzzy rules in the Java toolkit do not provide the sophisticated pattern matching capabilities of the Jess environment.
This simple demo shows the control of a crudely simulated shower (assumes perfect and instantaneous mixing). There are 10 rules used to control the shower. These rules are not really adequate or optimized in any way, but with them and some simple coded heuristics for checking error situations, they do a good job of keeping the shower under control. The object is to get a flow close to 12 litres/min and a temperature close to 36_ C.
If the show rule firings checkbox is on a second window will open and results of the rule firings on each cycle of the inferencing will be displayed (a cycle is a firing of all rules whose conditions are matched and the global combination of the outputs of these rules, followed by a defuzzification of the global outputs to change the hot and cold valve positions). The user can operate in manual mode or let the system do control by setting the auto Fuzzy control checkbox. In manual mode, the user can try moving the sliders and getting the temperature and flow in the target ranges. The values of the output flow and temperature will show with a green background when the conditions are satisfied. When in auto Fuzzy control mode things happen very fast and it is difficult to see all that is happening. To slow things down enter the number of milliseconds to delay between rule firings in the text box labeled Milliseconds between inference cycles at the bottom left.
The hot and cold pressures can be controlled by moving the slider positions (low limit of slider is 30, corresponding to atmospheric pressure and high limit is 90). The hot and cold temperature sliders can also be moved (low limit of 5 and high limit of 65). When in manual mode the hot and cold valve positions are also controllable by the user.
An example of a Jess rule:
(defrule cold_OK
"if temp
cold and pressure OK then change cold valve positive medium
and change hot valve zero"
(temp
?t&:(fuzzy-match ?t "cold"))
(flow
?f&:(fuzzy-match ?f "OK"))
=>
(assert
(change_hv (new FuzzyValue ?*hotValveChangeFvar* "PM"))
(change_cv (new FuzzyValue ?*coldValveChangeFvar* "Z"))
)
To start the demo press the button below
and a separate window will appear.