home Forums # Technical Support Can't get correct output values

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1839
    Unknown
    Member

    Juan: I’m sorry to bother you again. I’ve been looking everywhere to see if I can solve this by myself (so far to no avail)
    I just can’t get the correct output values for a Fuzzycontroller created in Qtfuzzylite 5.0

    My controller looks like this

    Engine* engine = new Engine;

    engine->setName(“Mono A Angulo”);

    InputVariable* inputVariable1 = new InputVariable;
    inputVariable1->setEnabled(true);
    inputVariable1->setName(“MonoSensor1”);
    inputVariable1->setRange(0.000, 255.000);
    inputVariable1->addTerm(new Triangle(“Negro”, 0.000, 63.500, 127.000));
    inputVariable1->addTerm(new Triangle(“Gris”, 63.500, 127.000, 190.500));
    inputVariable1->addTerm(new Triangle(“Blanco”, 127.000, 190.500, 255.000));
    engine->addInputVariable(inputVariable1);

    InputVariable* inputVariable2 = new InputVariable;
    inputVariable2->setEnabled(true);
    inputVariable2->setName(“Monosensor2”);
    inputVariable2->setRange(0.000, 255.000);
    inputVariable2->addTerm(new Triangle(“Negro”, 0.000, 63.500, 127.000));
    inputVariable2->addTerm(new Triangle(“Gris”, 63.500, 127.000, 190.500));
    inputVariable2->addTerm(new Triangle(“Blanco”, 127.000, 190.500, 255.000));
    engine->addInputVariable(inputVariable2);

    OutputVariable* outputVariable = new OutputVariable;
    outputVariable->setEnabled(true);
    outputVariable->setName(“Angulo”);
    outputVariable->setRange(0.000, 180.000);
    outputVariable->fuzzyOutput()->setAccumulation(new Maximum);
    outputVariable->setDefuzzifier(new Centroid(200));
    //outputVariable->setDefaultValue(90.000);
    outputVariable->setLockPreviousOutputValue(false);
    outputVariable->setLockOutputValueInRange(false);
    outputVariable->addTerm(new Triangle(“ANGmen”, 0.000, 45.000, 90.000));
    outputVariable->addTerm(new Triangle(“NC”, 45.000, 90.000, 135.000));
    outputVariable->addTerm(new Triangle(“ANGmas”, 90.000, 135.000, 180.000));
    engine->addOutputVariable(outputVariable);

    RuleBlock* ruleBlock = new RuleBlock;
    ruleBlock->setEnabled(true);
    ruleBlock->setName(“”);
    ruleBlock->setConjunction(new Minimum);
    ruleBlock->setDisjunction(new Maximum);
    ruleBlock->setActivation(new Minimum);
    ruleBlock->addRule(fl::Rule::parse(“if MonoSensor1 is Blanco and Monosensor2 is Blanco then Angulo is NC”, engine));
    ruleBlock->addRule(fl::Rule::parse(“if MonoSensor1 is Blanco and Monosensor2 is Gris then Angulo is ANGmas”, engine));
    ruleBlock->addRule(fl::Rule::parse(“if MonoSensor1 is Blanco and Monosensor2 is Negro then Angulo is very ANGmas”, engine));
    ruleBlock->addRule(fl::Rule::parse(“if MonoSensor1 is Gris and Monosensor2 is Blanco then Angulo is ANGmen”, engine));
    ruleBlock->addRule(fl::Rule::parse(“if MonoSensor1 is Gris and Monosensor2 is Gris then Angulo is NC”, engine));
    ruleBlock->addRule(fl::Rule::parse(“if MonoSensor1 is Gris and Monosensor2 is Negro then Angulo is somewhat ANGmas”, engine));
    ruleBlock->addRule(fl::Rule::parse(“if MonoSensor1 is Negro and Monosensor2 is Blanco then Angulo is very ANGmen”, engine));
    ruleBlock->addRule(fl::Rule::parse(“if MonoSensor1 is Negro and Monosensor2 is Gris then Angulo is somewhat ANGmen”, engine));
    ruleBlock->addRule(fl::Rule::parse(“if MonoSensor1 is Negro and Monosensor2 is Negro then Angulo is NC”, engine));
    engine->addRuleBlock(ruleBlock);

    Point3i sensor1M = fondo1.at<Vec3b>(s1cPos.y, s1cPos.x);// Scan for 0-255 color value
    short a = sensor1M.x; // Store only the first component For monochromatic usable in realtime execution
    double a1 = 252;
    inputVariable1->setInputValue(a1); // Forced Input for Monosensor1 AKA inputVariable1

    Point3i sensor2M = fondo1.at<Vec3b>(s1cPos.y, s1cPos.x);
    short b = sensor2M.x;
    double b1 = 252;
    inputVariable1->setInputValue(b1);

    cout << “S1 is ” << a1 << endl;
    cout << “S2 is ” << b1 << endl;

    engine->process();

    angle = outputVariable->getOutputValue(); // Angle is a type double variable
    cout << “Angle is ” << angle << endl;

    So far I haven’t had any luck geting my fuzzycontroller to work. It’s a type of line follower, but with a few modifications. The controller itself works as intended on qtfuzzylite 5.0 but the correct output for I1 = 252, I2 = 252 should be a solid 90, but instead shows me 112.5

    A lil insight about the controller It should take a number between 0-255 for each sensor and give me an angle between 0-180

    Also sorry for the variable names, but Whenever I use c++ to export, my variables refuse to get renamed.

    Am I skiping a step to retrieve my outputs? Also bear in mind I’m forcing inputs directly with a1 and b1

    #1840

    Hi,

    could you please post the engine in FLL code?

    Cheers.

    #1841
    Unknown
    Member

    Sure. Here

    Engine: Mono A Angulo
    InputVariable: MonoSensor1
    enabled: true
    range: 0.000 255.000
    term: Negro Triangle 0.000 63.500 127.000
    term: Gris Triangle 63.500 127.000 190.500
    term: Blanco Triangle 127.000 190.500 255.000
    InputVariable: Monosensor2
    enabled: true
    range: 0.000 255.000
    term: Negro Triangle 0.000 63.500 127.000
    term: Gris Triangle 63.500 127.000 190.500
    term: Blanco Triangle 127.000 190.500 255.000
    OutputVariable: Angulo
    enabled: true
    range: 0.000 180.000
    accumulation: Maximum
    defuzzifier: Centroid 200
    default: nan
    lock-previous: false
    lock-range: false
    term: ANGmen Triangle 0.000 45.000 90.000
    term: NC Triangle 45.000 90.000 135.000
    term: ANGmas Triangle 90.000 135.000 180.000
    RuleBlock:
    enabled: true
    conjunction: Minimum
    disjunction: Maximum
    activation: Minimum
    rule: if MonoSensor1 is Blanco and Monosensor2 is Blanco then Angulo is NC
    rule: if MonoSensor1 is Blanco and Monosensor2 is Gris then Angulo is ANGmas
    rule: if MonoSensor1 is Blanco and Monosensor2 is Negro then Angulo is very ANGmas
    rule: if MonoSensor1 is Gris and Monosensor2 is Blanco then Angulo is ANGmen
    rule: if MonoSensor1 is Gris and Monosensor2 is Gris then Angulo is NC
    rule: if MonoSensor1 is Gris and Monosensor2 is Negro then Angulo is somewhat ANGmas
    rule: if MonoSensor1 is Negro and Monosensor2 is Blanco then Angulo is very ANGmen
    rule: if MonoSensor1 is Negro and Monosensor2 is Gris then Angulo is somewhat ANGmen
    rule: if MonoSensor1 is Negro and Monosensor2 is Negro then Angulo is NC

    #1844

    Hi,

    I also see the output you mention in QtFuzzyLite. I cannot check the C++ code, but you could try the following:

    Engine* engine = FllImporter().fromFile("path/to/your/file.fll");
    //set the inputvariables, process the engine, check the output variables

    Just to discard if the problem is in your C++ code.

    Cheers.

    #1845
    Unknown
    Member

    AHhahahaa I was triying your solution when I realized that I’m duuuuuuuuuuuuuuuuuuuuuuuuuuuuumb :/

    inputVariable1->setInputValue(a1); // Forced Input for Monosensor1 AKA inputVariable1

    Point3i sensor2M = fondo1.at<Vec3b>(s1cPos.y, s1cPos.x);
    short b = sensor2M.x;
    double b1 = 252;
    inputVariable1->setInputValue(b1);

    I was forcing both variables as input1, now it works as intended. Thanks!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.