home Forums # Technical Support Java Runtime error

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #6894
    AvatarLewis Richardson
    Guest

    Hi Juan,

    I have been trying to implement fuzzylite in android studio. The code I am using to create the engine is out of QTFuzzyLite 6.0 (which is working without any issues).
    When adding rules, the following exception is thrown:

    java.lang.RuntimeException: [syntax error] expected variable or logical operator, but found <pedalSpeed>

    Here is the code I am using:

    engine = new Engine();
            engine.setName("S");
    
            pedalSpeed = new InputVariable();
            pedalSpeed.setName(String.valueOf(R.string.PEDALSPEED));
            pedalSpeed.setDescription("Cadence");
            pedalSpeed.setEnabled(true);
            pedalSpeed.setRange(0.000, 1.000);
            pedalSpeed.setLockValueInRange(false);
            pedalSpeed.addTerm(new Trapezoid("Stopped", 0.000, 0.000, 0.100, 0.100));
            pedalSpeed.addTerm(new Trapezoid("SlowerThanTarget", 0.100, 0.100, 0.250, 0.400));
            pedalSpeed.addTerm(new Triangle("OnTarget", 0.300, 0.500, 0.750));
            pedalSpeed.addTerm(new Trapezoid("FasterThanTarget", 0.650, 0.800, 1.000, 1.000));
            engine.addInputVariable(pedalSpeed);
    
            shiftTime = new InputVariable();
            shiftTime.setName(String.valueOf(R.string.SHIFTTIME));
            shiftTime.setDescription("When the last shift occured");
            shiftTime.setEnabled(true);
            shiftTime.setRange(0.010, 3.000);
            shiftTime.setLockValueInRange(false);
            shiftTime.addTerm(new Triangle("JustShifted", 0.000, 0.000, 1.750));
            shiftTime.addTerm(new Triangle("doneShifting", 1.250, 3.000, 3.000));
            engine.addInputVariable(shiftTime);
    
            pedalAccel = new InputVariable();
            pedalAccel.setName(String.valueOf(R.string.PEDALACCEL));
            pedalAccel.setDescription("Pedal Acceleration");
            pedalAccel.setEnabled(true);
            pedalAccel.setRange(-15.000, 14.980);
            pedalAccel.setLockValueInRange(false);
            pedalAccel.addTerm(new Triangle("FastNegative", -15.000, -15.000, -5.000));
            pedalAccel.addTerm(new Triangle("Normal", -10.000, 0.000, 10.000));
            pedalAccel.addTerm(new Triangle("FastPositive", 5.000, 15.000, 15.000));
            engine.addInputVariable(pedalAccel);
    
            ShiftOutput = new OutputVariable();
            ShiftOutput.setName(String.valueOf(R.string.OUTPUT));
            ShiftOutput.setDescription("");
            ShiftOutput.setEnabled(true);
            ShiftOutput.setRange(-1.000, 1.000);
            ShiftOutput.setLockValueInRange(false);
            ShiftOutput.setAggregation(new AlgebraicSum());
            ShiftOutput.setDefuzzifier(new Centroid(100));
            ShiftOutput.setDefaultValue(Double.NaN);
            ShiftOutput.setLockPreviousValue(false);
            ShiftOutput.addTerm(new Rectangle("ShiftDown", -1.000, -0.333));
            ShiftOutput.addTerm(new Rectangle("NoOutput", -0.333, 0.333));
            ShiftOutput.addTerm(new Rectangle("ShiftUP", 0.333, 1.000));
            engine.addOutputVariable(ShiftOutput);
    
            whenToShift = new RuleBlock();
            whenToShift.setName("whenToShift");
            whenToShift.setDescription("");
            whenToShift.setEnabled(true);
            whenToShift.setConjunction(new Minimum());
            whenToShift.setDisjunction(new Maximum());
            whenToShift.setImplication(new Minimum());
            whenToShift.setActivation(new Proportional());
            whenToShift.addRule(Rule.parse("if pedalSpeed is Stopped then ShiftOutput is NoOutput", engine));
            whenToShift.addRule(Rule.parse("if pedalSpeed is SlowerThanTarget then ShiftOutput is ShiftDown", engine));
            whenToShift.addRule(Rule.parse("if pedalSpeed is OnTarget then ShiftOutput is NoOutput", engine));
            whenToShift.addRule(Rule.parse("if pedalSpeed is FasterThanTarget then ShiftOutput is ShiftUP", engine));
            whenToShift.addRule(Rule.parse("if shiftTime is JustShifted then ShiftOutput is NoOutput", engine));
            whenToShift.addRule(Rule.parse("if pedalAccel is FastNegative then ShiftOutput is ShiftDown", engine));
            whenToShift.addRule(Rule.parse("if pedalAccel is FastPositive then ShiftOutput is ShiftUP", engine));
            engine.addRuleBlock(whenToShift);
    

    The error occurs when adding the first rule “if pedalSpeed is Stopped then ShiftOutput is NoOutput”. However if I comment this out, the error still occurs on the next line.

    Any idea what is going wrong?

    Thanks

    Lewis

    #6916

    Hi,

    I am sorry for late response. Your post was classified as spam and I had no visibility.

    I believe your problem is that String.valueOf(R.string.PEDALSPEED) is NOT actually pedalSpeed. Check that.

    Cheers,

    Juan

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