# CSC-104: Robots Rule!

## Course Overview

Learn to control robots before they control you

This introductory Computer Science Course will introduce you to the art of computer programming through interaction with robots. Over the course of the term you will build your own LEGO-based robot and learn to control it in a variety of interesting ways. By the end of the course, the successful student should be able to: Write programs that include scalar variables, arrays, structs, functions, and conditional and iterative control structures in Python; apply debugging strategies to diagnose and correct syntax, logic and run-time errors; apply the input/process/output model to the implementation of robots; design programs using a structured approach that includes algorithms and functional decomposition; discuss the interaction of computer hardware and software as applied to robotics; examine the social and ethical implications of robots

## Language & Resources

Like the title says, language info etc.

In class, you are required to use our lab iMacs. However, when working on your projects outside of class, you have a choice. If you'd like to continue using our iMacs, feel free! We have three spaces that you can use:

• Olin 107 (where we have class)
• Pasta lab (N104 in the Science & Engineering building)
• CS Resource room (Steinmetz Hall, 209A, just down the hall from my office)

All of these labs are available to you 24/7 using your ID card, except when classes are being held in them.

## Course Text

The Practice of Computing Using Python, Punch and Enbody, Addison Wesley.

## Example Assignment: Mystery Function

Looking more deeply at the robot's code, you are begining to suspect he has become sentient and is starting to program himself! You see the following function in the robot's code, but it was clearly written by a robot, since no human in their right mind would use variable names this meaningless!
```def Scramble(n):
letter = 3
pigeons = [2]
while(len(pigeons) > 0):
banana = False
for mango in pigeons:
if letter%mango == 0:
banana = True
if (banana == False):
pigeons.append(letter) #POINT B

print '`so far:', pigeons     #POINT A
letter+=1
return pigeons
```
What does this function actually do? To explain, rewrite the function with a proper name and proper variable names below.

## Example Lab: The Sense-Plan-Act Loop

Goals: by the end of this lab you will have:

• written a sense-plan-act loop for your robot
• written some more functions
• learned how to use the ultrasound sensor
• used your robot outside of Wold 118, because it is too hot in there.

0. Prelude: We'll begin with a very informal lecture on the sense-plan-act loop, as well as ultrasound sensors

1. A Basic SPA Loop

• Grab an ultrasonic sensor, if one is available
• Grab a microphone sensor if one is availablean>
• Inside a file called Lab6.py, write a function called RunRobot(), which takes no arguments, and returns no values.  Inside of RunRobot, create an infinite while loop.  The while loop should do three things in order:
• Sense: read the light sensor values for each light sensor on your robot, binding them to variables
• Plan: using variables representing each motor speed, set your motor speeds proportional to light sensor values such that the will steers TOWARD light.
• Act: Use SetBothMotors with the motor speed values above, in order to get the robot to do what you want.
• Test your robot in class, or some place cooler.  Show an instructor before proceeding.

2. Bells and Whistles

• Now, in the "Sense" phase, also read any other sensor values that are available to your robot.
• be sure to store each value in a separate variable!
• In the "Plan" Phase your robot should:
• if there is an obstacle, set motor speeds backwards
• otherwise, steer toward the light.
• Test your robot, and show instructor before proceeding.

3. Louder Bells and Whistles

• Now, modify your SPA loop in any of the following ways:
• if it's too loud, move backwards (while still facing the light) instead of forwards
• if an obstacle is too close (according to the ultrasound), turn in place.
• test your robot in the real world, show an instructor.

4. Impress us!

• add more "rules" to the "Plan" phase, so that your robot performs more sophisticated behaviors!

There will be weekly homework exercises. Homework exercises are for you to play with and reinforce the concepts we talk about in class. Each person must hand in his or her own solution. Where these exercises require python programs, you MUST hand in working code, including test measures. This will be explained more fully at the appropriate time.

There will be two programming projects. These projects will combine different programming concepts and multimedia techniques, and provide opportunities for creativity. Each student must complete his or her own programming project. You may discuss algorithms with each other, but you may NOT look at each other's code. To complete these projects on time, it is critical that you start each as early as possible and get help as soon as possible when needed.

There will be labs where you will work on exercises in-class and receive help from the lab assistant, your peers and instructor.

There will be one in-class midterm exam, and a final exam that must be completed individually. There may be "pop quizzes" and independent in-class exercises. The intent is to motivate you to keep up and provide feedback on your progress. Learning to program is like learning a foreign language: if you do not speak it during some part of every day your progress will be quite slow.

• Homework exercises: 15%
• Daily Micro-Quizzes: 5%
• Labs: 20%
• Midterm 1: 15%
• Midterm 2: 15%
• Final: 20%
• Attendance and Participation: 10%

Revisions: For each midterm, correct revisions to (non-zero) graded homework problems may be handed in with a new cover sheet. Doing so will redeem up to 50% of points lost.

## Schedule

• Week 1: Introduction: What are computers? What are Robots? Fundamentanls of Computation, Intro to Python.
• Week 2: Python, variables, data types, expressions, predicates and conditionals
• Week 3: conditionals and loops
• Week 4: functions and scope
• Week 5: lists and list manipulation
• Week 6: advanced functions and mapping
• Week 7: Recursion
• Week 8: File Input/Output
• Week 9: Dictionaries, Data Structures
• Week 10: Search, Advanced Robotics