Page 236 - The Ultimate Palm Robot
P. 236
Color profile: Generic CMYK printer profile
Composite Default screen
Bots /The Ultimate Palm Robot/ Mukhar & Johnson / 222880-6 / Chapter 8
Chapter 8 Taking Control of the BrainStem Robot 219
as you’ll shortly see, we’ll need two of them. The command for the timer is
cmdTMR_SET. It has two parameters. The first is the timer number; there are
24 timers that can be used. The second parameter is the number of 0.1 millisec-
onds to wait. Here are the message blocks that set the timers:
/* set timer 1 for 2 seconds */
message[mTIM1] {
MODULE, cmdTMR_SET, 1, 20000
}
/* set timer 2 for 2 seconds */
message[mTIM2] {
MODULE, cmdTMR_SET, 2, 20000
}
Now we need to construct the reflex vectors. Here is the general form of a
reflex vector:
vector[index] {
command index, command index, ...
}
Areflex vector consists of the keyword vector followed by an index. Within
the vector is a comma-separated list of command indices. When the reflex is
activated, the commands referenced by the indices will be executed.
In contrast to command indices that can be arbitrary, we sometimes need to
use specific indices for reflexes. The BrainStem has a number of predefined
reflex indexes. The BrainStem has 24 built-in timers. When a timer counts
down, the vector at a specific index is activated. The index 20 happens to
correspond to timer 1. (There are 24 timers, so timers 1 through 24 correspond
to reflex vectors 20 to 43.) When timer 1 completes, reflex vector 20 is activated.
When timer 2 completes, reflex vector 21 is activated.
What we will do is set one of the timers. When that timer counts down, it
will cause its associated reflex vector to execute its commands. These com-
mands will move the robot and set a second timer. When that timer counts
down, its associated reflex vector will execute its commands to move the robot
in the opposite direction, and reset the first timer. However, instead of using
20 or 21 as reflex vector indices, we’ll use the constants already defined in
P:\010Comp\Bots\880-6\ch08.vp
Monday, May 12, 2003 1:16:47 PM