Page 161 - Concise Encyclopedia of Robotics
P. 161
IF/THEN/ELSE I
In computers and smart robots, choices must often be made in the execu-
tion of a program. One of the most common programming decision
processes is called IF/THEN/ELSE. It can be expressed as a sentence: “If
A, then B; otherwise (or else) C.”
An example of an IF/THEN/ELSE process is shown in the illustration.
The intent is to determine the absolute value of a real number. Suppose a
computer is working with an input number, designated x. If x is negative
(that is, if x 0), then x must be multiplied by 1 to obtain the absolute
value |x|. If x is zero or positive, then x is equal to its absolute value. The
computer must compare the numerical value of x with zero. The machine
will then output the absolute value of the number, by either multiplying
x by 1 or by leaving x alone.
IF/THEN/ELSE processes are especially useful command structures
for robots. You might tell a robot,“Go to the kitchen and get me a paper
napkin.” The robot controller has a command structure stored on its
hard drive or in memory. It needs an alternative in case there are no
paper napkins in the kitchen. The programming might take the form: “If
this command can be executed, then carry out the task. Otherwise, output
the audio statement, ‘Your order cannot be completed because there are
no paper napkins in the kitchen.’”
Copyright 2003 by The McGraw-Hill Companies, Inc. Click Here for Terms of Use.