Page 235 - The Ultimate Palm Robot
P. 235
Color profile: Generic CMYK printer profile
Composite Default screen
Bots / The Ultimate Palm Robot/ Mukhar & Johnson / 222880-6 / Chapter 8
218 The Ultimate Palm Robot
message[mSRV1REV] {
MODULE, cmdSRV_REL, 1, 127, 0
}
/* servo 2 forward */
message[mSRV2FOR] {
MODULE, cmdSRV_REL, 2, 127, 1
}
/* servo 2 reverse */
message[mSRV2REV] {
MODULE, cmdSRV_REL, 2, 127, 0
}
Let’s look at one of those messages above in a little more detail. As we
mentioned earlier, each message block has an index. Here’s the first line of
the first message:
message[mSRV1FOR] {
This defines the start of a block with index 0, because we defined
mSRV1FOR to be 0. Any reflex vector that contains this index will execute this
message when it is activated. Next in the block is this line:
MODULE, cmdSRV_REL, 1, 127, 1
The first parameter is the symbolic constant MODULE, which we defined to
have the value 2. This is the module ID of the BrainStem. Next in the list is the
BrainStem command cmdSRV_REL. This is again a symbolic constant, but un-
like the indices we defined, the cmdSRV_REL macro is defined in the file
aCMD.tea. The command cmdSRV_REL takes three arguments: 1, 127, and 1.
The first value (1) is the servo number, so this command is for servo 1. The next
value (127) is the relative position that the servo should rotate to. This parameter
isasignedbyte,soyouarelimitedtovaluesfrom–128to127.Thefinalparameter
(1) is the direction that the servo should rotate. For this command, 1 is forward, 0
is reverse. Note that you must use commas to separate each parameter in the
commandmessage.Ifyouleaveoutanycommas,theprogramwillnotcompile.
Now, we’ll work on the timers. We’ll have the robot move in each direction
for two seconds before reversing direction. We need a two-second timer and,
P:\010Comp\Bots\880-6\ch08.vp
Monday, May 12, 2003 1:16:47 PM