Laboratory Exercise 1

Cluster V: Computers and Robots
COSMOS Program, UC Davis
12 July 2001

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 yesterday. 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.).

General Information About the Lab

The labs are running the Linux operating system distributed by Red Hat (versions 6.2 and 7.1). See Dr. Scalettar's page for information about using the computers, linux, and vi.

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. 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. Right click on firm0309.lgo to download the firmware. Save it on your disk, using the same name.

Next, take the gray serial cable and IR tower (from the lego kit) and attach them to serial port 1 of your computer (it's the left most connector as you face the computer's row of connectors). Set the robot so that it's IR port is facing the IR tower. Now, type:

nqc -firmware firm0309.lgo
in the terminal window. If you were successful, the robot will make a series of beeps, and you will see in the terminal window:
Downloading firmware:...................................................
Current Version: 00030001/00030009
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. You may type the programs in by hand (tedious!), or you may download the programs to your directory (much easier!). Right click on tankbot1.nqc to download the program to your directory. Save it on your disk, using the same name. To compile and download the program, type:
nqc -d tankbot1.nqc
in the terminal window. If you were successful, the robot will make a series of beeps and you will see in the terminal window:
Downloading Program:....complete
Battery Level = 8.1 V
The battery level may differ, depending on how new the batteries are.

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

Copy the tankbot1.nqc program to a new file, by typing:
cp tankbot1.nqc circles.nqc
Using the vi editor, modify the program circles.nqc so that it will go in a large circle, instead of straight. Follow the directions above to download the program to the robot. Test the program to find out the diameter of the circle.

[See p 59 of Unofficial Guide for useful output commands for the robot.]

Turning in Place

Copy the circles.nqc program to a new file, by typing:
cp circles.nqc turnInPlace.nqc
Write a program that will turn the robot in place. 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 (see p 67) since future programs will use this number a lot.

Tracing Shapes

If there's time, draw the following shapes: