Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Computer Science – Chapter 5 CSc 2010 Spring 2011 Marco Valero.

Similar presentations


Presentation on theme: "Introduction to Computer Science – Chapter 5 CSc 2010 Spring 2011 Marco Valero."— Presentation transcript:

1 Introduction to Computer Science – Chapter 5 CSc 2010 Spring 2011 Marco Valero

2 Overview Exteroceptor overview Camera sensor Light sensors Proximity sensors Lists Gamepad WWW Function redux

3 Exteroceptor Overview External sensors (exteroceptor) Camera ▫Capable of taking still pictures Light sensor ▫Three light sensors on front of the robot can detect brightness ▫Three light sensors on Fluke card as well Proximity sensor ▫IR sensors on robot as well as obstacle sensors on the Fluke card

4 The Camera Camera is located on the front of the Fluke dongle takePicture( ) ▫ = “color”, “gray”, or empty show(picture) ▫Displays the picture savePicture(picture, filename) ▫Saves the picture to disk Taking grayscale photos is easier than taking color

5 Light Sensing getLight() returns a list of all three values of light sensors getLight( ) returns a value of the given position ▫ = ‘left’ | ‘center’ | ‘right’ | 0 | 1 | 2 Low values imply bright light

6 Light Sensing Camera can also be used to sense light with the getBright() function getBright( ) ▫ = ‘left’ | ‘center’ | ‘right’ | 0 | 1 | 2 Higher the value, the brighter the light Normalizing the values relative to motion is a useful idea

7 Proximity Sensing Two IR sensors on the robot and three on the card Robot has getIR() and getIR( ) ▫ = 0 | 1 | ‘left’ | ‘right’ Boolean values determining whether path is clear or not ▫1 implies nothing impedes path, 0 implies something does getObstacle() and getObstacle( ) ▫ = 0 | 1 | 2 | ‘left’ | ‘center’ | ‘right’ ▫Values from 0 to 7000, with 0 implying nothing in sensor’s path and high numbers implying the presence of an object

8 Lists List is a sequence of objects ▫Numbers, letters, strings, images We have seen lists before with the range function Lists can contain no items as well ▫[]

9 List Operations len(N) ▫Returns the length of the list, N Index a list: list[index] ▫Returns the element located at index, where index is a number 0 or higher ▫If a list contains n elements, the last index is n – 1 Slice operator: list[begin:end] ▫Returns a view of the list that starts at the beginning positions and is less than the end Concatenate lists: + ▫mynewlist = mylist + myotherlist combines the two lists into a new list

10 List Operations Find an element: in ▫3 in [0, 1, 2, 3], ‘city’ in [‘car’, ‘dog’, ‘house’] Sort a list ▫Mylist.sort() Reverse a list ▫Mylist.reverse() Add to a list ▫Mylist.append(item)

11 Strings, a character sequence We can iterate through sequences of characters just like a list ABC = “ABCDEFGHIJKLMNOPQRSTUVWXYZ” for letter in ABC: speak(letter) String operation split ▫splits a string based on space as the separator and returns a list of strings ▫Sentence = “Obviously you’re not a golfer” ▫Words = Sentence.split()

12 Gamepad We can use a gamepad to control the robot getGamepad( ) ▫Returns the value of the device after input is received getGamepadNow( ) ▫Immediately returns the value of the device Axis values are from -1.0..1.0 Button values or on/off or 1/0

13 WWW We can use python modules to retrieve data from the web from urllib import * Data = urlopen(http://cs.gsu.edu/~nmancuso1/data.txt)http://cs.gsu.edu/~nmancuso1/data.txt print Data.read()

14 Functions Redux def ( ): Python returns a value for all functions, whether explicitly or implicitly def cube(x): return x*3 return


Download ppt "Introduction to Computer Science – Chapter 5 CSc 2010 Spring 2011 Marco Valero."

Similar presentations


Ads by Google