SRS Labs SRS Robot Level 1 Kit manual Programming, Program Descriptions

Page 28

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

(see the Software Tools section for Mac information)

AVRDUDE_PORT = com1

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:

oChange the rate at which the LED flashes.

oChange 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:

oExperiment with other PWM values, e.g. set both motors to 255 or -128.

oWhat 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

Image 28
Contents SRS Robot Level 1 Kit Getting Started Computer RequirementsRecommended Equipment USB port with a USB-to-serial converterKit Contents Vendor Information ARC Board Connection KitQty Vendor Part Preparation AVR Robot Controller 1.1 Assembly InstructionsSoldering Overview Prepare Boards ControllerSolder Components ‰ Resistors and diode‰ Switch and resonator ‰ Small capacitors and LEDsCleaning and Inspection Attach Connector to Battery Holder‰ Sockets, headers, and jumper ‰ Large capacitorsInstall Chips Serial CableAVR Robot Controller 1.1 Software Tools Programming CableBascom on Windows Tool OptionsWinAVR avr-gcc on Windows Customizing the Microcontroller Avr-gcc on Mac OSResources Http//sourceforge.net/projects/winavrChassis Assembly MotorsLight Sensors Bottom PlateTop Plate Final Assembly Wiring Connections Leftover PartsATmega16 Programming PartATmega16 Programming 11-3-2005 Part ATmega16 Programming 11-3-2005 Part ATmega16 Programming 11-3-2005 ATmega16 Programming 11-3-2005 Part Sample Programs Creating New ProgramsProgram Descriptions ProgrammingProgram BumpNGo RemoteControlProgram Turn Power PinsAVR Robot Controller 1.1 Hardware Description Physical Functional Input Connection Pin Name Output HeaderLeft and Right Motor Connectors Expansion Headers JP3 and JP10Left and Right Analog Inputs Left, Center, and Right Floor Sensor InputsPower Source In-System Programming and Option SelectProgram LED output Servo outputAVR Robot Controller 1.1 Schematic