Lesson Plan

advertisement
Lesson Plan
Course Title
Robotics and Automation
Session Title
Introduction to Robotics Part 5: Programming
Performance Objective
After completing this lesson, students will be able to demonstrate they have learned the basics
of robotic programming and control through satisfactory performance on the Introduction to
Robotics Part 5: Programming Quiz.
Specific Objectives
 Describe how a communication port allows a computer to interface with an
external device.
 Name the parts of a computer program, including initialization, main program loops,
functions, and statements.
 Define and use variables in a computer program.
 Create and use program loops.
 Differentiate three types of program loops, including WHILE loops, FOR loops, and
IF, ELSE conditional loops.
 Compile and download a computer program.
Preparation
TEKS Correlations
This lesson, as published, correlates to the following TEKS. Any changes/alterations to the
activities may result in the elimination of any or all of the TEKS listed.
Robotics and Automation

130.370 (c)
o (5) The student develops the ability to use and maintain technological products,
processes, and systems. The student is expected to:
(A) demonstrate the use of computers to manipulate a robotic or automated
system and associated subsystems;
(B) troubleshoot and maintain systems and subsystems to ensure safe and proper
function and precision operation;
(C) demonstrate knowledge of process control factors; and
(D) demonstrate knowledge of motors, gears, and gear trains used in the robotic
or automated systems.
Copyright © Texas Education Agency, 2013. All rights reserved.
1

130.370 (c)
o (6) The student develops an understanding of the advanced concepts of physics,
robotics, and automation. The student is expected to:
(C) demonstrate knowledge of feedback control loops to provide information;
and
(D) demonstrate knowledge of different types of sensors used in robotic or
automated systems and their operations.

130.370 (c)
o (9) The student learns the function and application of the tools, equipment, and
materials used in robotic and automated systems through specific project-based
assessments. The student is expected to
(C) use multiple software applications to simulate robot behavior and present
concepts.
Interdisciplinary Correlations
Reading I, II, III

110.47 (b)
o (3) The student reads for a variety of purposes with multiple sources, both
narrative and expository. The student is expected to:
(A) read functional texts to complete real-world tasks such as job applications,
recipes, and product assembly instructions; and
(B) read to complete academic tasks.

110.47 (b)
o (4) The student comprehends texts using effective strategies. The student is
expected to:
(A) use prior knowledge and experience to comprehend;
(B) determine and adjust purpose for reading; and
(C) self-monitor reading and adjust when confusion occurs by using appropriate
strategies.
English Language Arts and Reading, English IV

110.34 (b)
o (11) Reading/Comprehension of Informational Text/Procedural Texts. Students
understand how to glean and use information in procedural texts and documents.
Students are expected to:
(A) draw conclusions about how the patterns of organization and hierarchic
structures support the understandability of text; and
Copyright © Texas Education Agency, 2013. All rights reserved.
2
(B) evaluate the structures of text (e.g., format, headers) for their clarity and
organizational coherence and for the effectiveness of their graphic
representations.

110.34 (b)
o (26) Listening and Speaking/Teamwork. Students work productively with others in
teams. Students will continue to apply earlier standards with greater complexity.
Students are expected to participate productively in teams, offering ideas or
judgments that are purposeful in moving the team towards goals, asking relevant
and insightful questions, tolerating a range of positions and ambiguity in decisionmaking, and evaluating the work of the group based on agreed-upon criteria.
Teacher Preparation
The teacher does not have to be a programming expert; this lesson covers basic, necessary
information. Review the slide presentation and notes, definitions handout, and the quiz. The
teacher can cover program loops and programming syntax in more detail at his or her discretion;
however, that will require additional preparation. Review the references given in this lesson. For
student practice, have students search the Internet for a free Integrated Device Environment
(IDE) that is both simple and powerful. Most common, introductory programming example
lessons (like print) can be performed by looking at the output.
References
Free IDE and programming software programs suitable for student use are available on the
Internet. Select one prior to presenting this lesson and have students review the tutorials, user
guides, and programming guides.
Wikipedia
 http://en.wikipedia.org/wiki/C++
 http://en.wikipedia.org/wiki/Wikipedia:WikiProject_C%2B%2B
