CSCI 445 - Introduction to Robotics

Lab Home Page

Spring 2007

Contact Information:

Lab Instructor & Coordinator:

Rand Voorhies
Email: voorhies-AT-usc-DOT-edu
Hours: Lab sessions and by appointment


Robotic Explorations: An Introduction to Engineering Through Design, Fred G. Martin, 2001 (FM).
For information about this book refer to Course Home Page)

Meeting Time & Place:

Monday, 6:00pm - 8:50pm

Tuesday, 1:00pm - 3:50pm

Friday, 1:00pm - 3:50pm

Place: VHE 205

Lab Syllabus:

Lab Session


Assignments Due


Lab Introduction (in class)



Building a Robot



Mobile Robot Navigation

robot race (10pts.)


Sensor Calibration

traversing maze (5pts.)


Temporal Filtering

finding brightest location (10pts.)


Search And Rescue: Vision

line following (5pts.)


Search And Rescue: Vision



Search And Rescue: Manipulation



Search And Rescue: Localization

Milestone 1 (30pts.)


Search And Rescue: Localization



Search and Rescue: Communication

Milestone 2 (30pts.)


Search and Rescue: Communication



Search and Rescue: Communication



Search and Rescue: integration



Search and Rescue: integration

full in-lab demo (40pts.)


California Science Center Demo

Robot ready for Demo (20pts.).

Handyboard Driver Repository:

Lab 0: Lab Introduction

Introduction to Lab

Introduction to Book

Grading: Participation and Lab Experiments

Final Contest

Selecting Teammates

See Details …

Reading: None


Lab 1: Building the Handy Bug

A brief summary about building a robot

Introducing the Kit

Preparing the material needed for constructing the Handy Bug

Following the step by step procedure of building the Handy Bug (Acc. to FM's 2.2.1)

Presenting the Handy Board to examine its different parts

Handy Board Demo:

·         Its different parts

·         Downloading IC (Interactive C) to the Handy Board

·         First Program: Beeper

·         Working with Motor output

Connecting the Handy Board to the computer, Writing a simple program (Beep)

Working with motor output of handy board and experiencing with different motor commands

Working with digital input of the handy board (using the touch sensors)

Introduction to motors: torque and velocity concepts

Working with gears


Robot running first program (FM2.3.2), straight for 8 ft.

See Details …

Reading (from FM):

1.2.3 Introduction to lab
1.3 Handyboard
1.4 Overview of book
2.2.1 Handybug (first robot)
2.1 Interactive C
2.3.2 First program
4.5 Lego structure

4.1 DC motors
4.2 Gearing


Appendix E. Interactive C
Appendix D. Handyboard


Lab 2: Mobile Robot Navigation

Finishing the HandyBug according to the desired gear train

Sensors: Switch and flex sensor

Reactive systems and environments: emergent behaviors and randomness

Reactive system and metasensing


Traversing the maze

See Details ...


2.7 Emergence and meta-sensing
2.6 Randomness
3.1 Sensor Interfacing
3.2 Building Sensors
3.3 Switch sensor
3.5 Bend sensor


Lab 3: Sensor Calibration

Sensors: photosensor

Calibration: Manual vs. Automatic


Light seeking contest

See Details ...


3.4 Light/photo sensor circuit
2.4.2 Braitenberg vehicles
2.4.4 Light sensor software
2.4.5 Light sensor software
2.5 Light and bump sensor interaction


Lab 4: Temporal Filtering

Sensors: optosensor

Temporal/Spatial Filtering: hysterisis, etc


Line following contest

See Details ...


3.6 Reflective opto-sensor
3.7 Break beam sensor
3.8 Shaft encoding
6.5 Thresholding, hysterisis,and auto calibration


Lab 5 - 13: Final Contest Preparation

 Introducing the Expansion Board

 Devices: camera, servo motor, IR sensor, and compass


Vision: Finding victims

Manipulator: picking up a victim

Localization: Finding hospital

Communication: Pushing home a box

See Details ...


Check out: Capture the Flag

External power supply for Handyboard

6.3 Sonar
Devantech srf04 sonar ( code)
Compass: info, code, library

RELAY: SPDT Miniature PC Relay 12VDC coil rated 10A at 120VAC/24VDC, RadioShack number: 275-248A
sonar and compass code run in parallel (sonar in NO pin of relay)

4.4 Servo motors: code

CmuCam camera paper, manual, manual summary
External power supply for CMUcam

6.2 intro, 6.2.1, and 6.2.6 IR communication
send.ic, sonyxmit.icb, rec.ic, sony-ir.icb


Lab General Information Details:

Rules and Policies:


The lab is 40 percent of your overall grade. It is divided into two parts: Lab Sessions and Final Project.
The grades for these two parts are:

Lab Grade

50 pt.


20 pt.


Cleaning up

0 pt.


Experiment/Test Results

30 pts.


Final Project Grade

150 pt.

Milestone 1 & 2

60 pts.


Final in-lab demo

40 pt.


CSC demo

20 pt.


Advanced Implementations

30 pts.


Lab papers:

There is a final project paper

1) Cover Page: title and Author's name

