Blog

Setting up folders and survey.

Ms. Martin : February 2, 2010 9:14 pm : 2009 Fall Exploring CS

Once again, welcome to Exploring Computer Science!  I’m really looking forward to another fun semester learning about all kinds of technologies with you.

First of all, spend a second to create a folder for this class in your My Documents folder.  I’ll be coming by to make sure you’ve got that set up properly.

Then, spend some time answering this survey.  The first part is just background that will help me get to know you better and hopefully serve you better as an instructor.  The second part is to encourage you to get to know the website well.

2 Comments »

Website turnins

Ms. Martin : January 11, 2010 5:46 pm : 2009 Fall Exploring CS

This is going to sound crazy, but I don’t have a reasonable way for you guys to turn in your websites!  We’re going to use another teacher’s public-writeable folder.  I know this is not ideal, but it should work.

Click on the following link:

S:\mablache\Writeable\1stPeriod\MS MARTIN WEBSITES

This should open up a folder.  Create a folder called your_name.  Put all of your website files in it.

Leave a response »

HTML project

Ms. Martin : January 5, 2010 8:43 pm : 2009 Fall Exploring CS

Time to build a website composed of at least 3 pages!  As you know, being a self-learner is a theme in this class.  You will need to make heavy use of the tutorial to complete this assignment.  Have fun with it!

You will need to create a web site with exactly 3 pages to either sell a product or introduce someone other than yourself to the world.  I want to put these on the web, so please don’t include any identifying information beyond your first name (no last names, pictures, etc).

Look at other websites for inspiration and steal their ideasMy example (which is NOT COMLETE!!) should give you ideas, but your page should look very different — no copying and pasting!  Remember, you can right click and hit ‘view source’ to see the HTML for any page.

For this assignment, due at the end of Friday 1/8/2010, you must have at LEAST:

  • three pages (one of which MUST be index.html)
  • a title
  • a navigation bar
  • a footer (contact info, copyright, for more info… etc.)
  • one list (<ol> or <ul>)
  • one table
  • three images
  • centered text in two places
  • colored text
  • 2 different fonts
  • one colored background (for a paragraph, the body, a table…)
  • four links
  • three headings

Additional hints

Inserting images

The tutorial has good examples on how to use images as a background or simply as part of a page.  You can use any image you want by saving it into THE SAME DIRECTORY AS YOUR HTML.  You can then refer to it directly.  For example, if you save an image called apple.jpg, you can use the image in your page like so:

<img src="apple.jpg">

Linking between pages

You will create three different html pages saved in the same directory.  You can link between them by using their full file names.  For example, if you have a file named shop.html, you link to it like so:

<a href="shop.html">Shop</a>

Notice that this is exactly what I do in my example (Ms. Martin’s Phone Store)

5 Comments »

Robot sensors

Ms. Martin : December 15, 2009 5:53 pm : 2009 Fall Exploring CS

This text is remixed from http://wiki.roboteducation.org/CS110:Lab04.  Errors are my own.

Your robot has sensors that senses different aspects of its environment. The image below shows two types of sensors that your robot has – proximity and light sensors.  Notice that they’re on the opposite side of the robot as the camera so you will have to drive backward to use them!

ScribblerSensorDiag

The following is a list of external stimuli that the robot can sense and a description of how the robot senses them.

  • Light: There are three light sensors on your robot. These are located in the three holes on the front of your robot. These sensors can detect the levels of brightness (or darkness). Your robot can use these sensors to detect variations in ambient light in a room.
  • Proximity: At the front of the robot you will see two tiny lamps on each side of the robot. These are IR emitters. If the light that is emitted by these sensors get reflected by the presence of an obstacle, then the light will bounce back towards the robot and is captured by the IR sensor that is present in the tiny notch in the middle of the two IR emmiters (see figure above).
  • Line: If you look at the front portion of the Scribbler’s chassis (away from the third wheel), you will notice two pairs of tiny holes. These are also IR emitters and receivers and can be used to detect lines on the floor.

Once you are familiar with your robot’s sensors, you can use them to create interesting creature-like behaviors for your Scribbler.

Enter the following command in the Python Shell:

>>> senses()

