Fuzzy Logic Controllers. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

Similar documents
Linking Assembly Subroutine with a C Program

EE 5340/7340 Motorola 68HC11 Microcontroler Lecture 1. Carlos E. Davila, Electrical Engineering Dept. Southern Methodist University

ARTIFICIAL INTELLIGENCE. Uncertainty: fuzzy systems

Total: EEL 3701 Digital Logic & Computer Systems Final Exam Fall Semester 2007 COVER SHEET: Re-Grade Information: 1 (10) 2 (10) 3 (10) 4 (14) 5 (14)

Lecture 36 April 25, 2012 Review for Exam 3. Linking Assembly Subroutine with a C Program. A/D Converter

ME4447/6405. Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics. Instructor: Professor Charles Ume LECTURE 7

Mark McDermo2 Steven Smith. SOC Design. Taxonomy of Hardware Accelera+on Microcoded Co- Processor. MC68332 Time Processing Unit

Mark II Aiken Relay Calculator

FUZZY INFERENCE SYSTEMS

Homework 12 Solutions

Fuzzy Reasoning. Outline

CHAPTER 4 FREQUENCY STABILIZATION USING FUZZY LOGIC CONTROLLER

Lab 2 Part 1 Assembly Language Programming and 9S12 Ports

LECTURE #21: G-CPU & Assembly Code EEL 3701: Digital Logic and Computer Systems Based on lecture notes by Dr. Eric M. Schwartz

Introduction to Fuzzy Logic and Fuzzy Systems Adel Nadjaran Toosi

CHAPTER 5 FUZZY LOGIC CONTROL

FUZZY LOGIC TECHNIQUES. on random processes. In such situations, fuzzy logic exhibits immense potential for

Most of the HC12 s instructions access data in memory There are several ways for the HC12 to determine which address to access

ARTIFICIAL INTELLIGENCE - FUZZY LOGIC SYSTEMS

Module 1-D. Control Structure Applications. Tim Rogers 2017 [1.D]-1

ECE 3120 Computer Systems Arithmetic Programming

Dinner for Two, Reprise

Introduction 3 Fuzzy Inference. Aleksandar Rakić Contents

ECET Chapter 2, Part 2 of 3

Lecture 11: Advanced Arithmetic Instructions

Chapter 7 Fuzzy Logic Controller

Wed. Sept 6 Announcements

Sample Problem Set #1

Chapter 2: HCS12 Assembly Programming. EE383: Introduction to Embedded Systems University of Kentucky. Samir Rawashdeh

Ryerson University Department of Electrical and Computer Engineering ELE 538 Microprocessor Systems Final Examination December 8, 2003

S12CPUV2. Reference Manual HCS12. Microcontrollers. S12CPUV2/D Rev. 0 7/2003 MOTOROLA.COM/SEMICONDUCTORS

EE4390 Microprocessors

Background Fuzzy control enables noncontrol-specialists. A fuzzy controller works with verbal rules rather than mathematical relationships.

EE319 K Lecture 3. Introduction to the 9S12 Lab 1 Discussion Using the TExaS simulator. University of Texas ECE

Using the stack and the stack pointer

Introduction to Embedded Systems and Chapter 1: Introduction to HCS12/MC9S12. EE383: Introduction to Embedded Systems University of Kentucky

EE 308 Spring The HCS12 has 6 addressing modes

CHAPTER 3 FUZZY RULE BASED MODEL FOR FAULT DIAGNOSIS

Lecture notes. Com Page 1

Introduction 2 Fuzzy Sets & Fuzzy Rules. Aleksandar Rakić Contents

Menu Computer Organization Programming Model for the an example microprocessors (the G-CPU & Motorola 68HC11) Assembly Programming Look into my...

Mark Redekopp and Gandhi Puvvada, All rights reserved. EE 357 Unit 15. Single-Cycle CPU Datapath and Control

FUZZY INFERENCE. Siti Zaiton Mohd Hashim, PhD

ECE331 Handout 3- ASM Instructions, Address Modes and Directives

Why Fuzzy? Definitions Bit of History Component of a fuzzy system Fuzzy Applications Fuzzy Sets Fuzzy Boundaries Fuzzy Representation

What is all the Fuzz about?