2) Table of Content: not needed for short paper

3) Introduction: motivation, summary of problem, previous works

4) Design: implementation of solution, tradeoffs

5) Testing: validation of work, defining metric

6) Results: tables, graphs, images

8) Conclusion: summarize findings

9) Appendix: code, clarifications (mathematical derivations, for example)

equal and fair division of work among the team members
friendly and open communication among the team members
effective conflict resolution when disagreements arise
flexibility in scheduling team meetings


None of the assignments, exams, labs, or competition is optional. Failure to attend or turn in without discussion with the instructor beforehand will result in an F in the class

Questions/disputes of grades:

Any questions, concerns, or disputes of grades should be directed to the lab assistant.

Cheating and Academic Integrity:

The USC Student Conduct Code prohibits plagiarism. All USC students, and therefore all students in this course, are responsible for reading and following the Student Conduct Code, which appears in the current SCampus. Also look here for useful information from the Office for Student Conduct, including a guide to avoiding plagiarism, which defines plagiarism and includes examples and explanations of effective and ineffective paraphrasing.

Students who violate University standards of academic integrity are subject to disciplinary sanctions, including failure in the course and suspension from the University. Since dishonesty in any form harms the individual, other students, and the University, policies on academic integrity will be strictly enforced. We expect you to familiarize yourself with the Academic Integrity guidelines found in the current SCampus. Violations of the Student Conduct Code will be filed with the Office of Student Conduct, and appropriate sanctions will be given.

Lab 1 Details:

In this session you will prepare your robots for the Speed Contest. You will have maximum 2 hours to prepare yourselves.

1) Build your robots according to Handy Bug 9645:

- According to your book (pages 28-50), rebuild your robots if necessary. Please be quick so that you will have enough time to write and test your programs.

The following LEGO items should be used instead of the items described in the book*:

Item #

As in the book


Alternate Item



1x2 roof brick


1x2 brick



1x10 plate


1x6 plate


1x4 plate


1x8 plate



6x8 plate


6x10 plate



tire (42 mm)


Big tires with hub



1x6 technic beam


1x6 technic beam



6 stud axle


4 stud axle





alternate crank


* For Instructions on these changes, refer to the assistants.

2) Handy Board Demo:

- Its different parts (refer to appendix D of your book)

- A brief summary about the Expansion Board (refer to appendix)

- Downloading IC (Interactive C) to the Handy Board

- A brief summary on IC (Interactive C) (refer to appendix E of your book for more info. You should go through this appendix before starting to write codes so that you know all the features and limitations of the IC)

- First Program: Beeper

- The functions related to beeper are in Appendix E, pages 418 & 419 of your book. Go on and examine them.

- Working with Motor output

- The functions related to DC motors are in Appendix E, page 415. Examine them.

- Working with digital input (using the touch sensors)

- The functions related to input are in Appendix E, page 417. Examine them.

3) Write Programs to be familiar with beeper, motors and digital input

a) Write a program (both in the command prompt and in a file) to sound the beeper for 3 seconds with 500 Hz frequency, then be silent for 1 second, and then sound the beeper for 3 seconds with 100 HZ frequency, be silent for 1 second and finally sound the beeper for 2 seconds with 1000 Hz frequency

