The Xfuzzy 3 development environment
The simulation tool - Xfsim
The xfsim tool is dedicated to study feedback systems. The tool implements a simulation of the system behavior connected to the plant. The tool can be executed from the command line with the expression "xfsim file.xfl [file.cfg]", or from the main window of the environment with the option "Simulation" in the Verification menu.
The main window of xfsim is shown in the figure. The configuration of the simulation process is made at the left side of the window, while the right side shows the status of the feedback system. The bottom of the window contains a menu bar with the options "Load", "Save", "Run/Stop", "Reload" and "Close". The first option is used to load a configuration for the simulation process. The second one saves the present configuration on an external file. The Run/Stop option is used to start and stop the simulation process. The Reload option rejects the current simulation and reinitializes the tool. The last option exits the tool.
The configuration of a simulation process is done by the selection of the plant model connected with the fuzzy system and the description of the plant initial values, the end conditions, and a list of desired outputs for the simulation process. These outputs can be a log file to save the values of some selected variables, and graphical representations of these variables. The simulation status contains the number of iterations, the elapsed time for the initialization of the simulation, the values of the fuzzy system input variables, which represent the plant status, and the values of the fuzzy system output variables, which represent the action of the fuzzy system on the plant.
The plant connected to the fuzzy system is described by a file with '.class' extension, containing the Java binary code of a class describing the plant behavior. This class must implement the interface xfuzzy.PlantModel whose code is the following:
The function init() is used to initialize the plant with its default values, and must generate an exception when these values are not defined or cannot be assigned to the plant. The function init( double) is used to set the initial values of the plant status to the selected values. It also generates an exception when these values cannot be assigned to the plant. The function state() returns the values of the plant status, which correspond to the input variables of the fuzzy system. Finally, the function compute (double) modifies the plant status in terms of the fuzzy system output values. The user must write and compile this class on his own.
Defining a plant by a Java class offers a great flexibility to describe external systems. The simplest way consists in describing a mathematical model of the evolution of the plant from its state and the output values of the fuzzy system. In this scheme, the functions init and state assign and return, respectively, the values of the inner status variables, while the compute function implements the mathematical model. A more complex scheme consists in using a real plant connected to the computer (usually by a data acquisition board). In this case, the function init must initialize the data acquisition system, the function state must capture the current state of the plant, and the function compute must write the action on the data acquisition board as well as capture the new status of the plant.
The configuration of the simulation process also requires the introduction of some end conditions. The window for selecting them contains a set of fields with the limit values of the simulation state variables.
The initial state of the plant is described by using the following window. It contains a set of fields related to the plant variables, which correspond to the fuzzy system input variables.
The xfsim tool can provide graphical representations of the simulation process, as well as, saving the simulation results into a log file. The Insert key is used to introduce a new representation, as usual. This will open a window asking for the type of representation: either a log file, or a graphical plot. The window for describing a log file has a field to select the name of the file, and some buttons to choose the variables to be saved.
The window for describing the graphical representation contains two pulldown lists to select the variable assigned to the X and Y axis, and a set of buttons to choose the representation style.
The configuration of a simulation process can be saved to an external file, and loaded from a previously saved file. The contents of this file is composed by the following directives:
The directive xfsim_plant contains the file name of the Java binary code file describing the plant. The directive xfsim_init contains the value of the initial state of the plant. If this directive does not appear in the configuration file, the default initial state is assumed. The directive xfsim_limit contains the definition of the end conditions, which are expressed as a set of limits separated by the character &. The format of each limit is "variable < value" for the upper limits, and "variable > value" for the lower limits. The log files are described in the directive xfsim_log, which includes the name of the log file and the list of the variables to be saved. The graphical representations are defined by the directive xfsim_plot, which includes the names of the variables assigned to the X and Y axis, and the representation style. A style value of 0 means a plot with lines; value 1 indicates a dotted plot; value 2 makes the plot to use squares; and values 3, 4 and 5 indicate the use of circles of different sizes.
The next figure shows an example of a Java class implementing the plant model of a vehicle. This model can be connected to the fuzzy System Backward included in the Xfuzzy examples. The state of the vehicle is stored in the internal variable state. The functions init just assign the values to the state components: the first component is the X position; the second is the orientation of the vehicle with respect to a reference direction (phi); the third one is the Y position and the last one contains the current value of the angle of rotation of the wheels (gamma). These components correspond to the input variables of the fuzzy system. The function state returns the internal variable values. The vehicle dynamics is described by the function compute. The inputs to this function are the output variables of the fuzzy system. So, val contains the target value of the variable gamma (gref), while val  contains the output value of the first rule base (alpha), which is not used in the model. The change in the angle of rotation of the vehicle does not occur instantaneously, but has a certain inertia characterized by a time constant defined in the model. In each iteration, the new value of the gamma variable causes a change in the orientation angle and the position of the vehicle.
Once the plant model is described, the user must compile it to generate the .class binary file. Be aware of the value of the environment variable CLASSPATH, as it must contain the path to the interface definition. Hence, CLASSPATH must include the route "base/xfuzzy.jar", where base refers to the installation directory of Xfuzzy. (Note: in MS-Windows the path must include the route "base\xfuzzy.jar". Be aware of the separator).
The following graphs show the trajectories followed by the vehicle when
parking starts with different initial conditions.
The following graphs show the trajectories followed by the vehicle when parking starts with different initial conditions.
x = 0, y = 7, phi = 170
x = 6, y = 6, phi = -45
x = -10, y = 3, phi = 0
For comments, patches, bug reports, etc contact us at: