CS 1020 - Winter 2013 - Class 2

  • Quiz 1

  • Current Sciborgs
       - Time how long to run basic course
       - Talk about design choices:
          - gear ratios chosen
          - issues/problems
          - other design improvements people found

  • Handy Logo
       - How many people of heard of (or used) Logo before?
          - Logo is a programming language created in 1967 (http://en.wikipedia.org/wiki/Logo_(programming_language))
          - Designed for educational use
          - Most commonly known feature is the turtle which takes instructions and draws on the screen
       - Logo variations
          - many variations of Logo since then
          - Matt Dickerson teaches CS190 in NetLogo and uses it for his research for creating biological simulations
       - Handy Logo is a Logo variant designed/adapted specifically for the Handy Boards

  • Handy Logo interpreter
       - We can write programs and download them to the Handy boards like you did on Monday
       - However, we can also just execute commands one at a time using the same HandyLogo.jar application
          - make sure that your Handy board is connected otherwise it won't work!

       - Some simple commands:
          - beep
             - makes a beep
          - beep beep
             - makes two beeps
             - in Logo, you can chain multiple commands together in a sequence
          - beep beep beep

          - wait 5
             - for 5/10ths of a second, which by itself is pretty boring

          - wait 10 beep beep wait 10 beep
             - waits for a second and beeps twice, waits for another second and beeps once
             - again, notice that we can chain any single command together with any other command

          - print "banana
             - displays 'banana' on the LCD screen
             - only works for single words
             - only include starting quotes (but not ending quotes)
          - print [banana cream pie]
             - displays 'banana cream pie' on the LCD screen
          - print 5
             - displays '5' on the LCD screen

          - print 3 + 4
             - displays '7' on the LCD screen

  • The motors
       - referred to as a - d from top to bottom (or left to right)
       - you "select" a motor with the motor letter followed by a comma
          - a,
          - b,
       - you can select more than one motor if you want
          - ab,
          - abcd,
       - many commands to do for a motor:
          - on
             - turn it on
          - off
             - turn it off
          - toggle
             - swap on/off
          - onfor <tenths>
             - onfor 10
                - turn motor on for 10/10ths = 1 second
       - other example commands
          - a, on thisway
             - turn a on forward
          - b, on thatway
             - turn a on backwards
          - a, rd
             - reverse direction

  • procedures
       - what do you think of when I say "procedure"?
          - a procedure is a set of instructions/commands
       - procedures allow us to execute multiple commands by just calling a single command
       - we define a new procedure as follows:

          to <procedure_name>

          - "to" and "end" are keywords and will always be there indicating the beginning and end
          - <procedure_name> is any name you want that will define what the new procedure is called
          - <command> are the statements that will execute
       - for example

          to double-beep
             wait 10

       - we can write this in a file and then "load" this file like you've been loading our other programs
       - we can now execute this command just like any of the other commands
          - double-beep
             - beeps twice :)
  • look at simple_procedures.txt code
       - 6 different functions
       - what do they do?
       - what is that "stuff" at the top?
          - comments
             - comments are a way to communicate to other people (i.e. not code) what's going on
             - they're not run when the program runs
             - use them!
             - anything following a semi-colon is ignored either at the beginning of a line or later on

  • look at making_decisions.txt code
       - what do these functions do?
       - *how* do these functions work/what can you tell me?

  • sensors
       - we can ask questions about the different sensors
       - digital sensors
          - ask on/off, yes/no questions referenced by their number
             - switch 7
                - is switch 7 on?
             - switch 9
                - is switch 9 on?
          - the number corresponds to the number on the board
       - analog sensors
          - check ranges greater than (>) and less than (<)
             - (sensor 0) < 100
                - is sensor 0 less than 100?
             - (sensor 1) > 30
                - is sensor 1 greater than 30?

  • waituntil
       - stop executing code *until* that action happens
       - action is put inside square braces []
       - if it's a sensor, don't forget to put it in parenthesis as well!

  • boolean operators
       - and
          - are both of these conditions true
       - or
          - are one of these conditions true

  • if/ifelse
       - if a condition is true, execute some statements
          - the condition is put in parenthesis and
          - the statements are enclosed in square braces
          - if (switch 7)[
             wait 10
       - ifelse
          - adds an additional set of statements to be execute if the statement is NOT true
          - enclosed in a second set of square braces

  • menus
       - we can define up to 7 menu items that we can scroll through by using the "menu" command
       - these allow you to execute procedures using the "start" button and the scroll wheel
  • look at the top of menus_and_loops.txt code
       - we've defined three menu items
       - when we "load" the code onto the Handy board, we see these three procedures define and can run any of them
       - what do the first two procedures do?

  • look at the last function of menus_and_loops.txt code
       - what do you think it does?
          - it has a few new things
       - loop
          - keep executing the enclosed statements over, and over, and over, and over, and over, ...
       - variables
          - variables allow us to save values over time and in between procedure calls
          - defining a variable:
             - global [laston]
                - defines a new variable called "laston" that we can use later on
          - setting a variable: prepend with "set"
             - setlaston 1
                - set the variable "laston" to have the value 1
          - using the variable value
             - like sensors we can use <, > and also = to ask questions about a variable

  • now that we know what we're doing, let's look at some of the procedures you used last class

  • look at simple code (from day1)
       - a few things we'll talk about more next time...
       - one thing to note, we can redefine motors to make our code more usable
          to left-wheel

          - Use these! They'll make your code more readable

       - also rewritten questions about front and back bumper
          - we'll talk more about why these work next time...
          - for now, use them :)
       - playing a note
          - note frequency time

  • look at sciborg code (from day1)