home Forums # Technical Support Error in code in case variety of input and output variables

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2324
    Unknown
    Member

    Hi everyone! I have a fuzzy controller with 4 in put and 2 output variables as below:

    #include “fl/Headers.h”
    #include <iostream>

    using namespace std;
    double leftobs, frontobs, rightobs, angleobs;
    double vleft, vright;
    int main(int argc, char* argv[]){

    using namespace fl;
    Engine* engine = new Engine(“AvoidObstacle”);

    InputVariable* LeftObs = new InputVariable;
    LeftObs->setName(“LeftObs”);
    LeftObs->setRange(0.000, 480.000);
    LeftObs->addTerm(new Trapezoid(“NEAR”, 0.000, 0.000, 80.000, 400.000));
    LeftObs->addTerm(new Trapezoid(“FAR”, 80.000, 400.000, 480.000, 480.000));
    engine->addInputVariable(LeftObs);

    InputVariable* FrontObs = new InputVariable;
    FrontObs->setName(“FrontObs”);
    FrontObs->setRange(0.000, 480.000);
    FrontObs->addTerm(new Trapezoid(“NEAR”, 0.000, 0.000, 80.000, 400.000));
    FrontObs->addTerm(new Trapezoid(“FAR”, 80.000, 400.000, 480.000, 480.000));
    engine->addInputVariable(FrontObs);

    InputVariable* RightObs = new InputVariable;
    RightObs->setName(“RightObs”);
    RightObs->setRange(0.000, 480.000);
    RightObs->addTerm(new Trapezoid(“NEAR”, 0.000, 0.000, 80.000, 400.000));
    RightObs->addTerm(new Trapezoid(“FAR”, 80.000, 400.000, 480.000, 480.000));
    engine->addInputVariable(RightObs);

    InputVariable* AngleObs = new InputVariable;
    AngleObs->setName(“AngleObs”);
    AngleObs->setRange(-90.000, 90.000);
    AngleObs->addTerm(new Trapezoid(“LEFT”, -90.000, -90.000, -30.000, 0.000));
    AngleObs->addTerm(new Triangle(“FRONT”, -30.000, 0.000, 30.000));
    AngleObs->addTerm(new Trapezoid(“RIGHT”, 0.000, 30.000, 90.000, 90.000));
    engine->addInputVariable(AngleObs);

    OutputVariable* VLeft = new OutputVariable;
    VLeft->setName(“VLeft”);
    VLeft->setRange(0.000, 12.000);
    VLeft->setDefaultValue(fl::nan);
    VLeft->addTerm(new Trapezoid(“SLOW”, 0.000, 0.000, 2.000, 4.000));
    VLeft->addTerm(new Triangle(“LSLOW”, 2.000, 4.000, 6.000));
    VLeft->addTerm(new Triangle(“MID”, 4.000, 6.000, 8.000));
    VLeft->addTerm(new Triangle(“LFAST”, 6.000, 8.000, 10.000));
    VLeft->addTerm(new Trapezoid(“FAST”, 8.000, 10.000, 12.000, 12.000));
    engine->addOutputVariable(VLeft);

    OutputVariable* VRight = new OutputVariable;
    VRight->setName(“VRight”);
    VRight->setRange(0.000, 12.000);
    VRight->setDefaultValue(fl::nan);
    VRight->addTerm(new Trapezoid(“SLOW”, 0.000, 0.000, 2.000, 4.000));
    VRight->addTerm(new Triangle(“LSLOW”, 2.000, 4.000, 6.000));
    VRight->addTerm(new Triangle(“MID”, 4.000, 6.000, 8.000));
    VRight->addTerm(new Triangle(“LFAST”, 6.000, 8.000, 10.000));
    VRight->addTerm(new Trapezoid(“FAST”, 8.000, 10.000, 12.000, 12.000));
    engine->addOutputVariable(VRight);

    RuleBlock* ruleblock = new RuleBlock;
    ruleblock->addRule(Rule::parse(“if LeftObs is NEAR and FrontObs is NEAR and RightObs is NEAR and AngleObs is LEFT then VLeft is SLOW and VRight is L-SLOW”, engine)); //1
    ruleblock->addRule(Rule::parse(“if LeftObs is NEAR and FrontObs is NEAR and RightObs is NEAR and AngleObs is FRONT then VLeft is L-SLOW and VRight is SLOW”, engine)); //2
    ruleblock->addRule(Rule::parse(“if LeftObs is NEAR and FrontObs is NEAR and RightObs is NEAR and AngleObs is RIGHT then VLeft is L-SLOW and VRight is SLOW”, engine)); //3
    ruleblock->addRule(Rule::parse(“if LeftObs is NEAR and FrontObs is NEAR and RightObs is FAR and AngleObs is LEFT then VLeft is L-SLOW and VRight is SLOW”, engine)); //4
    ruleblock->addRule(Rule::parse(“if LeftObs is NEAR and FrontObs is NEAR and RightObs is FAR and AngleObs is FRONT then VLeft is L-SLOW and VRight is SLOW”, engine)); //5
    ruleblock->addRule(Rule::parse(“if LeftObs is NEAR and FrontObs is NEAR and RightObs is FAR and AngleObs is RIGHT then VLeft is L-SLOW and VRight is SLOW”, engine)); //6
    ruleblock->addRule(Rule::parse(“if LeftObs is NEAR and FrontObs is FAR and RightObs is NEAR and AngleObs is LEFT then VLeft is MID and VRight is MID”, engine)); //7
    ruleblock->addRule(Rule::parse(“if LeftObs is NEAR and FrontObs is FAR and RightObs is NEAR and AngleObs is FRONT then VLeft is L-FAST and VRight is L-FAST”, engine)); //8
    ruleblock->addRule(Rule::parse(“if LeftObs is NEAR and FrontObs is FAR and RightObs is NEAR and AngleObs is RIGHT then VLeft is MID and VRight is MID”, engine)); //9
    ruleblock->addRule(Rule::parse(“if LeftObs is NEAR and FrontObs is FAR and RightObs is FAR and AngleObs is LEFT then VLeft is L-SLOW and VRight is SLOW”, engine)); //10
    ruleblock->addRule(Rule::parse(“if LeftObs is NEAR and FrontObs is FAR and RightObs is FAR and AngleObs is FRONT then VLeft is MID and VRight is L-SLOW”, engine)); //11
    ruleblock->addRule(Rule::parse(“if LeftObs is NEAR and FrontObs is FAR and RightObs is FAR and AngleObs is RIGHT then VLeft is L-FAST and VRight is MID”, engine)); //12
    ruleblock->addRule(Rule::parse(“if LeftObs is FAR and FrontObs is NEAR and RightObs is NEAR and AngleObs is LEFT then VLeft is SLOW and VRight is L-SLOW”, engine)); //13
    ruleblock->addRule(Rule::parse(“if LeftObs is FAR and FrontObs is NEAR and RightObs is NEAR and AngleObs is FRONT then VLeft is SLOW and VRight is L-SLOW”, engine)); //14
    ruleblock->addRule(Rule::parse(“if LeftObs is FAR and FrontObs is NEAR and RightObs is NEAR and AngleObs is RIGHT then VLeft is SLOW and VRight is L-SLOW”, engine)); //15
    ruleblock->addRule(Rule::parse(“if LeftObs is FAR and FrontObs is NEAR and RightObs is FAR and AngleObs is LEFT then VLeft is SLOW and VRight is L-SLOW”, engine)); //16
    ruleblock->addRule(Rule::parse(“if LeftObs is FAR and FrontObs is NEAR and RightObs is FAR and AngleObs is FRONT then VLeft is L-SLOW and VRight is SLOW”, engine)); //17
    ruleblock->addRule(Rule::parse(“if LeftObs is FAR and FrontObs is NEAR and RightObs is FAR and AngleObs is RIGHT then VLeft is L-SLOW and VRight is SLOW”, engine)); //18
    ruleblock->addRule(Rule::parse(“if LeftObs is FAR and FrontObs is FAR and RightObs is NEAR and AngleObs is LEFT then VLeft is MID and VRight is L-FAST”, engine)); //19
    ruleblock->addRule(Rule::parse(“if LeftObs is FAR and FrontObs is FAR and RightObs is NEAR and AngleObs is FRONT then VLeft is L-SLOW and VRight is MID”, engine)); //20
    ruleblock->addRule(Rule::parse(“if LeftObs is FAR and FrontObs is FAR and RightObs is NEAR and AngleObs is RIGHT then VLeft is SLOW and VRight is L-SLOW”, engine)); //21
    ruleblock->addRule(Rule::parse(“if LeftObs is FAR and FrontObs is FAR and RightObs is FAR and AngleObs is LEFT then VLeft is L-FAST and VRight is FAST”, engine)); //22
    ruleblock->addRule(Rule::parse(“if LeftObs is FAR and FrontObs is FAR and RightObs is FAR and AngleObs is FRONT then VLeft is FAST and VRight is FAST”, engine)); //23
    ruleblock->addRule(Rule::parse(“if LeftObs is FAR and FrontObs is FAR and RightObs is FAR and AngleObs is RIGHT then VLeft is FAST and VRight is L-FAST”, engine)); //24
    engine->addRuleBlock(ruleblock);

    engine->configure(“”, “”, “Minimum”, “Maximum”, “Centroid”);

    while(1){
    cout<<“Enter Left-Obs = “;
    cin>>leftobs;
    cout<<“Enter Front-Obs = “;
    cin>>frontobs;
    cout<<“Enter Right-Obs = “;
    cin>>rightobs;
    cout<<“Enter Angle-Obs = “;
    cin>>angleobs;

    LeftObs->setInputValue(leftobs);
    FrontObs->setInputValue(frontobs);
    RightObs->setInputValue(rightobs);
    AngleObs->setInputValue(angleobs);
    engine->process();

    cout << “V-Left = ” << VLeft->getOutputValue();
    cout<<endl;
    cout << “V-Right = ” << VRight->getOutputValue();
    cout<<endl;
    }
    system(“pause”);
    return 0;
    }

    I can compile this, but when I run, I cause a error: Unhandled exception at 0x75d14878 in FuzzyliteExample.exe: Microsoft C++ exception: fl::Exception at memory location 0x00cbcdb8..
    I think this error come from the line engine->process();

    Please help me!

    #2328

    Hi,

    right after configure(), please

    (1) output the FLL code using: FL_LOG(engine->toString()),
    (2) Use the FLL to load it into QtFuzzyLite, where you will find out what the problem is.

    If you still have problems, post your FLL code here.

    Cheers.

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