b) Write a program (both in the command prompt and in a file) to turn on the motor connected to port No. 2 with 50% power, work for 3 seconds, sound the beeper, reverse the motor with full 50% power for 2 seconds, sound the beeper, turn off the motor for 2 seconds, then turn it on with full power for working 3 seconds, sound the beeper and turn it off

c) Write a program for your robot so that when one of its touch sensors is triggered, it will start rotating around itself until the same touch sensor is triggered for the second time.

4) An Introduction on gear concepts: torque vs. speed, gear ratio

- A brief explanation will be given to you about some concepts on gears (torque and gear ratio). For more information, refer to section 4.2 of your book.

5) Working with gears & examining various gear trains

- Build some gear train samples according to figures 4.34 (p. 161), 4.42, 4.43 (p. 165) & 4.44 (p. 166) to be familiar with different gear trains

- Examine different configurations of gear trains to find out the distances between each kind of gear both horizontally and vertically in terms of studs.

- Determine what gear train you are going to use for the speed contest (that gives you the maximum possible speed) and the corresponding calculations for the gear ratio. Examine different possible gear trains on your robot. You are going to implement what you have reached in the next lab. Keep in mind that you are not supposed to change the overall configuration of the robot. For example, you can not change the worm gear and the 24-tooth round gear that is attached to it. You can basically change other gears, add to them, change the length of the axles or their position, etc. Also keep in mind that there is a trade-off between the torque and speed.

Note: Don't lose any of your calculations although you may not be asked for them in the lab.

Experiment Criteria:

- Your robot should stop after it hits a wall after the end line. If your robots bumped to this wall, they should stop their motors using the touch sensors.

- Your robot should move as straight as possible.

- Your robot overall configuration should not be different from the original Handy Bug. You can add gears wherever you want, move the axles, move the motors and wheels, but you can not change the worm gear and the 24-tooth gear attached to it. Also you can not add anything to the length of your robots.

- After the contest, each group might want to improve its robot for a better time without any restriction such as the ones stated above (i.e. you can change the structure of your robots as well as any gear you want).

Experiment Preparation:

1) Implement whatever gear train you have chosen on your robot. Do necessary changes to your robot in order to implement the gear train.

2) Write and debug your program for the contest.

3) Test your robot to debug both its structure and the program.

Programming tips:

1) Try using functions for the things that your robot will do most of the times (e.g functions for going forward, backward, turning, checking sensors, etc) so that you could use them in your future programs.

2) Try using the white buttons on the handyboard (start or stop) in your programs when you want to start the motion of your robot. It's much better than using the on/off switch on the handyboard.

3) Try printing explanatory messages on the LCD screen so that you would be able to figure out in which stage of your program is the robot working at, whenever necessary.

Lab 2 Details:

In this lab, you will use contact (both switches and flex) sensors on your robots and write programs to avoid obstacles and collision.

1) Tunnel Contest:

In this experiment, you are to write a program for your robot to go in and out of a pre-designed tunnel with a dead end, touched it and come out of it while not get stuck in it.

    - Experiment Rules:

a) Every robot should make through the tunnel in a reasonable amount of time.

b) Your robot should back up whenever it bumps to a wall (obstacle).

c) After backing up, it should turn in an angle not greater than 45 degrees. (In normal turnings)

d) You should minimize the number of bumps to the opposite wall after your robot backs up from a particular wall.

e) Your robot should never reverse its direction in the tunnel.

f) Keep in mind that the angle in which your robot will start going through the tunnel is not known to you prior to the contest. Your robot should perform satisfactorily regardless of this angle.

g) Your robot should make a RANDOM turn when the number of consecutive bumps in a 2 seconds range of time exceeds 4: you may just hit the dead end

h) The turning angle for the random turn should be more than 45 degrees. The upper limit of this angle is up to you.

i) The tunnel shape can look like the figure below:

    - Programming tips:

a) Use Appendix E (Interactive C Reference) of your book for syntaxes, built-in functions, etc.

