          ------------------------------------------------------------
          Fuzzy-Pong Demo: Fuzzy Controller Outperforms PID Controller
          ------------------------------------------------------------

A fuzzy logic controller which moves a ping-pong ball inside a vertical tube
was developed by the TIL applications engineering staff to demonstrate how a
fuzzy controller performs better than a traditional PID controller.  In this
application, a ping-pong ball is moved between two setpoints by varying the
voltage applied to a fan connected to the bottom of the tube as shown in Figure
2 [not present in this text-only version].  The controller was developed for
the Hitachi H8/325 Evaluation board.  Building on a previous, independently
developed PID control scheme, the fuzzy controller simply replaced the PID
equations in the source code of the controller, with the rest of the original
code left intact.

The physical system consists of the tube with the fan attached to the bottom,
an ultrasonic transducer mounted on the fan guard for position sensing, the
sensor control hardware, fan speed control hardware, a power supply, a ping-
pong ball and the H8/325 Evaluation board.  The evaluation board is also
connected to a PC through a serial port to provide information on the system to
the outside world, but all control processing is carried out on the board
itself.  

The inputs to the fuzzy system are Error, the difference between the setpoint
and the current position, and dError, the difference between the present Error
and the previous Error.  The output of the controller is a number which sets
the voltage supplied to the fan through pulse width modulation carried out by
the H8/325.  The inputs were scaled to ensure they remained within the
specified universe of discourse, and the range of output values allowed was
determined by manually varying the voltage applied to the fan and observing the
effects on the position of the ping-pong ball.  The voltage settings necessary
to raise the ball quickly and slowly, drop the ball quickly and slowly, and
hold the ball steady were determined in this manner and incorporated into five
triangular output membership functions.

Next, the membership functions for the inputs were determined by running the
original controller and observing the range of values that Error and dError
covered.  These values were then scaled, and membership functions were
developed for the scaled values.   Initially, general, evenly spaced sets of
five membership functions for both Error and dError were created.

An initial rulebase was developed after a cursory analysis of the dynamics of
the physical system.  Beginning with the assumption that the desired response
was to move the ball from one setpoint to another as quickly as possible with
as little overshoot and undershoot as possible, a rulebase which would provide
maximum acceleration while the ball was "far" from the setpoint and switch to
maximum deceleration as the ball came "near" the setpoint was defined, using
the membership functions defined for Error, dError, and the output.  The rules
shown in Figure 3 [not present in this text-only version] were created using
the notations NB, NS, Z, PS, and PB to represent negative big, negative small,
zero, positive small, and positive big, respectively, for the inputs, and DQ,
DS, M, RS, and RQ to represent drop quickly, drop slowly, maintain, raise
slowly and raise quickly, respectively, for the output.

These rules and the accompanying membership functions were defined using the
TILShell graphical user interface, and then converted into H8/300 assembly code
by the Togai InfraLogic MicroFPL Development System.  This assembly code was
assembled and linked using the Hitachi H8/300 development package, and
downloaded into the evaluation board.  The rules and membership functions were
tuned further by observing the response of the ball and then varying the rules
and membership functions to minimize overshoot, undershoot, and transition time
between setpoints.  The final rulebase is given in Figure 4, [not present in
this text-only version] where the shading indicates rule changes due to tuning.
 The resulting controller performed better than the PID controller (see Graphs
1 and 2 [not present in this text-only version]) by reducing overshoot and
undershoot while maintaining a rapid transition time.  The waveform of the
voltages supplied to the fan was also much smoother than that of the PID, and
the fuzzy controller was much less sensitive to changes in the setpoint values
than the PID controller.

A means of automating the tuning process was also investigated.  A preliminary
automatic membership function tuning utility for the input variables was
developed.  Several sets of these automatically generated membership functions
performed as well as the PID controller.  Further development of this utility
is progressing.
--
Copyright (c) Togai InfraLogic, 1992.  All rights reserved.
Permission to freely distribute this document, provided that it remains
complete and intact, is hereby granted.