Instructional Aids
 Introduction to Robotics Parts 1-4 slide presentations and notes (for review)
 Introduction to Robotics Part 5: Programming slide presentation and notes
 Programming guide found on the Internet
 User’s guide found on the Internet
 Definitions Used in Computer Programming handout for each student
 Introduction to Robotics Part 5: Programming Quiz for each student
 Introduction to Robotics Part 5: Programming Quiz key
Materials Needed
Copyright © Texas Education Agency, 2013. All rights reserved.
3


Integrated Device Environment (IDE) programming software
Robotic kits with parts and supplies that are designed to work together
This lesson is based on programming using free IDE found on the Internet. Commercial vendors
of robotic kits offer parts and supplies that are designed to work together and are relatively
inexpensive. One robotic kit is recommended for every two students, but there can be as many
as four students for every robotic kit if needed.
Equipment Needed
 Computer
 Projection unit and screen
 Cable to connect PC to microcontroller (USB-USB or USB-serial)
Learner Preparation
The recommended prerequisite to this lesson is Introduction to Robotics Parts 1-4.
Introduction
Introduction (LSI Quadrant I)
Say
Today we are going to learn about programming. Programming is the way we make every
computer and most electronic devices work.
Ask
Does anyone know what a computer program is?
Say
A computer program has a sequence or series of instructions that tell the device what to do.
Ask
Can we just type in any instruction or use any type of language we want?
Say
No. We know that we need to write a program in a specific computer language.
Ask
Does anyone know some names of the types of computer programming languages?
Say
Well, there are a lot of them. Most of you mentioned Java, Basic, Visual Basic, HTML and
Fortran. No, spreadsheet software is not considered computer language.
Say
We are going to be learning about a language called C++. C++ is the underlying programming
language for just about the entire PC industry, but C++ is considered to be a hard language to
learn. We are going to try to make it easy by showing you how to apply programming
to robotics.
Show
Introduction to Robotics Part 5: Programming slide presentation
Copyright © Texas Education Agency, 2013. All rights reserved.
4
Outline
Outline (LSI Quadrant II)
Instructors can use the slide presentation, handouts, and note pages in conjunction with the
following outline.
MI
Outline
Notes to Instructor
I.
Introduction to programming
A. Electronic devices are becoming
increasingly computerized.
B. Computers require a program to operate.
C. Understanding the basics of computer
programming is increasingly considered to
be a component of literacy the same as
math and English.
D. Hardware and software can no longer be
separated into separate domains.
Programming is
considered to be one
of the hardest things
you do in robotics.
Students who do this
well will have a career
for life. (Slides 1-5)
II.
Introduction to C
A. It takes a program to write a program.
B. The programming environment is usually
called an IDE.
C. Theoretically, you could write a program
using any text editor, but you could
not debug, compile, or download
that program.
D. The program goes into a microcontroller,
where it is run (executed).
E. More information about the components
of an IDE can be found on the Internet
The best way for
students to learn
about programming
and IDEs is to start
writing simple
programs. (Slides 6-8)
III.
Microcontroller basics
A. Inputs and outputs are electrical signals.
B. The microcontroller converts the electrical
signals into data, performs some logic and
processing on that data according to the
program, and produces electrical output
signals based on that processing.
(Slides 9-16)
.
Distribute Definitions
Used in Computer
Programming handout
to each student.
Copyright © Texas Education Agency, 2013. All rights reserved.
5
C. The operations the program performs are
based on binary logic.
D. Features and specifications are given.
IV.
Programming application
A. This is a continuation of the material from
Introduction to Robotics Part 4: Sensors.
B. The simplest sensor is a switch.
C. Students learn to write a program that
reads the switch value.
D. Start with a simple program that does not
do anything.
E. The bumper sensor produces data; data
requires a name and a place in memory to
store it.
F. Defining a variable does both of
those things.
G. Variables must be defined during
initialization of the program, which comes
before the main program loop.
Have the students
troubleshoot the
problem. This may be
one of the most
important skills
students can develop.
However, be ready to
step in if students get
too frustrated. (Slides
17-18)
V.
Program description
A. Describe each part of the program, piece
by piece.
B. Syntax is critical.
C. Syntax refers to the rules involved in
creating a computer program.
D. The rules involve both keywords and
formatting characters.
E. These combine to form statements
and functions.
F. Abstractions are user-defined keywords.
Students may want to
start work directly on
a program that makes
their robot work.
(Slides 19-26)
Program example
A. Modify the simple program found on
slide 19 step by step.
B. We start with our first statement.
C. The statement must go inside a loop.
(Slides 27-45)
VI.
Slide 26- Abstractions
are used in
programming
examples in the slide
presentation.
Copyright © Texas Education Agency, 2013. All rights reserved.
6
D. There are three types of program loops.
Go over each type and access the
additional information provided by
the links.
E. Make the statement work by adding
variables to the program, which must be
defined before they can be used.
F. Go over the steps in the programming
example given so students know why as
well as how they create program loops.
VII.
More programming practice
A. A switch is either on or off.
B. A switch creates binary (digital) data.
C. Sometimes we need analog data.
D. Analog data has many values instead of
just two values.
(Slides 46-51)
Slide 46 is the second
example.
VIII. Learn by doing
A. Students now need to apply what they
have learned by adding more sensors and
more control.
B. Students are now ready for the design
challenges, where they build and program
their robot without step-by-step
instructions. This is covered in
Introduction to Robotics Part 6: Design
Challenges.
(Slide 52)
IX.
Distribute the
Introduction to
Robotics Part 5:
Programming Quiz.
Allow appropriate
time for the students
to take the quiz.
Introduction to Robotics Part 5:
Programming Quiz
A. Students will take the quiz.
B. Teacher will grade quiz.
Copyright © Texas Education Agency, 2013. All rights reserved.
7
Verbal
Linguistic
Logical
Mathematical
Visual
Spatial
Musical
Rhythmic
Bodily
Kinesthetic
Intrapersonal
Interpersonal
Naturalist
Existentialist
Application
Guided Practice (LSI Quadrant III)
The teacher guides the students through the Introduction to Robotics Part 5: Programming slide
presentation and then provides guidance and instruction while students are trying to build their
own programs.
Independent Practice (LSI Quadrant III)
Most of this lesson is independent practice. Students read and follow the directions given in the
programming guide they located on the Internet or purchased through a vendor to write the
programs listed. Students should review Definitions Used in Computer Programming handout.
Summary
Review (LSI Quadrants I and IV)
 Question