b) You can get ideas from the obstacle avoidance exercise in your book (page 72-73).

c) Try using functions as much as possible. Write basic functions of your robot like turning left or right, left-sensing or right-sensing, etc as different functions in your code so that you will be

d) Use user buttons of the Handy Board in your programs in order to be familiar with these for future use (like start and stop button).

e) Debug your robot so that it goes as straight as possible when it is supposed to to that.

f) Test your robot for turning and backing up to see it works as desired.

g) Debug your bumpers so that your robot can sense left or right bumps correctly and effectively.

h) Use the concept of Meta-Sensing in your program. Meta-Sensing is basically the ability of your robot to monitor its own performance and decide to solve the problem that it senses. For example, when it reaches the dead-end, it can sense it and decide to do a random turn to get out of the trouble.

i) You can get ideas for your program from the Randomness concept (pages 87-89) and Meta-Sensing (pages 89-94).

j) Try to implement a way in your program to show when it's doing the random turn. For example you can use the LCD screen to print a message on it or use the beeper.

Lab 3 Details:

In this lab, you will use light sensors together with contact/touch sensors on your robots and write programs to practice light seeking concepts.

Light Seeking experiment:

In this experiment, your robot should first go towards the light source from any locations. You can get ideas about this from your book (pages 80-85). Keep in mind the problems that you face in this exercise and try to solve them for the next practice. You can start with a wide open environment (without obstacle).

a) Light sensors are very sensitive to ambient light. When you are working in an area where ambient light is dominant, calibration of your sensors is vital. You should find out the range of sensor readings in the environment that you are working and use it in your calibration.

b) Light sensors are actually "Dark Sensors"! They report small values when brightly illuminated and large values in the dark. Keep that in mind!

c) Shielding the sensors is again important specially when you are dealing with a kind of light seeking/avoiding. You can shield your sensors in different ways. For example, if you want to omit the effect of ambient light from above, you can shield only the top of the sensor, or if you want to have side sensing, you can use semi-tube shields. Try to use different shields to find out which is most appropriate for your practice.

d ) Find out the maximum and the minimum sensor readings in the area and use them as upper and lower limits for the report range of your sensors.

e) The sensor reading range (analog input) is between 0 and 255, however the range of motor power is between 0 and 100. Therefore you should normalize your sensor readings so that the d>

f) The location of sensors on your robot is also important when it is supposed to seek/avoid light. Try different locations and angles to see which is the suitable for best performance.

g) Make sure that both of your sensors report almost the same results when faced the same situation.

Sometimes when the robot is at a dark region it can't quickly find the light. After doing the above practices, use the ideas in your book (pages 286-292) for writing a simple wandering program using your photo sensors (not optosensors). The basic idea of wandering is moving in a waddling fashion in different directions until a certain criteria is met (for example the amount of light gets below a certain threshold or your robot is off the line in a line following practice).


a) Use light sensor readings as the criteria for your wandering program.

b) Use parameterized fixed thresholds and Calibration by demonstration methods to set the thresholds in your program.

c) Use the wandering program to seek light. Compare it with your previous program to see which one works better

Lab 4 Details:

In this lab, you will use optosensors on your robots and write programs to do line following.

Line Following experiment:

In this experiment, you will use optosensors on your robots and write a program for following a line. A curve with black electrical tape is made on the white table and your robots should follow this curve to the end of it and return (see figure below).

Mount the optosensor on your robot and try to practice with it to see how it works and what are the issues you have to keep in mind when using it. You can find useful information about the optosensors in your book (pages 118-126).


a) Try to shield your optosensor from its back to avoid any ambient light interfering with the light that your sensor emits.

b) Keep in mind that the angle in which the light is emitted from the sender and is received by the receiver in return is important and should be taken into account.

c) Like the photo sensors, optosensors return larger values in dark.

Rules for Line Following Contest:

a) Your robot should follow the line (curve) from the start point to the end point and return to start point again.

b) Each time your robot goes completely off the line, you will get one negative point.

c) If you get 3 negative points during the contest, you will have to do it again until you finish the contest with less than 3 negative points.

