The Xfuzzy 3 development environment

The SysGen model generation tool - Xfsg

The xfsg hardware synthesis tool (Xfuzzy to System Generator) allows the automatic conversion of the XFL3 specification of a hierarchical fuzzy system, consisting of the combination of different inference modules and crisp blocks, into a Simulink model that can be simulated in the MATLAB environment and implemented on Xilinx FPGAs. However, not all XFL3 specifications are likely to be implemented through xfsg. In particular, fuzzy systems that can be implemented by this tool must employ functions or families of triangular membership functions with overlapping degree 2 and use simplified defuzzification methods.

The graphical user interface of xfsg can be invoked from the main window of the Xfuzzy environment, using the "To Sysgen" option in the Synthesis menu, or through the corresponding icon of the icon bar. The main window of xfsg is divided into five parts: a zone with information on the location and the name of the used files, a tree structure that shows the rule bases and crisp blocks that make up the system, an area that initially shows the interconnection of the different system components, a zone of global options, and a series of buttons located in the lower part of the window.

The zone of information about files and directories is divided into three fields. The Input XFL file field contains the absolute path of the XFL3 specification file selected when the tool is launched. This field is informative, it can not be modified by the user. The Name for Output files field allows you to configure the prefix of the xfsg output files. By default, the name of the input fuzzy system appears. Finally, the Output directory field indicates the absolute path of the directory where the output files generated by the tool will be located. In this case, the directory that contains the system specification appears by default.

The upper area of the window also includes a button (identified by the text XFSG) that, when pressed, displays a dialog box listing the different operators, defuzzification methods, types of membership functions and crisp blocks that may appear in fuzzy systems synthesized by the tool. These functions are defined in what is called the "xfsg package" in Xfuzzy terminology. To the right of the button is a text that advises the user to use only the functions included in this package to ensure that no problem will occur when implementing the system.

In the left central zone of the window the tree structure of the fuzzy system is shown, with the elements that compose it grouped under the categories RuleBases and CrispBlocks. Initially, or whenever the top level of the system specification is selected, a window with the components that make up the system and its interconnection appears in the right area. When a specific rule base is selected within the RuleBases category, the interface shown in the following figure appears in this zone, allowing to define the different parameters that dimension the inference module. Specifically, can be defined the number of bits used to encode inputs, output, antecedent membership degrees, and slopes of the membership functions. Also in this zone are displayed certain values calculated from the system specification. Specifically, the number of membership functions and the values of the breakpoints and slopes for each input, as well as the matrix representation of the corresponding rule base.

When a crisp block is selected in the tree structure, the right middle part of the interface shows a single field to be filled relative to the number of bits defined for the output of the block.

When all the parameters related to the rule base or the crisp block have been configured, it is necessary to press the Apply button to save the changes (otherwise the information entered in the form will be lost). After that, the red icon that appeared initially next to the knowledge base is replaced by the green icon shown in the figure. When the parameters of all the rule bases and crisp blocks that make up the system have been defined, a green icon appears next to the top level of the system specification and the Save Configuration and Generate Files buttons in the lower area of the graphical user interface are enabled.

The Save Configuration button allows to save the system configuration through an XML file that stores information relative to the implementation options of the different components of the system (see Configuration file section). The configurations saved by this option can be loaded at a later time using the Load Configuration button.

Before clicking the Generate Files button, the user can configure the options that appear in the Global Options zone of the graphical user interface. The functionality of each of the options is as follows:

  • Include Rule’s Confidence Factors: When this option is activated, an array with the degree of certainty of the rules will be included in the ".m" output file for each of the system rule bases. This option is contemplated in the XFL3 specification language although it is not currently used for hardware implementations of inference systems.

  • Generate txt file: When activated, a ".txt" file containing textual information about the structure of the system will be created.

  • Generate Simulink model: If this option is activated, the ".mdl" file corresponding to the Simulink model of the fuzzy system will be created.

  • Use Simplified Components: If this option is activated, simplified components will be used whenever possible, that is, when the defuzzification method is Fuzzy Mean or Takagi-Sugeno, the antecedent connective is the product operator and the rule base is completely specified.

Output files

Once the parameters of the different system components and the global options have been defined, the Generate Files button can be pressed to generate the following files in the indicated output directory:

  • <FLC>.m is a MATLAB ".m" file that contains the initialization of the variables of each of the XfuzzyLib library blocks that are used to implement the fuzzy system. This file is always generated, independently of the options chosen in the Global Options zone.

  • <FLC_aux>.mdl contains a Simulink model of the fuzzy system that uses the modules included in the XfuzzyLib library.

  • <FLC>.txt contains a text description of the inputs and outputs of each rule base and crisp block. It also includes the component of the XfuzzyLib library used. If such component does not exist, it is specified with null.

Configuration file

