TWK 
---> --->
[Jump to Cover]
[Jump to Contents]
[Jump to Introduction]
[Jump to Concepts]
[Jump to Realization]
[Jump to Conclusion]
[Jump to Appendix]
 
<<  Cricket Hardware 
 
Options for System Integration  >> 

3.2.3 Programming Software

Besides using Cricket Logo, it is also possible to program Crickets with a graphical user interface. At the MIT Media Lab, a program called "Logo Blocks" was developed. It runs on Apple Macintosh computers and uses appealing puzzle-style elements which are connected to each other in order to visualize a program structure. At the CCE on the other hand, "GrafLogo" was created as a diploma thesis. Running on Windows 95 machines, this interface program basically follows ISO rules for flow diagrams. 
  
Both approaches – graphical user interfaces as well as Logo source code programming – have certain advantages and shortcomings. The following sections try to explain and illustrate the differences. 
 - Cricket Logo
This brief introduction to Cricket Logo (adapted from [6]) lists and explains the operators and constructs that are already supported by the first version of the Cricket ("Green Dot Cricket", which is being used at the CCE). Later versions still work with this code, their command resources are merely extended. 
Procedures:
Procedures are defined using Logo ‘to’ and ‘end’ syntax: 
to procedure_name 
  procedure_body 
end
Motors:
The Cricket can control two motors, which are named A and B. A bi-color LED indicates the state of each motor. 
  
Motor commands are used by first selecting the motor (using ‘a,’, ‘b,’, or ‘ab,’) and then telling it what to do (e.g., ‘on’, ‘off’, ‘rd’, etc.) 
 
a, Selects motor A to be controlled.
b, Selects motor B to be controlled.
ab, Selects both motors to be controlled simultaneously.
on Turns the selected motor(s) on.
off Turns the selected motor(s) off.
thisway  Sets the selected motor(s) to go the ‘thisway’ direction, which is defined as the way that makes the indicator LEDs light up green.
thatway  Sets the selected motor(s) to go the ‘thatway’ direction, which is defined as the way that makes the indicator LEDs light up red.
rd Reverses the direction of the selected Motors. Whichever way they were going, they will go the opposite way.
         
Timing and Sound:
The timing commands are useful to cause the Cricket to do something for a length of time. For example, one might say ‘ab, on wait 20 off’ to turn both motors on for two seconds. 
  
Please note that there are two different reference values for timing: 0.1 second units, used in ‘wait’, and 0.004 second units, used in ‘note’ and ‘timer’. 
  
wait amount  Delays for ‘amount’ of time, where ‘amount’ is given in 0.1 second units. E.g., ‘wait 10’ inserts a delay of one second.
beep  Plays a short beep.
note pitch dur  Plays a note of a specified pitch and duration. Increasing values of ‘pitch’ creates lower tones. The ‘dur’ value is specified in 4 millisecond units, so ‘250’ means one second.
timer  Reports value of free-running elapsed time device. Time units are reported in 4 millisecond counts.
resett  Resets elapsed time counter to zero.
 
Sensors: 
The Cricket can read two sensors, named A and B. 
  
sensora  Reports the value of sensor A, as a number from 0 to 255.
sensorb  Reports the value of sensor B, as a number from 0 to 255.
switcha  Reports true if a switch plugged into sensor A is pressed, and false if not.
switchb  Reports true if a switch plugged into sensor B is pressed, and false if not.
 
Program Control: 
Cricket Logo supports the following control structures: 
 
loop [body]  Repetitively executes the ‘body’ part indefinitely.
repeat n [body]  Executes the ‘body’ part ‘n’ times. ‘n’ may be a constant number or a calculated value.
if cond [body]  If ‘cond’ is true (i.e., not zero), executes the ‘body’ part.
ifelse cond [body-1] [body-2]  If ‘cond’ is true, executes the ‘body-1’ part; otherwise, executes the ‘body-2’ part.
waituntil [cond]  Loops repeatedly testing ‘cond’, continuing subsequent program execution after it becomes true. Note that ‘cond’ must be in square brackets (unlike in ‘if’ and ‘ifelse’).
stop  Terminates the execution of this procedure, returning control to the calling procedure.
output value  Terminates the execution of the procedure, reporting ‘value’ as the result.
 
 Numbers: 
Cricket Logo uses 8-bit numbers. All number are within 0 to 255. All arithmetic operators must be separated by a space on either side. E.g., the expression ’3+4’ is not valid! Use ‘3  +  4’ instead. 
  
+, -, *, /  Infix addition, subtraction, multiplication, division.
and, or  Infix bitwise AND, OR operations.
not  Prefix bitwise NOT operation.
random  Reports a pseudo-random number from 0 to 255.
 
Global Variables: 
Global variables are created using the ‘global [list]’ directive at the beginning of the procedures buffer. E.g., ‘global [hello, world]’ creates two globals, named ‘hello’ and ‘world’. Additionally, two global-setting primitives are created: ‘sethello’ and ‘setworld’. Thus, after the global directive is interpreted, one can say ‘sethello 3’ to set the value of ‘hello’ to 3, and ‘sethello hello + 1’ to increment the value of ‘hello’. 
Procedure Inputs and Outputs: 
Procedures can accept arguments using the colon syntax. E.g., 
to abc :times  
  ab,  
  repeat :times [on wait 20 rd]  
end 
creates a procedure named ‘abc’ that takes an input which is used as a counter. 
  