Lecture 5 Assembly Programming: Arithmetic

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

CodeWarrior. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

Introduction to Programming the 9S12 in C Huang Sections 5.2 and 5.3. You will be able to use all of the Motorola data manuals on the exam.

Why Fuzzy Fuzzy Logic and Sets Fuzzy Reasoning. DKS - Module 7. Why fuzzy thinking?

EE 3170 Microcontroller Applications

MC9S12 Assembler Directives A Summary of MC9S12 Instructions Disassembly of MC9S12 op codes. Summary of HCS12 addressing modes ADDRESSING MODES

Fuzzy Logic Based Path Planning for Quadrotor

1. Memory Mapped Systems 2. Adding Unsigned Numbers

ECE L A B 1 Introduction ASSEMBLY PROGRAMMING WITH MINIIDE

Fuzzy Logic. Sourabh Kothari. Asst. Prof. Department of Electrical Engg. Presentation By

Decimal, Hexadecimal and Binary Numbers Writing an assembly language program

Fuzzy Sets and Fuzzy Logic. KR Chowdhary, Professor, Department of Computer Science & Engineering, MBM Engineering College, JNV University, Jodhpur,

What is all the Fuzz about?

Lotfi Zadeh (professor at UC Berkeley) wrote his original paper on fuzzy set theory. In various occasions, this is what he said

Introduction to Intelligent Control Part 2

Y = (A + C) (A + B) (B + C)

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

Lecture 5 Fuzzy expert systems: Fuzzy inference Mamdani fuzzy inference Sugeno fuzzy inference Case study Summary

Cross Assembly and Program Development

Fuzzy Sets and Fuzzy Logic

Fuzzy Networks for Complex Systems. Alexander Gegov University of Portsmouth, UK

ECE 331: PC Lab 3 Stack and Subroutines

68HC12 Training Lab Student Exercise Book

An ability to program a microcontroller to perform various tasks

Deciphering Data Fusion Rule by using Adaptive Neuro-Fuzzy Inference System

N bit is set if result of operation in negative (MSB = 1) Z bit is set if result of operation is zero (All bits = 0)

Demonstration Model of fuzzytech Implementation on M68HC12

EE319 K Lecture 7. Address mode review Assembler, Debugging Psuedo ops 16 bit timer finite state machines. University of Texas ECE

Lecture 6 Assembly Programming: Branch & Iteration

