Introduction to Programming with LEGO® Robotics
Lecture Notes |
Learn to program in Java. Teach Lego robots various
stunts. Study the
fundamental notions behind computer programming, such
as abstraction, modularity, data structures, syntax,
and procedures. Play with Legos some more.
- When: Tu/Fri 1:30-2:50, Fall 2002
- Where: Sci 217
- Faculty: Jim Mahoney
- Text: Java Programming from the Beginning by K. N. King.
- Credits: 4 ( 9 hours/week outside class )
- Prereq: none
- Fri Sep 6
- Tues Sep 10
- Fri Sep 13
- Tues Sep 17 -
also see JimsCar.java and DriveTheCar.java
- Tues Oct 1 - lab time. Also see lejos code and readme.txt for JimsRobot.
- Fri Oct 4
- Tues Oct 8 -
- Tues Oct 15 - conditionals. See expanded JimsRobot,
FollowTheBlackAndWhiteRoad, LegoMusic, LightSensor, Bumper, and
other files in this directory.
- Fri Oct 25 - arrays
and for loops.
Also see TinyEdgeFollower.
- Tues Oct 29 - Arrays of objects. Zork.
- Fri Nov 1 - intro graphics
- In the javacode/ directory, see StringArt.java,
(Too much math, but some nice pictures just the same.)
- Nov 12 - do/while, packages
- Nov 20 - subclasses and inheritance
- Nov 22 - the NervousShapes program in javacode/nov22/
- Tues Nov 26 - Jim's Dijekstra project - an example of project documentation and layout
(also see this java applet.)
- for Fri Sep 6
- Read chapter 1 in King's book.
- Send me (firstname.lastname@example.org) some email telling me that
you're taking the class, and how comfortable you are with
computers, including whether you own a computer,
and if so what kind and what programs you typically run
on it, as well as which of the following sound
easy and which sound hard:
- Visit the web page http://marlboro.vt.us/.
- Find Sun's Java website with an internet search engine.
- Create a text file on your computer or a lab computer.
- Get to the command prompt, and rename the text file.
- Transfer the text file to your computer account on akbar,
which is the computer with your email account, using
a file transfer program like sftp.
- for Fri Sep 13
- Read In the Beginning was the Command Line
- Read through chapter 2 in the text
- Make sure that you can
You can do this either on akbar (ssh to get there), or on your own
computer (after installing JDK and an editor like XEmacs and setting
your PATH appropriately).
- Create a java text file SomeFile.java with a legal java program,
like the HelloWorld.java program or any in the text.
- Get to the command line, in the directory where that file lives.
- Compile and run the file.
- Put in some errors to see what kinds of errors you get.
- In the text, do exercises 6 and 10 on pg 80 of the text.
- Write a program that asks for the radius of a circle, and then
prints the area of the circle. (The formula is Area=Pi*radius*radius
where Pi=3.14159...) Feel free to base it on the SampleProgram.java
file I showed in class. How accurate is the answer? And is there
a way to do "radius squared"? How do you find that out?
(You'll want to use the SimpleIO and Convert classes by the textbook
author for this one. Follow his instructions in the appendix for
downloading them. You can also find them on our website, along with
my code on akbar in http::akbar/~mahoney/cs/courses/fall02/javacode/jpb/
right near http::akbar/~mahoney/cs/courses/fall02/javacode/SampleProgram.java)
- If all this doesn't get finished by Friday's class, bring in your
questions to class and we'll see where you all are.
- for the week of Fri Sep 20
- Read chapter 3 in King's book, on Classes and Objects
- Do chapter 3, exercise 2, 5 on page 123.
- Do programming project 3 on page 125 of the text.
That is, type in the Fraction class as described in section
3.8 of the text, into a file Fraction.java. Add the methods that
the problem requests. Then create another file, TestFraction.java
that creates some Fraction objects and tests them.
- Optional: Add the Fraction methods described in problem
4 on page 125. (This will lead you into some of the behavior of
the Java String class.)
- for the week of Fri Sep 27
- Reading assignments only. Class time used to work on
first lego robot project, due next week.
(You need to get started on this now.)
- Learn about Lego Java OS (LeJOS) by reading
- Optional: start reading chapter 4 in King's book, on Conditionals.
- for the week of Fri Oct 4
- Build a lego vehicle with two motors, one of which runs
wheels or treads on either side. (Optional: Attach a bumper
with a touch sensor on the front.)
- Write a LeJOS program which moves the vehicle in a rough square,
and download and run it on your Lego robot.
Your program should make the robot
- First, beep twice.
- Then do these steps four times:
- Go forward.
- Turn right by about 90 degrees.
- Stop all the motors.
- Finally, beep three times.
- Email me the java code and a description of your vehicle.
- Optional #1: use the digital camera to document your vehicle.
Create a web page describing your first project and code.
- Optional #2: (After you can use an "if" statement.)
attach a touch sensor to the front of your robot.
Write a program which goes forward until the robot bumps
into something, and then turns away from the wall when it does.
- for Fri Oct 11
- Read chapter 4 in our text, on conditionals ("if" and "while") and
- Do exercises 6, 11, and 21 on pages 174-176.
- Do programming projects 9 (wind speed) and 11 (fibonnaci numbers)
on page 178. Email me your .java files.
- for Fri Oct 25
- Add either a light sensor or a bumper to your earlier
lego robot. Write some LeJOS java code that has it do
something interesting - you've seen examples of
following a black/white border, and changing direction when
it bumps into something. We'll use Fri Oct 18 class time
to work on these.
- for Fri Nov 1
- Read chapter 5, on arrays. Also check out section 13.1,
on page 542 and following.
- Do Exercise 5, 9, and 11 on pages 215 and 216.
- Do Programming Project 6, on page 217.
- Look at the TicTac.java program. Adopt the code so that the X's make some winning
moves. Add a lpoop which tests to see if one player has won.
- for Fri Nov 8
- Read chapters 6 and 7, which cover graphics and
class (i.e. static) methods in Java.
- Submit a proposal for a final project.
- On page 292 and the following, do exercises 3, 7, 17, and 21.
- Do one of the following two programming projects:
- number 7 on page 295 - adding numbers given on the command line, or
- number 5 on page 252 - the checkerboard.
- for Tues Nov 19
- Pick one of your Lego robot earlier programming projects,
one that has more than one file. Convert part of into a package,
and add some documentation. See LegoNotesNov12.html.
- for Tues Nov 26
- Read chapter 11 in the text, on Subclasses and inheritance.
- Do either one of the the following two things:
- Do exercise 4 on page 479 of the text, a Person and Employee class,
and exercise 10(c) on page 480.
- Do programming project 2 on pg 481, add a Triangle class
to the NervousShapes program. (You'll need to download
and be able to run the files in javacode/nov22 which I showed
Syllabus (tentative, as of 9/1/02)
Sep 6: chap 1, Computer Basics
Sep 10,13: chap 2 part 1, writing and debugging a Java program
Sep 17,20: chap 2 part 2, and introduce Lego/LeJOS classes (project 1 assign)
Sep 24,27: chap 3 classes and objects using LeJOS examples
Oct 1,4: chap 4 control structures
Oct 8,11: digression into LeJOS examples -- project 1 due --
Oct 15,17: chap 5 arrays (skip chapter 6) -- midterm --
Oct 25: chap 7 more classes, using LeJOS examples (enough time?)
Oct 28,1: chap 8 more flow control
Nov 5,8: chap 9 primitive types (really needed?) (term project assign)
Nov 12,14: chap 10 more on classes, continue LeJOS examples and work
Nov 19,22: chap 11 subclasses and inheritance
Nov 26: chap 14 files
Dec 2-6: open time for term project work
Dec 10 open time for term project work
- Text Editors for programming
- Windows: TextPad (commerical, demo available)
- Macintosh : BBEdit (commercial) and BBEditLite (free)
- any: Emacs and
powerful but complicated (my personal favorite)
- any: Vim - another hacker's favorite
- java.sun.com - the
- Download J2SE 1.4
You want the "SDK" - Software Developer's Kit
- Various windows installation stuff -
- Java Programming - the website for King's book
- Java Documentation
- LeJOS - Lego Java OS
- Shopping for Legos
Last modified: Tue Nov 26 02:28:04 EST 2002