Scribbler Sensor Values:

  • Light: The values being reported by the three light sensors are: 135 (left), 3716 (center), and 75 (right). In general, the lower the values, the brighter the light being sensed. This snapshot was taken when the center light sensor was covered by a finger.
  • Line: In the presence of a line under the Scribbler (the line has to be aligned with the length of the robot) the Scribbler can detect a bright edge against a dark edge (that forms a line). The display shows the values of left and right sensors (both are 1). If the right sensor is on a dark area of an edge or a line and the left sensor is on a lighter area or edge, the sensor values would be (left=0, right=1). If the edge is reversed, the values would be (left=1, right=0).
  • IR: The IR values displayed are also left and right (in the same orientation as the light). Their values will be either 1 or 0. If there is an obstacle detected, the value will be 0. It is 1 otherwise.
  • Stall: The stall sensor detects that the robot is not moving even though the motors are. That is, it is stuck somewhere. Its values can be 0 or 1, 0 implies it is not stalled and 1 implies it is.

Unfortunately, some of the sensors are pretty flaky.  Try to get the line sensor to get different values for left and right, for example.  It doesn’t really happen, so it’s not very useful!

Obtaining Sensory Information

In addition to using the senses operation, you can use various functions in the Myro library to obtain these sensor values. These are listed below:

Light Sensors

  • getLight(<POSITION>): This returns the current value in the <POSITION> light sensor. Your Scribbler has three light sensors (see picture above). <POSITION> can either be ‘left’, ‘center’, ‘right’ or one of the numbers 0, 1, 2. The positions 0, 1, and 2 correspond to the left, center, and right sensors. For example, keep your robot in the same position and try the following:
>>> getLight('left')
>>> getLight(0)
>>> getLight('center')
>>> getLight(1)
>>> getLight('right')
>>> getLight(2)

Proximity Sensors

  • getIR(<POSITION>): This returns the values of the IR sensors. <POSITION> can be 0 or ‘left’ and 1 or ‘right’. Try the following:
>>> getIR('left')
>>> getIR('right')
>>> getIR(0)
>>> getIR(1)

Obstacle Sensor

obstacleSensorThe Fluke dongle has an additional set of obstacle sensors on it. These are
also IR sensors but behave very differently in terms of the kinds of values
they report. The following functions are available to obtain values of the
obstacle IR sensors:

  • getObstacle() Returns a list containing the two values of all IR sensors
  • getObstacle(<POSITION>) Returns the current value in the <POSITION> IR sensor. <POSITION> can either be one of ‘left’, ‘center’, or ‘right’ or one of the
    numbers 0, 1, or 2. The positions 0, 1, and 2 correspond to the left, center, and
    right sensors.  Try the following:

    >>> getObstacle()
    >>> getObstacle('center')
    >>> getObstacle(1)
    >>> getObstacle('right')
    >>> getObstacle(2)
    >>> getObstacle('left')
    >>> getObstacle(0)

Stall Sensor

  • getStall(): This returns the values of the internal stall sensors (propioceptors). Its value can be 0 (the robots is not stalled) or 1 (it is stalled and cannot continue to move). It gets set whenever the motors of the robot are trying to move but the robot is no longer moving. Try the following:
>>> getStall()

Line Sensors

  • getLine(<POSITION>): This returns the values of the line sensors. <POSITION> can be 0 or ‘left’ and 1 or ‘right’. Try the following:
>>> getLine(0)
>>> getLine('left')
>>> getLine('right)
>>> getLine(1)

Now that you are familiar with your robot’s sensing capabilities, you can use this knowledge to make different decisions.

Making Decisions

When I had you look at and modify the light sensing program, one of the first lines in the sensing loop was

if rightSensor > 2000:

The first line above uses a conditional expression: rightSensor > 2000. You should read it as if it were asking the question (or testing the condition):

Is the value returned by the right light sensor greater than 2000?

These questions are called conditional expressions and their answers are either a yes or a no. In Python, a yes is equivalent to the value True and a no to the value False. The operator > is a way of asking if the thing on its left (in this case, the value returned by the right light sensor) is greater than to the value on its right (in this case 2000).

Relational operations are used for comparisons. For example: less than (<), less than or equal to(<=), greater than (>), greater than or equal to (>=), equal to (==) and not equal to (!=). Try the following to a get a sense for how these conditional expressions can be used:

>>> 4 > 5
>>> 5 <= 30
>>> 1 != 1
>>> 4 != 6
>>> 67 > 2
>>> (3+4) >= (2-1)
>>> "old bag" != "new bag"

The if statement has the following structure:

if <CONDITION>:
   <do something>
   <do something>
   ...

That is, if the condition specified by <CONDITION> is True then whatever is specified in the body of the if statement is executed. If the condition is False, all the statements under the if command are skipped over.

You can create more complex conditional expressions using the logical operations (also called Boolean operations): and, or, and not. Try the following examples:

>>> (20 < 7) and (81 > 31)
>>> not ( (20 < 7) and (81 > 31) )
>>> (2 > 3) or (3 > 4)
>>> (1 > 7) or (3 > 2)

We can define the meaning of logical operators as follows:

  • <expression-1> and <expression-2>: Such an expression will result in a value True only if both <expression-1> and <expression-2> are True. In all other cases (i.e. if either one or both of <expression-1> and <expression-2> are False) it results in a False.
  • <expression-1> or <expression-2>: Such an expression will result in a value True if either <expression-1> or <expression-2> are True or if both are True. In all other cases (i.e. if both of <expression-1> and <expression-2> are False) it results in a False.
  • not <expression>: Such an expression will result in a value True if <expression> is False or False if <expression> is True). I.e., it flips or complements the value of expression.