Final Exam. Controller, F. Expert Sys.., Solving F. Ineq.} {Hopefield, SVM, Comptetive Learning,

Chapter 2 HCS12 Assembly Language

CHAPTER 3 ADAPTIVE NEURO-FUZZY INFERENCE SYSTEM

Chapter 4 Fuzzy Logic

HC11 Instruction Set Architecture

ECET Chapter 2, Part 3 of 3

HC11 Instruction Set Architecture

Dra. Ma. del Pilar Gómez Gil Primavera 2014

INTERNATIONAL JOURNAL OF COMPUTER ENGINEERING & TECHNOLOGY (IJCET)

Introduction to Programming

2. Arithmetic Instructions addition, subtraction, multiplication, divison (HCS12 Core Users Guide, Sections 4.3.4, and ).

Figure 2-1: Membership Functions for the Set of All Numbers (N = Negative, P = Positive, L = Large, M = Medium, S = Small)

Fuzzy Sets and Systems. Lecture 1 (Introduction) Bu- Ali Sina University Computer Engineering Dep. Spring 2010

History of the Microprocessor. ECE/CS 5780/6780: Embedded System Design. Microcontrollers. First Microprocessors. MC9S12C32 Block Diagram

Exam 1 Feb. 23, 25, 27?

Decision Making: Fuzzy Logic

A Brief Idea on Fuzzy and Crisp Sets

538 Lecture Notes Week 2

Outlines. Fuzzy Membership Function Design Using Information Theory Measures and Genetic Algorithms. Outlines

fuzzytech ST6 Explorer Edition

CS/ECE 5780/6780: Embedded System Design

REASONING UNDER UNCERTAINTY: FUZZY LOGIC

A Simple MC9S12 Program

Self-learning Mobile Robot Navigation in Unknown Environment Using Evolutionary Learning

Transcription:

Fuzzy Logic Controllers

Control System Models the physical system Uses sensor feedback to generate a new system control signal Controller requires accurate mathematical model of system Requires accurate, often complex system of equations These equations are not always readily available http://wwweng.uwyo.edu/electrical/faculty /barrett/68hc12/fuzzy_logic.pdf 2

Motivation for Fuzzy Logic People do not require precise, numerical information input, and yet they are capable of highly adaptive control. 1 Fuzzy logic deals with reasoning that is approximate rather than fixed and exact Similar to neural networks Proponents claim fuzzy systems are much closer to human control processes Skeptics deride fuzzy logic for lack of mathematical rigor However, fuzzy logic controllers are in heavy use For example, HCS12 has dedicated machine instructions for fuzzy logic! It must have enough demand to warrant this kind of support. 1 Professor Lotfi Zadeh, UC Berkeley, 1965 3

Fuzzy Logic Fuzzy logic is a form of many-valued logic or probabilistic logic Compared to traditional binary variables (true or false) fuzzy logic variables have a truth value that ranges in degree between 0 and 1 Fuzzy logic has the concept of partial truth, where the truth value may range between completely true and completely false Conventional (Boolean) Set Theory Fuzzy Set Theory 38 C 40.1 C 41.4 C 38.7 C 38 C 40.1 C 41.4 C 38.7 C 39.3 C 37.2 C 42 C Strong Fever 39.3 C 37.2 C 42 C Strong Fever http://www.cse.lehigh.edu/~munoz/cse335/classes/fuzzylogic.ppt 4

Fuzzy Logic Controller Overview Rely on if-then rules rather than mathematical equations A simple form of an expert system An expert system has rules to map input signals to output system responses Uses confidence factors to assign a system output From: http://wwweng.uwyo.edu/electrical/faculty/barrett/68hc12/fuzzy_logic.pdf 5

Advantages Advantages and Disadvantages Useful where system equations are difficult to develop Solutions can be developed quickly and intuitively Mimics human control logic Uses imprecise language Other advantages Inherently robust Fails safely Modified and tweaked easily Disadvantages Operator's experience required System complexity 6

Example Applications Sendai subway system train controller HVAC controllers Industrial automation for process control Videos Flexible robot control http://www.youtube.com/watch?v=r7dhudg5ri4 Anti-sway control of a crane http://www.youtube.com/watch?v=fb1efdzpofy Mobile robot control http://www.youtube.com/watch?v=ob6ume9pyfi 7

Possible Instances to Use Fuzzy Logic When it is difficult to obtain a mathematical model of the process. If fuzzy logic has been previously applied to a similar application with success. If you have some knowledge about the process variables and their interdependencies. If you can easily do experiments to find good values for the fuzzy logic parameters. 8

Recall Boolean logic Any Boolean logic function can be implemented as an AND-OR network This network implements three functions of two inputs A control output signal is asserted if its rule (i.e., AND- OR expression) is satisfied From: Designing with Microcontrollers, Tom Almy, http://www.almy.us 9

Fuzzy logic In fuzzy logic we don t use True and False values, but allow a continuum of values from totally false (0) to totally true (1) The inputs and outputs can have multiple levels A process called fuzzification converts the input levels into fuzzy levels A membership function determines the fuzzy levels Example: input voltages less than 1 are totally false and those greater than 4 are totally true; other values have intermediate truth From: Designing with Microcontrollers, Tom Almy, http://www.almy.us 10

Fuzzy logic The result is that all of the output signals may be asserted to some extent! In Boolean logic The output of an AND gate is false if any input is false (i.e., the output is the minimum of the inputs) The output of an OR gate is the maximum of its inputs In fuzzy logic the AND/OR logic network becomes a minimum function followed by a maximum function Instead of the AND logic operation, take the minimum of the inputs fuzzy levels Instead of the OR logic operation, take the maximum of the inputs from the first level 11

Fuzzy logic control Steps Map input values to fuzzy input membership values ( fuzzification ) Evaluate rules to generate output membership values Convert output membership values to a digital value ( defuzzification ) http://wwweng.uwyo.edu/electrical/faculty /barrett/68hc12/fuzzy_logic.pdf 12

Fuzzification Given an input datum, the controller must first assign a degree of membership, a value ranging from zero to one, to each fuzzy membership function http://wwweng.uwyo.edu/electrical/faculty /barrett/68hc12/fuzzy_logic.pdf 13

Rule evaluation Apply expert rules to input membership functions Rules should cover all possible combinations of the input variables Rules map combinations of inputs to output fuzzy membership functions Rule format: if (antecedent 1) AND (antecedent 2), then (desired response) The minimum degree of membership among the input functions is assigned to the output membership function (this is the confidence factor) 14

Rule evaluation (continued) If there are multiple rules that assign an output function, take the maximum of the confidence factors as the degree of the membership for that output fuzzy function. Namely, use the most dominant rule to assign the output membership function. We still need to convert the output membership function values to a form suitable to control system ( defuzzification ). 15

Defuzzification Each output membership function has a nominal output value Si To combine them, average the output values of all the functions, but weighted by their fuzzy membership values http://wwweng.uwyo.edu/electrical/faculty /barrett/68hc12/fuzzy_logic.pdf 16

Example - Fuzzy logic based robot controller Want robot to avoid obstacles Robot has two IR distance sensors (values 0..$FF) Output is the motor command, from 0 (hard left) to $FF (hard right) $80 means go straight http://wwweng.uwyo.edu/electrical/faculty/barrett/68hc12/fuzzy_logic.pdf 17

Development steps Determine linguistic variables describing all inputs to the controller left sensor input: very weak, weak, medium, strong, very strong right sensor input: very weak, weak, medium, strong, very strong Each linguistic variable must be defined with a set of input membership functions For the HC12 a trapezoidal function must be used http://wwweng.uwyo.edu/electrical/faculty/barrett/68hc12/fuzzy_logic.pdf 18

Development steps (continued) Input membership function Specify using: farthest left point, farthest right point, left slope, and right slope Full membership corresponds to $FF very weak $00, $50, $00, $10 weak $40, $70, $10, $10 medium $60, $A0, $10, $10 strong $90, $C0, $10, $10 very strong $B0, $FF, $10, $00 300 250 200 150 100 50 very weak weak medium strong very strong 0 0 50 100 150 200 250 300 19

Development steps (continued) Determine fuzzy rules that map input to output membership functions Rules are intuitive based on considering all possible input sensor value scenarios Rule format: IF (antecedent 1) AND (antecedent 2), THEN (desired output) 20

Development steps (continued) Rules in table form http://wwweng.uwyo.edu/electrical/faculty/barrett/68hc12/fuzzy_logic.pdf 21

Development steps (continued) Output membership function design process Use singleton functions for the fuzzy output membership functions ( singleton : each function is defined by a single value) Medium Left ($40) Small Left ($60) Zero ($80) Small Right ($A0) Medium Right ($C0) (Assumption: $80 keeps robot on straight path) 22

Development steps (continued) Define output values of all output fuzzy membership functions The controller will take a weighted average of the values, weighted by their fuzzy membership values Output = Σ (Si Fi) / Σ (Fi) for i = i..n where: Si is the Singleton value Fi is the output membership value for fuzzy logic output function i 23

// Define the tables for the input value membership functions. // Specify using: farthest left pt, farthest right pt, left slope, right slope int veryweaktable[] = { 0x00, 0x50, 0x00, 0x10 }; int weaktable[] = { 0x40, 0x70, 0x10, 0x10 }; int mediumtable[] = { 0x60, 0xa0, 0x10, 0x10 }; int strongtable[] = { 0x90, 0xc0, 0x10, 0x10 }; int verystrongtable[] = { 0xb0, 0xff, 0x10, 0x00 }; // Define the values for the output members. #define mediumleft 0x40 // hard left turn #define smallleft 0x60 #define zero 0x80 // go straight #define smallright 0xa0 #define mediumright 0xc0 // hard right trun // Utility functions for min, max. int min(int a, int b) { return (a<b? a : b); } int max(int a, int b) { return (a>b? a : b); } int max(int a, int b, int c, int d) { return max( max(a,b), max(c,d) ); // 4-input max function } int max(int a, int b, int c, int d, int e) { return max( max(a,b,c,d), e ); // 5-input max function } int max(int a, int b, int c, int d, int e, int f) { return max( max(a,b,c,d), max(e,f) ); // 6-input max function } int fuzzification(int x, int table[]) { int x0 = table[0]; // Leftmost point int x1 = table[1]; // Rightmost point int s0 = table[2]; // Left slope int s1 = table[3]; // Right slop int y0 = (x0==0? 255 : 0); int y1 = (x1==255? 255 : 0); if (x < x0 x > x1) return 0; // Value at leftmost point // Value at rightmost point Mobile Robot Example Code C++ This is simple program that directly implements the robot controller. A better version would be able to handle an arbitrary number of variables and rules. See http://www.codeproject.com/a rticles/316668/cplusplus-fuzzy- Logic-API-plus-Simple-DSL, for example } // Estimate value at x. int y = min(y0 + s0*(x-x0), y1 - s1*(x-x1)); y = min(y, 255); // Clip to 255 return (int) y; 24

void main(void) { EnableInterrupts; for(;;) { // Some code needed to read left and right sensor values. int leftsensor; int rightsensor; // Perform fuzzification to determine input membership values. int lvw = fuzzification(leftsensor, veryweaktable); int lw = fuzzification(leftsensor, weaktable); int lm = fuzzification(leftsensor, mediumtable); int ls = fuzzification(leftsensor, strongtable); int lvs = fuzzification(leftsensor, verystrongtable); int rvw = fuzzification(rightsensor, veryweaktable); int rw = fuzzification(rightsensor, weaktable); int rm = fuzzification(rightsensor, mediumtable); int rs = fuzzification(rightsensor, strongtable); int rvs = fuzzification(rightsensor, verystrongtable); Mobile Robot Example Code C++ // Perform rule evaluation to determine output membership values. // Each rule is of the form IF (a AND b) OR (c AND d) THEN e int gomediumleft = max( min(lw,rvs), min(lw,rs), min(lvw,rvs), min(lvw,rs) ); int gosmallleft = max( min(ls,rvs), min(lm,rvs), min(lm,rs), min(lw,rm), min(lvw,rm), min(lvw,rw)); int gozero = max( min(lvs,rvs), min(ls,rs), min(lm,rm), min(lw,rw), min(lvw,rvw) ); int gosmallright = max( min(rs,lvs), min(rm,lvs), min(rm,ls), min(rw,lm), min(rvw,lm), min(rvw,lw)); int gomediumright = max( min(rw,lvs), min(rw,ls), min(rvw,lvs), min(rvw,ls) ); // Perform defuzzification to determine a precise output value. // The output is just the weighted sum of the members. int outvalue = (gomediumleft*mediumleft + gosmallleft*smallleft + gozero*zero + gosmallright*smallright + gomediumright*mediumright)/ (gomediumleft + gosmallleft + gozero + gosmallright + gomediumright); } // Some code needed to send the control output to the actuators. } /* loop forever */ 25

HCS12 Fuzzy Logic Instructions Four HCS12 instructions: MEM: grade of membership REV: MIN-MAX rule evaluation REVW: MIN-MAX rule evaluation with optional rule weighting WAV: performs weighted average calculations See Section 9 in the CPU12 reference manual Supplementary instructions: ETBL, TBL, EDIV, EDIVS, EMACS, EMAX, EMAXM, EMIND, EMINM, EMUL, EMULS 26

Line 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Line 2 ;Fuzzy Logic Controller for A Mobile Robot Line 3 ;Description: This program takes in two Infrared Line 4 ;sensor values and computes a di Line 5 ;rection control signal to avoid Line 6 ;wall collisions. The two sensor Line 7 ;values are read from memory Line 8 ;locations $6000 and $6001 and Line 9 ;the control output value is Line 10 ;written to memory location $6002 Line 11 ; Line 12 ; Authors: Daniel Pack and Steve Barrett Line 13 ; Date: 8-21-2000 Line 14 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Line 15 ; Data Section Line 16 O_R_VS EQU $00 ;Offset values input and output mem fns Line 17 O_R_ST EQU $01 ; Right Sensor Strong Line 18 O_R_ME EQU $02 ; Right Sensor Medium Line 19 O_R_WE EQU $03 ; Right Sensor Weak Line 20 O_R_VW EQU $04 ; Right Sensor Very Weak Line 21 O_L_VS EQU $05 ; Left Sensor Very Strong Line 22 O_L_ST EQU $06 ; Left Sensor Strong Line 23 O_L_ME EQU $07 ; Left Sensor Medium Line 24 O_L_WE EQU $08 ; Left Sensor Weak Line 25 O_L_VW EQU $09 ; Left Sensor Very Weak Line 26 O_ML Line 27 O_SL Line 28 O_ZR Line 29 O_SR Line 30 O_MR EQU $0A ; Medium Left EQU $0B ; Small Left EQU $0C ; Zero EQU $0D ; Small Right EQU $0E ; Medium Right Line 31 MARKER EQU $FE ; rule separator Line 32 ENDR EQU $FF ; end of rule marker Mobile Robot Example Code - Assembly 27

Line 33 ORG $6000 Line 34 RSENSOR RMB $01 ; Allocating Line 35 LSENSOR RMB $01 ; memory locations Line 36 CONTROLS RMB $01 ; for input/output variables Mobile Robot Example Code - Assembly Line 37 ; Fuzzy Input Membership Function Definitions for Right Sensor Line 38 R_Very_Strong FCB $B0, $FF, $10, $00 Line 39 R_Strong FCB $90, $C0, $10, $10 Line 40 R_Medium FCB $60, $A0, $10, $10 Line 41 R_Weak FCB $40, $70, $10, $10 Line 42 R_Very_Weak FCB $00, $50, $00, $10 Line 43 ; Fuzzy Input Membership Function Definitions for Left Sensor Line 44 L_Very_Strong FCB $B0,$FF,$10,$00 Line 45 L_Strong FCB $90,$C0,$10,$10 Line 46 L_Medium FCB $60,$A0,$10,$10 Line 47 L_Weak FCB $40,$70,$10,$10 Line 48 L_Very_Weak FCB $00,$50,$00,$10 Line 49 ;Fuzzy Output Membership Function Definitions Line 50 Medium_Left FCB $40 Line 51 Small_Left FCB $60 Line 52 Zero FCB $80 Line 53 Small_Right FCB $A0 Line 54 Medium_Right FCB $C0 28

Line 55 ; Locations for fuzzy membership values Line 56 R_VS RMB $01 Line 57 R_ST RMB $01 Line 58 R_ME RMB $01 Line 59 R_WE RMB $01 Line 60 R_VW RMB $01 Line 61 L_VS RMB $01 Line 62 L_ST RMB $01 Line 63 L_ME RMB $01 Line 64 L_WE RMB $01 Line 65 L_VW RMB $01 Mobile Robot Example Code - Assembly Line 66 ; Output Fuzzy Logic Membership Values - initialize to zero Line 67 ML FCB $00 Line 68 SL FCB $00 Line 69 ZR FCB $00 Line 70 SR FCB $00 Line 71 MR FCB $00 29

In HCS12, rules are stored as antecedent one, antecedent two, $FE, desired output, $FE Line 72 ; Rule Definitions Line 73 Rule_Start FCB O_R_VS,O_L_VS,MARKER,O_ZR,MARKER Line 74 FCB O_R_VS,O_L_ST,MARKER,O_SL,MARKER Line 75 FCB O_R_VS,O_L_MD,MARKER,O_SL,MARKER Line 76 FCB O_R_VS,O_L_WE,MARKER,O_ML,MARKER Line 77 FCB O_R_VS,O_L_VW,MARKER,O_ML,MARKER Line 78 FCB O_R_ST,O_L_VS,MARKER,O_SR,MARKER Line 79 FCB O_R_ST,O_L_ST,MARKER,O_ZR,MARKER Line 80 FCB O_R_ST,O_L_MD,MARKER,O_SL,MARKER Line 81 FCB O_R_ST,O_L_WE,MARKER,O_ML,MARKER Line 82 FCB O_R_ST,O_L_VW,MARKER,O_ML,MARKER Line 83 FCB O_R_MD,O_L_VS,MARKER,O_SR,MARKER Line 84 FCB O_R_MD,O_L_ST,MARKER,O_SR,MARKER Line 85 FCB O_R_MD,O_L_MD,MARKER,O_ZR,MARKER Line 86 FCB O_R_MD,O_L_WE,MARKER,O_SL,MARKER Line 87 FCB O_R_MD,O_L_VW,MARKER,O_SL,MARKER Line 88 FCB O_R_WE,O_L_VS,MARKER,O_MR,MARKER Line 89 FCB O_R_WE,O_L_ST,MARKER,O_MR,MARKER Line 90 FCB O_R_WE,O_L_MD,MARKER,O_SR,MARKER Line 91 FCB O_R_WE,O_L_WE,MARKER,O_ZR,MARKER Line 92 FCB O_R_WE,O_L_VW,MARKER,O_SL,MARKER Line 93 FCB O_R_VW,O_L_VS,MARKER,O_MR,MARKER Line 94 FCB O_R_VW,O_L_ST,MARKER,O_MR,MARKER Line 95 FCB O_R_VW,O_L_MD,MARKER,O_SR,MARKER Line 96 FCB O_R_VW,O_L_WE,MARKER,O_SR,MARKER Line 97 FCB O_R_VW,O_L_WE,MARKER,O_ZR,ENDR Mobile Robot Example Code - Assembly 30

Line 98 ; Main Program Line 99 ORG $4000 Line 100 ; Fuzzification---------------------------------------------------- ; Fuzzification Procedure ; MEM function determines grade of membership. ; ; Registers must be set up as follows: ; A: must hold the current crisp value of system input variable ; X: must point to 4-byte data structure describing the trapezoidal ; membership function for a label of the system input ; Y: must point to the fuzzy input (RAM location) where the resulting ; grade of membership is to be stored ;------------------------------------------------------------------ ; Perform fuzzification for right sensor Line 101 LDX #R_Very_Strong ; Start of Input Mem func Line 102 LDY #R_VS ; Start of Fuzzy Mem values Line 103 LDAA RSENSOR ; Right Sensor Value Line 104 LDAB #5 ; Number of iterations Line 105 Loopr MEM ; Assign mem value Line 106 DBNE B,Loopr ; Do all five iterations ; Perform fuzzification for left sensor Line 107 LDAA LSENSOR ; Left Sensor Value Line 108 LDAB #5 ; Number of iterations Line 109 Loopl MEM ; Assign mem value Line 110 DBNE B,Loopl ; Do all five iterations Mobile Robot Example Code - Assembly All the preceding code is just setup and initialization. The bulk of the actual work is done here, by the MEM instruction. 31

; Fuzzy Logic Rule Evaluation------------------------------------- ; REV function performs an unweighted evaluation of a list of rules, ; using fuzzy input values to produce fuzzy outputs. ; ;Before executing REV, perform the following set up operations. ; X: must point to the first 8-bit element in the rule list. ; Y: must point to the base address for fuzzy inputs and outputs ; A: must contain the value of $FF, and the CCR V bit must = 0 ; (LDAA #$FF places the correct value in A and clears V) ; Clear fuzzy outputs to zeros ;----------------------------------------------------------------- Line 111 LDY #R_VS ; Process rules Line 112 LDX #Rule_Start ; Point X to the start addr Line 113 LDAA #$FF ; Initialize min and V bit Line 114 REV ; Evaluate rules Line 115 ; Defuzzification Process-------------------------------- ; WAV function performs weighted average calculations on ; values stored in memory. ; X: used to reference one source operand list ; Y: used to reference second source operand list ; B: used a s counter to control number of elements to ; be included in the weighted average ;------------------------------------------------------------- Line 116 LDX #Medium_Left ; Start of output mem func Line 117 LDY #ML ; Start of mem values Line 118 LDAB #$05 ; Five elements sum Line 119 WAV ; Computing a crisp value Line 120 EDIV ; Extended divide - 32 bit/16 bit Line 121 TFR Y,D ; Store answer to D Line 122 STAB CONTROLS ; Save the answer Line 123 END Mobile Robot Example Code - Assembly The REV and the WAV instructions do the bulk of the work here too. 32

Summary / Questions Fuzzy logic is a superset of conventional (Boolean) logic that has been extended to handle the concept of partial truth; i.e., truth values between "completely true" and "completely false". It has been used for control applications and recognition systems. What are the advantages and disadvantages of fuzzy logic? 33