Page 237 - The Ultimate Palm Robot
P. 237
Color profile: Generic CMYK printer profile
Composite Default screen
Bots / The Ultimate Palm Robot/ Mukhar & Johnson / 222880-6 / Chapter 8
220 The Ultimate Palm Robot
aGPReflexes.tea (which we will need to #include into the source file). The con-
stants for the timers are aGP_RFX_TIMER_1 and aGP_RFX_TIMER_2.
Finally, each reflex vector will contain the command ID numbers of the com-
mands we want executed. Here is the complete reflex vector for timer 1:
vector[aGP_RFX_TIMER_1] {
mSRV1REV, mSRV2FOR, mSRV1REV, mSRV2FOR, mTIM2
}
Each vector contains a list of one or more message indexes separated by
commas. The message given by the index is executed when the reflex vector is
started. In this case, the messages are given by the symbolic constants for the
indices 1, 2, and 5. When timer 1 completes, the vector will cause servo 1 to ro-
tate in reverse, servo 2 to rotate forward, and then it will set timer 2. The vector
for timer 2 is here:
vector[aGP_RFX_TIMER_2] {
mSRV1FOR, mSRV2REV, mSRV1FOR, mSRV2REV, mTIM1
}
When timer 2 completes, the vector will cause servo 1 to rotate forward,
servo 2 to rotate in reverse, and then it will set timer 1. The reflexes will con-
tinue to cycle until you interrupt the program. You may be wondering why
each reflex vector repeats the commands for the servos twice. The simple an-
swer is that commanding the servos once doesn’t work, and commanding
them twice does work.
Here’s the final program. The source code for reflexes is stored in LEAF
files. We’ve named this code to_fro.leaf. If you don’t want to type this code,
you can find it on the CD-ROM in the \Other Applications\ToFro directory.
/* file: to_fro.leaf */
#include <aCmd.tea>
#include <aGPReflexes.tea>
/* assume the BrainStem has address 2 */
#define MODULE 2
/* message ids */
P:\010Comp\Bots\880-6\ch08.vp
Monday, May 12, 2003 1:16:47 PM