SRS Labs SRS Robot Level 1 Kit Manual Do Utilizador

Página de 34
 Sample 
Programs 
A good way to get started with a new program is to make a copy of a folder for an existing program, then rename the 
new folder and its .bas or .c file. (For C programs, you will also need to edit the makefile to reflect the name change 
for the .c file. Look for the SRC= line. You may also change the PRG= line for consistency.) 
C Programming 
Each sample program is in its own folder. Each of these folders contains the C files needed for the program and a 
“makefile” that provides information for the tools. All the files created by the build process are stored in this folder 
as well. The concept of a makefile will be new to many people, even experienced programmers. You do not need to 
understand the makefile, but it’s important that you do not rename it! 
 
The makefile is set up to use the BASCOM programmer (supplied with the kit). If you will be using an AVRISP, 
you’ll need to override the settings in the makefile. You can modify the makefile (in each program folder), but a 
better way is to define environment variables: 
 
AVRDUDE_PROGRAMMER = avrisp 
 
AVRDUDE_PORT = com1 
(see the Software Tools section for Mac information
 
When using Programmers Notepad, but sure to use LaunchPN.bat (from the “C Samples” folder) to start it. To build 
a program, open a C file that is part of the program you want to build. Make any edits you want, save the file, then 
choose the Tools/Make All command to build. This will automatically use the makefile in the same folder as your C 
file. An “output” window will show the results of your build. (If you get a message that “the system cannot find the 
file specified,” you probably just need to restart Programmers Notepad using LaunchPN.bat.) To download the 
program, make sure the robot is on, then choose the Tools/Program command. 
 
(You can also use the command line to build and download your programs. Run setpath.bat (from “C Samples”) in 
the command window to set up the environment, then call make manually.) 
Program Descriptions 
Program 1 
Purpose: Learn how to use outputs to make the green LED flash. 
Programs: FlashLED, FlashLEDAlias -- note how the code in FlashLEDAlias is easier to read; you don’t need the 
comments to explain what’s going on. 
Extensions
o  Change the rate at which the LED flashes. 
o  Change the code so that the LED is on longer than it is off. 
Program 2 
Purpose: Learn how to use inputs to detect obstacles, lighting the LED when a bumper (whisker) is touched. 
Programs: Whisker, WhiskerAlias 
Extension: Add code so that touching either bumper turns on the LED. 
Challenge: Make the LED flash at four different rates when bumpers are: open-open, open-closed, closed-closed, 
closed-open. 
Program 3 
Purpose: Drive! Learn how to control the motors. 
Program: PWM 
Extensions
o  Experiment with other PWM values, e.g. set both motors to 255 or -128. 
o  What happens when you use 128 for the left motor PWM and 255 for the right motor PWM? 
o  What happens when you use -100 for the left motor PWM and 100 for the right motor PWM? 
o  Flash the LED once a second for five (or three) seconds before starting. 
o  Wait for a bumper touch (instead of delay) before starting the motors. 
o  Make a bumper touch cause the robot to back up, then stop. 
o  Make the robot go forward 10 inches, then turn left 90 degrees. 
o  Make the robot do the previous extension 4 times. 
28  
11-3-2005