Yan Tran
2/5/2004
91.548 Lab1: The Handy Cricket

1. For the first experiment, a motor was attached to the "a" motor interface and a sensor was attached to the "a" sensor port. To activate the motor, the following code found in the programming reference was downloaded to the cricket and run:

to flippy
repeat 10 [a, onfor 10]
end

The code causes the "a" motor to flip back and forth ten times.

To test the "a" sensor, light and touch sensors were attached and the following code was used to report values back to the Cricket Logo software:

to foo
loop [ send sensora ]
end

By covering-up or exposing light sensors or moving touch sensors, different values were relayed to the Cricket Logo screen.

2. The second experiment called for making one cricket send an infrared signal to another cricket which reacts in some way. The following code was downloaded to the first cricket:

to sender
send random % 3
wait 5
sender
end

The following code was downloaded to the second cricket:

to receiver
waituntil [newir?]
if ir = 0 [a, onfor 4]
if ir = 1 [beep beep]
if ir = 2 [beep a, onfor 4]
receiver
end

Both crickets were then activated and their IR interfaces were pointed at each other. As a result, the second cricket would turn on its motor, beep, or beep and turn on its motor based on the value that it received from the first cricket. This would allow an observer to see figure out which value was received. This would continue until either cricket was deactivated.

3. Experiment 3 called for passing a software token between crickets so that the cricket with the software token exhibited a behavior. Two crickets were used for this experiment. The first cricket had the following code downloaded to it:

to first
send 25
waituntil [newir?]
if ir = 25 [beep beep beep beep]
first
end

The second cricket had this code:

to second
waituntil [newir?]
if ir = 25 [a, onfor 20]
send 25
second
end

The second cricket was activated so it would wait for a signal from the first cricket. The first cricket was then activated. It sent the number 25 to the second cricket and waited for a reply. The second cricket received the 25 and then turned on its motor for an interval and then sent 25 back to the first cricket. The first cricket broke out of it's waiting loop and then beeps 4 times. Both crickets then loop back to the begin of their respective procedures.

4. For the fourth experiment, assistance was provided by Joseph Giardina. The problem called for devising an experiment to detemine if the cricket used a 0 or 1 based index for arrays. According to the cricket programming reference, global arrays are stored at the beginning of memory. That means that the first element of an array should start at byte address 0 of the array. Numerical arrays are two bytes in size. This means that the first element should also occupy byte address 1. Cricket's programming language allows for setting the values of individual bytes. Setting the value of either byte 0 or byte 1 should also set the value of the first value of the first declared array. Thus, setting byte 0 to 1 and byte 1 to 0 means that the first element of the array is set to 256. Setting byte 0 to 0 and byte 1 to 1 means that the first element of the array has the value of 1. Setting both bytes to 1 will set the value of the first array element to 257. If arrays have 0-based indices, then doing an "aget" on element 0 should retreive the values at addresses 0 and 1 as a 2 byte integer. The following code tests hypothesis:

array [ bar 2 ]
to foo
db 0 1
db 1 0
db 2 0
db 3 0
send aget bar 0
end

The preceding code sets the first 4 byte addresses in memory to 1,0,0,0 respectively and then retrieves the value at index value 0 of the array bar. The result of running this code displayed 256.

The code was then altered to the following:

to foo
db 0 0
db 1 1
db 2 0
db 3 0
send aget bar 0
end

The preceding code sets the first 4 byte addresses in memory to 0,1,0,0 respectively. The result of running this code displayed 1.

When changing either of the two preceding procedures to retrieve bar's value at index 1 with "send aget bar 1" the result was 0.

From this it can be concluded that the cricket uses 0-based indexing for arrays.

5. The fifth problem called for creating a visualization of values retrieved from the serial port when having a cricket interface with another device through IR. A linux program that displays a room was created that has wall lights that change color and intensity based on values retrieved from the serial port. Code for accessing the serial port was adapted from Andrew Oswald's work, downloadable at http://www.cs.uml.edu/~fredm/courses/91.548-spr03/student/woswald/serial/handin.tgz. The rest of the code was taken from previous course work for Graphics I. The full source is downloadable at http://www.cs.uml.edu/~fredm/courses/91.548/student/ytran/lab1/room.cpp.