home › Forums › # Technical Support › Error when running application › Reply To: Error when running application
Hi Juan,
Thank you for your response. I’m relatively new to fuzzy logic so please bear with me. The following code is what i’m using. I have no compiler errors but only when running the application.
public void fuzzyMethod(double carspeed, double acceleration){
Engine engine = new Engine();
engine.setName(“Driver-Classifier”);
/*Speed input value
Speed range set between 0 and 95km/hr
Three terms – slow, normal, fast
*/
InputVariable speed = new InputVariable();
speed.setEnabled(true);
speed.setName(“SPEED”);
speed.setRange(0.000,95.000);
speed.addTerm(new Triangle(“SLOW”,0.000,25.000,50.000 ));
speed.addTerm(new Triangle(“NORMAL”,45.000,55.000,65.000));
speed.addTerm(new Triangle(“FAST”, 55.000, 75.000,95.000));
engine.addInputVariable(speed);
/*
Accelerometer values in z-axis direction – left to right
*/
InputVariable zaxis = new InputVariable();
zaxis.setEnabled(true);
zaxis.setName(“Z Axis Acceleration”);
zaxis.setRange(-4.500,4.500);
//Deceleration
zaxis.addTerm(new Triangle(“HARD DECELERATION”,1.500,3.00,4.500 ));
zaxis.addTerm(new Triangle(“DECELERATION”,0.500,1.5,2.5));
//Calm/Neutral
zaxis.addTerm(new Triangle(“NEUTRAL”,-0.5,0,0.5));
//Acceleration
zaxis.addTerm(new Triangle(“ACCELERATION”,-0.500,-1.250,-2.000));
zaxis.addTerm(new Triangle(“HARD ACCELERATION”,-1.500,-3.000,-4.500));
engine.addInputVariable(zaxis);
OutputVariable drivingStyle = new OutputVariable();
drivingStyle.setName(“DRIVING STYLE”);
drivingStyle.addTerm(new Triangle(“CALM”,0,0.5,1));
drivingStyle.addTerm(new Triangle(“NORMAL”,1,1.5,2));
drivingStyle.addTerm(new Triangle(“AGGRESSIVE”,2, 2.5, 3));
engine.addOutputVariable(drivingStyle);
//Set Rules
RuleBlock ruleBlock = new RuleBlock();
//SLOW SPEED
ruleBlock.addRule(Rule.parse(“if SPEED is SLOW and Z-AXIS ACCELERATION is HARD DECELERATION then DRIVING STYLE is AGGRESSIVE”, engine));
ruleBlock.addRule(Rule.parse(“if SPEED is SLOW and Z-AXIS ACCELERATION is DECELERATION then DRIVING STYLE is NORMAL”, engine));
ruleBlock.addRule(Rule.parse(“if SPEED is SLOW and Z-AXIS ACCELERATION is NEUTRAL then DRIVING STYLE is NORMAL”, engine));
ruleBlock.addRule(Rule.parse(“if SPEED is SLOW and Z-AXIS ACCELERATION is ACCELERATION then DRIVING STYLE is NORMAL”, engine));
ruleBlock.addRule(Rule.parse(“if SPEED is SLOW and Z-AXIS ACCELERATION is HARD ACCELERATION then DRIVING STYLE is AGGRESSIVE”, engine));
//NORMAL SPEED
ruleBlock.addRule(Rule.parse(“if SPEED is NORMAL and Z-AXIS ACCELERATION is HARD DECELERATION then DRIVING STYLE is AGGRESSIVE”, engine));
ruleBlock.addRule(Rule.parse(“if SPEED is NORMAL and Z-AXIS ACCELERATION is DECELERATION then DRIVING STYLE is AGGRESSIVE”, engine));
ruleBlock.addRule(Rule.parse(“if SPEED is NORMAL and Z-AXIS ACCELERATION is NEUTRAL then DRIVING STYLE is NORMAL”, engine));
ruleBlock.addRule(Rule.parse(“if SPEED is NORMAL and Z-AXIS ACCELERATION is ACCELERATION then DRIVING STYLE is AGGRESSIVE”, engine));
ruleBlock.addRule(Rule.parse(“if SPEED is NORMAL and Z-AXIS ACCELERATION is HARD ACCELERATION then DRIVING STYLE is AGGRESSIVE”, engine));
//TOO FAST
ruleBlock.addRule(Rule.parse(“if SPEED is FAST and Z-AXIS ACCELERATION is HARD DECELERATION then DRIVING STYLE is AGGRESSIVE”, engine));
ruleBlock.addRule(Rule.parse(“if SPEED is FAST and Z-AXIS ACCELERATION is DECELERATION then DRIVING STYLE is AGGRESSIVE”, engine));
ruleBlock.addRule(Rule.parse(“if SPEED is FAST and Z-AXIS ACCELERATION is NEUTRAL then DRIVING STYLE is AGGRESSIVE”, engine));
ruleBlock.addRule(Rule.parse(“if SPEED is FAST and Z-AXIS ACCELERATION is ACCELERATION then DRIVING STYLE is AGGRESSIVE”, engine));
ruleBlock.addRule(Rule.parse(“if SPEED is FAST and Z-AXIS ACCELERATION is HARD ACCELERATION then DRIVING STYLE is AGGRESSIVE”, engine));
engine.addRuleBlock(ruleBlock);
speed.setInputValue(carspeed);
zaxis.setInputValue(acceleration);
engine.process();
//Log.d(“fuzzy”,drivingStyle.getOutputValue()+ ” “);