Laboratory Exercise 1
LSP 350: Computers & Society
Lehman College-- CUNY
7 September 2005
NQC and Locomotion
Today's lab starts with compiling and downloading simple NQC
programs to the lego robot. The programs focus on locomotion
and will work best with either the tracks or the feet you
build for the robot last week. Sensors are not needed for
the programs in this lab.
Design requirements: This lab assumes that the
two motors are wired to output ports A and C. Further, each
motor is attached to a means of locomotion (legs, treads,
feet, etc.).
Programs: The base programs in this lab are from the Baum textbook, and have been linked here for convenience.
General Information About the Lab
The computers in Gillet 219
are dual-boot machines, running the Linux operating system and Windows
XP. When you turn the computer on, you will be given an option of
which operating system you would like to use. Choose Windows, and
when you reach the login screen, do not change the user name (it should
be "student") and hit return to continue. The machine will boot
up like a normal Windows machine after that. The software we will
be using for the course, Bricx Command Center, will appear as an icon
on the desktop. It provides a graphical front end to the NQC
system.
Food and drink are not allowed in the computer laboratories.
There is a printer that may be used for class-related materials
only. Before leaving the lab for the day, make sure that the
computers and their monitors are shut down.
Every machine has an accessible USB port for portable keychain
drives. You might find it useful to bring one to store your
programs, since files left on the laboratory machines are erased on a
regular basis.
Getting Started
First, log on the computer and bring up the
class website.
On the website, there's several programs that will be used for
today's lab (including this lab). Open BricxCC from the icon on
the desktop. BricxCC is a graphical front end to NQC. It will
allow you to edit
programs, compile and download them to your robot, as well as download
firmware and control robot functions (such as sound and motion) from
the computer. Take a few minutes to look at the menus and find
the
commands for downloading firmware and compiling/downloading programs.
Next, take the IR tower (from the lego kit)
and attach them to USB port 1 of your computer (for the front row of
computers, it's on the front of the computer; for all other computers,
it's on the back of the computers, under a door on the left
side). To test that the tower is working, set
the robot so that it's IR port is facing the IR tower. Turn on
your robot, and choose the Piano option from the menu to play a few
notes on your robot. Note that for some of the computers, you may
have to reverse the order, and plug the tower in first and then open
BricxCC.
Before NQC programs can be loaded, the firmware
must be installed. As long as the batteries are not removed for
more than a minute, this only has to be done once. The firmware is
located in the Student Data folder in the subfolder for our
class. Use the menu option to download the firmware. If you
were successful, the robot will
make a series of beeps. It will take a bit for the firmware to
completely load onto the robot, so, be patient.
Note: The robot must be turned on to download the firmware or programs.
Compiling and Loading NQC programs
Now, we're ready to load programs onto the robot.
For your first program, you can type the program in or cut-and-paste it from the webpage. Copy tankbot1.nqc
to the BricxCC window. Now, using the menu options compile and
download the program to your robot. Take the robot out to the
hallway, place it on the floor,
and click on run. This simple program (loaded in Program 1)
will go forward forever. After you make sure it works, stop
the program and turn off the robot to conserve the batteries.
Turning in Circles
Next, modify your program to have the robot
go in a large circle, instead of a straight line. After you have
made the modification in the BricxCC window, compile and download the
program to your robot as before. Follow
the directions
above to download the program to the robot. Test
the program to find out the diameter of the circle.
Turning in Place
Next, write a program that will turn the robot in place. Take your previous program and use the "Save As" to make a new version for this exercise. Your
robot should rotate a full 360 degrees before stopping. Note
that the strength of the batteries and the floor surface will
affect how long you need to wait before completing a full turn
and turning off the engines.
Use a constant to store the amount of time needed for a complete
turn since future programs will use this number a
lot.
Tracing Shapes
If there's time, draw the following shapes:
- A "figure 8": this is based on the circles.nqc program.
- A square: this uses the same idea as turnInPlace.nqc
to turn the corners. Use constants for turning time and straight
time (see tankbot2.nqc).
- A hexagon: Figure out the turning time for 360 degrees and
divide by 6 for the turns.
- The first letter of your first name.
If,
after demonstrating your programs, you still have time, you can go on
to the lab for next week, or work on your robot (in the hallway, since
no loose Lego pieces are allowed in the computer laboratory).
Finishing up for the Day
To get credit for this laboratory, you need to show and explain your
programs to Prof. St. John, as well as demonstrate that they run using
your robot.
We must be out of the computer laboratory by 11:50am. As such, if
you are not ready to demonstrate your work by 11:45am, you can do so in
the next laboratory. Before leaving the room, make sure that all
computers and monitors are turned off, that any paper and trash have been removed, and that all chairs are returned
to their proper places. Also, make sure you pack up your IR tower
in your shoe box, since they're difficult to replace.