Beyond Simple Decisions

You can combine if-statements with the else-statements to make two-way decisions as follows:

if <condition>:
   <do something>
else:
   <do something else>

That is, if the <condition> is true it will do the commands specified in <do something>. If, however, the <condition> is false, it will <do something else>. You can also extend the if-statement to help specify multiple options using the elif-statement as follows (notice the last else):

if <condition-1>:
   <command set 1>
elif <condition-2>:
   <command set 2>
elif <condition-3>:
   <command set 3>
   ...
   ...
else:
   <last command set>
Leave a response »

Tasks for December 14 and 15

Ms. Martin : December 13, 2009 4:22 pm : 2009 Fall Exploring CS

For the next couple of days, you will be working with Python functions, looping, random numbers and taking pictures.

Please make sure you have a comment at the top of your programs saying who is in your group.  Place all activities in a single file.  Feel free to play around and try things!  Just make sure all your group members get a turn at the keyboard and that you’re staying focused on Python.  Reading the news, playing games, etc, will severely lower your grade. There’s a lot to explore here.  If you’re bored, ask me for some Python tutorials, ask me how to use the other sensors, etc — the sky is the limit.

Activity 1: go function

Write a function named go that takes distance as a parameter and makes the robot go that many inches.  To do this, you will need to experiment with how much distance a robot covers over different amounts of time and write an equation to relate distance to time.  To do this, you may want to get a marker and have your robot draw lines that you can then measure with a ruler.

The call go(6) should make your robot go 6 inches, the call go(0) shouldn’t do anything and a call on go(1.5) should make your robot go 1.5 inches.

Activity 2: random movement

Write a function that makes your robot go forward a random number of inches between 1 and 6, then turns a random amount (range of your choice) and repeats.  Your function should take one parameter: how long the robot should repeat this for.  For example, the call rand_moves(10) should make your robot make random moves for 10 seconds.  Similarly, a call on rand_moves(15) should make your robot move randomly for 15 seconds.

Activity 3: pictures

Write a function that will take a picture, show it, wait 3 seconds, go forward 1 second.  Your function should take one parameter: the number of times to repeat this.  For example, a call on pictures(10) should make your robot take a picture, display it, wait 3 seconds, go forward 1 second and repeat the whole thing 10 times.

Activity 4: random pictures

Write a function that will make your robot go forward and turn randomly and then take a picture.  Once the picture is shown on the screen, the user should be asked whether the picture shows what they’re looking for.  Your robot should repeat this behavior until the user says that yes, they saw what they were looking for.  For example, if your robot is meant to be looking for a whiteboard eraser that’s a couple of feet away, you might have to say no to three or four pictures before the robot orients itself such that your camera takes a picture of the eraser.

This example will help — copy it and run it to see how it works:

def ask_question():
    ans = raw_input("Do you think robots are amazing? ")
    while(ans != "yes"):
        ans = raw_input("No seriously... robots are awesome, right?" )
    print "!!!"

Notice that this prompts the user over and over again until they agree that robots are amazing.  In other words, while the user’s answer isn’t yes, the value of the variable ans gets a new value from the user.  You will need to use this same idea to get the user to react to each picture the robot takes.

Activity 5: creep bot!

Combine your knowledge of the joyStick() command with taking pictures to have your robot repeatedly take pictures as you drive it around.  How well can you navigate without seeing your robot?

3 Comments »

Robot Python so far

Ms. Martin : December 13, 2009 3:55 pm : 2009 Fall Exploring CS

Movement

joyStick()
Pops up a window that allows you to move the robot using a mouse-driven joystick.

backward(SPEED, SECONDS)
Move backwards at SPEED (value in the range -1.0…1.0) for a time given in SECONDS, then stop.

forward(SPEED, TIME)
Move forward at SPEED (value in the range -1.0…1.0) for a time given in seconds, then stop.

stop()
Stops the robot.

