Spark! Fuzzy Logic Editor Help


Variables | Sets | Rules | API | Integration | Tutorial


Export .h File

Many of the Spark! API functions require the index of the fuzzy variable to be passed in (see functions like set_value() and get_value()).  This index does not correspond to the position of the variable in the Spark! UI.  

The get_mom_output() function returns the index of the "winning" output set.  Again, this index does not correspond to the position of the set in the output variable so we must know which index belongs to which set.

The index values should be obtained from the .h file that is exported by Spark!

Some common questions are:

Naming Conventions

Variable names are converted to all capital letters and any spaces in the name are converted to underscores.

For output sets, the names are converted just like variable names and are pre-pended with "<OUT VAR ID>_", where "<OUT VAR ID>" is the name of the output variable.

Back to top

How do I export the .h file?

Select "File | Export .h File" or click on the toolbar icon:

Back to top

Where do I put the .h file?

It is recommended that the .h file resides with the .cpp file that is using it.

Back to top

What do I name the .h file?

You can name it anything you want.  It is recommended that you name it the same as the model name it was exported from.

Back to top

What is the USE_SPARK_NAMESPACE used for?

This is used in case you have more than one Spark! model in a single application.  With more than one Spark! model, it is possible that you have duplicate variable  names.  If they do not have the same index value you will get strange results indeed.  Spark! uses namespaces to resolve these conflicts.

If you define USE_SPARK_NAMESPACE you have to qualify the variable's index identifier with the namespace.  The namespace is the same as the .h file's name.

For example if we have an application with two Spark! models: model_1.spk and model_2.spk the .h's exported may look like:

 

model_1.h model_2.h
#ifdef USE_SPARK_NAMESPACE
namespace MODEL_1
{
#endif // USE_SPARK_NAMESPACE

enum 
{
FUZZY_VAR_2 = 0, // id: Fuzzy var 2 
FUZZY_VAR_1 = 1, // id: Fuzzy var 1 
OUTPUT = 2 // id: Output 
// Define output terms for MOM defuzzification
OUTPUT_SET_1 = 0, // Output Set: Set 1 
OUTPUT_SET_2 = 1, // Output Set: Set 2
OUTPUT_SET_3 = 2 // Output Set: Set 3

}; // end enum

#ifdef USE_SPARK_NAMESPACE
} // end namespace MODEL_1
#endif // USE_SPARK_NAMESPACE
#ifdef USE_SPARK_NAMESPACE
namespace MODEL_2
{
#endif // USE_SPARK_NAMESPACE

enum 
{
FUZZY_VAR_1 = 0, // id: Fuzzy var 1 
FUZZY_VAR_2 = 1, // id: Fuzzy var 2 
OUTPUT = 2 // id: Output 
// Define output terms for MOM defuzzification
OUTPUT_SET_1 = 0, // Output Set: Set 1 
OUTPUT_SET_2 = 1, // Output Set: Set 2
OUTPUT_SET_3 = 2 // Output Set: Set 3

}; // end enum

#ifdef USE_SPARK_NAMESPACE
} // end namespace MODEL_2
#endif // USE_SPARK_NAMESPACE

If we did not define USE_SPARK_NAMESPACE there would be a conflict between FUZZY_VAR_1's value of 1 for model_1 and it's value of 0 for model_2.

With the namespaces we don't have that conflict because we access them with the namespace:

MODEL_1::FUZZY_VAR_1
MODEL_2::FUZZY_VAR_1

Back to top