home Forums # Technical Support Wrong outputs in java.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1522
    Unknown
    Member

    Hello.

    At start i want to tell, that fuzzylite is really a great product. It helps me a lot, but I recently stuck with on problem. I am writing code for my robot (that is similar to khepera) in java. Simple get to the the point task. This is the code in fll

    Engine: TS - get to point
    InputVariable: Z
      enabled: true
      range: 0.000 300.000
      term: NR Triangle 0.000 0.000 300.000
      term: FR Triangle 0.000 300.000 300.000
    InputVariable: Fi
      enabled: true
      range: -3.140 3.140
      term: N Triangle -3.140 -3.140 0.000
      term: P Triangle 0.000 3.140 3.140
      term: Z Triangle -3.140 0.000 3.140
    OutputVariable: Vleft
      enabled: true
      range: -100.000 100.000
      accumulation: Maximum
      defuzzifier: WeightedAverage
      default: nan
      lock-previous: false
      lock-range: false
      term: front Constant 50.000
      term: back Constant -50.000
      term: fastBack Constant -100.000
      term: fastFront Constant 100.000
      term: slow Constant 5.000
    OutputVariable: Vright
      enabled: true
      range: -100.000 100.000
      accumulation: Maximum
      defuzzifier: WeightedAverage
      default: nan
      lock-previous: false
      lock-range: false
      term: front Constant 50.000
      term: back Constant -50.000
      term: fastBack Constant -100.000
      term: fastFront Constant 100.000
      term: slow Constant 5.000
    RuleBlock: 
      enabled: true
      conjunction: Minimum
      disjunction: Maximum
      activation: Minimum
      rule: if Z is NR and Fi is N then Vleft is back and Vright is front
      rule: if Z is NR and Fi is Z then Vleft is slow and Vright is slow
      rule: if Z is FR and Fi is Z then Vleft is fastFront and Vright is fastFront
      rule: if Z is FR and Fi is P then Vleft is fastFront and Vright is fastBack

    For example, for inputs: Z = 100, Psi = 1; outputs are 36.66 for left wheel and 3.665 for the right wheel. This is okay, so i imported it to java. But in there i am getting weird outputs. For the same inputs (100, 1), I’ve got 1 for left wheel and -75 for right wheel. Regardless of the input values, one wheels get value = 1 and second one some negativ values(depends if Fi is positive or negetavie) and i dont understand why.

    Code in java:

    public class ToTarget {
    	Engine engine;
    	public ToTarget() {
    		engine = new Engine();
    		engine.setName("TS - get to point");
    
    		InputVariable inputVariable1 = new InputVariable();
    		inputVariable1.setEnabled(true);
    		inputVariable1.setName("Z");
    		inputVariable1.setRange(0.000, 300.000);
    		inputVariable1.addTerm(new Triangle("NR", 0.000, 0.000, 300.000));
    		inputVariable1.addTerm(new Triangle("FR", 0.000, 300.000, 300.000));
    		engine.addInputVariable(inputVariable1);
    
    		InputVariable inputVariable2 = new InputVariable();
    		inputVariable2.setEnabled(true);
    		inputVariable2.setName("Fi");
    		inputVariable2.setRange(-Math.PI,Math.PI);
    		inputVariable2.addTerm(new Triangle("N", -Math.PI, -Math.PI, 0.000));
    		inputVariable2.addTerm(new Triangle("P", 0.000, Math.PI, Math.PI));
    		inputVariable2.addTerm(new Triangle("Z", -Math.PI, 0.000, Math.PI));
    		engine.addInputVariable(inputVariable2);
    
    		OutputVariable outputVariable1 = new OutputVariable();
    		outputVariable1.setEnabled(true);
    		outputVariable1.setName("Vleft");
    		outputVariable1.setRange(-100.000, 100.000);
    		outputVariable1.fuzzyOutput().setAccumulation(new Maximum());
    		outputVariable1.setDefuzzifier(new WeightedAverage());
    		outputVariable1.setDefaultValue(0);
    		outputVariable1.setLockOutputRange(false);
    		outputVariable1.addTerm(new Constant("front", 50.000));
    		outputVariable1.addTerm(new Constant("back", -50.000));
    		outputVariable1.addTerm(new Constant("fastBack", -100.000));
    		outputVariable1.addTerm(new Constant("fastFront", 100.000));
    		outputVariable1.addTerm(new Constant("slow", 5.000));
    		engine.addOutputVariable(outputVariable1);
    
    		OutputVariable outputVariable2 = new OutputVariable();
    		outputVariable2.setEnabled(true);
    		outputVariable2.setName("Vright");
    		outputVariable2.setRange(-100.000, 100.000);
    		outputVariable2.fuzzyOutput().setAccumulation(new Maximum());
    		outputVariable2.setDefuzzifier(new WeightedAverage());
    		outputVariable2.setDefaultValue(0);
    		outputVariable2.setLockOutputRange(false);
    		outputVariable2.addTerm(new Constant("front", 50.000));
    		outputVariable2.addTerm(new Constant("back", -50.000));
    		outputVariable2.addTerm(new Constant("fastBack", -100.000));
    		outputVariable2.addTerm(new Constant("fastFront", 100.000));
    		outputVariable2.addTerm(new Constant("slow", 5.000));
    		engine.addOutputVariable(outputVariable2);
    
    		RuleBlock ruleBlock = new RuleBlock();
    		ruleBlock.setEnabled(true);
    		ruleBlock.setName("");
    		ruleBlock.setConjunction(new Minimum());
    		ruleBlock.setDisjunction(new Maximum());
    		ruleBlock.setActivation(new Minimum());
    		ruleBlock.addRule(Rule.parse("if Z is NR and Fi is N then Vleft is back and Vright is front", engine));
    		ruleBlock.addRule(Rule.parse("if Z is NR and Fi is Z then Vleft is slow and Vright is slow", engine));
    		ruleBlock.addRule(Rule.parse("if Z is FR and Fi is Z then Vleft is fastFront and Vright is fastFront", engine));
    		ruleBlock.addRule(Rule.parse("if Z is FR and Fi is P then Vleft is fastFront and Vright is fastBack", engine));
    		engine.addRuleBlock(ruleBlock);
    	}
    public double[] process(double z, double fi)
    {
    	double output[] = new double[2];
    	engine.setInputValue("Z", z);
    	engine.setInputValue("Fi", fi);
    	engine.process();
    	output[0] = engine.getOutputValue("Vleft");
    	output[1] = engine.getOutputValue("Vright");
    	return output;
    }

    I am trying it, using function “process”.

    I am also using other system, Mamdani, to avoid colliders at the route (also in java) and it is working properly. Can you tell me what is wrong?

    #1523

    Hi,

    thank you for your post and your kind words.

    I assume that you are using QtFuzzyLite to design your controller and from there you obtained the FLL code.

    In Java, could you please export your engine to FLL and make sure that it is the same controller as the one you designed?

    You can export in Java as follows: new FllExporter().toString(engine); or perhaps engine.toString() would do the trick too.

    Cheers.

    #1525
    Unknown
    Member

    I have found little difference in model from QtFuzzyLite and model from java. In FLL i have “lock-previous: false”, and in java: “lock-valid: false”, but in the other system, Mamdani, everything works fine, even with that difference. How does we even know from FLL what system we are using? Mamdani is diffrent from Takagi-Sugeno and QtFuzzyLittle knows that, but code that he exports does not.

    #1526
    Unknown
    Member

    Any chance to help? I am out of any idea. Models are the same in java and QtFuzzyLite. System is working in matlab and Qt. I even tried it in version 4.0. Takagi-Sugeno is just not working when exported (at least to java) :(.

    #1527

    Hi,

    I have confirmed your issue. I will revise to find out what is going on and will let you know.

    Cheers.

    #1528

    Hi Polak,

    the issues you are having is because you are using fuzzylite 5.0 in C++ (or QtFuzzyLite 5), and the java version has not yet been updated. The operation of defuzzifiers changed in version 5.0. I expect to update the java version before the end of the year.

    Could you please change the activation operator of your rule block to the AlgebraicProduct?

    #1529

    More information on the defuzzification differences between fuzzylite 4.0 (or jfuzzylite-1.0, equivalently) and 5.0 can be found here http://fuzzylite.com/cpp/#Weighted_Defuzzifiers

    #1530
    Unknown
    Member

    It is as you said. I used QtFuzzyLite 5 with java 4. I thought that may be a problem, so I downloaded QtFuzzyLite 4, but it didn’t helped. However changing activation operator to the AlgebraicProduct fixed the problem :). Now i can move on with my project :). Thanks a lot!

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