The configuration of the synthesis process with xfsg can be saved in an XML file to be retrieved at a later time. It must be taken into account that the syntax of the configuration file can change in successive Xfuzzy versions and that only configuration files generated by the current version can be loaded, So the old XML files must be adapted to the right format by adding the new tags.

The appearance of the configuration file reflects the tree structure that represents the system. The root of this file is the label called system, which has three attributes: name, rulebases and crisps. The first one indicates the name of the system, while the other two indicate the number of rule bases and crisps blocks, respectively. (If the system does not contain any crisp blocks, this attribute does not appear).

The file includes three main elements: rulebases, crisps and options. The rulebases tag contains information about the rules bases, each of them identified by a rulebase tag. This element has as attributes: name, which indicates the name of the rule base; inputs, which indicates the number of inputs; and outputs, which indicates the number of outputs. The child elements of this tag define each of the parameters of the rule base: bits_input (number of bits for inputs), bits_output (number of bits for outputs), bits_membership_degree (number of bits for membership degree) and bits_MF_slopes (number of bits for slopes).

The crisps element appears empty when the system does not include any block of this type. Otherwise, each block is defined by a crisp tag that includes the attributes: name, which indicates the name of the crisp block; inputs, which indicates the number of inputs; and outputs, which indicates the number of outputs. The only parameter that can be defined for this type of elements is the number of bits used to encode the output (bitsize_output).

<?xml version="1.0" encoding="UTF-8" ?> 
<system name="Backward" rulebases="2" crisps="1">
  <rulebases>
  <rulebases>
    <rulebase name="interpolacion" inputs="2" outputs="1">
      <bits_input>10</bits_input> 
      <bits_output>10</bits_output> 
      <bits_membership_degree>10</bits_membership_degree> 
      <bits_MF_slopes>10</bits_MF_slopes> 
    </rulebase>
    <rulebase name="suavizado" inputs="1" outputs="1">
      <bits_input>10</bits_input> 
      <bits_output>10</bits_output> 
      <bits_membership_degree>10</bits_membership_degree> 
      <bits_MF_slopes>2</bits_MF_slopes> 
    </rulebase>
  </rulebases>
  <crisps>
    <crisp name="Resta" inputs="2" outputs="1">
      <bitsize_output>10</bitsize_output> 
    </crisp>
  </crisps>
  <options>
    <include_rule_confidence_factor_mfile>false</include_rule_confidence_factor_mfile>
    <gen_txtfile>false</gen_txtfile>
    <gen_simmodel>true</gen_simmodel>
    <use_simp_components>true</use_simp_components>
    <outputFile>Backward</outputFile>
    <outputDirectory>C:\Xfuzzy\examples\Tools\xfsg\OUT</outputDirectory>
</system>    
 

Finally, the option tag is used to identify the different options that appear in the Global Options and Files and directory information sections of the xfvhdl graphical user interface. The child elements of this tag are: include_rule_confidence_factor_mfile, gen_txtfile, gen_simmodel, use_simp_components, outputFile and outputDirectory. The first four admit a Boolean value (true or false) that indicates the activation or not of the corresponding option.

The saved configurations can be subsequently loaded using the Load Configuration button, without the need to enter all the values again.

Error messages

If an error or warning occurs during the generation of the xfsg output files, the user will be notified in the Xfuzzy message area. The list of possible errors together with the description of the causes that motivate them is illustrated in the following table.

Error
Descripción

Can´t create output directory

Appears when the tool cannot create the directory indicated as output

There isn´t a Simulink component to this rulebase. You must creat it !!!

Occurs when there is no prototype architecture within XfuzzyLib to implement one of the system rule bases

You can´t use a simplified component

Occurs when the Use Simplified Components option has been selected, but a rule base cannot use the simplified component

Invalid membership function to calculate the weight of the rules

Appears when the Weighted Fuzzy Mean defuzzifier is used and the second characteristic parameter of these methods is missing in the definition of the output membership functions.

Membership functions incorrect for inputs

Appears when a type of membership function that is not allowed is used. The tool supports normalized free triangles and families of triangles, where the first and/or the last element can be trapezoids

The rulebase is not complete

Occurs when the consequent is not defined for all the possible combinations of input labels

Invalid name system, Invalid name rulebase, Invalid name crisp

Occurs when a configuration file is loaded and the names of the rule bases and crisp blocks or the system name do not correspond to those that appear in the Xfuzzy specification

Invalid rule

Indicates that a rule includes some operator that has not been taken into account within the tool


--------------------------------------------------------------------------------------
S. Sánchez-Solano, E. del Toro, M. Brox, P. Brox, I. Baturone
Model-Based Design Methodology for Rapid Development of Fuzzy Controllers on FPGAs
IEEE Transactions on Industrial Informatics, 2012
DOI: 10.1109/TII.2012.2211608

For comments, patches, bug reports, etc contact us at:   xfuzzy-team@imse-cnm.csic.es

©IMSE-CNM 2018