0% found this document useful (0 votes)
43 views9 pages

Case Study 1

Uploaded by

kavitamishra9700
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views9 pages

Case Study 1

Uploaded by

kavitamishra9700
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Int. J. Engng Ed. Vol. 21, No. 1, pp. 178±186, 2005 0949-149X/91 $3.00+0.

00
Printed in Great Britain. # 2005 TEMPUS Publications.

Implementing Fuzzy Logic for Machine


Intelligence: A Case Study*
M. D. HURLEY, W. L. XU and GLEN BRIGHT
Institute of Technology and Engineering, College of Sciences, Massey University, Palmesrton North,
New Zealand. E-mail: [email protected]
Intelligent machines are machines with microcontroller(s), actuators and sensors embedded and of
reprogrammable intelligence. The Mechatronics course at Massey University, New Zealand,
teaches students how to design intelligent machines in an integrated manner. The success of the
teaching/learning would be achieved in a way that the students are able to apply what they have
learnt from various courses to the design of an intelligent machine. To this end, each student is
required to do a design project. This paper presents a sample project that deals with real-time
implementation of fuzzy logic for machine intelligence on microcomputer. The objectives identified
for the project were to modify Rug-Warrior Pro, an autonomous mobile robot platform, to have a
long-ranging capability and to implement obstacle avoidance in an unmapped and changing
environment as the machine intelligence. The hardware interfacing and software drivers of the
sensors are given, and the techniques for coding the membership functions and defuzzification
operation of fuzzy logic are discussed. The machine behaviours are formulated by an If±Then rule
base that mimics human heuristic, and the resultant program offers an excellent alternative to more
common vector-based navigation methods with a fraction of the processing requirements resulting
in a fast-responding, reliable application.

INTRODUCTION The Rug-Warrior Pro can be controlled directly


