Page 221 - The Ultimate Palm Robot
P. 221
Color profile: Generic CMYK printer profile
Composite Default screen
Bots / The Ultimate Palm Robot/ Mukhar & Johnson / 222880-6 / Chapter 8
204 The Ultimate Palm Robot
The program we will look at is the one named chase.tea in the aUser directory.
Here is the complete source code for the program:
/* chase.tea */
/* BrainStem PPRK program */
/* Move toward sensor detection, otherwise spin */
/* Only moves in direction of one sensor */
#include <aCore.tea>
#include <aPPRK.tea>
#include <aA2D.tea>
#define SPEEDR 100
#define SPEEDL 100
#define DRANGE 175
void main()
{
int b;
int r1;
int r2;
int r3;
/* five second wait before starting */
aCore_Sleep(30000);
aCore_Sleep(20000);
while (1)
{
r1=aA2D_ReadInt(APPRK_IR1);
r2=aA2D_ReadInt(APPRK_IR2);
r3=aA2D_ReadInt(APPRK_IR3);
b=0;
if (r1>DRANGE) b = b | 1;
if (r2>DRANGE) b = b | 2;
if (r3>DRANGE) b = b | 4;
switch (b)
{
case 1:
aPPRK_Go(0,SPEEDL,-SPEEDL,0);
b=1;
P:\010Comp\Bots\880-6\ch08.vp
Monday, May 12, 2003 1:16:44 PM