d) The winner is the one who finishes the contest faster and with less negative points. The time has 50% of your total score (i.e. if you finish the contest the fastest, you will get 50% of the total score). The other half of the score is determined according to your negative points (i.e. you will lose 15% with each negative point). For example if you finish the fastest with 1 negative point, your total score will be 50 + (50 - 15) = 85.

e) You are not allowed to change your robots gear train. You can only improve your speed by your program (software not hardware). For example the way you manage to follow the line affects your speed.

Writing the program for Line Following:

a) You can get ideas for your program from your book (pages 286-306).*

b) Write 2 programs for line following: One with "Thresholding with Hysteresis" concept (pages 288-289) and one with "Sensor Histories" concept (pages 291-292)**. Show the TA how each one works. Then use the one with the better performance for the contest.

c) As an extra credit, you can use built-in sensor history routines (pages 293-306) in order to: 1) Be familiar with the built-in IC routines that average the sensor readings and 2) See if this method will improve your robot performance or not.

* For information about how to use Multitasking capabilities of IC and the Processes, refer to your book (pages 419-421).

** A brief explanation of the programming concepts:

"Thresholding with Hysteresis"

- Using one fixed threshold for the line set point, is not reliable in practice since there are a variety of sources of noise and other degradations of sensor performance and therefore one is likely to face occasional pulses in sensor readings that are beyond the line threshold and will deceive the robot in determining whether it is actually on the line or not. Instead, using two thresholds (one as line set point and one as floor set point) will lower the possibility of being deceived by the noises. Determining the values for these two thresholds is a matter of calibration that can be done by demonstration. I.e. placing the robot once on the line and once on the floor (table) and reading the sensor values and then using these as set points (thresholds).

"Sensor Histories"

- One other way to find the line set point (or threshold) is using the sensor reading history to determine the maximum and minimum values that the sensor had read and then determining a kind of average for those and using it as the threshold. The averaging technique is also important. Sometimes the arithmetic average does not work properly because the maximum values recorded as the robot passes over the line are much higher than typical line values and therefore this pushes the threshold well up into and sometimes over the value that will be seen by the sensor as the robot crosses over the line. In this case, using weighted average techniques will help preventing the threshold to be TOO high. For example you can assign more weight to the the minimum value in order to push the threshold down.

Final Contest Details:

For the final project, you will need to be be familiar with the Expansion board, servo motor, camera, sonar, and compass.

The Expansion board (EXPBD):

The Expansion Board adds a wealth of new capabilities to the Handy Board: 10 additional analog inputs, 9 digital outputs, 6 servo motor outputs, 4 LEGO sensor inputs, easy connection of the Polaroid 6500 ultrasonic ranging system, and an open prototyping area.

The Expansion Board simply plugs into a standard Handy Board. The LCD screen is plugged into a new connector provided on the Expansion Board.

Remember that in order to use the expansion board, you should have the file: lib_hb.lis which should contain the following lines:


If your c:\ic\libs folder does not have these files, ask the assistants for help. Also please note that the analog and digital sensor functions are now contained in separate files. When using the Expansion Board, expsens.c must be loaded; when not using the Expansion Board, load hbsensor.c instead.
For more information on the expansion board, refer to the Appendices section which is taken from the Gleason Research Web Site.

Working with the servo motor:

a) Connect the Expansion board onto your Handy board (ask the assistants for help).

b) Connect the servo motor to the expansion board's Servo Motor output

c) Experiment with the servo motor and position it in different angles (For more information about how to work with servo motor, refer to the Appendix of the Lab Manual).

d) Find out the Maximum and Minimum Values that the servo can have for rotation (remember the this servo motor can only rotate 180 degrees).

e) Find a relationship between the values that the servo takes and the angle in which it rotates (for converting the servo values to angles).

f) Write a program to position the servo motor in different positions using the knob on the Handy Board.

Vision using CMUcam

  • CCD (charge coupled device) and CMOS (complementary metal oxide semiconductor) image sensors are two different technologies for capturing images digitally, each with unique strengths and weaknesses that make them appropriate to different applications. CMUcam is a CMOS camera.

  • The CMUcam provide a high-level information extracted from a camera image to an external processor that controls the robot in order to track an object. Here, the Handyboard first configures CMUcam's streaming data mode, for instance specifying the tracking mode for a particular bounded set of RGB values. It then processes the data in real time and outputs high-level information back to the Handyboard.

