Flowcharts PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

6.

5
2005 Robomatter Inc. RE 2.5_RW 1.1
Programming
Flowcharts
A owchart visually represents and organizes the steps used to write the programit is a diagram of the ow of the
process. When programmers write code, they need to give the robot instructions that are both sequential and specic.
Flowcharts enable programmers to work these steps out before needing to translate their behaviors into code.
Reading owcharts
Move from step to step in the chart by following the lines between them. Perform any action listed when you
reach a Statement Block (rectangle), and then choose from several different paths to follow when you reach a
Decision Block (diamond).
Flowcharts
Start
Take one step forward
Gone 50
steps?
End
No
Yes
Start of program Marks the beginning of
the program, begin here. Follow the line to get to
the next block.
Statement block A statement to execute,
or a behavior to perform.
Decision block A decision point in your program.
Ask a simple question, and do different things depending
on the answer.
Yes/No (also True/False, etc.) Answers to the question
posed in the decision block. Follow the line labeled with the
appropriate answer.
End of program Marks the end of the program.
If you reach this point, the program is done!
Exercises
1. In the owchart above, what will be the rst action you take? _________________________________________________________
2. If you havent gone 50 steps yet, what will you do next? ____________________________________________________________
3. If youve gone 50 steps, what do you do? ______________________________________________________________________
4. Describe the eventual result of your actions if you follow the owchart above from start to nish. ________________________________
_____________________________________________________________________________________________________
NAME DATE
Parts of a Flow Chart
6.6
2005 Robomatter Inc. RE 2.5_RW 1.1
Programming
Exercise
5. On a separate sheet of paper, make a owchart organizing the ow of getting ready to go to school in the morning.
Be sure to include the following steps in your chart, but dont be afraid to add other things if you need them!
Select something to wear
Take a shower
Eat breakfast
Leave house for school
Get out of bed
Look for your shoes
Brush your teeth
Put toast in the toaster
Check your alarm clock
Turn on shower
Put your shoes on
Hit snooze button
Get dressed
Comb your hair
Check the time
Writing Flowcharts
How do you get from a complex task to an organized owchart describing how to do it? Start with a owchart
containing just the task. Now break it down into smaller, more specic steps in another owchart. Then, go back
and see if you can break down any of those behaviors into simpler parts. Keep on repeating this process until youve
reached steps that are simple enough for your robot to perform!
Start
End
Flowcharts
NAME DATE
Wash hands
Wash hands
Start
Turn on water
End
Dispense soap
Wash hands till clean
Rinse soap off
Turn off water
Dry hands
Wash hands
till clean
Wash hands
Start
Turn on water
End
Dispense soap
Rub hands together
Rinse soap off
Turn off water
Dry hands
Hands
clean?
No
Yes
6.7
2005 Robomatter Inc. RE 2.5_RW 1.1
Programming
Exercises
6. What behavior does the ow chart below describe?
7. Create owcharts to represent these short tasks:
a. If its raining, bring an umbrella.
b. Take twenty paces, then turn and shoot.
c. Go forward until the Touch Sensor (on port 1) is pressed in, then stop.
d. Follow Liberty Avenue for 2 miles, then take a left turn onto 40th Street. Go until you reach the bridge,
but dont cross the bridge. Instead, make a right turn onto Foster Street, then take the rst left turn.
Follow that road until you reach the National Robotics Engineering Consortium building.
e. Turn on oven. Cook turkey for 4 hours or until meat thermometer reaches 180 degrees.
8. Make a ow chart for the process of crossing the street.
Hint: Looking both ways wont do any good unless you use that information to make some decisions.
9. Bonus: Write a ow chart that tells you how to read ow charts.
Start
Pump air
Tire at rated
pressure?
End
No
Yes
NAME DATE
Flowcharts
6.8
2005 Robomatter Inc. RE 2.5_RW 1.1
Programming
Flowcharts
Exercises
1. In the owchart above, what will be the rst action you take?
Take one step forward.
2. If you havent gone 50 steps yet, what will you do next?
Take another step forward
3. If youve gone 50 steps, what do you do?
Nothing, you have reached the end of the ow chart.
4. Describe the eventual result of your actions if you follow the owchart above from start to nish.
You will walk forward for 50 steps.
Teacher
6.9
2005 Robomatter Inc. RE 2.5_RW 1.1
Programming
Flowcharts
Teacher
5. (This is a sample answer only. Student answers may vary.)
Check your
alarm clock
Hit snooze button
Brush teeth
Take shower
Comb hair
Get dressed
No
Yes
Get out of bed
Put toast
in the toaster
Eat breakfast
Turn on shower
Select something
to wear
Leave house
Look for shoes
Put shoes on
Adjust water
temperature
No
Yes
No
Yes
Start
Time
to get up?
Water at
correct
temperature
End
Found
shoes?
Wait
No
Yes
Check
time to
leave
6.10
2005 Robomatter Inc. RE 2.5_RW 1.1
Programming
Exercises
6. What behavior does the ow chart below describe?
The behavior shown in the owchart is lling a tire with air from a pump.
7. a. If its raining, bring an umbrella. b. Take twenty paces, then turn and shoot.
c. Go forward until the Touch Sensor (on port 1)
is pressed in, then stop.
Take 20 paces
Teacher
Flowcharts
Note: Stopping the robot is not the same as the program stopping
because its reached its end. Stopping the robot means bringing it to
a physical halt, whereas ending the program simply means no more
commands are issued.
This is an important distinction to make for later on.
Bring umbrella
No
Yes
Take a step
Turn around
Shoot
No
Yes
Stop robot
End
Start
Raining
Outside?
Start
Gone 20
paces?
End
Start
Go forward
Touch
sensor
pressed?
No
End
Yes
6.11
2005 Robomatter Inc. RE 2.5_RW 1.1
Programming
Flowcharts
Teacher
7. d. Follow Liberty Avenue for 2 miles, then take a left turn onto 40th Street. Go until you reach the bridge,
but dont cross the bridge. Instead, make a right turn onto Foster Street, then take the rst left turn.
Follow that road until you reach the National Robotics Engineering Consortium building.
No
Follow Liberty Ave.
No
Turn left onto 40th St.
Follow 40th St.
No
Follow Foster St.
No
Turn left
Follow street
Turn right onto Foster St.
Start
End
Yes
Yes
Yes
Yes
Gone
2 miles?
Reached
bridge?
Reached
left turn?
Reached
NREC?
6.12
2005 Robomatter Inc. RE 2.5_RW 1.1
Programming
7. e. Turn on oven. Cook turkey for 4 hours or until meat thermometer reaches 180 degrees.
8. Make a ow chart for the process of crossing the street.
Hint: Looking both ways wont do any good unless you use that information to make some decisions.
Teacher
Flowcharts
No
Turn on oven
Wait
Yes
Yes
No
Note: This key word in this exercise is the word
OR between the two conditions. As an additional
exercise, consider the ways in which this diagram
would change if you replaced the word OR with the
word AND.
Note: This solution is good, but a truly
well-thought out solution will include a
description of how you should cross the
street (continuing to look both ways for
oncoming trafc).
The important thing here is to note that
you must make a decision with the data
you gather by lookingyou dont just look
for lookings sake, a point which is often
overlooked.
Start
End
4 hours
elapsed?
Therm.
at 180?
No
Look left
No
Yes
Start
End
See cars
coming?
See cars
coming?
Look right
Cross street
Yes
6.13
2005 Robomatter Inc. RE 2.5_RW 1.1
Programming
9. Bonus: Write a ow chart that tells you how to read ow charts.
Flowcharts
Teacher
No
Yes
No
Yes
Yes
Yes
No
Yes
No
No
End
Start
Reached
a statement
block?
Go the start block
in the owchart
Follow the line to
the next block
Perform the action listed in the
Statement Block
Follow the YES line
to the next block
Follow the NO line
to the next block
ERROR in owchart
Reached
an end
block?
Reached
a decision
block?
Answer
to question
is Yes?
Answer
to question
is No?

You might also like