turnLeft(SPEED, SECONDS)
Turn left at SPEED (value in the range -1.0..1.0) for a time given in seconds, then stops.

turnRight(SPEED, SECONDS)
Turn right at SPEED (value in the range -1.0..1.0) for a time given in seconds, then stops.

wait(TIME)
Pause for the given amount of TIME seconds. TIME can be a decimal number.

General Python

# Comment text
Any text preceded by a # character is ignored by Python.  This is really helpful for giving yourself and others who read your programs some background information.

def <FUNCTION NAME>(<PARAMETERS>):
    <SOMETHING>
    ...
    <SOMETHING>

Defines a new function named <FUNCTION NAME>. A function name should always begin with a letter and can be followed by any sequence of letters, numbers, or underscores (_), and not contain any spaces. Try to choose names that appropriately describe the function being defined.

print(TEXT)
Display TEXT on the prompt

raw_input(TEXT)
Reads text from the user.  Results must be saved in a variable to be used later as in:

name = raw_input("What is your name? ")
print "Hello", name

Repetition

for <variable> in <sequence>:
    <do something>
    <do something>
    ...

while timeRemaining(<seconds>):
    <do something>
    <do something>
    ...

These are different ways of doing repetition in Python. The first version will assign <variable> successive values in <sequence> and carry out the body once for each such value. The second version will carry out the body for <seconds> amount of time. timeRemaining is a Myro function.

Random

Whenever you want to use random numbers in your programs, you have to write the following at the top:

from random import *

random()
Pick a random value between 0.0 and 1.0

randint(MIN, MAX)
Pick a random whole number between MIN and MAX

Pictures

pic = takePicture()
show(pic)

The first line commands the robot to take a picture and save it in a variable called pic. The second line displays this picture on the screen.

grayPic = takePicture("gray")
show(grayPic)

This example is very similar to the previous but the picture is black and white.  Taking a black and white picture is less time-demanding.

Leave a response »

Introduction to Scribblers and Python

Ms. Martin : December 7, 2009 5:10 pm : 2009 Fall Exploring CS

Python is a modern, easy-to-use, full-featured programming language that we will be learning to use by programming scribbler robots.  These are simple little “tank” robots that have a number of sensors including a color camera, infrared sensors and light sensors.  Our computers will connect to them using bluetooth.

scribbler

In order to start using your robot, you have to make sure that your bluetooth dongle is connected to the computer with the matching number in the upper right corner of the screen.  You also need to make sure the numbers on the robot, green board and dongle match.

python for robotsOnce you are sure all numbers match, you will need to click on the desktop icon that says ‘Python for ROBOTS.’

Once IDLE loads up, type in these commands:

from myro import *
initialize("com3")

Your screen should look like the following:

commands

You should get a popup asking you to accept the bluetooth communication.  Click on it:

bluetooth

You should then be asked for a bluetooth passkey.  Type in 1234 as follows:

passkey

If your screen does not say “Hello, I’m ” and a robot name, you need to update the robot’s software!  Run the following command:

>>> upgrade(“scribbler”)

To personalize your robot, you can give it a name.  For example, to name a robot “SuperBot”

>>> setName(“SuperBot”)

You are now ready to send commands to your robot!  For today, I want us to make sure there are no technical hurdles and then experiment with some of the basic commands.  To start, try typing in joyStick() and use the mouse to direct your robot around the room.  How far can it get before it is out of range?  Make sure you’re doing this on the floor so your bot doesn’t fall off the table!!

Your robot can produce songs!  This is going to get pretty annoying, but it’s in the name of learning, right?  Each group is going to write a robot song.  The basic idea is that you will be using a beep command.  Try this:

>>> beep(1, 440)

You should have heard a tone play for 1 second at 440Hz.  Hz?  Remember frequency?  beep is a command that creates waves at specified frequencies.  It turns out that 440 is the frequency of an A.  Try creating a beep at a higher frequency:

>>> beep(1, 800)

It sounds higher-pitched, right?  The human ear can hear roughly between 20 Hz – 20 kHz.  Can you hear a beep(1, 20000)?  What about beep(1, 20)?

In order to create your song, you will create a new robot command!  For example, I will call mine mySong.  Here is what my code looks like:

song

  • Notice the red stuff at the top?  That’s a comment.  Python ignores it, but it’s helpful for lowly humans to know what’s going on!  Always put a comment with your names at the top of the file!
  • Notice also that all of the statements in the definition of mySong are indented.  That’s really important.
  • Notice the def keyword.  It’s used to define a new command which in Python is called a function.  Functions always have parentheses after them.