What are the three types of loops?
 Answer
Infinite, Counting, Conditional (WHILE, FOR, IF/ELSE)

Question
What two things happen when you define a variable?
 Answer
You give the variable a name and set aside a particular amount of memory space.
Evaluation
Informal Assessment (LSI Quadrant III)
 Observation
 Question and answer
 Time on task
 Ability to follow directions
Copyright © Texas Education Agency, 2013. All rights reserved.
8
Formal Assessment (LSI Quadrant III, IV)
Introduction to Robotics Part 5: Programming Quiz
The teacher may use the Definitions Used in Computer Programming handout as a form
of assessment.
Extension
Extension/Enrichment (LSI Quadrant IV)
Students spend time on design challenges after they have completed Introduction to Robotics
Parts 1-5.
Copyright © Texas Education Agency, 2013. All rights reserved.
9
Definitions Used in Computer Programming
1. Microprocessor- a multipurpose programmable device; a central processing unit with
memory and associated circuits on an integrated circuit chip
2. Microcontroller- a computer on a chip; contains a CPU, volatile and non-volatile
memory, a clock, and an input/output control unit on an integrated circuit chip;
designed for a specific task
3. IDE- Integrated Development Environment; a set of programs run from a single user
interface; a software application that provides comprehensive facilities to computer
programmers for software development
4. Computer program- a sequence of instructions that are executed by a CPU
5. Programming language- a vocabulary and set of grammatical rules to instruct a
computer to perform specific tasks; some languages are better at dealing with numbers,
some for file management, some are more procedural, and others are more functional;
newer languages are more object oriented
6. Machine language- a programming language understood by computers that consists
entirely of numbers
7. High level language- a computer programming language that resembles natural
language which is used to simplify programming; an assembler/compiler converts high
level language to machine language
8. Open source- a program or device available to the general public free of charge to use
or modify
9. Proprietary- privately owned by an entity having exclusive rights to it; protected by
secrecy, patent, or copyright
10. Syntax- the set of rules that define how symbols and words are used in a
programming language
11. Interface- to bring together; in electronics, something that allows two different devices
to communicate and work together
12. Keywords- words and names defined as part of a computer language to perform
specific tasks
Copyright © Texas Education Agency, 2013. All rights reserved.
10
Definitions Used in Computer Programming (continued)
13. Abstraction- representation of something in a simpler, more general form by
removing details
14. Variable- a value that can change
15. Program loop- a sequence of instructions that continually repeat
16. Infinite loop- continues to repeat a computer instruction sequence without a functional
way to stop
17. Counting loop- goes through a program instruction sequence a defined number of times
18. Conditional loop- repeats a program instruction sequence depending on the presence
or absence of a defined condition; used to transfer program control from one program
segment to another
19. Comment- language inserted into a computer program that is not designed to run as an
instruction; used to describe or make the code easier to understand
20. Statement- smallest standalone part of a computer program containing executable
code; a single command
21. Function- section of a computer program that performs a specific task; usually a group
of commands
22. Analog- contains continuously variable or non-quantized data; smooth
23. Digital- uses discrete or quantized values; has only certain values like on or off
24. Binary- has only two values, zero and one
Copyright © Texas Education Agency, 2013. All rights reserved.
11
Name________________________________Date________________Class_________
Introduction to Robotics Part 5: Programming
Quiz
1.
What is the main reason to write a computer program?
A
to learn mathematics
B
to understand technology
C
to solve a problem
D
to impress your friends
2.
What does IDE stand for?
A
Independent Device Enterprise
B
Integrated Development Environment
C
Iterating Decision Enclosure
D
Instant Decision Environment
3.
What does the term int in the following instruction mean?
int bumper
A
B
C
D
bumper is a 16 bit variable
bumper has an intermediate value
bumper has a value between 0 and 255
read the bumper switch to input a value
4.
How do you know some typed text in C++ is actually a statement?
A
it is terminated with a comma
B
it is terminated with a semicolon
C
it is enclosed by curly brackets
D
it has a double slash in front of it
5.
How do you know some typed text in C++ is a function?
A
it is terminated with a comma
B
it is terminated with a semicolon
C
it is enclosed by curly brackets
D
it has a double slash in front of it
6.
What type of loop is a FOR loop?
A
a counting loop
B
a decision loop
C
an infinite loop
D
a conditional loop
Copyright © Texas Education Agency, 2013. All rights reserved.
12
7.
What type of loop is a WHILE loop?
A
a counting loop
B
a decision loop
C
an infinite loop
D
a conditional loop
8.
What type of loop is an IF loop?
A
a counting loop
B
a decision loop
C
an infinite loop
D
a conditional loop
9.
What do you use in C++ to create a comment?
A
it is terminated with a comma
B
it is terminated with a semicolon
C
it is enclosed by curly brackets
D
it has a double slash in front of it
10.
What is a microcontroller?
A
a multipurpose programmable device
B
a computer on a chip
C
smallest standalone part of a computer program
containing executable code
D
a sequence of instructions that continually repeat
11.
What two things does an IDE do?
12.
What two things happen when you define a variable?
Copyright © Texas Education Agency, 2013. All rights reserved.
13
13.
Describe the following computer program in as much detail as possible:
void setup() {
// put your setup code here, to run once;
}
void loop() {
// put your main code here, to run repeatedly;
}
Matching:
14.
Machine language
A
words and names defined as part of a computer
language to perform specific tasks
15.
Statement
B
a programming language understood by computers
that consists entirely of numbers
16.
Computer program
C
the set of rules that define how symbols and words are
used in a programming language
17.
Syntax
D
has only two values, zero and one
18.
Keywords
E
smallest standalone part of a computer program
containing executable code
19.
Function
F
a sequence of instructions that are executed by a CPU
20.
Binary
G
section of a computer program that performs a
specific task
Copyright © Texas Education Agency, 2013. All rights reserved.
14
Introduction to Robotics Part 5: Programming
Quiz Answer Key
1.
What is the main reason to write a computer program?
A
to learn mathematics
B
to understand technology
C
to solve a problem
D
to impress your friends
2.
What does IDE stand for?
A
Independent Device Enterprise
B
Integrated Development Environment
C
Iterating Decision Enclosure
D
Instant Decision Environment
3.
What does the term int in the following instruction mean?
int bumper
A
B
C
D
bumper is a 16 bit variable
bumper has an intermediate value
bumper has a value between 0 and 255
read the bumper switch to input a value
4.
How do you know some typed text in C++ is actually a statement?
A
it is terminated with a comma
B
it is terminated with a semicolon
C
it is enclosed by curly brackets
D
it has a double slash in front of it
5.
How do you know some typed text in C++ is a function?
A
it is terminated with a comma
B
it is terminated with a semicolon
C
it is enclosed by curly brackets
D
it has a double slash in front of it
6.
What type of loop is a FOR loop?
A
a counting loop
B
a decision loop
C
an infinite loop
D
a conditional loop
Copyright © Texas Education Agency, 2013. All rights reserved.
15
7.
What type of loop is a WHILE loop?
A
a counting loop
B
a decision loop
C
an infinite loop
D
a conditional loop
8.
What type of loop is an IF loop?
A
a counting loop
B
a decision loop
C
an infinite loop
D
a conditional loop
9.
What do you use in C++ to create a comment?
A
it is terminated with a comma
B
it is terminated with a semicolon
C
it is enclosed by curly brackets
D
it has a double slash in front of it
10.
What is a microcontroller?
A
a multipurpose programmable device
B
a computer on a chip
C
smallest standalone part of a computer program containing
executable code
D
a sequence of instructions that continually repeat
11.
What two things does an IDE do?




