Cricket Handy Cricket Kyeongseo Hwang Mike Nicholas Ver

  • Slides: 20
Download presentation
Cricket (Handy Cricket) Kyeongseo Hwang (Mike) Nicholas Ver Hoeve

Cricket (Handy Cricket) Kyeongseo Hwang (Mike) Nicholas Ver Hoeve

Agenda n n About Cricket (HW) History of Logo (Built in interpreter) Intro to

Agenda n n About Cricket (HW) History of Logo (Built in interpreter) Intro to Cricket Logo Demo

About Cricket LIGHT SENSOR TOUCH SENSOR MAG. REED SWITCH IR SENSOR DC MOTOR BREAK

About Cricket LIGHT SENSOR TOUCH SENSOR MAG. REED SWITCH IR SENSOR DC MOTOR BREAK BEAM SENSOR

History of Logo n n Logo: Developed in BBN (a Cambridge University research firm),

History of Logo n n Logo: Developed in BBN (a Cambridge University research firm), in 1966 n By Seymour Papert, Wally Feurzeig n Modeled after LISP n Now in multiple dialects; Exper. Logo, ARLogo, MIT Star. Logo, Net. Logo, etc. Cricket Logo developed in MIT by Brian Silverman with Fred Martin beginning in 1995

Intro to Cricket Logo n n n n Procedure definition with inputs and return

Intro to Cricket Logo n n n n Procedure definition with inputs and return values Global variables and local procedure inputs Control structures: if, repeat, and loop 16 -bit number system: addition, subtraction, multiplication, division, remainder, comparison, bitwise operations, random function Motor and sensor primitives Timing functions and tone-playing functions Data recording and playback primitives IR Communications primitives

Intro to Cricket Logo

Intro to Cricket Logo

Motor Command n n n n n a, b, ab, on off onfor #

Motor Command n n n n n a, b, ab, on off onfor # thisway/ thatway rd setpower # Motor A Motor B Motor A and B Selected motor On Selected motor Off Selected motor will turn on for #/10 secs. Sets direction Reverses the direction set power level

Sensor Command n n switcha n return 1 if switched plugged into sensor A

Sensor Command n n switcha n return 1 if switched plugged into sensor A is pressed switchb n return 1 if switched plugged into sensor A is pressed sensora n Report the value of sensor A 0~255 sensorb n Report the value of sensor B 0~255

Timing and tone-playing n Timing n n n ab, on wait 20 off ab,

Timing and tone-playing n Timing n n n ab, on wait 20 off ab, onfor 20 wait # timer resett Tone-playing n n beep note 110 30 www. handyboard. com/cricket/program

Control Structures n n n n repeat times [body] loop [body] if condition [body]

Control Structures n n n n repeat times [body] loop [body] if condition [body] ifelse condition [body-1] [body-2] waituntil [condition] stop(!) output returning_value

Numbers n 16 bit number system n n All arithmetic operators separated by a

Numbers n 16 bit number system n n All arithmetic operators separated by a space n n -32768 ~ +32767 3+4 Normal expression precedence rules are not used, evaluated left to right n 3+5*7=? n (3 + (4 * 5)) = ?

Number Operator (cont) n n n + * / % < n Infix Infix

Number Operator (cont) n n n + * / % < n Infix Infix addition subtraction multiplication division modulus (remainder after integer division). LESS-THAN test. Results in 1 if left-hand value is less than right-hand value; 0 otherwise.

Number Operator (cont) n n > Infix GREATER-THAN test. Results in 1 if left-hand

Number Operator (cont) n n > Infix GREATER-THAN test. Results in 1 if left-hand value is greater-than right-hand value; 0 otherwise. = Infix equality test. n n n Results in 1 if left-hand value is equal to right-hand value; 0 otherwise. and Infix AND operation (bitwise). or Infix OR operation (bitwise). xor Infix exclusive-OR operation (bitwise). not prefix NOT operation (logical inversion, not bitwise). random Reports pseudo-random number from 0 to 32767. n Use the modulus operator to reduce the range; e. g. , (random % 100) yields a number from 0 to 99.

Procedure Definition with input to flash 1 repeat 10 [a, onfor 5 wait 5]

Procedure Definition with input to flash 1 repeat 10 [a, onfor 5 wait 5] end to flash 2 : n repeat : n [a, onfor 5 wait 5] end global [temp] to detect settemp sensora if temp < 30 [output 1] if temp < 50 [output 2] output 3 end

Variables n n n Global variable n global [variable-list] e. g. global [cat dog]

Variables n n n Global variable n global [variable-list] e. g. global [cat dog] n Stored in RAM -> data recording and playback functions n Integer only Global-setting primitive n setcar, setdog e. g. setcat 3 setcat + 1 Global Array n array [clicks 10 clacks 15] n Array indices start at 0 n aget name index n aset name index n No buffer-overrun checking n Stored consecutively in memory n stored in the Cricket's non-volatile memory

Data Recording and Playback to take-data resetdp repeat 2500 [record sensora wait 10] end

Data Recording and Playback to take-data resetdp repeat 2500 [record sensora wait 10] end n n n resetdp position erase # record value Recall

Recursion to fact : n if : n = 1 [output 1] output n

Recursion to fact : n if : n = 1 [output 1] output n * fact : n – 1 end -> repeat fact 3 [beep wait 1] Normal Recursion has uncertain max depth, can be as low as 5 n Supports Tail Recursion converting the recursive call into a goto statement to beep-forever beep wait 1 beep-forever end n

Multi-Tasking n n supports a limited form of multi-tasking One “background task” n n

Multi-Tasking n n supports a limited form of multi-tasking One “background task” n n repeatedly checks a condition When true it interrupts and processes when [switcha] [beep] loop [a, onfor 5 rd] n n n only one background task operating at any given time. If a when statement is executed after the background task has already been started, the subsequent when task supercedes the earlier one To stop the background task from operating, use the primitive “whenoff”.

Samples n Files at www. cs. rit. edu/~kxh 7583/PLC/ n Demo the multi-taking n

Samples n Files at www. cs. rit. edu/~kxh 7583/PLC/ n Demo the multi-taking n n IR communication between crickets Background Operation

Reference n n www. handyboard. com/cricket http: //gleasonresearch. com/ http: //lcs. www. media. mit.

Reference n n www. handyboard. com/cricket http: //gleasonresearch. com/ http: //lcs. www. media. mit. edu/people/fr edm/projects/cricket/redlogo. html http: //www. papert. org/ http: //www. mathsnet. net/logo/turtlelog o/