Fuzzy Control Lecture 6.1
Fuzzy Control Fuzzy Sets Design of a Fuzzy Controller –Fuzzification of inputs: get_inputs() –Fuzzy Inference –Processing the Rules: find_rules() –Centroid Defuzzification –Output Defuzzification: find_output() –A Fuzzy Control Example -- Floating Ping-Pong Ball
Fuzzy Logic
Normal “Crisp” logic where everything must be either True or False leads to PARADOXES
The sentence on the other side of the line is false The sentence on the other side of the line is false
A barber has a sign that reads: “I shave everyone who does not shave himself” Who shaves the barber?
Fuzzy Logic Lotfi Zadeh - Fuzzy Sets Membership functions –Degree of membership between 0 and 1 Fuzzy logic operations on fuzzy sets A and B –NOT A => 1 - A –A AND B => MIN(A,B) –A OR B => MAX (A,B)
Membership Functions Young Age Not Young
Membership Functions Old Age Not Old
Membership Functions Age Not Old Not Young Middle Age = Not Old AND Not Young
Probabiltiy vs. Fuzziness Probability describes the uncertainty of an event occurrence. Fuzziness describes event ambiguity. Whether an event occurs is RANDOM. To what degree it occurs is FUZZY.
Probability: There is a 50% chance of an apple being in the refrigerator. Fuzzy: There is a half an apple in the refrigerator.
Fuzzy logic acknowledges and exploits the tolerance for uncertainty and imprecision.
Fuzzy Control Map to Fuzzy Sets Fuzzy Rules IF A AND B THEN L * * Defuzzification Inputs Output get_inputs(); fire_rules(); find_output();
Algorithm for a fuzzy controller do_forever { get_inputs(); fire_rules(); find_output(); }
get_inputs(); Given inputs x1 and x2, find the weight values associated with each input membership function. ZNMNSPSPM X W = [0, 0, 0.2, 0.7, 0]
Fuzzy Inference fire_rules(); find_output(); Rule 1: If x1 is A1 and x2 is B1 then y is L1 Rule 2: If x1 is A2 and x2 is B2 then y is L2 Given: x1 is a and x2 is b What is y?
Fuzzy Control Fuzzy Sets Design of a Fuzzy Controller –Fuzzification of inputs: get_inputs() –Fuzzy Inference –Processing the Rules: find_rules() –Centroid Defuzzification –Output Defuzzification: find_output() –A Fuzzy Control Example -- Floating Ping-Pong Ball
A Fuzzy Controller
Fuzzy Control Fuzzy Sets Design of a Fuzzy Controller –Fuzzification of inputs: get_inputs() –Fuzzy Inference –Processing the Rules: find_rules() –Centroid Defuzzification –Output Defuzzification: find_output() –A Fuzzy Control Example -- Floating Ping-Pong Ball
The 68HC12 MEM Instruction
Neg_med Neg_small Zero Pos_small Pos_med
Fuzzy Control Fuzzy Sets Design of a Fuzzy Controller –Fuzzification of inputs: get_inputs() –Fuzzy Inference –Processing the Rules: find_rules() –Centroid Defuzzification –Output Defuzzification: find_output() –A Fuzzy Control Example -- Floating Ping-Pong Ball
Fuzzy Inference
Fuzzy Control Fuzzy Sets Design of a Fuzzy Controller –Fuzzification of inputs: get_inputs() –Fuzzy Inference –Processing the Rules: find_rules() –Centroid Defuzzification –Output Defuzzification: find_output() –A Fuzzy Control Example -- Floating Ping-Pong Ball
The 68HC12 REV Instruction
Fuzzy Control Fuzzy Sets Design of a Fuzzy Controller –Fuzzification of inputs: get_inputs() –Fuzzy Inference –Processing the Rules: find_rules() –Centroid Defuzzification –Output Defuzzification: find_output() –A Fuzzy Control Example -- Floating Ping-Pong Ball
Fuzzy Control Fuzzy Sets Design of a Fuzzy Controller –Fuzzification of inputs: get_inputs() –Fuzzy Inference –Processing the Rules: find_rules() –Centroid Defuzzification –Output Defuzzification: find_output() –A Fuzzy Control Example -- Floating Ping-Pong Ball
Fuzzy Control Fuzzy Sets Design of a Fuzzy Controller –Fuzzification of inputs: get_inputs() –Fuzzy Inference –Processing the Rules: find_rules() –Centroid Defuzzification –Output Defuzzification: find_output() –A Fuzzy Control Example -- Floating Ping-Pong Ball
;Fuzzy Control ;Data Structures ball_positionrmb24 ball_speedrmb24 in_out_arrayrmb16 rulesrmb129 centrmb cent
;Main program fuzzy ;get_inputs() ;JSRget_position;position in D STD2,-X;push on data stack LDD#ball_position;D -> ball_position STD2,-X;push on data stack JSRFILLWT;fill.weights ;JSRget_speed;speed in D STD2,-X;push on data stack LDD#ball_speed;D -> ball_speed STD2,-X;push on data stack JSRFILLWT;fill.weights ;fire_rules() LDD#in_out_array;D -> in_out_array STD2,-X;push on data stack LDD#rules;D -> rules STD2,-X;push on data stack JSRFIRERULES;fire rules ;find_output() LDD#rules;D -> rules STD2,-X;push on data stack LDD#cent;D -> cent STD2,-X;push on data stack JSRFINDOUT;find output BRAfuzzy
; Fill Weight Arrays ; fill.weights ( xi memfunc_addr -- ) FILLWT LDY 2,X+ ;Y -> input membership functions LDD 2,X+ ;B = xi PSHX ;save X TFR Y,X ;X -> membership functions LDY 2,X ;Y -> input weight table PSHB ;save xi LDD 4,X+ ;B = #mem functs; X->1st memb fnc PULA ;A = xi FW1 MEM ;fuzzy membership grade DBNE B,FW1 PULX ;restore X RTS
; Fire all rules ; firerules ( in.out_addr rules_addr -- ) FIRERULES LDD 2,X+ ;D -> rules LDY 2,X+ ;Y -> in.out.array PSHX TFR D,X ;X -> rules INX INX ;X -> Wout addr PSHY ;save Y LDY 2,X+ ;Y -> Wout, X -> 1st rule LDAB 0,Y ;B = #out.memb.fncs FR0 CLR 1,X+ ;clear W array DBNE B, FR0 PULY ;Y -> in.out.array LDAA #$FF REV ;rule evaluation PULX RTS
; Find Output value ; calc.output ( rules cent_addr -- output_value ) FINDOUT LDD 2,X+ ;D -> cent LDY 2,X+ ;Y -> rules PSHX TFR D,X ;X -> cent array LDY 2,Y ;Y -> Warray LDAB 0,Y ;B = #out.memb.fncs INY ;Y -> W array WAV EDIV ;Y = quotient TFR Y,D ;D = quotient A = 0, B = output PULX STD 2,-X RTS