12.
A computer program used to write a computer program
The IDE allows students to write a computer program that can be downloaded from
any PC
Allows users to write code in a language that is easier to use than the machine
level code
Converts the higher level language to the machine code that is specific to a family
of microprocessors
What two things happen when you define a variable?


Gives the variable a name
Assigns the variable a memory location
Copyright © Texas Education Agency, 2013. All rights reserved.
16
13.
Describe the following computer program in as much detail as possible:
void setup() {
// put your setup code here, to run once;
}
void loop() {
// put your main code here, to run repeatedly;
}
void
setup()
()
{
{}
;
//
No value is returned
Program section names
No value is given
Functions
Functions
Statements
Comments
Matching:
14.
15.
16.
17.
18.
19.
20.
Machine language
B
A
words and names defined as part of a computer
language to perform specific tasks
Statement
E
B
a programming language understood by computers
that consists entirely of numbers
Computer program
F
C
the set of rules that define how symbols and words are
used in a programming language
Syntax
C
D
has only two values, zero and one
Keywords
A
E
smallest standalone part of a computer program
containing executable code
Function
G
F
a sequence of instructions that are executed by a CPU
Binary
D
G
section of a computer program that performs a
specific task
Copyright © Texas Education Agency, 2013. All rights reserved.
17
Download