Procedures may return values using the ‘output’ primitive; e.g., 
to go  
  ab,  
  repeat times [on wait 10 rd]  
end  

to times  
  if sensora < 20 [output 1]  
  if sensora < 50 [output 2]  
  output 3  
end 

The ‘go’ procedure will execute 1, 2, or 3 times depending on the value of sensor A. 
IR Communication: 
Crickets can send infrared signals to each other using the ‘send’ primitive, and receive them using the ‘ir’ primitive. The ‘ir’ primitive reports the value sent by ‘send’ less a constant offset of 127; e.g., if one Cricket issues a ‘send 128’, another Cricket’s ‘ir’ primitive receives a 1. 
  
While a Cricket is not running a procedure, codes from 128 to 134 are interpreted to launch one of the seven command lines on the Cricket Logo screen. Household TV remotes may also be used to cause the Cricket to launch one of its seven command lines. Use a Sony remote, or a universal remote set to talk to a Sony TV, and use the keys numbered 1 through 7. 

 - Graphical User Interfaces 

Logo is a fairly simple programming language, compared to other procedural languages like Basic or Pascal, but it is still hard for kids to get started. Especially the fact that all arithmetic operators must be separated by a space on either side has proved to be a source of frustration for many kids. 
  
Although this kind of initial frustration may be necessary from an educational point of view, i.e., to understand that computers do not ‘think’ but just follow the programmer’s detailed instructions, both the MIT Media Lab and the CCE have decided to develop graphical user interfaces for Cricket Logo. 
  
Click to view full-size image Click to view full-size image
 
"Logo Blocks"   has been designed at the MIT Media Lab and runs on Apple Macintosh PowerPC computers with at least 32MB of RAM. It is an iconic version of Cricket Logo, allowing the user to design programs by dragging blocks (each containing a bit of Logo code) from a palette and assembling them into a "stack", after which they may be downloaded to the Cricket. On the Macintosh, this is done by connecting the "Interface Cricket" to the modem port. 
  
Impressive about Logo Blocks is its clearly arranged screen design. This is achieved by subdividing the palette options into the four groups called Action, Control, Sensor, and Procedure. Thus, not all blocks need to be shown at the same time, and the selection is provided dynamically depending on the selected group. Logo Blocks needs no lines to be drawn in order to connect the elements, the puzzle-style connectors already represent connections. 
  
At the CCE, however, no Macintosh computers are available, therefore the "GrafLogo" user interface has been designed for Windows 95 machines. It was completed earlier this year as a diploma thesis. The thesis documentation contains a profound description  of the GrafLogo program, so the following is only a brief introduction. 
  
The GrafLogo interface design is entirely in German language. As kids can only use English programs at the age of about 13, since they start learning English in the 5th grade, this approach was chosen in order to allow even younger kids to use the program. There is very little text on the screen, anyway. All elements and options are selected using the mouse. The user can literally put the keyboard aside. 
  
Even complex structures are created by mouse clicks, as context menus and property dialog boxes open up when you click the right mouse button, which is the usual procedure in Windows 95. In the dialogs, only the allowed choices are presented at a time, all others are grayed out. This avoids the input of invalid commands from the beginning. 
  
These are selected dialog boxes and a context menu from GrafLogo: 
  
 
On the screen, the needed elements are selected, arranged, moved, and given properties and values; then, they are linked in flowchart style. All elements and symbols are oriented at the ISO rules for control flow diagrams. 
  
Sensors and motors can be given real names, which has been requested by many kids during the beta testing – using aliases like "steering" and "rear_bumper" instead of the expressions "motor a" and "sensor a" leads to less confusion and helps to understand the program at a later time. 
  
GrafLogo’s screen design and the way it is used make the program intuitive and give kids the confidence that it is just as easy to work with as any Windows 95 program they know. By avoiding to confront younger kids with plain source code programming, you can keep them motivated and still give them a sense of achievement, as they can on their own ‘tell the Crickets what to do’. 
  
Internally, the GrafLogo software uses a quite complicated method of "potentials" to translate the object-oriented diagrams into plain Cricket Logo code, including loops and branches. This will not be discussed here, please refer to the GrafLogo documentation for further details. 
  
Once the Logo code is generated, it can be looked at before being transferred to the Cricket via the so-called Interface Cricket on the PC’s serial communications port. The possibility to see the code is optional, but it can be very interesting to show the kids the way to "real" programming. 
  
For a proficient programmer, neither "Logo Blocks" nor "GrafLogo" can be as efficient as the plain Cricket Logo source code. But in the CCE environment, where most kids do not have a lot of experience with programming languages, these graphical user interfaces are an interesting approach to realize simple applications for Crickets. 
  
The fact that the two programs are just front ends which translate visual elements into Logo code is very helpful when improvements to a Logo program are needed: kids can analyze and understand the generated code, then change it to fulfill their requirements. By doing so, they can optimize the code or add Logo functionality that is not supported by the graphical interface, e.g. calculating functions or procedures that can take and return parameter values. 
  
"Logo Blocks" and "GrafLogo" are easy to learn, and thus gives mentors and kids at Computer Clubhouses a visual environment, where they can quickly set up a program for a new Cricket application. "Cricket Logo" on the other hand is a powerful programming language supporting all functions a Cricket can provide. 
 
<<  Cricket Hardware 
Options for System Integration  >> 
 
(C) '98 counter