from the keyboard by way of Interactive C's
FUZZY LOGIC HAS found many applications in command line or it is able to operate autono-
machine intelligences and behaviours based mously under the control of its on-board micro-
controls, and its implementations can be either controller. The `brains' of the Rug-Warrior Pro is
on PCs or microcontrollers [1]. The student project the Motorola MC68HC811E2 microcontroller.
presented in this paper was to develop a fuzzy logic This uses the Motorola MC68HC11 microproces-
approach to obstacle avoidance for an educational sor with extended memory. It contains 256 bytes of
mobile robot and to implement it on the embedded RAM, and 2048 bytes of EEPROM.A time-shar-
microcomputer. The mobile robot used in the ing operating system allows the execution of paral-
project is Rug-Warrior Pro, which was developed lel processes. For example, one process may be
by the Massachusetts Institute of Technology used for motor control, while another independent
(MIT) for use in robotics courses [2]. It is a small process is used for reading and processing informa-
autonomous robot designed for educators, tion from the sensors [2, 8].
researchers, and hobbyists and works in an The machine behaviours are formulated by a set
unmapped and changing environment. The Rug- of If±Then rules that mimic human heuristic and
Warrior Pro is a microprocessor-based mobile are coordinated in fuzzy logic. To have a long-
robot kit that contains the complete processing, ranging capability for the purpose of obstacle
memory, and sensor circuitry (Brains), as well as avoidance, the Rug-Warrior Pro was modified to
the motors, wheels, chassis and custom body parts include three sets of ultrasonic sensors. The hard-
(Brawn). ware interfacing and software drivers of the
The Rug-Warrior Pro may be programmed sensors are given, and the techniques for coding
from either a Mac or an IBM PC using Interactive the fuzzy logic operation are discussed in the
C. Interactive C is a compilation environment for paper. The learning outcomes achieved in the
many Motorola 6811-based robots and embedded project for the course Mechatronics are sensor
systems. The code is downloaded from Interactive and signal processing, motor drive and control,
C to the Rug-Warrior Pro via the serial port. microcontroller interfacing and software driver,
Library routines and self-test code are provided machine intelligence and programming, and inte-
for all the robot's standard sensors and actuators, gration of mechatronic components. The project
such as motor routines and printing to the LCD. presented as a case study promotes students' can-
do attitude in implementing what they have
learned in advanced topics including machine
* Accepted 20 May 2004. intelligence.

178
Implementing Fuzzy Logic for Machine Intelligence 179

Table 1. Sensor interfacing configuration switch has three pins, pin 3 being ground, pin 2 is
Vcc and pin 1 is the output. When the switch is
Sensor Set Enable Pin Output
open, the output is ground, when closed the output
Left PD2 PE7 is Vcc. The bump switches are connected to a 10-
Centre PA3 PE6 pin connector that is hard-wired on the microcon-
Right PD3 PE5 troller board. The analogue output for the bump
switches is received on the PE3 line of the micro-
controller [3]. When one or more of the bump
OBSTACLE SENSORS AND THEIR switches are triggered, a binary value is returned
INTERFACING AND SOFTWARE DRIVERS to the microcontroller (via PE3). The return values
are shown in Table 2.
Ultrasonic sensors For this application, only the two front bump
For obstacle detection operation, an ultrasonic switches were being used; the output line for the
ranging system was chosen. The sensor system rear bump switch was hard-wired to ground, there-
used was a Velleman Parking Radar kit available fore only analogue outputs of 0±3 could be
from Dick Smith Electronics stores. The output of received from the bump switches.
the sensor kit is either high or low; no ranging data
is provided from the kit [7]. The ultrasonic detec-
tion module works on a very simple principle. It FUZZY LOGIC FOR OBSTACLE
transmits a 40 kHz signal from an ultrasonic AVOIDANCE
transducer and, with the receiving transducer, the
echo from the transmitter is monitored at a Why fuzzy logic?
sampling frequency of 26 Hz. When an echo is For the obstacle avoidance algorithm, a fuzzy
received, the resultant output from the receiver is logic system was chosen. There are two main
then conditioned before being used to drive a piezo reasons why a fuzzy logic system was chosen: the
buzzer. The resultant output to the piezo buzzer is first is due to the ultrasonic sensors that are used,
an active low signal on the negative pin (i.e. when and the second is because of processing require-
an obstacle is detected, the signal is low). For the ments. Ultrasonic sensors in a distance ranging
application of obstacle avoidance, the piezo buzzer system such as the one used in this application are
was removed and the negative pin was connected notorious for providing imprecise data, and using
to the Rug-Warrior's microcontroller. a fuzzy logic system aids in ensuring that this lack
Three sets of ultrasonic sensors (and so three of precision has minimal effects on the overall
Velleman Parking Radar kits) were required, one functionality of the program. One of the main
to detect objects on the left, one set for the centre considerations for the implementation of this
and one set for the right. This meant that three application was the processing speed of the micro-
digital inputs and three digital outputs were controller and thus the reaction time of the robot.
required. The digital inputs were available in the With this in mind, it was necessary to minimise the
form of PE5, PE6 and PE7 (Port E, lines 5±7). number of instructions and calculations required.
These lines were used to receive the output (or echo Many obstacle avoidance techniques that do not
line) from the sensors [2, 3]. In order to get the use a fuzzy logic system work by dividing the area
required three digital outputs, the two infrared surrounding the robot into a grid pattern and then
emitters and the piezo buzzer were removed from calculating the probability of an obstacle being
the microcontroller. This left the digital output present in each square of the grid based on the
lines PD2, PD3 and PA3 available for the sensor sensor data. These methods require a vast number
enable lines. of calculations and so significantly increase the
response time of the robot. Fuzzy logic requires
Bump Switches much fewer calculations and so is more suited for
The Rug-Warrior Pro comes standard with this application. For this application of fuzzy logic
three bump switches; one on the front left, one for machine intelligence, there were three basic
on the front right and one at the rear. Each bump steps to developing the program:

Table 2. Returned values for bump switches

Rear (Bit 2) Left (Bit 1) Right (Bit 0) Returned Value Analogue Value

0 0 0 000 0
0 0 1 001 1
0 1 0 010 2
0 1 1 011 3
1 0 0 100 4
1 0 1 101 5
1 1 0 110 6
1 1 1 111 7
180 M. D. Hurley et al.

. converting the obstacle detection algorithm to object and return again, this time-of-flight must be
get distance-ranging data; halved.
. developing a fuzzy logic algorithm based on the ToF ˆ Number of Clock Cycles x Clock Period
ranging data; and ˆ No. of cycles x 0.5 us
. combining the ranging system with the fuzzy Distance ˆ (ToF / 2) x Speed of Sound
logic algorithm and the bump switches to get ˆ (ToF / 2) x 342 m/s
an overall obstacle avoidance program.
Both these calculations can be combined, giving
Distance ranging the result as: Distance ˆ ToF x 0.0000855, where
The distance ranging algorithm is very simple the distance is in metres.
and is conducted separately for each set of sensors. If no echo is detected, the result is that the
The enable bit is set to allow the signal to be set by distance is set to the maximum, which for this
the transmitter. For the left set of sensors, this is application is one metre.
PD3, and Port D is located at address 0x1008 and PE7 ˆ peek (0x100A) & 0b10000000;
0b00001000 indicated bit 3 at that address [4]. That if (PE7 ˆ ˆ 0)
is, bit_set (0x1008, 0b00001000). { left_time ˆ peekword (0x100E)
The internal clock on the microcontroller is then - left_start;
checked and the transmit time is stored as a left_dist ˆ (float) left_time * 0.0000855;
variable. For the left set, it is left_start. The }
internal clock, also called the E-clock, is located else
at address 0x100E. Thus, left_start ˆ peekword left_dist ˆ 1.0;
(0x100E). Once the object distance has been calculated, the
The output or echo bit is then checked. If an enable bit for the transmit signal is cleared, turning
echo has been received, the E-clock is again off the transmit signal. The operation is then
checked and the signal's time-of-flight is calcu- returned to the main program returning the obsta-
lated. This time-of-flight is simply the time the cle distance. That is:
echo is received minus the transmit time. The
result is the number of machine cycles that have bit_clear (0x1008, 0b00001000);
elapsed. Once the time-of-flight has been calcu- return (left_dist);
lated, this is then converted into a distance by
taking into account the speed of sound and the Membership functions
clock frequency. However, as the time-of-flight (or For a fuzzy logic operation, two main parts are
ToF) is the time taken for the signal to travel to the required. The first is the membership functions

Fig. 1. Distance ranging algorithm.


Implementing Fuzzy Logic for Machine Intelligence 181

Fig. 2. Distance membership functions.

and, the other part that a fuzzy logic operation membership functions. They are used to convert
requires is the rule base, which defines the required the ranging data into near and far components. For
outputs for any given combination of inputs [5, 6]. distances less than 0.25 m (25 cm), near ˆ 1 and
The membership functions are used for converting far ˆ 0. For distances greater than 0.75 m (75 cm),
the discreet data from the inputs, in this case the near ˆ 0 and far ˆ 1. For distances greater than
ranging data, into a fuzzy value between zero and 0.25 m and less than 0.75 m, the result is a combina-
one, or converting the fuzzy output values into tion of near and far [6].
discrete values for output. For this application In order to convert the ranging data into fuzzy
there were three sets of membership functions values, these membership functions need to be
required, one for the inputs (distance) and two for converted into calculations that can be implemen-
the outputs (i.e., translational and rotational speed). ted using Interactive C. Below is the code that is
The ranging data (inputs) use the distance used to do this.

Fig. 3. Translational speed membership functions.


182 M. D. Hurley et al.

float NEAR (float dist_near) required. The fuzzy value for each parameter is
{ multiplied by the speed at the maximum point of
if (dist_near < ˆ 0.25) the membership function (refer to Fig. 3), then the
return (1.0); three are added together. That is, the fuzzy value
else if (dist_near > ˆ 0.75) for slow is multiplied by 0.0, the medium fuzzy by
return (0.0); 25.0 and the fast fuzzy value by 50.0. By adding
else these values together, the required speed can be
return ( (±2.0 * dist_near) ‡ 1.5); found.
}
float DEFUZZIFY_SPEED (void)
float FAR (float dist_far) {
{ float speed;
if (dist_far < ˆ 0.25) speed ˆ (max_SLOW * 0.0)
return (0.0); ‡ (max_MED * 25.0)
else if (dist_far > ˆ 0.75) ‡ (max_FAST * 50.0);
return (1.0); return (speed);
else }
return ( (2.0 * dist_far)Ð0.5);
} Calculating the rotational speed output follows
the same principle as the translational speed;
There are two required outputs for the fuzzy however, the rotational speed has five parts: turn
logic system, the translational speed and the rota- right big (TRB), turn right small (TRS), turn zero
tional speed. These two outputs are the values that (TZ), turn left small (TLS), and turn left big
are used for the robot's drive function. The trans- (TLB). The outputs for rotational speed can be
lational speed is divided into three parts: slow, in the range of ÿ50 to 50, where ÿ50 is TLB and 50
medium and fast, as shown in Fig. 3, with the is TRB (refer to Fig. 4).
maximum speed being 50 for this application. This Converting the rotational speed calculations to
is reflected as a percentage of the robot's maximum code for Interactive C uses the following function:
speed. The top speed is not used in this application,
because slowing the robot down gives a better float DEFUZZIFY_SA (void)
response as it allows more time for the robot to {
react as the environment changes. For the output float SA;
variable, a fuzzy value for each parameter (i.e. SA ˆ (max_TLB*-
slow, medium and fast) is received. These fuzzy 50.0) ‡ (max_TLS*25.0) ‡ (max_TZ*0.0)
values are combined to give the required output. ‡ (max_TRS*25.0) ‡ (max_TRB*50.0);
In order to convert the fuzzy values into a return (SA);
discrete speed, only one simple calculation is }

Fig. 4. Rotational speed membership functions.


Implementing Fuzzy Logic for Machine Intelligence 183

Table 3. Rule base for robotic behaviours

Rule Left Centre Right Speed Rotation

A Near Near Near Slow TRB


B Near Near Far Medium TRS
C Near Far Near Slow TZ
D Near Far Far Fast TRS
E Far Near Near Medium TLS
F Far Near Far Slow TRB
G Far Far Near Fast TLS
H Far Far Far Fast TZ

Fuzzy rule base The fuzzy value for the output is the smallest of the
For a fuzzy logic system, the rule base defines input values, so SLOW and TRB equal the result
the required outputs for any given combination of from the minimum calculation. By conducting this
inputs. The variables for each input or output are for each rule, fuzzy values for all the output
defined by the membership functions. For the parameters can be derived. Looking at the rule
distance inputs, they are either near or far; for base (Table 3), it is obvious that there is going to
translation speed output, they are slow, medium or be more than one value for each parameter. In this
fast and for the rotational speed output they are application there are either two or three values for
turn right big (TRB) turn right small (TRS), turn each. This means it is necessary to decide what the
zero (TZ), turn left small (TLS) or turn left big final output is going to be. Using a maximum
(TLB) [6]. For example, if an object is near to the calculation does this according to the fuzzy infer-
left, centre and right sensors, then rule A applies ence [5]. The final value is the maximum value
(refer to Table 3). This would make the translation from the values calculated above. For example,
speed slow and the rotation turn right big (or rules A, C and F will all give a value for the output
TRB). In converting the rule base, the rules are SLOW; the final value for this output is the largest
expressed as a simple If±Then rule; for example, in of these three values. This is given in the Inter-
the case of rule A, this is converted into an If±Then active C code procedure below:
rule as:
float MAX (float max1, float max2, float max3)
IF (left ˆ Near) & (centre ˆ Near) {
& (right ˆ Near) THEN (speed ˆ slow) float max_val;
& (rotation ˆ TRB) max_val ˆ max1;
if (max2 > max_val)
Fuzzy logic operation max_val ˆ max2;
For calculating the fuzzy values for the outputs, if (max3 > max_val)
it is necessary to combine the input fuzzy values max_val ˆ max3;
with the rule base. The fuzzy value for each rule return (max_val);
output is the smallest fuzzy value from the rule }
inputs. For example, take rule A: Once this operation is complete, fuzzy values
IF (left ˆ Near) & (centre ˆ Near) will have been found for each of the output
& (right ˆ Near) THEN (speed ˆ slow) parameters, which are subsequently defuzzified to
& (rotation ˆ TRB) get discrete values that may be used to drive the
robot.
To find the fuzzy values for the output, it is
necessary to find the smallest input value. Taking Overall machine intelligence
the near component for the three inputs (left, The overall functionality of the program is a
centre and right), a calculation is done to find combination of the bump switches, the ultrasonic
the minimum value. The Interactive C code is as distance ranging and the fuzzy logic operation. To
follows: begin, the status of the bump switches are checked.
float MIN (float min1, float min2, float min3) If one is closed, the robot will reverse and turn
{ away from the object by 90; if both are closed, the
float min_val; robot will reverse and turn 180. When neither of
min_val ˆ min1; the bump switches is closed (the normal case), the
if (min2 < min_val) program receives ranging data from the sensors
min_val ˆ min2; then uses this to conduct the fuzzy logic opera-
if (min3 < min_val) tions. The outputs from the fuzzy logic operation
min_val ˆ min3; are a translational speed and a rotational speed,
return (min_val); and these are used to drive the robot using default
} the library function: drive (trans_vel, rot_vel).
Figure 5 shows the flowchart of the fuzzy logic
In this case, the outputs are SLOW and TRB. obstacle avoidance algorithm, and Fig. 6 shows the
184 M. D. Hurley et al.

Fig. 5. Algorithm for fuzzy logic obstacle avoidance.

Fig. 6. The running robot with embedded fuzzy logic intelligence.


Implementing Fuzzy Logic for Machine Intelligence 185

Fig. 7. Operation limitation on external corners.

Fig. 8. Operation limitation on internal corners.


final robot and its negotiation of objects on a
platform. and off quickly. This means that there is a signifi-
cant delay between the time they are enabled and
the time that they begin to transmit a signal. For
PROBLEMS AND LIMITATIONS this reason, the enable lines in the program are not
cleared once the echo has been received. For future
There are three main limitations for the overall applications, it is recommended that these sensors
operation of this application. These are due to the be replaced with others that are designed for a
sensors used. The first is external corner deflection ranging application such as the Polaroid 3500
(Fig. 7), which occurs when the robot approaches series of ultrasonic sensors.
an external corner. Instead of the transmitted
signal reflecting back towards the receiver, it is
deflected away, making it appear to the robot that CONCLUSION
no obstacle is present. For this application, the use
of the bump switches is the only way that this The use of fuzzy logic in association with the
problem may be overcome. When the robot makes ultrasonic sensors for intelligent obstacle avoid-
contact with the obstacle, one or both of the bump ance has been implemented successfully and works
switches will be triggered, causing the robot to with a good level of reliability. The Rug-Warrior
reverse and turn away from the obstacle. Pro proved to be an excellent platform for the
The second limitation of this application is implementation of this project. With a few modi-
caused when the robot approaches internal corners fications, it was able to handle the requirements
(Fig. 8). The transmitted signal reflects around the with ease, which also gives the potential for future
inside of the corner before returning to the recei- modifications and development. The platform
ver, which causes the signal to travel further and so does, however, appear to possess a few issues
causes ranging errors. Using a fuzzy logic system, with some of the expansion ports and also there
these errors are minimised to a point where, for is occasional unexplained freezing of the micro-
this application, they have little or no noticeable controller. The power consumption of the entire
effect. However, for larger applications, they must package is one point of a possible problem; it will
be taken into account. run effectively as it is but, with increased function-
The final major limitation with this application ality, power drain may need to be considered. One
results from the sensor kits that have been used. As solution may be to provide a long-life battery pack
they were designed for providing either an on or or perhaps a separate power supply for the ultra-
off result, they are unsuited for being switched on sonic sensors.

REFERENCES

1. I. Baturone et al., Microelectronic Design of Fuzzy Logic Based Systems, CRC Press, Boca Raton
(2000).
2. J. L. Jones, A. M. Flynn and B. A. Seiger, Mobile Robots: Inspiration to Implementation (2nd
edition), A. K. Peters, Massachusetts (1999).
3. J. L. Jones, Rug-Warrior Pro Assembly Guide, A. K. Peters, Massachusetts.
4. A. Wright, R. Sargent and C. Witty, Interactive C Users Guide (0.9 ed.), Newton Research Labs
(1997).
5. L. X. Wang, A Course in Fuzzy Systems and Control, Prentice-Hall International, New Jersey (1997).
6. W. L. Xu, S. K. Tso and Y. H. Fung, Fuzzy reactive control of a mobile robot incorporating a real/
virtual target switching strategy, Robotics and Automation Systems, 23 (1998), pp. 171±186.
7. Velleman Components NV, Velleman Parking Radar Manual (http://www.velleman-kit.com/).
8. Motorola, M68HC11E Family Data Sheet (http://www.motorola.com/semiconductors/).

M. D. Hurley received a B.E. in Mechatronics with honours from Massey University, New
Zealand, in May 2004. He now serves as an automation engineer in the New Zealand army.
186 M. D. Hurley et al.

W. L. Xu received a Ph.D. in Mechatronics and Robotics from Beijing University of


Aeronautics and Astronautics, China, in 1988. He is a Senior Lecturer in Mechatronics at
the Institute of Technology and Engineering, Massey University, Palmerston North, New
Zealand. Prior to joining Massey in 1999, he worked at the City University of Hong Kong,
the University of Stuttgart, Germany, and Southeast University, China. His current
research interests include intelligent Mechatronics, advanced robotics and intelligent
control. He is a senior member of IEEE and serves as Associate Editor for IEEE
Transactions on Industrial Electronics and Regional Editor for the International Journal
of Intelligent Systems Technologies and Applications.

Glen Bright graduated from the University of Natal, South Africa, with a Ph.D. in
Mechatronics and Robotics in 1993. He currently leads the Mechatronics and Robotics
Research Group (MR2G), which has active members in New Zealand, South Africa and
North America. He is an active member of IEEE, ISPE, IASTED and a newly appointed
CIRP member. His research interests include Internet Manufacturing, reconfigurable
machines for Agile Manufacturing, Automated Guided Vehicle technologies and wireless
communication for materials handling and automated machines.

You might also like