i made an .fcl file in qtfuzzylite.I want to load it in python 2.7 with fcl Reader.It must do some calculation with the given inputs then it must give the output value.when i run the program it writes Key Error 'PNEU
I used this example:
http://pyfuzzy.sourceforge.net/doc/quickstart.html
import fuzzy.storage.fcl.Reader
system = fuzzy.storage.fcl.Reader.Reader().load_from_file("Ballpositioner2.fcl")
# preallocate input and output values
my_input = {
"REQ_POS" : 0.0,
"REQ_ANGLE" : 0.0,
"DESIRED" : 0.0,
}
my_output = {
"PNEU" : 3,
}
# if you need only one calculation you do not need the while
# set input values
my_input["REQ_POS"] = 10
my_input["REQ_ANGLE"] = 20
my_input["DESIRED"] = 30
# calculate
system.calculate(my_input, my_output)
# now use outputs
b = my_output["PNEU"]
line 3:0 extraneous input u'VAR_INPUT' expecting Identifier
Traceback (most recent call last):
File "D:\Szabolcs\szte\Szakdolgozat\Python\python 27\ewrwewerwer.py", line 23, in <module>
system.calculate(my_input, my_output)
File "C:\Python27\lib\site-packages\fuzzy\System.py", line 93, in calculate
self.defuzzify(output)
File "C:\Python27\lib\site-packages\fuzzy\System.py", line 76, in defuzzify
output[name] = self.variables[name].getValue()
KeyError: 'PNEU'
A copy of my most recent reply on the old forums:
It's not writing it for the output. It's assigning to the output. You won't get a key error on assignment. If the key isn't there during assignment the key just gets added. The error is when it's accessing self.variables[name]. On access it will give the key error if the key isn't there. The traceback shows this is happening during system.calculate, so self is equal to system, and thus system.variables does not have the key 'PNEU'. The system variable is assigned when reading the file, leading to the conclusion that 'PNEU' is not in the file.
Use a file that has 'PNEU' in it or use a different key that is actually in the file.
Ballpositioner2.fcl must contain information about PNEU? Because it's in there.
FUNCTION_BLOCK
VAR_INPUT
REQ_POS: REAL;
REQ_ANGLE: REAL;
DESIRED: REAL;
END_VAR
VAR_OUTPUT
PNEU: REAL;
END_VAR
FUZZIFY REQ_POS
ENABLED : TRUE;
RANGE := (-35.000 .. 35.000);
TERM FAR := Ramp 0.000 -35.000;
TERM CENTER := Triangle -35.000 0.000 35.000;
TERM CLOSE := Ramp 0.000 35.000;
END_FUZZIFY
FUZZIFY REQ_ANGLE
ENABLED : TRUE;
RANGE := (-45.000 .. 45.000);
TERM RIGHT := Ramp 2.000 45.000;
TERM LEFT := Ramp -2.000 -45.000;
TERM HORIZONTAL := Triangle -2.000 0.000 2.000;
END_FUZZIFY
FUZZIFY DESIRED
ENABLED : TRUE;
RANGE := (-35.000 .. 35.000);
TERM FAR := Ramp 0.000 -35.000;
TERM CENTER := Triangle -35.000 0.000 35.000;
TERM CLOSE := Ramp 0.000 35.000;
END_FUZZIFY
DEFUZZIFY PNEU
ENABLED : TRUE;
RANGE := (0.000 .. 255.000);
TERM LEFT := Triangle 0.000 42.500 85.000;
TERM NOTHING := Triangle 85.000 127.500 170.000;
TERM RIGHT := Triangle 172.500 215.000 255.000;
METHOD : COG;
ACCU : HSUM;
DEFAULT := nan;
END_DEFUZZIFY
RULEBLOCK
ENABLED : TRUE;
AND : MIN;
OR : MAX;
ACT : MIN;
RULE 1 : if REQ_POS is FAR and REQ_ANGLE is LEFT and DESIRED is FAR then PNEU is LEFT
RULE 2 : if REQ_POS is FAR and REQ_ANGLE is LEFT and DESIRED is CENTER then PNEU is LEFT
RULE 3 : if REQ_POS is FAR and REQ_ANGLE is LEFT and DESIRED is CLOSE then PNEU is LEFT
RULE 4 : if REQ_POS is FAR and REQ_ANGLE is RIGHT and DESIRED is FAR then PNEU is RIGHT
RULE 5 : if REQ_POS is FAR and REQ_ANGLE is RIGHT and DESIRED is CENTER then PNEU is LEFT
RULE 6 : if REQ_POS is FAR and REQ_ANGLE is RIGHT and DESIRED is CLOSE then PNEU is LEFT
RULE 7 : if REQ_POS is FAR and REQ_ANGLE is HORIZONTAL and DESIRED is FAR then PNEU is NOTHING
RULE 8 : if REQ_POS is FAR and REQ_ANGLE is HORIZONTAL and DESIRED is CENTER then PNEU is LEFT
RULE 9 : if REQ_POS is FAR and REQ_ANGLE is HORIZONTAL and DESIRED is CLOSE then PNEU is LEFT
RULE 10 : if REQ_POS is CENTER and REQ_ANGLE is LEFT and DESIRED is FAR then PNEU is RIGHT
RULE 11 : if REQ_POS is CENTER and REQ_ANGLE is LEFT and DESIRED is CENTER then PNEU is LEFT
RULE 12 : if REQ_POS is CENTER and REQ_ANGLE is LEFT and DESIRED is CLOSE then PNEU is LEFT
RULE 13 : if REQ_POS is CENTER and REQ_ANGLE is RIGHT and DESIRED is FAR then PNEU is RIGHT
RULE 14 : if REQ_POS is CENTER and REQ_ANGLE is RIGHT and DESIRED is CENTER then PNEU is RIGHT
RULE 15 : if REQ_POS is CENTER and REQ_ANGLE is RIGHT and DESIRED is CLOSE then PNEU is LEFT
RULE 16 : if REQ_POS is CENTER and REQ_ANGLE is HORIZONTAL and DESIRED is FAR then PNEU is RIGHT
RULE 17 : if REQ_POS is CENTER and REQ_ANGLE is HORIZONTAL and DESIRED is CENTER then PNEU is NOTHING
RULE 18 : if REQ_POS is CENTER and REQ_ANGLE is HORIZONTAL and DESIRED is CLOSE then PNEU is LEFT
RULE 19 : if REQ_POS is CLOSE and REQ_ANGLE is LEFT and DESIRED is FAR then PNEU is RIGHT
RULE 20 : if REQ_POS is CLOSE and REQ_ANGLE is LEFT and DESIRED is CENTER then PNEU is RIGHT
RULE 21 : if REQ_POS is CLOSE and REQ_ANGLE is LEFT and DESIRED is CLOSE then PNEU is LEFT
RULE 22 : if REQ_POS is CLOSE and REQ_ANGLE is RIGHT and DESIRED is FAR then PNEU is RIGHT
RULE 23 : if REQ_POS is CLOSE and REQ_ANGLE is RIGHT and DESIRED is CENTER then PNEU is RIGHT
RULE 24 : if REQ_POS is CLOSE and REQ_ANGLE is RIGHT and DESIRED is CLOSE then PNEU is RIGHT
RULE 25 : if REQ_POS is CLOSE and REQ_ANGLE is HORIZONTAL and DESIRED is FAR then PNEU is RIGHT
RULE 26 : if REQ_POS is CLOSE and REQ_ANGLE is HORIZONTAL and DESIRED is CENTER then PNEU is RIGHT
RULE 27 : if REQ_POS is CLOSE and REQ_ANGLE is HORIZONTAL and DESIRED is CLOSE then PNEU is NOTHING
END_RULEBLOCK
END_FUNCTION_BLOCK
if you comment out
b = my_output["PNEU"]
and put
print my_output
what output does that give?