I encourage you to download robotsong.py (just click on the link at left or on the calendar) and play it yourself.  To play the song, go to ‘Run Module’ as follows:

runWhen you are ready to write your own robot song, go to ‘File > New Window’ and get a new program file.  Save it using a descriptive name of your choice and make sure it has .py at the end!  I highly recommend that you create a folder in your home directory called robot to keep all of your robot files together.

=====

If you get done early, experiment with the following commands:

forward(1, 1)

What do the two numbers in the parentheses seem to represent?

print "Hello"

Can you print numbers?

name = raw_input("What is your name?")
print "Hi", name

Think back to your Scratch experience.  What do you think name is?

Leave a response »

Guest Speaker: Stuart Reges from the University of Washington

Ms. Martin : September 25, 2009 4:18 pm : 2009 AP CS A, 2009 Fall Creative Computing 1, 2009 Fall Exploring CS

Stuart Reges is a lecturer at the University of Washington who has written an excellent Java textbook, teaches really great courses and has played a large role in inspiring me to teach.  Stuart’s talk today touched on a number of intriguing topics he explored over the summer, some with direct ties to computer science and others with less obvious ones.  The goal was to give you an opportunity to come into contact with some fascinating, deep ideas you might not otherwise encounter.

Stuart started by showing us examples of fractals or infinitely repeating patterns.  He talked about how these are generated algorithmically, generally by writing a computer program, but that the same self-similarity pops up in parts of real life.  For example, dirt close up looks very similar to a canyon from far away.  Given this principle, animators tend to use fractal patterns to generate realistic looking landscapes. 

He then showed us some data that surprisingly enough exhibited fractal characteristics.  It turns out that when looking at county population data, about 30% of the populations start with a digit of 1, 17% with a digit of 2 and so on with decreasing frequencies.  That stays true if the populations are doubled!  That self-similarity can be described as fractal and the phenomenon relates to Benford’s Law.   Stuart was able to explore this phenomenon and confirm it by writing short computer programs to sift through the data.

We then learned about meta which is a concept many computer scientists are fascinated by.  We realized through some examples that our daily life includes an incredible amount of meta-information.  That’s a big part of why computers are so bad at acting human — they aren’t able to keep track of all the background information.

Finally, Stuart showed us a nifty algebraic card trick which he says convinced him to study math in college!

Leave a response »

Guest speaker: Mike Dussault from Valve

Ms. Martin : September 18, 2009 3:00 pm : 2009 Fall Exploring CS

We were honored to get a visit from Mike Dussault, a game programmer at Valve Software.  Mike talked about the game development process as well as how he and others he knows became good at what they do.  Like many of you, I’m not a gamer, but I learned a lot of interesting things about the creative and business processes of building software as well as some cool specifics about 3D animation.

Mike talked to us about his path to becoming a game programmer: he taught himself to program in high school, made a cool demo, presented it to a company and got hired.  He said that to get good at something, the best thing to do is to take on a project that seems impossible since it takes 10 000 hours of practice to expertise.

Mike also told a couple of interesting paths other people took.  The guy who designed Gollum’s head in Lord of the Rings started out coloring in comic reels and worked his way up by always taking on bigger challenges.  The game Portal was created from a demo some DigiPen students had put together.  To become great, Mike says, you have to be willing to put yourself out there and persist.

We learned about the game development process followed by Valve.  There, everyone in the company is free to give ideas or show demos that could become games.  The company decides which games to create in a somewhat democratic way but the CEO and founder always has the final word.  After teams have worked months on a game script, he may ask for a significant change that enhances the game.  Once a game has been selected and a preliminary script approved, artists work on storyboards and concept art as programmers start putting the action together.  Teams that work together on a game are composed of artists, designers, marketing and programmers.

One thing that struck me is how long the games Mike talked about took to develop.  Half-Life 2 was 4 years in the making and he mentioned another game, Duke Nukem Forever, that was 10 years in the making but was eventually cut because it wasn’t relevant anymore.

Hopefully, you were all inspired by Mike’s path and got some good ideas for our upcoming project!

1 Comment »

Sprite interactions

Ms. Martin : September 16, 2009 7:48 pm : 2009 Fall Exploring CS

I spent about 15 minutes at the start of the period demonstrating some of Scratch’s interactive commands.  I showed using random numbers, changing backgrounds, reacting to clicks and key presses, conditionals, operands, the color touching sensor, broadcasting and copying scripts.  I then asked everyone to build me a racing game or some other program in which sprites were competing.  Everyone came up with great ways to practice the new constructs!

I forgot to give period 1 my survey but period 2 filled it out before getting to work.

Leave a response »
« Page 1, 2 »