conditional expressions using a single statement

TER 3MI – ROBOTICS
CONDITIONAL EXPRESSIONS USING A SINGLE LOGIC STATEMENT
Conditional Expressions are generally defined by the desired outcome. Most Conditional Expressions
use the form:
IF (STATEMENT) THEN (OUTPUT)
BOTH the STATEMENT and the OUTPUT can have only 2 possible states: TRUE or FALSE (or any analog of
TRUE and FALSE. eg. ON or OFF, HI or LO, 1 or 0)
There are also only 2 kinds of relationships possible with this kind of expression:
1. Direct Relationship:
For Example:
Light Circuit -
IF (STATEMENT is TRUE) THEN (OUTPUT is TRUE) or
IF (STATEMENT is FALSE) THEN (OUTPUT is FALSE)
IF (SWITCH is ON) THEN (LIGHT is ON)
the desired outcome is a lit bulb!
2. INVERSE Relationship: IF (STATEMENT is TRUE) THEN (OUTPUT is FALSE) or
IF (STATEMENT is FALSE) THEN (OUTPUT is TRUE)
For Example:
Night LightIF (NO LIGHT DETECTED) THEN (LIGHT is ON)
again, the desired outcome is a
lit bulb but it is only turned on in the ABSENCE of light!
Another way to write Conditional Expressions involving electrical or electronic circuits is using the
terms HI and LO. So, the Light Switch example COULD be:
IF (SWITCH is HI) THEN (LIGHT is HI)
EXERCISE 1:
Write the Conditional Expressions for the following systems. Note whether the relationship
between the statement and the output is direct or inverse. Remember, the expression is defined by
the desired outcome!!
1.
2.
3.
4.
5.
Burglar Alarm
Thermostat
Alarm Clock
School Fire Alarm
Toilet Tank
IF THEN ELSE Expressions
Often, it is useful to incorporate all possible outputs in an expression to help avoid uncertainty and
ambiguity. Many industrial systems incorporate a counting function that uses a simple Conditional
Expression. For example, a packaging machine is programmed to fill a box with 25 widgets, then release
the box. A counter keeps track of the number of widgets in the box. Every time a new widget is placed
in the box, the counter adds one to its count. Each time the counter reaches 25, the filled box is
released and a new, empty box loaded, ready to be filled. The expression looks like this:
IF (COUNTER < 25) THEN (FILL BOX)
The trouble is, this doesn’t fully account for the entire function of the machine. There should be an
alternate OUTPUT once the COUNTER reaches the limit of 25. The complete expression can be written
as:
IF (COUNTER <25) THEN (FILL BOX) ELSE (RELEASE BOX)
This means that as long as the condition is TRUE, the first output will occur. Once the condition is FALSE,
the output switches to the ELSE option. This can be shown graphically as follows:
INPUT
(ADD 1
WIDGET)
COUNTER
<25
YES
CONTINUE
FILLING
BOX
NO
RELEASE
FILLED BOX
This graphic is called a PROCESS FLOWCHART and is used to graphically design and analyze complex
systems without having to actually write a program.




The rectangles describe a simple action.
The diamond defines the decision and the 2 possible outcomes.
The arrows indicate the flow of data and sequence of events within the system.
Notice that one process cycles back into the system (called FEEDBACK) and the other exits the
system.
Although there are many symbols or BLOCKS that can be used in flowcharts to represent different kinds
of steps, accurate flowcharts can be created using very few (e.g. Process, Decision, Start, delay).
A flowchart is ideal for a process that has sequential process steps. The steps will be executed in a
simple order that may change as the result of some simple decisions. In the flowchart, these blocks are
connected using arrows to indicate the sequence of the steps. The different blocks imply different types
of program actions. Programs always need a start block, but PLC programs rarely stop so the stop block
is rarely used. Other important blocks include operations and decisions. The other functions may be
used but are not necessary for most PLC applications.
The basic element of a flowchart is a simple action, which can be anything from PUSHING A BUTTON to
making a cash payment, and is represented as a box containing a description of the action. The mapping
of 'what follows what' is shown with arrows between sequential action boxes, as in the illustration. This
also shows the boxes for flowchart start and end points of which there are normally one each.
Fig. 1. Basic Flowchart elements
Processes become more complex when decisions must be made on which, out of an alternative set of
actions, must be taken. The decision is shown in a Flowchart as a diamond-shaped box containing a
simple question to which the answer is 'yes' or 'no' as in Fig. 2. More complex decisions are made up of
combinations of simple decision boxes.
Fig. 2. Decisions in Flowcharts
EXERCISE 2: Rewrite the conditional expressions you completed above as PROCESS FLOWCHARTS.
Flowchart-Based Design
Design a garage door controller using a flowchart. The behavior of the garage door controller is as
follows,
- there is a single button in the garage, and a single button remote control.
- when the button is pushed the door will move up or down.
- if the button is pushed once while moving, the door will stop, a second push will start
motion again in the opposite direction.
- there are top/bottom limit switches to stop the motion of the door.
- there is a light beam across the bottom of the door. If the beam is cut while the door is
closing the door will stop and reverse.
- there is a garage light that will be on for 5 minutes after the door opens or closes.
http://www.edrawsoft.com/How-to-draw-flowchart.php
http://engineeronadisk.com/V2/book_PLC/engineeronadisk-81.html
http://sites.google.com/site/automatedmanufacturingsystems/
http://sites.google.com/site/automatedmanufacturingsystems/Home/flowchart_ans