Working with the Polaroid 6500 Sonar (No Longer used):

a) Sonar Ranging is one of the most common forms of distance measurement used in Mobile Robotics. The principle is: a speaker (Transducer) is used to emit a short burst of sound (Ping). The sound wave travels through the air and reflects off a target back to the Transducer (Echo). By measuring the Time of Flight between Ping and Echo detection, one can calculate the distance between the target and transducer. The Polaroid 6500 ultrasonic ranges from 6 inches to 35 feet. It thas a minimum range of 6 inches because it uses the same device to both emit and receive sound waves. That is, sound emitted sonar sensor to see how it works (REMEMBER: There is a high voltage (400 volts) on the sonar sensor so don't touch the metal parts of it although it's not dangerous because of the low current). For more information on the Sonar Sensor refer to your book (pages 271-280).

d) Use the drivers presented in the MARTIN book to write a program for your handy bug so that it won't go nearer than 2 ft of any obstacle (Obstacle Avoidance).

Final Competition: Robot Search and Rescue


The final competition is going to be a a search and rescue mission done by a group of 2 robots. The contest will be held on December 4th and 5th, 2006.
The specifications and rules of the contest:


Search and rescue entails finding victims and transferring them to a designated place. Also, to add explicit cooperation, the robots have to pick up a supply box that needs to be pushed by more than one robot.

Competition Rules:

a) The field The dimensions, markings, and starting position. Extra sensors, accomodition from the field will be discussed after experiments. The robots starts at a predefined location and they are to disperse properly.

b) The Robots: Size, color and appearance of the robots.

c) The competition: We are playing against a standard, not each other. There is a time limit to complete all tasks

d) Scoring:Points are rewarded following each successful task. A bonus point will be rewarded when the last task is completed below the time limit

e) Fouls: Points will be taken off when bumping into the victims.

f) Length of competition: 10 minute period.

Design and Implementation

The following are the preliminary design decomposition. Note that the end they have to be merged to one whole system.

Robot building
· Locomotion: building chassis
· Power system: added external batteries to lengthen operation time
· Manipulator: pick up a victim
· Control: control the robot to move properly.

· Recognize victims: their lift orientation

· Robustly detecting location now that obstacles and other robots are on the way

Multi-robot communication
· Information encoding
· Ask for help
· Dynamic task decomposition
· Implicit communication or stigmergy
· Locations of other robots

Extra Implementation
· Human-Robot interaction: Speech synthesizer and recognizer
· Omni control: reinforcement learning, NN, kinematics

Design requirements and limitations:

a) You are allowed to use whatever sensor you have worked with in your designs. There is no limitation on the number of the motors you can use, although it is important that the weight and power consumption be considered.
b) You are welcome to use anything on your robots that is not presented in the lab, i.e. a different kind of motor, a different kind of sensor, other LEGO parts, so long as it is safe for people and other robots.
c) Any weakness in your robot's behavior, like non-functional sensors, will not affect your score in the game but will be considered in your final grade for the project.
d) You have to treat the victims as if they are real people.
e) Because each team runs a separate session, the there is no restriction on the IR communication coding.


Your final project grade (30% of the final grade) is divided into the following parts:

- Milestone 1 (vision and manipulation): 30 pt.
- Milestone 2 (M1 + localization): 30 pt.
- Final in-lab demo: 40 pt.
- CSC demo: 20 pt.
- Advanced Implementation: 30 pt.


You can either submit your reports in a web-based format or a word-format.
Also, if you have a programming part, your isolated portion of the program should be included in the report
Your report will be your about your specific problem but it should consist of the following:

- Introduction: problem, background, basic concepts, etc.
- Design concepts (both software and hardware): advantages and disadvantages
- Testing
- Result
- Discussion: Unsolved problems
- Contest result and Conclusion

Webmaster: Christian Siagian

The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees