1 / 14

Introduction to Computer Science – Chapter 5

Introduction to Computer Science – Chapter 5. CSc 2010 Spring 2011 Marco Valero. Overview. Exteroceptor overview Camera sensor Light sensors Proximity sensors Lists Gamepad WWW Function redux. Exteroceptor Overview. External sensors ( exteroceptor ) Camera

hesper
Download Presentation

Introduction to Computer Science – Chapter 5

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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(<option>) • <option> = “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(<position>) returns a value of the given position • <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(<position>) • <position> = ‘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(<position>) • <position> = 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(<position>) • <position> = 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(<device>) • Returns the value of the device after input is received • getGamepadNow(<device>) • 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) print Data.read()

  14. Functions Redux def <identifier>(<parameters>): <expression-list> • Python returns a value for all functions, whether explicitly or implicitly def cube(x): return x*3 • return <expression>

More Related