MIT Yellow Brick Logo Documentation

Pre-release version 99-03-03

Fred Martin <fredm@media.mit.edu>
Brian Silverman <bss@media.mit.edu>

 

How to Boot the RCX with the MIT Firmware.

The MIT Yellow Brick Logo system uses a special firmware program that replaces the LEGO firmware. Before you can use Yellow Brick Logo, you must install the MIT firmware.

Depending on your platform (Windows or Macintosh), see the following instructions:

Windows: Double-click on the Microworlds project named Download, and follow the instructions on the screen.

Macintosh: Double-click on the MIT RCX Downloader application, and follow the instructions on the screen.

If you wish to use your RCX with the LEGO software again, you must drain the power so that the MIT firmware is erased and the LEGO software can reload the LEGO firmware. The best way to do this is to remove the batteries (yanking just one will do) while the RCX is turned on. This will cause the RCX to lose its RAM contents in just a few seconds. If you remove the batteries when the RCX is off, it can take 5 to 10 minutes before the RAM contents evaporate.

 

Running Yellow Brick Logo.

Make sure Microworlds version 2.03 is installed on your computer, then double-click the file "Yellow Brick Logo." You should see the following screen:

That's it for our introduction; I hope it's enough to get started. Following is a list of all the Logo primitives, control structures, and other computational facilities that Yellow Brick Logo supports.

 

List of Logo Commands.

Yellow Brick Logo understands the following Logo commands:

Motors.

a,
talk to motor A.
b,
talk to motor B.
c,
talk to motor C.
ab,
talk to motors A and B.
bc,
talk to motors B and C.
ac,
talk to motors A and C.
abc,
talk to motors A, B, and C.
on
turn motor on.
onfor tenths
turn motor on for tenths tenths-of-seconds.
off
turn motor off sharply.
coast
turn motor off, allowing it to coast to a stop.
rd
reverse motor direction.
thisway
set motor direction to right-arrow direction.
thatway
set motor direction to left-arrow direction.
setpower level
set motor power to level. 1= slow, 8= full power.

 

Sensors.

The View button may be used to cycle through a display of the three sensor values and the numeric display. A caret indicates which sensor port is being displayed. While viewing sensor values, holding down the Prgm button will display counter value rather than direct sensor reading (in other words, if you are using a counter on a given sensor, hold down the Prgm button to see the counter value.)

switch1
reports value of switch in sensor 1, as true "1" or false "0".
switch2
reports value of switch in sensor 2.
switch3
reports value of switch in sensor 3.
 
sensor1
reports value of sensor1, from 0 to 1023.
sensor2
reports value of sensor2.
sensor3
reports value of sensor3.
 
counter1
reports rotational position of blue rotation sensor 1.
resetc1
resets rotation count to 0.
counter2
resetc2
prims. for counter on sensor port 2.
counter3
resetc3
prims. for counter on sensor port 3.
 
sensor1'
reports rate of change of sensor on port 1. high positive values mean that sensor value is rising quickly; large negative values mean that sensor value is falling quickly.
sensor2'
not implemented.
sensor3'
not implemented.

 

Control Structures.

repeat num [...]
repeat [...] num times.
 
loop [...]
infinite loop.
 
if test [...]
if expression test is true, do [...]
 
ifelse test [.a.][.b.]
if expression test is true, do [.a.], otherwise, do [.b.]
 
waituntil [test]
loop waiting until expression test is true.
 
wait tenths
wait for tenths tenths-of-seconds.
 
stop
causes a procedure to exit immediately, returning to its caller.
 
output value
causes a procedure to exit immediately, returning value to its caller as the result.

 

Expressions/Numeric.

Make sure there is a space between all arithmetic operators. E.g, "if sensor1>500 [beep]" won't work, use "if sensor1 > 500 [beep]" instead.

Use parentheses to get expressions to parse the right way. E.g.:

if (sensor1 > 500) and (sensor2 > 500) [beep]

Numbers range from -32768 to +32767. "true" is any number but 0; "false" is zero.

+
addition
-
subtraction
*
multiplication
/
division
%
remainder of division. e.g., "10 % 7" is 3.
 
=
test for equality.

<

test for less-than. e.g., "3 < 6" is true.
>
test for greater-than.
 
and
true if two expressions are true. e.g., "(3 < 6) and (4 < 5)" is true.
or
true if either of two expressions is true.
not
true if expression is false, and vice-versa. e.g., "not 3 < 4" is false.
 
abs n
reports the absolute value of n.

 

Procedure Inputs, Global Variables, Local Variables, and Arrays.

Inputs to procedures are done using standard "dots" Logo syntax; e.g.:

to double :n
  output :n * 2
end
 

Global variables are defined using phrase "global [gname1 gname2 ...]" at beginning of procedures buffer. This creates reporter named "gname1" and modifier named "setgname1" for each global. For example:

global [foo]
 
to test
  setfoo 3
  print foo + 4
end
 

When running the test procedure, the number 7 is printed.

Yellow Brick Logo automatically defines n and m as user globals.

Local variables are defined using the let primitive, set using the make primitive, and accessed using the "dots" (colon) operator. The following demonstrates creating, accessing, and setting a local variable:

to local-test
  let [x 3]
  print :x wait 10
  make "x 4
  print :x
end

Arrays are declared using the keyword array at the beginning of the procedures buffer. For example,

array [foo 10 bar 20]

creates an array named foo consisting of 10 elements, and an array named bar consisting of 20 elements.

Array elements are set with the aset primitive, which takes three inputs: the name of the array, the index, and the value. E.g.:

aset foo 5 23

sets element 5 of array foo to the value 23.

Array elements are accessed with the aget primitive, which takes two inputs: the name of the array and the index. E.g.:

aget foo 5

retrieves element 5 of array foo.

Array indicies start at zero. Therefore an array of ten elements would use indicies 0 through 9. There is no error checking to verify that array operations are within the bounds of array declarations.

 

IR Communication.

Multiple RCX bricks can communicate with each other using infrared communications commands. Please note that RCX bricks running MIT Logo firmware cannot communicate with RCX bricks running LEGO firmware. RCX bricks running MIT firware can only communicate with other RCX's running MIT firmware.

The IR communications is byte-oriented. One brick sends a byte, and another brick receives it.

To send a byte, use the send value primitive. value should be a number in the range of 0 to 255.

To receive a byte, use the ir primitive. ir returns the last byte received.

To test if a new byte has been received, check the newir? primitive. This will return true the first time checked after a new IR byte has been received.

Here is an example. On one brick, run the following command to randomly send the number 1, 2, or 3 every second:

every 10 [send 1 + (random % 3)]

On the second brick, run the following program, which waits until an IR value is received, and then chooses one of three actions based on its value:

to irdemo
loop [
  waituntil [newir?]
  if ir = 1 [beep]
  if ir = 2 [a, onfor 5]
  if ir = 3 [b, onfor 5]
]
end

 

Multi-tasking.

Yellow Brick Logo supports up to 8 concurrent tasks. There are three kinds of tasks: a periodic task, which runs repeatedly at a fixed interval, a conditional task, which runs each time that its condition becomes true, and a background task, which runs continuously.

The periodic task is created with the every primitive. For example:

every 30 [beep]

will cause the RCX to start beeping, making a beep every 3 seconds.

The conditional task is created with the when primitive. For example:

when [switch1] [beep]

will launch a task that continually checks the state of switch 1. Each time the switch is pressed, the RCX will beep.

Note that the conditional task is edge-triggered. This means that it fires only once for each time that the condition becomes true. Thus, in the switch 1 example, the RCX will not keep beeping if the switch is held down. The when fires only once each time the switch goes from false to true.

The background task is started with the launch command. This is typically used in conjunction with loop to keep the background task running. For example, if it is desired to have an action repeatedly taken while a condition is true, build a loop and test for the condition using the if statement, and then get it going with launch:

launch [loop [
  if switch1 [beep]
]]

 

Miscellaneous.

timer
A free-running timer. Reports elapsed time in milliseconds.
resett
resets millisecond timer to zero.
 
print n
displays the value of n on the RCX screen. numbers above 9999 are displayed as 9999, and numbers less than -9999 are displayed as -9999.
 
beep
emits a short beep.
 
note pitch duration
plays a note at midi-step pitch for duration length of time. pitch must be in the range of 60 to 96 (inclusive); duration is specified in tenths-of-seconds.
 
pgrm
reports the state of the Prgm button (true or false). If the display is in View sensor mode, then Prgm button works as described earlier (allows viewing of counter values), and does not report true.
 
vbat
reports a number representing the battery voltage.
 
random
reports a randomly obtained number in the range of 0 to 32767. To obtain a random number in a smaller range, use the remainder operator; e.g.: (random % 100) yields a number from 0 to 99.

 

Some Example Programs.

The following program will repeatedly check light sensor 1. If it's too dark, motor A will be turned on. If it's light, motor B will be turned on:

to follow-line-edge
  loop [
    ifelse sensor1 < 600
      [a, on b, off]
      [a, off b, on]
  ]
end
 

The next example will turn motor A on. When touch sensor 1 is pressed, motor A will reverse for 2 seconds, and then go forward again. The whole time it's doing this, it will beep every 3 seconds, just for fun:

to back-and-forth
  a, on
  when [switch1] [rd wait 20 rd]
  every 30 [beep]
end
 

Note that the when and every commands each launch a process to do their work for them.

 

Downloading and Running Programs.

Click the Download button on the screen to download all procedures and the run-line code.

Press the green Run button on the RCX to run the run-line code.

While a Logo program is executing, an animated display of 5 dots will be shown on the RCX screen. Press the Run button to stop the program from running.

 

Power-saving.

When running MIT Logo, the RCX will automatically power off after ten minutes since you last interacted with it, even if it's running a Logo procedure.

The RCX may be put to sleep under program control using the sleep primitive.

In order to keep the RCX alive, run the resetpd (reset power down) primitive, at least once every ten minutes.

 

Serial Port.

On the Macintosh: Yellow Brick Logo defaults to using the modem port. To change it to use the printer port (make sure Appletalk is turned off in the Chooser, or that you're using Ethernet and not the printer port), go into the Gadgets menu and bring up the Microworlds Command Center, and then type into it printer-port.

On the PC: Yellow Brick Logo defaults to using COM1. To change it to use COM2, go into the Gadgets menu and bring up the Microworlds Command Center, and then type into it serial-port-alt.

 

Changes From Earlier Versions.

99-03-03.
Improved synchronization between Logo and the RCX, hopefully getting rid of spurious "Interface not connected" errors.
Fixed a (Mac-only) problem that prevented clicking into Run Button Line field.
 
99-01-21.
Fixed a bug with multitasking, allowing more than one process to work at a time.
Added note primitive.
Added resetpd primitive.
Changed IR commands to ir, newir?, and send.
Added local variables.
Added n and m as pre-defined globals.
 
98-12-28.
Added multitasking support: launch, every, and when primitives.
Added data collection primitives, random, and array functions.
Added vbat battery level primitive.
 
98-11-22.
Fixed power bug: when brick is turned off, it no longer drains batteries.
Added: encoder support, Prgm button functionality, auto-power-off, abs primitive, sensor1' concept.
 
98-09-21.
First distribution.

 

Known Problems and Limitations.